]> git.phdru.name Git - m_librarian.git/commitdiff
Download from the given library path
authorOleg Broytman <phd@phdru.name>
Sun, 5 Jun 2016 14:42:29 +0000 (17:42 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 5 Jun 2016 14:44:52 +0000 (17:44 +0300)
Useful for multiple databases.

m_librarian/download.py
scripts/ml-search.py

index 75f2b114ba9ce27ed88ed8cc0524c3074b2e5647..817f736352907d7fb9ab7d50effbd7b24f21139e 100755 (executable)
@@ -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)
index 2f5767bc9408553e4ce4c4c74e7c247dccb10ffb..18004fd71ad533e1f8262190eb075ec01af2ec9f 100755 (executable)
@@ -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')