Walk an unpacked egg's contents, skipping the metadata directory
503577
def walk_egg(egg_dir):
    """"""
    walker = sorted_walk(egg_dir)
    base, dirs, files = next(walker)
    if 'EGG-INFO' in dirs:
        dirs.remove('EGG-INFO')
    yield base, dirs, files
    for bdf in walker:
        yield bdf
433149
def normalize(self):
        
        if self.has_egg_file():
            if self.has_zip():
                self.__remove_zip()
        else:
            if self.has_egg_folder():
                if not self.has_zip():
                    self.__zip_egg_folder()
                self.__remove_egg_folder()
            self.__rename_zip_to_egg()
1220847
def get_buildout_eggs(buildout, query=None):
    
    eggs = set()
    for name in get_buildout_parts(buildout, query=query):
        if name == 'buildout':
            continue  # skip eggs from the buildout script itself
        path = os.path.join(buildout['buildout'].get('bin-directory'), name)
        if os.path.isfile(path):
            eggs.update(parse_eggs_list(path))
    return list(eggs)
771104
def unpack(destdir):
    """"""

    if not nav:
        sys.exit(1)

    ecode = 0
    try:
        anchore_print("Unpacking images: " + ' '.join(nav.get_images()))
        result = nav.unpack(destdir=destdir)
        if not result:
            anchore_print_err("no images unpacked")
            ecode = 1
        else:
            for imageId in result:
                anchore_print("Unpacked image: " + imageId)
                anchore_print("Unpack directory: "+ result[imageId])
    except:
        anchore_print_err("operation failed")
        ecode = 1

    contexts['anchore_allimages'].clear()
    
    sys.exit(ecode)
1280896
def _skip_source(source):
    '''
    
    '''
    if source.invalid:
        if source.uri and source.type and source.type in ("deb", "deb-src", "rpm", "rpm-src"):
            pieces = source.mysplit(source.line)
            if pieces[1].strip()[0] == "[":
                options = pieces.pop(1).strip("[]").split()
                if options:
                    log.debug("Source %s will be included although is marked invalid", source.uri)
                    return False
            return True
        else:
            return True
    return False
876337
def cleanup_tmpdir(dirname):
    """"""
    if dirname is not None and os.path.exists(dirname):
        shutil.rmtree(dirname)
548734
def clean(ctx):
    

    clean_command = "python setup.py clean"
    report.info(ctx, "package.clean", "cleaning up built package artifacts")
    ctx.run(clean_command)

    egg_name = f"{ctx.metadata['package_name']}.egg-info"
    report.info(ctx, "pacakge.clean", "removing build directories")
    for artifact in ("dist", "build", egg_name, f"src/{egg_name}"):
        artifact_dir = ctx.directory / artifact
        if artifact_dir.is_dir():
            report.debug(ctx, "package.clean", f"removing directory {artifact_dir!s}")
            ctx.run(f"rm -rf {artifact_dir!s}")
972861
def skip(type_name, filename):
    """"""
    report = ['Skipping {} file: {}'.format(type_name, filename)]
    report_stats = ReportStats(filename, report=report)
    return report_stats
1252304
def Clean():
  """"""
  # Find all the compiled proto files and unlink them.
  for (root, _, files) in os.walk(ROOT):
    for filename in files:
      full_filename = os.path.join(root, filename)
      if full_filename.endswith("_pb2.py") or full_filename.endswith(
          "_pb2.pyc"):
        os.unlink(full_filename)
99999
def load_egg(filepath, update=True):
    
    try:
        egg = Egg(**dd.io.load(filepath))
    except:
        # if error, try loading old format
        with open(filepath, 'rb') as f:
            egg = pickle.load(f)

    if update:
        if egg.meta:
            old_meta = egg.meta
            egg.crack()
            egg.meta = old_meta
            return egg
        else:
            return egg.crack()
    else:
        return egg
1107505
def copy_metadata_to(self, target_dir):
        ""
        # normalize the path (so that a forward-slash in egg_info will
        # match using startswith below)
        norm_egg_info = os.path.normpath(self.egg_info)
        prefix = os.path.join(norm_egg_info, '')
        for path in self.ei_cmd.filelist.files:
            if path.startswith(prefix):
                target = os.path.join(target_dir, path[len(prefix):])
                ensure_directory(target)
                self.copy_file(path, target)
617667
def get_script_from_egg(name, dist):
  """"""
  if dist.metadata_isdir('scripts') and name in dist.metadata_listdir('scripts'):
    return (
        os.path.join(dist.egg_info, 'scripts', name),
        dist.get_metadata('scripts/%s' % name).replace('\r\n', '\n').replace('\r', '\n'))
  return None, None
776417
def unpack_archive(archive_format, archive_path, source_path):
    """"""
    if archive_format not in ('zip', 'tar'):
        raise ValueError('Unknown archive format "%s".' % archive_format)
    if archive_format == 'zip':
        with zipfile.ZipFile(archive_path) as archive:
            archive.extractall(source_path)
    if archive_format == 'tar':
        with tarfile.open(archive_path) as archive:
            archive.extractall(source_path)
1134891
def eggs_clean(context):
    ""
    #pylint: disable=unused-argument
    dirs = set()
    dirs.add('.eggs')
    for name in os.listdir(os.curdir):
        if name.endswith('.egg-info'):
            dirs.add(name)
        if name.endswith('.egg'):
            dirs.add(name)
    rmrf(dirs)
785036
def delete_all_eggs(self):
        
        path_to_delete = os.path.join(self.egg_directory, "lib", "python")
        if os.path.exists(path_to_delete):
            shutil.rmtree(path_to_delete)
1361838
def install_as_egg(self, destination_eggdir):
        ''''''
        with zipfile.ZipFile(self.filename) as zf:
            self._install_as_egg(destination_eggdir, zf)
429951
def load_eggs(entry_point_name):
    """"""

    def _load_eggs():
        distributions, errors = working_set.find_plugins(Environment())
        for dist in distributions:
            # pylint: disable=unsupported-membership-test
            if dist not in working_set:
                LOGGER.debug('Adding plugin %s from %s', dist, dist.location)
                working_set.add(dist)

        def _log_error(item, err):
            if isinstance(err, DistributionNotFound):
                LOGGER.debug('Skipping "%s": ("%s" not found)', item, err)
            elif isinstance(err, VersionConflict):
                LOGGER.error('Skipping "%s": (version conflict "%s")', item, err)
            elif isinstance(err, UnknownExtra):
                LOGGER.error('Skipping "%s": (unknown extra "%s")', item, err)
            else:
                LOGGER.error('Skipping "%s": %s', item, err)

        for dist, err in errors.items():
            _log_error(dist, err)

        for entry in sorted(
            working_set.iter_entry_points(entry_point_name),
            key=lambda entry: entry.name,
        ):
            try:
                entry.load(require=True)
            except Exception as exc:  # pylint: disable=broad-except
                _log_error(entry, exc)

    return _load_eggs