From: Oleg Broytman Date: Sun, 5 Jun 2016 14:42:29 +0000 (+0300) Subject: Download from the given library path X-Git-Tag: 0.0.11~5 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=75f3b7fc7d6f76d04857b204256e6b9f3c6f5cba;p=m_librarian.git Download from the given library path Useful for multiple databases. --- 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')