(self, remaining, temp_dir)
return package
Unpack zipfile package, if specified, and make its temp dir current.
Unpack zipfile package, if specified, and make its temp dir current.
Unpack zipfile package if specified and make its temp dir current .
def _parse_package_arg_and_unpack(self, remaining, temp_dir):
        """Unpack zipfile package, if specified, and make its temp dir current."""
        # first positional arg: program or package name
        package = None
        try:
            arg_package = remaining[0]
        except KeyError:
            pass
        else:
            if os.path.isdir(arg_package):
                os.chdir(arg_package)
                remaining.pop(0)
                package = arg_package
            elif zipfile.is_zipfile(arg_package):
                remaining.pop(0)
                # extract the package to a temp directory
                # and make that the current dir for our run
                zipfile.ZipFile(arg_package).extractall(path=temp_dir)
                os.chdir(temp_dir)
                # if the zip-file contains only a directory at the top level,
                # then move into that directory. E.g. all files in package.zip
                # could be under the directory package/
                contents = os.listdir(u'.')
                if len(contents) == 1:
                    os.chdir(contents[0])
                # recursively rename all files to all-caps to avoid case issues on Unix
                # collisions: the last file renamed overwrites earlier ones
                for root, dirs, files in os.walk(u'.', topdown=False):
                    for name in dirs + files:
                        try:
                            os.rename(os.path.join(root, name), os.path.join(root, name.upper()))
                        except OSError:
                            # if we can't rename, ignore
                            pass
                package = arg_package
        # make package setting available
        return package
def _parse_package_arg_and_unpack ( self , remaining , temp_dir ) : # first positional arg: program or package name package = None try : arg_package = remaining [ 0 ] except KeyError : pass else : if os . path . isdir ( arg_package ) : os . chdir ( arg_package ) remaining . pop ( 0 ) package = arg_package elif zipfile . is_zipfile ( arg_package ) : remaining . pop ( 0 ) # extract the package to a temp directory # and make that the current dir for our run zipfile . ZipFile ( arg_package ) . extractall ( path = temp_dir ) os . chdir ( temp_dir ) # if the zip-file contains only a directory at the top level, # then move into that directory. E.g. all files in package.zip # could be under the directory package/ contents = os . listdir ( u'.' ) if len ( contents ) == 1 : os . chdir ( contents [ 0 ] ) # recursively rename all files to all-caps to avoid case issues on Unix # collisions: the last file renamed overwrites earlier ones for root , dirs , files in os . walk ( u'.' , topdown = False ) : for name in dirs + files : try : os . rename ( os . path . join ( root , name ) , os . path . join ( root , name . upper ( ) ) ) except OSError : # if we can't rename, ignore pass package = arg_package # make package setting available return package