diff --git a/pym/cl_utils.py b/pym/cl_utils.py index d4d7ace..4532cae 100644 --- a/pym/cl_utils.py +++ b/pym/cl_utils.py @@ -30,9 +30,13 @@ import getpass from types import StringType try: - from magic import open as type_file, MAGIC_NONE as MAGIC_NONE + from magic2 import open as type_file, MAGIC_NONE as MAGIC_NONE except ImportError: - from magic import open as type_file, NONE as MAGIC_NONE + try: + from magic2 import open as type_file, NONE as MAGIC_NONE + except: + type_file = None + MAGIC_NONE = None import cl_lang tr = cl_lang.lang() @@ -73,11 +77,39 @@ class _warning: self.warning.append(warning) return True +class proxy_type_file: + def __init__(self,flags): + self.flags = flags + + def load(self): + pass + + def setflags(self,flags): + self.flags = flags + + def close(self): + pass + + def file(self,filename): + if os.path.exists(filename): + if self.flags == 0x410: + processFile = process("file","-bi",filename) + if processFile.success(): + return processFile.read().rstrip() + else: + processFile = process("file","-b",filename) + if processFile.success(): + return processFile.read().rstrip() + return None + class typeFile: """Получение типа файла""" def __init__(self, magic=0x410): - self.magicObject = type_file(MAGIC_NONE) + if type_file is None: + self.magicObject = proxy_type_file(MAGIC_NONE) + else: + self.magicObject = type_file(MAGIC_NONE) self.magicObject.load() self.magicObject.setflags(magic)