From 8e40b59c00456c3345d1f0320801d6ab3321b3d9 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Sun, 16 Feb 2014 22:42:16 -0500 Subject: [PATCH] Support both debian's and pypi's python-magic libraries, which are different... --- fdroidserver/common.py | 12 ++++++++---- setup.py | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 4fc6de6b..5e424dae 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1136,8 +1136,11 @@ def scan_source(build_dir, root_dir, thisbuild): scanignore = getpaths('scanignore') scandelete = getpaths('scandelete') - ms = magic.open(magic.MIME_TYPE) - ms.load() + try: + ms = magic.open(magic.MIME_TYPE) + ms.load() + except AttributeError: + ms = None def toignore(fd): for i in scanignore: @@ -1187,7 +1190,7 @@ def scan_source(build_dir, root_dir, thisbuild): if suspect in curfile.lower(): handleproblem('usual supect', fd, fp) - mime = ms.file(fp) + mime = magic.from_file(fp, mime=True) if ms is None else ms.file(fp) if mime == 'application/x-sharedlib': handleproblem('shared library', fd, fp) elif mime == 'application/x-archive': @@ -1204,7 +1207,8 @@ def scan_source(build_dir, root_dir, thisbuild): if 'DexClassLoader' in line: handleproblem('DexClassLoader', fd, fp) break - ms.close() + if ms is not None: + ms.close() # Presence of a jni directory without buildjni=yes might # indicate a problem (if it's not a problem, explicitly use diff --git a/setup.py b/setup.py index 43a7afe0..7bbec283 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ setup(name='FDroidServer', 'fdroid-icon.png']), ], install_requires=[ + 'python-magic', 'PIL', ], classifiers=[