Makes sure this egg distribution is stored only as an egg file.

        The egg file will be created from another existing distribution format
        if needed.
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()
601351
def clean():
    """"""
    shutil.rmtree('{PROJECT_NAME}.egg-info'.format(PROJECT_NAME=PROJECT_NAME), ignore_errors=True)
    shutil.rmtree('build', ignore_errors=True)
    shutil.rmtree('dist', ignore_errors=True)
    shutil.rmtree('htmlcov', ignore_errors=True)
    shutil.rmtree('__pycache__', ignore_errors=True)
319594
def tidy_eggs_list(eggs_list):
    
    tmp = []
    for line in eggs_list:
        line = line.lstrip().rstrip()
        line = line.replace('\'', '')
        line = line.replace(',', '')
        if line.endswith('site-packages'):
            continue
        tmp.append(line)
    return tmp
1203229
def run(self):
        

        self.announce("Moving library files", level=3)

        # We have already built the libraries in the previous build_ext step

        self.skip_build = True

        bin_dir = self.distribution.bin_dir

        libs = [os.path.join(bin_dir, _lib) for _lib in 
                os.listdir(bin_dir) if 
                os.path.isfile(os.path.join(bin_dir, _lib)) and 
                os.path.splitext(_lib)[1] in [".dll", ".so"]
                and not (_lib.startswith("python") or _lib.startswith("bpy"))]

        for lib in libs:

            shutil.move(lib, os.path.join(self.build_dir,
                                          os.path.basename(lib)))

        # Mark the libs for installation, adding them to 
        # distribution.data_files seems to ensure that setuptools' record 
        # writer appends them to installed-files.txt in the package's egg-info
        #
        # Also tried adding the libraries to the distribution.libraries list, 
        # but that never seemed to add them to the installed-files.txt in the 
        # egg-info, and the online recommendation seems to be adding libraries 
        # into eager_resources in the call to setup(), which I think puts them 
        # in data_files anyways. 
        # 
        # What is the best way?

        self.distribution.data_files = [os.path.join(self.install_dir, 
                                                     os.path.basename(lib))
                                        for lib in libs]

        # Must be forced to run after adding the libs to data_files

        self.distribution.run_command("install_data")

        super().run()
1021283
def install(self, new_egg, new_egg_gpg_sig):
        

        # make sure a valid egg was provided
        if not new_egg:
            the_message = 'Must provide a valid Core installation path.'
            logger.debug(the_message)
            return {'success': False, 'message': the_message}

        # if running in gpg mode, check for valid sig
        if self.config.gpg and new_egg_gpg_sig is None:
            the_message = "Must provide a valid Core GPG installation path."
            logger.debug(the_message)
            return {'success': False, 'message': the_message}

        # debug
        logger.debug("Installing the new Core %s", new_egg)
        if self.config.gpg:
            logger.debug("Installing the new Core GPG Sig %s", new_egg_gpg_sig)

        # Make sure /var/lib/insights exists
        try:
            if not os.path.isdir(constants.insights_core_lib_dir):
                logger.debug("Creating directory %s for the Core." %
                             (constants.insights_core_lib_dir))
                os.mkdir(constants.insights_core_lib_dir)
        except OSError:
            logger.info("There was an error creating %s for core installation." % (
                constants.insights_core_lib_dir))
            raise

        # Copy the NEW (/tmp/insights-core.egg) egg to /var/lib/insights/newest.egg
        # Additionally, copy NEW (/tmp/insights-core.egg.asc) to /var/lib/insights/newest.egg.asc
        try:
            logger.debug("Copying %s to %s." % (new_egg, constants.insights_core_newest))
            shutil.copyfile(new_egg, constants.insights_core_newest)
            shutil.copyfile(new_egg_gpg_sig, constants.insights_core_gpg_sig_newest)
        except IOError:
            logger.info("There was an error copying the new core from %s to %s." % (
                new_egg, constants.insights_core_newest))
            raise

        logger.debug("The new Insights Core was installed successfully.")
        return {'success': True}
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
521536
def egg_name(self):
        """"""
        filename = "%s-%s-py%s" % (
            to_filename(self.project_name), to_filename(self.version),
            self.py_version or PY_MAJOR
        )

        if self.platform:
            filename += '-' + self.platform
        return filename
