|
|
|
@ -44,13 +44,23 @@ def timeout(seconds):
|
|
|
|
|
signal.signal(signal.SIGALRM, original_handler)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from magic import open as type_file, MAGIC_NONE as MAGIC_NONE
|
|
|
|
|
except ImportError:
|
|
|
|
|
from magic import (open as type_file, MAGIC_NONE, MAGIC_CONTINUE,
|
|
|
|
|
MAGIC_MIME_TYPE, MAGIC_COMPRESS,
|
|
|
|
|
MAGIC_MIME_ENCODING, MAGIC_SYMLINK)
|
|
|
|
|
except ImportError as e:
|
|
|
|
|
try:
|
|
|
|
|
from magic import open as type_file, NONE as MAGIC_NONE
|
|
|
|
|
from magic import (open as type_file, NONE as MAGIC_NONE,
|
|
|
|
|
CONTINUE as MAGIC_CONTNUE, MIME_TYPE as MAGIC_MIME_TYPE,
|
|
|
|
|
COMPRESS as MAGIC_COMPRESS,MIME_ENCODING as MIME_ENCODING,
|
|
|
|
|
SYMLINK as MAGIC_SYMLINK)
|
|
|
|
|
except:
|
|
|
|
|
type_file = None
|
|
|
|
|
MAGIC_NONE = None
|
|
|
|
|
MAGIC_NONE = 0
|
|
|
|
|
MAGIC_SYMLINK = 0x002
|
|
|
|
|
MAGIC_COMPRESS = 0x004
|
|
|
|
|
MAGIC_CONTINUE = 0x020
|
|
|
|
|
MAGIC_MIME_TYPE = 0x010
|
|
|
|
|
MAGIC_MIME_ENCODING = 0x400
|
|
|
|
|
|
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
|
|
|
setLocalTranslate('cl_lib3',sys.modules[__name__])
|
|
|
|
@ -273,22 +283,33 @@ class proxy_type_file:
|
|
|
|
|
def close(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def _get_cmd_by_flags(self,flags):
|
|
|
|
|
"""
|
|
|
|
|
Получить команду для выполнения по флагам
|
|
|
|
|
"""
|
|
|
|
|
paramdict = {MAGIC_CONTINUE:"-k",
|
|
|
|
|
MAGIC_SYMLINK:"-L",
|
|
|
|
|
MAGIC_MIME_TYPE:"--mime-type",
|
|
|
|
|
MAGIC_MIME_ENCODING:"--mime-encoding",
|
|
|
|
|
MAGIC_COMPRESS:"-z"}
|
|
|
|
|
appendParam = map(lambda x:paramdict[x],
|
|
|
|
|
filter(lambda x:flags & x,
|
|
|
|
|
sorted(paramdict.keys())))
|
|
|
|
|
fileCmd = getProgPath('/usr/bin/file')
|
|
|
|
|
return [fileCmd,'-b']+appendParam
|
|
|
|
|
|
|
|
|
|
def file(self,filename):
|
|
|
|
|
if path.exists(filename):
|
|
|
|
|
if self.flags == 0x410:
|
|
|
|
|
processFile = process("file","-bi",filename)
|
|
|
|
|
if processFile.success():
|
|
|
|
|
return processFile.read().rstrip()
|
|
|
|
|
else:
|
|
|
|
|
processFile = process("file","-bz",filename)
|
|
|
|
|
if processFile.success():
|
|
|
|
|
return processFile.read().rstrip()
|
|
|
|
|
processFile = \
|
|
|
|
|
process(*(self._get_cmd_by_flags(self.flags)+[filename]))
|
|
|
|
|
if processFile.success():
|
|
|
|
|
return processFile.read().rstrip()
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
class typeFile:
|
|
|
|
|
"""Получение типа файла"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, magic=0x410):
|
|
|
|
|
def __init__(self, magic=MAGIC_MIME_ENCODING|MAGIC_MIME_TYPE):
|
|
|
|
|
if type_file is None:
|
|
|
|
|
self.magicObject = proxy_type_file(MAGIC_NONE)
|
|
|
|
|
else:
|
|
|
|
|