def _read_info_json(self, pypm_file): """Read cached info.json (as dict) from the .d/ directory If cached version is missing, read from the package file itself, which would be an expensive operation. """ info_json_loc = xjoin(pypm_file + '.d', 'info.json') try: s = self.repository.uptree.open_and_read(info_json_loc) except IOError as e: # There seems to be no .d/info.json file; perhaps this is a # 'custom' that is not managed by pypm-builder. So let's extract # info.json from the package file (.pypm) even though that is # expensive (so we will also warn the user) LOG.info( 'ALERT: Cache file (.d/info.json) missing; extracting from %s', pypm_file) s = PackageFile(pypm_file).retrieve_info_json() d = json.loads(s) # It is not clear whether info.json's "name" field is canonical (i.e., # lower case safe version of name, that is guarateed to be same). # Therefore, we do one final conversion there. d['name'] = pkg_resources.safe_name(d['name']).lower() return d
def install_local_file(pypmenv, pypmfile): # nodeps = True (always!) """Install a local .pypm files Dependency is not automatically resolved, although we should do this in future """ assert pypmfile.endswith(BinaryPackage.EXTENSION) and P.exists(pypmfile) LOG.debug('Installing local package "%s"', pypmfile) bpkg = PackageFile(pypmfile).to_binary_package() # sanity check if bpkg.pyver != pypmenv.pyenv.pyver: raise ValueError( 'cannot install a {0} package on python {1}; {2}'.format( bpkg.pyver, pypmenv.pyenv.pyver, pypmfile)) if bpkg.osarch != PLATNAME: raise ValueError( 'incompatible platform {0}; {1}'.format( bpkg.osarch, pypmfile)) pkg = RepoPackage.create_from(bpkg, relpath=pypmfile, tags='local') with pypmenv.locked(): installer.Installer(pypmenv)._install(pkg, pypmfile)
def extract_package(self, pypm_filename): """Extract files of the package over Python directory""" bpkgfile = PackageFile(pypm_filename) pyenv = self.pypmenv.pyenv if isinstance(pyenv, python.UserLocalPythonEnvironment): return self._extract_pep370(bpkgfile) else: return self._extract_generic(bpkgfile)
def do_copy_custom(self, subcmd, opts, *paths): """${cmd_name}: Copy packages into the appropriate repository Use this command to *manually* copy the *custom* PyPM packages that won't be built by the *automated* pypm-builder/grail. This includes the following cases, 1. "extra" PyPM packages available in the "GoldBits" directory of ActivePython (eg: as.openssl) 2. Proprietary packages (eg: pyimsl from VNI) Use ``MultiRepositoryConfig`` (etc/activestate.conf) to configure how to allocate the custom packages, i.e., where to put them in "free" or "be" repo. Example:: $ bin/pypm-repository -c etc/activestate.conf copy_custom \ $NAS/ActivePython/2.7.0.2/GoldBits/internal/extra/*.pypm ${cmd_usage} ${cmd_option_list} """ with self.bootstrapped(): mreposet = MultiRepositorySet( self.options.multi_repository_set_path, self.options.configfile) for path in paths: bpkg = PackageFile(path).to_binary_package() repo = mreposet.get_repository(bpkg) target_path = P.join(repo.path, 'pool', bpkg.name[0], bpkg.name[:2], os.path.basename(path)) sh.mkdirs(P.dirname(target_path)) action = 'OVERWRITE' if P.exists(target_path) else 'CREATE' LOG.info('%s %s %s', action, repo.name, target_path) if not opts.dry_run: if P.exists(target_path) and not opts.force: raise IOError('cannot overwrite: %s' % target_path) sh.cp(path, target_path) repo.uptree.mark_dirty(target_path)
def extract_package(self, pkg_filename, name): bpkgfile = PackageFile(pkg_filename) pyenv = self.pypmenv.pyenv return self._extract_to_install_scheme(bpkgfile, name)