home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1374 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.6 KB  |  43 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
  6. __docformat__ = 'restructuredtext en'
  7. import re
  8. from calibre.utils import zipfile
  9.  
  10. def update(pathtozip, patterns, filepaths, names, compression = zipfile.ZIP_DEFLATED, verbose = True):
  11.     z = zipfile.ZipFile(pathtozip, mode = 'a')
  12.     for name in z.namelist():
  13.         for pat, fname, new_name in zip(patterns, filepaths, names):
  14.             if pat.search(name):
  15.                 if verbose:
  16.                     print 'Updating %s with %s' % (name, fname)
  17.                 
  18.                 if new_name is None:
  19.                     z.replace(fname, arcname = name, compress_type = compression)
  20.                 else:
  21.                     z.delete(name)
  22.                     z.write(fname, new_name, compress_type = compression)
  23.                 break
  24.                 continue
  25.         
  26.     
  27.     z.close()
  28.  
  29.  
  30. def extract(filename, dir):
  31.     zf = zipfile.ZipFile(filename)
  32.     zf.extractall(dir)
  33.  
  34.  
  35. def extract_member(filename, match = re.compile('\\.(jpg|jpeg|gif|png)\\s*$', re.I)):
  36.     zf = zipfile.ZipFile(filename)
  37.     names = zf.namelist()
  38.     for name in names:
  39.         if match.search(name):
  40.             return (name, zf.read(name))
  41.     
  42.  
  43.