From 75f3b7fc7d6f76d04857b204256e6b9f3c6f5cba Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 5 Jun 2016 17:42:29 +0300 Subject: [PATCH] Download from the given library path Useful for multiple databases. --- m_librarian/download.py | 12 +++++++----- scripts/ml-search.py | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/m_librarian/download.py b/m_librarian/download.py index 75f2b11..817f736 100755 --- a/m_librarian/download.py +++ b/m_librarian/download.py @@ -11,12 +11,14 @@ __all__ = ['download'] _library_path = None -def download(archive, filename): - global _library_path - if _library_path is None: - _library_path = get_config().get('library', 'path') +def download(archive, filename, path=None): + if path is None: + global _library_path + if _library_path is None: + _library_path = get_config().get('library', 'path') + path = _library_path - zf = ZipFile(os.path.join(_library_path, archive), 'r') + zf = ZipFile(os.path.join(path, archive), 'r') infile = zf.open(filename) outfile = open(filename, 'wb') copyfileobj(infile, outfile) diff --git a/scripts/ml-search.py b/scripts/ml-search.py index 2f5767b..18004fd 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -146,7 +146,8 @@ def _search_books(case_sensitive, search_type, args): "(found %d).\n" % count) sys.exit(1) book = books[0] - download(book.archive, '%s.%s' % (book.file, book.extension.name)) + download(book.archive, '%s.%s' % (book.file, book.extension.name), + args.path) return count = 0 for book in books: @@ -289,6 +290,7 @@ if __name__ == '__main__': parser.add_argument('-s', '--series', help='search by series') parser.add_argument('-a', '--archive', help='search by archive (zip file)') parser.add_argument('-f', '--file', help='search by file name') + parser.add_argument('-p', '--path', help='path to the library archives') parser.add_argument('--get', action='store_true', help='download exactly one book') parser.add_argument('--id', help='search by database id') -- 2.39.2