527416
def _build_egg(egg, archive_filename, to_dir):
    """"""
    with archive_context(archive_filename):
        # building an egg
        log.warn('Building a Setuptools egg in %s', to_dir)
        _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
    # returning the result
    log.warn(egg)
    if not os.path.exists(egg):
        raise IOError('Could not build the egg.')
423478
@Override
    public File exportExploded(File baseDirectory, String directoryName) {
        final Archive<?> archive = this.getArchive();
        Validate.notNull(archive, "No archive provided");
        Validate.notNull(baseDirectory, "No baseDirectory provided");

        // Directory must exist
        if (!baseDirectory.exists()) {
            throw new IllegalArgumentException("Parent directory does not exist");
        }
        // Must be a directory
        if (!baseDirectory.isDirectory()) {
            throw new IllegalArgumentException("Provided parent directory is not a valid directory");
        }

        return export(archive, new File(baseDirectory, directoryName));
    }
990289
def require_metadata():
    ""
    egg_info_dir = os.path.join(here, 'setuptools.egg-info')
    if not os.path.exists(egg_info_dir):
        msg = (
            "Cannot build setuptools without metadata. "
            "Run `bootstrap.py`."
        )
        raise RuntimeError(msg)
990380
def __install_eggs(self, config):
        
        egg_carton = (self.directory.install_directory(self.feature_name),
                      'requirements.txt')
        eggs = self.__gather_eggs(config)

        self.logger.debug("Installing eggs %s..." % eggs)
        self.__load_carton(egg_carton, eggs)

        self.__prepare_eggs(egg_carton, config)
999542
public static FSDataOutputStream tryCreateFile(FileSystem fs, Path file) throws IOException {
    try {
      FSDataOutputStream os = fs.create(file, false);
      return os;
    } catch (FileAlreadyExistsException e) {
      return null;
    } catch (RemoteException e) {
      if( e.unwrapRemoteException() instanceof AlreadyBeingCreatedException ) {
        return null;
      } else { // unexpected error
        throw e;
      }
    }
  }
1174265
def working_set(self, extra=()):
        
        options = self.options
        b_options = self.buildout['buildout']

        # Backward compat. :(
        options['executable'] = sys.executable

        distributions = [
            r.strip()
            for r in options.get('eggs', self.name).split('\n')
            if r.strip()]
        orig_distributions = distributions[:]
        distributions.extend(extra)

        if self.buildout['buildout'].get('offline') == 'true':
            ws = zc.buildout.easy_install.working_set(
                distributions,
                [options['develop-eggs-directory'], options['eggs-directory']]
                )
        else:
            ws = zc.buildout.easy_install.install(
                distributions, options['eggs-directory'],
                links=self.links,
                index=self.index,
                path=[options['develop-eggs-directory']],
                newest=self.buildout['buildout'].get('newest') == 'true',
                allow_hosts=self.allow_hosts)

        return orig_distributions, ws
583010
def dist_is_editable(dist):
    # type: (Distribution) -> bool
    
    for path_item in sys.path:
        egg_link = os.path.join(path_item, dist.project_name + '.egg-link')
        if os.path.isfile(egg_link):
            return True
    return False
231740
def save(self, filename):
        
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        
        projex.text.xmlindent(self._xroot)
        xtree = ElementTree.ElementTree(self._xroot)
        xtree.write(filename, encoding=self.encoding(), xml_declaration=True)
        return True
736752
public static boolean createNewFile(File file) throws IOException {
        createFolder(file.getParent());
        return (!file.exists() || file.delete()) && file.createNewFile();
    }
857422
def egg_info_writer(cmd, basename, filename):
    # type: (setuptools.command.egg_info.egg_info, str, str) -> None
    
    setupcfg = next((f for f in setuptools.findall()
                     if os.path.basename(f) == 'setup.cfg'), None)
    if not setupcfg:
        return
    parser = six.moves.configparser.ConfigParser()  # type: ignore
    parser.read(setupcfg)
    if not parser.has_section('rcli') or not parser.items('rcli'):
        return
    config = dict(parser.items('rcli'))  # type: typing.Dict[str, typing.Any]
    for k, v in six.iteritems(config):
        if v.lower() in ('y', 'yes', 'true'):
            config[k] = True
        elif v.lower() in ('n', 'no', 'false'):
            config[k] = False
        else:
            try:
                config[k] = json.loads(v)
            except ValueError:
                pass
    cmd.write_file(basename, filename, json.dumps(config))