diff --git a/oml/fulltext.py b/oml/fulltext.py index d1cd5ee..d7d6d3e 100644 --- a/oml/fulltext.py +++ b/oml/fulltext.py @@ -7,30 +7,15 @@ from sqlalchemy.sql import operators logger = logging.getLogger(__name__) - -def get_prefix(): - import settings - return os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Books/') - -def get_ids(books): - from item.models import File - ids = [b[0] for b in File.query.filter(operators.in_op(File.path, books)).values('sha1')] - return ids - def find_fulltext_macos(query): - prefix = get_prefix() + import settings + from item.models import File + prefix = os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Books/') cmd = ["mdfind", "-onlyin", prefix, query] books = subprocess.check_output(cmd).decode().strip().split('\n') books = [path[len(prefix):] for path in books] - return get_ids(books) - -def find_fulltext_windows(query): - prefix = get_prefix() - prefix = os.path.normpath(prefix) - cmd = ['findstr', '/i', '/c:' + query, '/d:' + prefix] - books = subprocess.check_output(cmd).decode().strip().split('\n') - books = [b.split(':')[0] for b in books] - return get_ids(books, prefix) + ids = [b[0] for b in File.query.filter(operators.in_op(File.path, books)).values('sha1')] + return ids def find_fulltext(query): ids = [] diff --git a/oml/media/cbr.py b/oml/media/cbr.py index 0c29fe2..fdade82 100644 --- a/oml/media/cbr.py +++ b/oml/media/cbr.py @@ -10,10 +10,13 @@ def cover(path): try: from unrar import rarfile rar = rarfile.RarFile(path) - files = rar.namelist() - if files: - cover = ox.sorted_strings(files)[0] - data = rar.read(cover) + for cover in ox.sorted_strings(rar.namelist()): + try: + data = rar.read(cover) + except: + data = None + finally: + return data except: data = None return data diff --git a/oml/media/cbz.py b/oml/media/cbz.py index b08c972..83fba49 100644 --- a/oml/media/cbz.py +++ b/oml/media/cbz.py @@ -15,12 +15,14 @@ def cover(path): return data files = [f.filename for f in z.filelist] if files: - cover = ox.sortedstrings(files)[0] - try: - data = z.read(cover) - except: - data = None - return data + for cover in ox.sortedstrings(files): + try: + data = z.read(cover) + except: + data = None + finally: + return data + def info(path): data = {} diff --git a/oml/update.py b/oml/update.py index 8e533d9..83c490a 100644 --- a/oml/update.py +++ b/oml/update.py @@ -196,7 +196,7 @@ def install(): shutil.copy(os.path.join(settings.updates_path, 'release.json'), os.path.join(settings.data_path, 'release.json')) upgrade_app() # FIXME: still needed? - if old_version < '20160112-651-de984a3' and platform != 'win32': + if old_version < '20160112-651-de984a3': subprocess.call(['./ctl', 'postupdate', '-o', old_version, '-n', new_version]) return True return True @@ -253,7 +253,6 @@ def upgrade_app(): shutil.copytree(bundled_app, app) except: logger.debug('Failed to update Application', exc_info=True) - ''' elif sys.platform == 'win32': current_version = get_trayicon_version() if current_version != '0.2.0.0': @@ -263,7 +262,6 @@ def upgrade_app(): startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE subprocess.Popen(cmd, cwd=settings.base_dir, start_new_session=True, startupinfo=startupinfo) - ''' def getVersion(data): ''' diff --git a/oml/utils.py b/oml/utils.py index 6e6d924..5130156 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -369,23 +369,12 @@ def update_static(): ) def check_pid(pid): - if sys.platform == 'win32': - import ctypes - kernel32 = ctypes.windll.kernel32 - SYNCHRONIZE = 0x100000 - process = kernel32.OpenProcess(SYNCHRONIZE, 0, pid) - if process != 0: - kernel32.CloseHandle(process) - return True - else: - return False + try: + os.kill(pid, 0) + except: + return False else: - try: - os.kill(pid, 0) - except: - return False - else: - return True + return True def check_pidfile(pid): try: diff --git a/requirements-shared.txt b/requirements-shared.txt index 3b4600f..ced1c73 100644 --- a/requirements-shared.txt +++ b/requirements-shared.txt @@ -1,4 +1,5 @@ requests==2.21.0 +tornado==5.1.1 chardet html5lib #ox>=2.0.666 diff --git a/requirements.txt b/requirements.txt index 16e5d69..bef4257 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,3 @@ pyopenssl>=0.15 pyCrypto>=2.6.1 pillow netifaces -tornado==5.1.1