(zip_fname, cwd=None)
expand a zip
expand a zip
expand a zip
def expand_zip(zip_fname, cwd=None):
    "expand a zip"
    unzip_path = '/usr/bin/unzip'
    if not os.path.exists(unzip_path):
        log.error('ERROR: {} does not exist'.format(unzip_path))
        sys.exit(1)
    args = [unzip_path, zip_fname]
    # Does it have a top dir
    res = subprocess.Popen(
        [args[0], '-l', args[1]], cwd=cwd,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    contents = []
    for line in res.stdout.readlines()[3:-2]:
        contents.append(line.split(None, 3)[-1])
    commonprefix = os.path.commonprefix(contents)
    if not commonprefix:
        extdir = os.path.join(cwd, os.path.basename(zip_fname[:-4]))
        args.extend(['-d', os.path.abspath(extdir)])

    process_command(args, cwd=cwd)
def expand_zip ( zip_fname , cwd = None ) : unzip_path = '/usr/bin/unzip' if not os . path . exists ( unzip_path ) : log . error ( 'ERROR: {} does not exist' . format ( unzip_path ) ) sys . exit ( 1 ) args = [ unzip_path , zip_fname ] # Does it have a top dir res = subprocess . Popen ( [ args [ 0 ] , '-l' , args [ 1 ] ] , cwd = cwd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , ) contents = [ ] for line in res . stdout . readlines ( ) [ 3 : - 2 ] : contents . append ( line . split ( None , 3 ) [ - 1 ] ) commonprefix = os . path . commonprefix ( contents ) if not commonprefix : extdir = os . path . join ( cwd , os . path . basename ( zip_fname [ : - 4 ] ) ) args . extend ( [ '-d' , os . path . abspath ( extdir ) ] ) process_command ( args , cwd = cwd )