X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fdownload.py;h=e10e9fe0e49fad48421354bce8ebd04915710ce6;hb=3186348a27fe281df2fd98382de0585e3bbca5db;hp=30412013123eb317883464c7fef5d9c1cf0c790e;hpb=67a025f168498a481ce10798ed66fa3d79af008d;p=m_librarian.git diff --git a/m_librarian/download.py b/m_librarian/download.py index 3041201..e10e9fe 100755 --- a/m_librarian/download.py +++ b/m_librarian/download.py @@ -64,12 +64,12 @@ def _compile_format(): _library_path = None -def download(book, path=None, a_format=None): - if path is None: +def download(book, dest_path=None, lib_path=None, a_format=None): + if lib_path is None: global _library_path if _library_path is None: _library_path = get_config().get('library', 'path') - path = _library_path + lib_path = _library_path global format, compile_format, compiled_format if a_format: @@ -92,19 +92,20 @@ def download(book, path=None, a_format=None): if '%(extension)s' not in compiled_format: compiled_format += '.%(extension)s' filename = compiled_format % bdict + full_path = os.path.join(dest_path, filename) try: - os.makedirs(os.path.dirname(filename)) + os.makedirs(os.path.dirname(full_path)) except OSError: pass # Already exists - zf = ZipFile(os.path.join(path, book.archive), 'r') + zf = ZipFile(os.path.join(lib_path, book.archive), 'r') infile = zf.open('%s.%s' % (book.file, book.extension.name)) - outfile = open(filename, 'wb') + outfile = open(full_path, 'wb') copyfileobj(infile, outfile) outfile.close() infile.close() zf.close() dt = mktime(book.date.timetuple()) - os.utime(filename, (dt, dt)) + os.utime(full_path, (dt, dt)) def test():