def _make_executable_if_needed(filename):
# If this is an executable or a script, make it +x
if MAGIC is not None:
filetype = MAGIC.from_file(filename)
if isinstance(filetype, bytes):
# Older versions of python-magic return bytes instead of a string
filetype = filetype.decode('ascii')
if 'executable' in filetype or 'script' in filetype:
try:
logging.info('Making executable because of file type: %s', filetype)
file_stat = os.stat(filename)
os.chmod(filename, file_stat.st_mode | stat.S_IEXEC)
except Exception: #pylint: disable=broad-except
pass
评论列表
文章目录