|
|
|
@ -414,7 +414,7 @@ def chownR(directory, uid, gid):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class proxy_type_file:
|
|
|
|
|
class UnixUtilityFile:
|
|
|
|
|
def __init__(self, flags):
|
|
|
|
|
self.flags = flags
|
|
|
|
|
|
|
|
|
@ -427,6 +427,9 @@ class proxy_type_file:
|
|
|
|
|
def close(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def errno(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def _get_cmd_by_flags(self, flags):
|
|
|
|
|
"""
|
|
|
|
|
Получить команду для выполнения по флагам
|
|
|
|
@ -450,13 +453,27 @@ class proxy_type_file:
|
|
|
|
|
return processFile.read().rstrip()
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def buffer(self, data):
|
|
|
|
|
processFile = Popen(
|
|
|
|
|
self._get_cmd_by_flags(self.flags) + ["-"],
|
|
|
|
|
stdout=PIPE, stdin=PIPE, stderr=None)
|
|
|
|
|
try:
|
|
|
|
|
out, err = processFile.communicate(input=data)
|
|
|
|
|
if processFile.returncode == 0:
|
|
|
|
|
return out.rstrip()
|
|
|
|
|
finally:
|
|
|
|
|
try:
|
|
|
|
|
processFile.terminate()
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
class typeFile(object):
|
|
|
|
|
"""Получение типа файла"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, magic=MAGIC_MIME_ENCODING | MAGIC_MIME_TYPE):
|
|
|
|
|
if type_file is None:
|
|
|
|
|
self.magicObject = proxy_type_file(MAGIC_NONE)
|
|
|
|
|
self.magicObject = UnixUtilityFile(MAGIC_NONE)
|
|
|
|
|
else:
|
|
|
|
|
self.magicObject = type_file(MAGIC_NONE)
|
|
|
|
|
self.magicObject.load()
|
|
|
|
@ -478,7 +495,6 @@ class typeFile(object):
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def getMTypeBuf(self, buf):
|
|
|
|
|
#buftype = typeFile(magic=0).getMTypeBuf
|
|
|
|
|
self.magicObject.setflags(self.magic & (~(self.magic&0x4)))
|
|
|
|
|
|
|
|
|
|
rdtype = self.getMTypeBuf_(buf)
|
|
|
|
@ -506,7 +522,7 @@ class typeFile(object):
|
|
|
|
|
try:
|
|
|
|
|
return "{} ({})".format(
|
|
|
|
|
self.getMTypeBuf_(gz.communicate(input=buf)[0]),
|
|
|
|
|
rdtype)
|
|
|
|
|
rdtype)
|
|
|
|
|
finally:
|
|
|
|
|
try:
|
|
|
|
|
gz.terminate()
|
|
|
|
@ -516,10 +532,10 @@ class typeFile(object):
|
|
|
|
|
def getMType(self, filename):
|
|
|
|
|
"""Информация о типе файла"""
|
|
|
|
|
try:
|
|
|
|
|
ret = self.magicObject.file(filename)
|
|
|
|
|
return self.magicObject.file(filename)
|
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
|
try:
|
|
|
|
|
ret = self.magicObject.file(filename.decode('utf-8'))
|
|
|
|
|
return self.magicObject.file(filename.decode('utf-8'))
|
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
|
return None
|
|
|
|
|
# fix for kernel 3.7.7 (bad work samba)
|
|
|
|
|