From dabb57982685a2fe05cf82f68794425cf0aea9fb Mon Sep 17 00:00:00 2001 From: Labrys Date: Mon, 2 Jan 2017 15:45:55 -0500 Subject: [PATCH] Fix #1843: Medusa does not start with Python 2.7.13 http://bugs.python.org/issue29082 --- lib/knowit/providers/mediainfo.py | 6 ++++- lib/unrar2/windows.py | 44 ++++++++++++++++++------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/knowit/providers/mediainfo.py b/lib/knowit/providers/mediainfo.py index a47f7397ee..48c7c532ac 100644 --- a/lib/knowit/providers/mediainfo.py +++ b/lib/knowit/providers/mediainfo.py @@ -122,7 +122,11 @@ def _create_native_lib(): arch = 'x86_64' if is_64bits else 'i386' lib = os.path.join(os_folder, arch) logger.debug('Loading native mediainfo library from %s', lib) - lib = windll.MediaInfo = windll.LoadLibrary(os.path.join(lib, 'MediaInfo.dll')) + dll_filename = os.path.join(lib, 'MediaInfo.dll') + if sys.version_info[:3] == (2, 7, 13): + # http://bugs.python.org/issue29082 + dll_filename = str(dll_filename) + lib = windll.MediaInfo = windll.LoadLibrary(dll_filename) lib.MediaInfo_Inform.restype = c_wchar_p lib.MediaInfo_New.argtypes = [] diff --git a/lib/unrar2/windows.py b/lib/unrar2/windows.py index 19cca3d7b0..6533aeae9b 100644 --- a/lib/unrar2/windows.py +++ b/lib/unrar2/windows.py @@ -66,15 +66,24 @@ dll_name = "unrar.dll" if architecture_bits == 64: dll_name = "x64\\unrar64.dll" - -volume_naming1 = re.compile("\.r([0-9]{2})$") + +volume_naming1 = re.compile("\.r([0-9]{2})$") volume_naming2 = re.compile("\.([0-9]{3}).rar$") volume_naming3 = re.compile("\.part([0-9]+).rar$") - + try: - unrar = ctypes.WinDLL(os.path.join(os.path.split(__file__)[0], 'UnRARDLL', dll_name)) + dll_filename = os.path.join(os.path.split(__file__)[0], 'UnRARDLL', dll_name) + + if sys.version_info[:3] == (2, 7, 13): + # http://bugs.python.org/issue29082 + dll_filename = str(dll_filename) + unrar = ctypes.WinDLL(dll_filename) except WindowsError: - unrar = ctypes.WinDLL(dll_name) + dll_filename = dll_name + if sys.version_info[:3] == (2, 7, 13): + # http://bugs.python.org/issue29082 + dll_filename = str(dll_filename) + unrar = ctypes.WinDLL(dll_filename) class RAROpenArchiveDataEx(ctypes.Structure): @@ -173,7 +182,7 @@ class PassiveReader: def __init__(self, usercallback = None): self.buf = [] self.ucb = usercallback - + def _callback(self, msg, UserData, P1, P2): if msg == UCM_PROCESSDATA: data = (ctypes.c_char*P2).from_address(P1).raw @@ -182,7 +191,7 @@ def _callback(self, msg, UserData, P1, P2): else: self.buf.append(data) return 1 - + def get_result(self): return ''.join(self.buf) @@ -196,10 +205,10 @@ def __init__(self, arc): raise IncorrectRARPassword self.arc.lockStatus = "locked" self.arc.needskip = False - + def __iter__(self): return self - + def next(self): if self.index>0: if self.arc.needskip: @@ -207,9 +216,9 @@ def next(self): self.res = RARReadHeaderEx(self.arc._handle, ctypes.byref(self.headerData)) if self.res: - raise StopIteration + raise StopIteration self.arc.needskip = True - + data = {} data['index'] = self.index data['filename'] = self.headerData.FileNameW @@ -223,7 +232,7 @@ def next(self): self.index += 1 return data - + def __del__(self): self.arc.lockStatus = "finished" @@ -253,9 +262,9 @@ def init(self, password=None): if password: RARSetPassword(self._handle, password) - + self.lockStatus = "ready" - + self.isVolume = archiveData.Flags & 1 @@ -287,7 +296,7 @@ def read_files(self, checker): self.needskip = False res.append((info, reader.get_result())) return res - + def extract(self, checker, path, withSubpath, overwrite): res = [] @@ -300,7 +309,7 @@ def extract(self, checker, path, withSubpath, overwrite): fn = os.path.split(fn)[-1] target = os.path.join(path, fn) else: - raise DeprecationWarning, "Condition callbacks returning strings are deprecated and only supported in Windows" + raise DeprecationWarning, "Condition callbacks returning strings are deprecated and only supported in Windows" target = checkres if overwrite or (not os.path.exists(target)): tmpres = RARProcessFile(self._handle, RAR_EXTRACT, None, target) @@ -327,6 +336,3 @@ def get_volume(self): if match1 != None: return int(match1.group(1)) + 1 return 0 - - -