Esempio n. 1
0
def zipfiles(files, zip_out_fn, use_genus, todisk=None):
    """
    Write a zipfile from a list of files

    @param zip_out_fn: the output file name
    @type dir: string

    @param zip_file: name of zip file
    @type zip_file: string

    @param use_genus: use the genus at the zipfile directory name
    @type use_genus: bool

    @param todisk: specify path if you want the zip written to disk as well
    @type todisk: string
    """
    zip_file = tempfile.TemporaryFile()

    zipf = zipfile.ZipFile(zip_file, "w", compression=zipfile.ZIP_DEFLATED)
    for fn in files:
        print "Compressing %s ..." % fn
        archive_name = fn if not use_genus else fn[fn.rfind(get_genus(fn)) :]
        zipf.write(os.path.abspath(fn), archive_name, zipfile.ZIP_DEFLATED)
    zipf.close()
    return zip_file
Esempio n. 2
0
def zipfiles(files, use_genus, zip_out_fn=None, gformat=None, todisk=None):
    '''
  Write a zipfile from a list of files
  NOTE: Internal use only do not use as stand-alone! Will produce
  unexpected results.

  @param files: The filenames of the files to be zipped
  @type files: list

  @param use_genus: use the genus at the zipfile directory name
  @type use_genus: bool

  @param zip_out_fn: the output file name
  @type dir: string

  @param gformat: the format of the graphs being written out
  @type zip_file: string

  @param todisk: specify path if you want the zip written to disk as well
  @type todisk: string
  '''
    if zip_out_fn:  # No filename provided for the zip archive
        print "Creating permanent file on disk %s ..." % zip_out_fn
        zip_file = zip_out_fn
        if not os.path.exists(zip_file):
            os.makedirs(os.path.dirname(zip_file))
    else:
        zip_file = tempfile.TemporaryFile(
            dir="/data/pytmp")  # Don't close before done since auto delete

    zipf = zipfile.ZipFile(zip_file,
                           'w',
                           compression=zipfile.ZIP_DEFLATED,
                           allowZip64=True)
    for fn in files:
        print "Compressing %s ..." % fn
        archive_name = fn if not use_genus else fn[fn.rfind(get_genus(fn)):]

        if isinstance(files, dict):
            archive_name = os.path.splitext(archive_name)[0] + "." + gformat
            fn = files[fn]

        zipf.write(os.path.abspath(fn), archive_name, zipfile.ZIP_DEFLATED)
    zipf.close()

    return zip_file
Esempio n. 3
0
def zipfiles(files, use_genus, zip_out_fn=None, gformat=None, todisk=None):
  '''
  Write a zipfile from a list of files
  NOTE: Internal use only do not use as stand-alone! Will produce
  unexpected results.

  @param files: The filenames of the files to be zipped
  @type files: list

  @param use_genus: use the genus at the zipfile directory name
  @type use_genus: bool

  @param zip_out_fn: the output file name
  @type dir: string

  @param gformat: the format of the graphs being written out
  @type zip_file: string

  @param todisk: specify path if you want the zip written to disk as well
  @type todisk: string
  '''
  if zip_out_fn: # No filename provided for the zip archive
    print "Creating permanent file on disk %s ..." % zip_out_fn
    zip_file = zip_out_fn
    if not os.path.exists(zip_file):
      os.makedirs(os.path.dirname(zip_file))
  else:
    zip_file = tempfile.TemporaryFile(dir="/data/pytmp") # Don't close before done since auto delete

  zipf = zipfile.ZipFile(zip_file, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=True)
  for fn in files:
    print "Compressing %s ..." % fn
    archive_name = fn if not use_genus else fn[fn.rfind(get_genus(fn)):]

    if isinstance(files, dict):
      archive_name = os.path.splitext(archive_name)[0]+"."+gformat
      fn = files[fn]

    zipf.write(os.path.abspath(fn), archive_name, zipfile.ZIP_DEFLATED)
  zipf.close()

  return zip_file