def do_copy_custom(self, subcmd, opts, *paths): """${cmd_name}: Copy packages into the appropriate custom repository Use this command to copy the "extra" PyPM packages available in the "GoldBits" directory of ActivePython to the "custom" repo, making them available in pypm-custom.as.com. Example:: $ bin/pypm-repository -c etc/activestate.conf copy_custom \ /net/nas/data/languages/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.reposets['custom'].get_repository( pyver = bpkg.pyver, osarch = bpkg.osarch, ) target_path = os.path.join(repo.path, os.path.basename(path)) LOG.info('cp: %s\n => %s', path, target_path) sh.cp(path, target_path) repo.uptree.mark_dirty(target_path)
def _pep370_fix_path_unix(): """If ~/.local/bin is not in $PATH, automatically add them Do this only with the user's consent. And do not run this check more than once (i.e., run only when PyPM is *first run*). """ if sys.platform.startswith('win'): return # MSI does this on Windows # Proceed only when the terminal is interactive and was never run before isatty = (sys.stdin.isatty() and sys.stdout.isatty()) firstrun_file = P.join(application.locations.user_cache_dir, '.firstrun-pep370') if (not isatty) or P.exists(firstrun_file): return import site from datetime import datetime pathenv = [ P.abspath(x.strip()) for x in os.environ.get('PATH', '').split(':') ] binpath = P.abspath(P.join(site.USER_BASE, 'bin')) profile = P.expanduser('~/.profile' if sys.platform == 'darwin' else '~/.bashrc') profile_lines = [ '# PEP 370 PATH added by PyPM on %s' % datetime.now(), 'export PATH=%s:$PATH' % binpath, ] already_in_profile = P.exists(profile) and profile_lines[1] in [ l.strip() for l in open(profile).readlines() ] # Proceed only if ~/.local/bin is neither in $PATH, nor added to profile if binpath in pathenv or already_in_profile: return # Add to profile on the user's consent msg = ('Packages will install their script files to "%s" ' '(as per PEP 370). This directory is not yet in your $PATH. ' 'Would you like PyPM to add it by appending to "%s"?') % ( concise_path(binpath), concise_path(profile)) if textui.askyesno(wrapped(msg, '*** '), default=True): if P.exists(profile): sh.cp(profile, profile + '.bak') # take a backup first with open(profile, 'a') as f: f.write('\n%s\n' % '\n'.join(profile_lines)) print('You may now reopen your shell for the changes to take effect.') sh.mkdirs(P.dirname(firstrun_file)) with open(firstrun_file, 'w') as f: pass # prevent future runs
def _pep370_fix_path_unix(): """If ~/.local/bin is not in $PATH, automatically add them Do this only with the user's consent. And do not run this check more than once (i.e., run only when PyPM is *first run*). """ if sys.platform.startswith('win'): return # MSI does this on Windows # Proceed only when the terminal is interactive and was never run before isatty = (sys.stdin.isatty() and sys.stdout.isatty()) firstrun_file = P.join(application.locations.user_cache_dir, '.firstrun-pep370') if (not isatty) or P.exists(firstrun_file): return import site from datetime import datetime pathenv = [P.abspath(x.strip()) for x in os.environ.get('PATH', '').split(':')] binpath = P.abspath(P.join(site.USER_BASE, 'bin')) profile = P.expanduser('~/.profile' if sys.platform == 'darwin' else '~/.bashrc') profile_lines = [ '# PEP 370 PATH added by PyPM on %s' % datetime.now(), 'export PATH=%s:$PATH' % binpath, ] already_in_profile = P.exists(profile) and profile_lines[1] in [ l.strip() for l in open(profile).readlines() ] # Proceed only if ~/.local/bin is neither in $PATH, nor added to profile if binpath in pathenv or already_in_profile: return # Add to profile on the user's consent msg = ( 'Packages install script files to "%s" ' '(as per PEP 370). This directory is not yet in your $PATH. ' 'Would you like PyPM to add it to $PATH by modifying (with backup) "%s"?' ) % (binpath, profile) if textui.askyesno(wrapped(msg, '*** '), default=True): if P.exists(profile): sh.cp(profile, profile+'.bak') # take a backup first with open(profile, 'a') as f: f.write('\n%s\n' % '\n'.join(profile_lines)) print ('You may now reopen your shell for the changes to take effect.') sh.mkdirs(P.dirname(firstrun_file)) with open(firstrun_file, 'w') as f: pass # prevent future runs
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 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)