Create a new zip archive containing files
    filename: The name of the zip file to be created
    paths: A list of files or directories
    strip_dir: Remove this prefix from all file-paths before adding to zip
197924
def zip(filename, paths, strip_prefix=''):
    
    if isinstance(paths, basestring):
        paths = [paths]

    filelist = set()
    for p in paths:
        if os.path.isfile(p):
            filelist.add(p)
        else:
            for root, dirs, files in os.walk(p):
                for f in files:
                    filelist.add(os.path.join(root, f))

    z = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
    for f in sorted(filelist):
        arcname = f
        if arcname.startswith(strip_prefix):
            arcname = arcname[len(strip_prefix):]
        if arcname.startswith(os.path.sep):
            arcname = arcname[1:]
        log.debug('Adding %s to %s[%s]', f, filename, arcname)
        z.write(f, arcname)

    z.close()
1373709
def create_file_name(file, base_dir)
      file_name = file.split("/").delete_if { |f| f.include?(".") }.first
      unless File.exists?(File.join(base_dir, file_name))
        Dir.mkdir(File.join(base_dir, file_name))
      end
      file_name
    end
617956
def path_to_zip(path):
    
    if not os.path.exists(path):
        raise IOError("%s doesn't exists!" % path)

    with tempfile.NamedTemporaryFile(delete=False) as ntf:
        zip_fn = ntf.name

    with zipfile.ZipFile(zip_fn, mode="w") as zip_file:
        for root, dirs, files in os.walk(path):
            for fn in files:
                zip_file.write(os.path.join(root, fn))

    return zip_fn
1317300
def create_dirs(fname, is_file=False):
    
    fname = os.path.abspath(fname)
    if is_file:
        fname = os.path.dirname(fname)

    if not os.path.exists(fname):
        os.makedirs(fname)
932291
def _makedirs(path):
    
    dirname, _ = os.path.split(path)
    try:
        os.makedirs(dirname)
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise
145631
def mktree(newdir):
    
    if os.path.isdir(newdir):
        pass
    elif os.path.isfile(newdir):
        raise OSError("a file with the same name as the desired "
                      "dir, '%s', already exists." % newdir)
    else:
        os.makedirs(newdir)
1055936
def add_directory(self, path, ignore=None):
        
        for root, dirs, files in os.walk(path):
            arc_prefix = os.path.relpath(root, os.path.dirname(path))
            # py3 remove pyc cache dirs.
            if '__pycache__' in dirs:
                dirs.remove('__pycache__')
            for f in files:
                dest_path = os.path.join(arc_prefix, f)

                # ignore specific files
                if ignore and ignore(dest_path):
                    continue

                if f.endswith('.pyc') or f.endswith('.c'):
                    continue
                f_path = os.path.join(root, f)

                self.add_file(f_path, dest_path)
886892
def create(asset_dir, dest_dir):
    
    val = validate(asset_dir=asset_dir)
    if val != 0:
        return 1
    try:
        asset_zip = make_asset_zip(asset_dir_path=asset_dir, destination_directory=dest_dir)
    except AssetZipCreationError:
        _, ex, trace = sys.exc_info()
        msg = 'AssetZipCreationError: Problem with asset zip creation\n{e}'.format(e=str(ex))
        print('ERROR: {m}'.format(m=msg))
        return 1
    print('Created asset zip file: {z}'.format(z=asset_zip))
    return 0
1316270
def makedirs(name, mode=0o777, exist_ok=False):
    

    if os.path.exists(name):
        if not exist_ok:
            raise FileExistsError("File exists: " + name)
    else:
        os.makedirs(name, mode)
68410
def create_cbz(directory):
    """"""
    if not os.path.isdir(directory):
        print("ERROR: Directory", directory, "not found.")
        return
    base = os.path.basename(directory.rstrip(os.path.sep))
    zipname = '%s.cbz' % base
    zipname = os.path.join(directory, zipname)
    d = os.path.join(directory, 'inorder')
    if os.path.isdir(d):
        # use directory with ordered symlinks
        directory = d
    if os.path.exists(zipname):
        os.remove(zipname)
    with zipfile.ZipFile(zipname, 'w') as myzip:
        for filename in sorted(os.listdir(d)):
            fullname = os.path.join(d, filename)
            if is_image(fullname):
                myzip.write(fullname)
        myzip.comment = get_cbz_comment()
    print("INFO: Created", zipname)
589885
def create_zip_from_file(zip_file, fname):
    
    with zipfile.ZipFile(zip_file, 'w') as myzip:
        myzip.write(fname)
1289090
def pack_epub(directory, file):
    
    with zipfile.ZipFile(file, 'w', zipfile.ZIP_DEFLATED) as zippy:
        base_path = os.path.abspath(directory)
        for root, dirs, filenames in os.walk(directory):
            # Strip the absolute path
            archive_path = os.path.relpath(root, base_path)
            for filename in filenames:
                filepath = os.path.join(root, filename)
                archival_filepath = os.path.join(archive_path, filename)
                zippy.write(filepath, archival_filepath)
977915
def extract_zip(zip_path, target_folder):
    
    with zipfile.ZipFile(zip_path) as archive:
        archive.extractall(target_folder)
930255
def get_archive_file_list(archive_filename):
    
    if archive_filename.endswith('.zip'):
        with closing(zipfile.ZipFile(archive_filename)) as zf:
            return add_directories(zf.namelist())
    elif archive_filename.endswith(('.tar.gz', '.tar.bz2', '.tar')):
        with closing(tarfile.open(archive_filename)) as tf:
            return add_directories(list(map(unicodify, tf.getnames())))
    else:
        ext = os.path.splitext(archive_filename)[-1]
        raise Failure('Unrecognized archive type: %s' % ext)
808460
def mkdir(dirname):
    
    dir_list = []

    while not client.isdir(dirname):
        dir_list.append(dirname)
        dirname = os.path.dirname(dirname)
    while len(dir_list) > 0:
        logging.info("Creating directory: %s" % (dir_list[-1]))
        try:
            client.mkdir(dir_list.pop())
        except IOError as e:
            if e.errno == errno.EEXIST:
                pass
            else:
                raise e
253130
def create_dir(self, params, delete=False):
        
        # create experiment path and subdir
        fullpath = os.path.join(params['path'], params['name'])
        self.mkdir(fullpath)

        # delete old histories if --del flag is active
        if delete and os.path.exists(fullpath):
            os.system('rm %s/*' % fullpath)
     
        # write a config file for this single exp. in the folder
        self.write_config_file(params, fullpath)
387595
def create_zip(files, trim_arcname=None, target_file=None, **zipfile_args):
    
    zipname = None
    azip = None
    if not target_file:
        azip = tempfile.NamedTemporaryFile(mode='wb', delete=False)
        zipname = azip.name
    else:
        azip = target_file
        zipname = target_file.name if hasattr(azip, 'read') else azip
    slog.info('Package %d files to "%s"'%(len(files), azip.name))
    fileNum = len(files)
    curFile = 0
    zipfile_args['mode'] = 'w'
    if not zipfile_args.get('compression'):
        zipfile_args['compression'] = zipfile.ZIP_DEFLATED
    with zipfile.ZipFile(azip, **zipfile_args) as zipf:
       for f in files:
           percent = round(curFile/fileNum*100)
           sys.stdout.write('\r%d%%'%(percent))
           sys.stdout.flush()
           zipf.write(f, f[trim_arcname:] if trim_arcname else None )
           curFile = curFile+1

       sys.stdout.write('\r100%\n')
       sys.stdout.flush()

    if hasattr(azip, 'close'):
        azip.close()
    return zipname