def install_pythonz(): PythonzInstaller.install(INSTALLER_ROOT) # for bash shrc = yourshrc = "bashrc" logger.log( """ Well-done! Congratulations! The pythonz is installed as: %(ROOT)s Please add the following line to the end of your ~/.%(yourshrc)s [[ -s %(PATH_ETC)s/%(shrc)s ]] && source %(PATH_ETC)s/%(shrc)s After that, exit this shell, start a new one, and install some fresh pythons: pythonz install 2.7.2 pythonz install 3.2 For further instructions, run: pythonz help The default help messages will popup and tell you what to do! Enjoy pythonz at %(ROOT)s!! """ % { 'ROOT': ROOT, 'yourshrc': yourshrc, 'shrc': shrc, 'PATH_ETC': PATH_ETC.replace(os.getenv('HOME'), '$HOME') })
def read(cls, url): try: r = urllib.urlopen(url) except IOError: logger.log(traceback.format_exc()) raise DownloadError('Failed to fetch.') return r.read()
def install_pythonz(): PythonzInstaller.install(INSTALLER_ROOT) # for bash shrc = yourshrc = "bashrc" logger.log(""" Well-done! Congratulations! The pythonz is installed as: %(ROOT)s Please add the following line to the end of your ~/.%(yourshrc)s [[ -s %(PATH_ETC)s/%(shrc)s ]] && source %(PATH_ETC)s/%(shrc)s After that, exit this shell, start a new one, and install some fresh pythons: pythonz install 2.7.2 pythonz install 3.2 For further instructions, run: pythonz help The default help messages will popup and tell you what to do! Enjoy pythonz at %(ROOT)s!! """ % {'ROOT': ROOT, 'yourshrc': yourshrc, 'shrc': shrc, 'PATH_ETC': PATH_ETC.replace(os.getenv('HOME'), '$HOME')})
def call(self, cmd): if is_str(cmd): cmd = shlex.split(cmd) if self._debug: logger.log(cmd) fp = ((self._log and open(self._log, 'a')) or None) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd) while p.returncode is None: while any(select.select([p.stdout], [], [])): line = to_str(p.stdout.readline()) if not line: break if self._verbose: logger.log(line.strip()) if fp: fp.write(line) fp.flush() p.poll() if fp: fp.close() return p.returncode
def read(self, url): try: r = urllib.urlopen(url) except IOError: logger.log(traceback.format_exc()) raise CurlFetchException('Failed to fetch.') return r.read()
def fetch(cls, url, filename): b = ProgressBar() try: urllib.urlretrieve(url, filename, b.reporthook) sys.stdout.write('\n') except IOError: sys.stdout.write('\n') logger.log(traceback.format_exc()) raise DownloadError('Failed to fetch.')
def readheader(self, url): try: req = HEADRequest(url) res = urllib2.urlopen(req) except IOError: logger.log(traceback.format_exc()) raise CurlFetchException('Failed to fetch.') if res.code != 200: raise CurlFetchException('Failed to fetch.') return res.info()
def configure(self): s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose) cmd = "./configure --prefix=%s %s %s" % ( self.install_dir, self.options.configure, " ".join(self.configure_options), ) if self.options.verbose: logger.log(cmd) s.check_call(cmd)
def configure(self): s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose) cmd = "./configure --prefix=%s %s %s" % ( self.install_dir, self.options.configure, ' '.join( self.configure_options)) if self.options.verbose: logger.log(cmd) s.check_call(cmd)
def read_head_info(cls, url): try: req = HEADRequest(url) res = urllib2.urlopen(req) except IOError: logger.log(traceback.format_exc()) raise DownloadError('Failed to fetch.') if res.code != 200: raise DownloadError('Failed to fetch.') return res.info()
def run_command(self, options, args): if not args or len(args) > 1: self.parser.print_help() return pkg = Package(args[0], options.type) pkgname = pkg.name if not is_installed(pkg): logger.error("`%s` is not installed." % pkgname) return logger.log(os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python'))
def run_command(self, options, args): if not args or len(args) > 1: self.parser.print_help() return pkg = Package(args[0], options.type) pkgname = pkg.name if not is_installed(pkg): logger.error("`%s` is not installed." % pkgname) return logger.log(os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python'))
def shell(self, cmd): if self._debug: logger.log(cmd) if is_sequence(cmd): cmd = ''.join(cmd) if self._log: if self._verbose: cmd = "(%s) 2>&1 | tee '%s'" % (cmd, self._log) else: cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log) returncode = subprocess.call(cmd, shell=True, cwd=self._cwd) if returncode: raise ShellCommandException('%s: failed to `%s`' % (returncode, cmd))
def shell(self, cmd): if self._debug: logger.log(cmd) if is_sequence(cmd): cmd = ''.join(cmd) if self._log: if self._verbose: cmd = "(%s) 2>&1 | tee '%s'" % (cmd, self._log) else: cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log) returncode = subprocess.call(cmd, shell=True, cwd=self._cwd) if returncode: raise ShellCommandException('%s: failed to `%s`' % (returncode, cmd))
def _update_config(self, options, args): # config.cfg update # TODO: Automatically create for config.cfg download_url = PYTHONZ_UPDATE_URL_CONFIG if not download_url: logger.error("Invalid download url in config.cfg. `%s`" % download_url) sys.exit(1) distname = Link(PYTHONZ_UPDATE_URL_CONFIG).filename download_file = PATH_ETC_CONFIG logger.info("Downloading %s as %s" % (distname, download_file)) try: Downloader.fetch(download_url, download_file) except DownloadError: logger.error("Failed to download. `%s`" % download_url) sys.exit(1) logger.log("The config.cfg has been updated.")
def run_command(self, options, args): if not args or len(args) > 1: self.parser.print_help() sys.exit(1) pkg = Package(args[0], options.type) pkgname = pkg.name if not is_installed(pkg): logger.error("`%s` is not installed." % pkgname) sys.exit(1) for bin in ('python3', 'python', 'pypy3', 'pypy'): path = os.path.join(PATH_PYTHONS, pkgname, 'bin', bin) if os.path.exists(path): break else: # fallback path = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python') logger.log(path)
def run_command(self, options, args): if not args or len(args) > 1: self.parser.print_help() sys.exit(1) pkg = Package(args[0], options.type) pkgname = pkg.name if not is_installed(pkg): logger.error("`%s` is not installed." % pkgname) sys.exit(1) for bin in ('python3', 'python', 'pypy3', 'pypy'): path = os.path.join(PATH_PYTHONS, pkgname, 'bin', bin) if os.path.exists(path): break else: # fallback path = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python') logger.log(path)
def installed(self, path): logger.log("# Installed Python versions") for d in sorted(os.listdir(PATH_PYTHONS)): if path: logger.log(' %-16s %s/%s' % (d, PATH_PYTHONS, d)) else: logger.log(' %s' % d)
def installed(self, path): logger.log("# Installed Python versions") for d in sorted(os.listdir(PATH_PYTHONS)): if path: logger.log(' %-16s %s/%s' % (d, PATH_PYTHONS, d)) else: logger.log(' %s' % d)
def all(self): logger.log('# Available Python versions') for type, versions in PYTHON_VERSIONS_URLS.iteritems(): if versions: logger.log(' # %s:' % type) for version in (version for version in sorted(versions.keys())): logger.log(' %s' % version)
def call(self, cmd): if is_str(cmd): cmd = shlex.split(cmd) if self._debug: logger.log(cmd) fp = ((self._log and open(self._log, 'a')) or None) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd) while p.returncode is None: while any(select.select([p.stdout], [], [])): line = to_str(p.stdout.readline()) if not line: break if self._verbose: logger.log(line.strip()) if fp: fp.write(line) fp.flush() p.poll() if fp: fp.close() return p.returncode
def all(self, py_type): logger.log('# Available Python versions') py_types = [py_type] if py_type else PY_TYPES for type_ in py_types: logger.log(' # %s:' % type_) for version in sorted(PY_INSTALLERS[type_].supported_versions): logger.log(' %s' % version)
def installed(self): logger.log("# Installed Python versions") cur = get_using_python_pkgname() for d in sorted(os.listdir(PATH_PYTHONS)): if cur and cur == d: logger.log(' %s (*)' % d) else: logger.log(' %s' % d)
def all(self, py_type): logger.log('# Available Python versions') py_types = [py_type] if py_type else PY_TYPES for type_ in py_types: logger.log(' # %s:' % type_) for version in sorted(PY_INSTALLERS[type_].supported_versions): logger.log(' %s' % version)
def run_command(self, options, args): if args: command = args[0] if command not in command_map: self.parser.error("Unknown command: `%s`" % command) return command = command_map[command] command.parser.print_help() return self.parser.print_help() logger.log("\nCommands available:") commands = [command_map[key] for key in sorted(command_map.keys())] for command in commands: logger.log(" %s: %s" % (command.name, command.summary)) logger.log("\nFurther Instructions:") logger.log(" https://github.com/saghul/pythonz")
def run_command(self, options, args): if args: command = args[0] if command not in command_map: self.parser.error("Unknown command: `%s`" % command) return command = command_map[command] command.parser.print_help() return self.parser.print_help() logger.log("\nCommands available:") commands = [command_map[key] for key in sorted(command_map.keys())] for command in commands: logger.log(" %s: %s" % (command.name, command.summary)) logger.log("\nFurther Instructions:") logger.log(" https://github.com/saghul/pythonz")
def systemwide_pythonz(): PythonzInstaller.install(INSTALLER_ROOT) PythonzInstaller.systemwide_install() logger.log(""" Well-done! Congratulations! The pythonz is installed as: %(ROOT)s After that, exit this shell, start a new one, and install some fresh pythons: pythonz install 2.7.2 pythonz install 3.2 For further instructions, run: pythonz help The default help messages will popup and tell you what to do! Enjoy pythonz at %(ROOT)s!! """ % {'ROOT':ROOT})
def systemwide_pythonz(): PythonzInstaller.install(INSTALLER_ROOT) PythonzInstaller.systemwide_install() logger.log(""" Well-done! Congratulations! The pythonz is installed as: %(ROOT)s After that, exit this shell, start a new one, and install some fresh pythons: pythonz install 2.7.2 pythonz install 3.2 For further instructions, run: pythonz help The default help messages will popup and tell you what to do! Enjoy pythonz at %(ROOT)s!! """ % {'ROOT': ROOT})
def all(self): logger.log('# Available Python versions') for type, installer in zip( ['cpython', 'stackless', 'pypy', 'pypy3', 'jython'], [ CPythonInstaller, StacklessInstaller, PyPyInstaller, PyPy3Installer, JythonInstaller ]): logger.log(' # %s:' % type) for version in installer.supported_versions: logger.log(' %s' % version)
def all(self, py_type): logger.log('# Available Python versions') groups = zip(PY_TYPES, [CPythonInstaller, StacklessInstaller, PyPyInstaller, PyPy3Installer, JythonInstaller]) if py_type: groups = filter(lambda (impl, _): impl in py_type, groups) for type_, installer in groups: logger.log(' # %s:' % type_) for version in sorted(installer.supported_versions): logger.log(' %s' % version)
def run_command(self, options, args): logger.log(__version__)
def installed(self): logger.log("# Installed Python versions") for d in sorted(os.listdir(PATH_PYTHONS)): logger.log(' %s' % d)
def installed(self): logger.log("# Installed Python versions") for d in sorted(os.listdir(PATH_PYTHONS)): logger.log(' %s' % d)
def all(self): logger.log('# Available Python versions') for type, installer in zip(['cpython', 'stackless', 'pypy', 'pypy3', 'jython'], [CPythonInstaller, StacklessInstaller, PyPyInstaller, PyPy3Installer, JythonInstaller]): logger.log(' # %s:' % type) for version in installer.supported_versions: logger.log(' %s' % version)
def run_command(self, options, args): logger.log(__version__)
def __init__(self): returncode = subprocess.call("command -v curl > /dev/null", shell=True) if returncode: logger.log("pythonz required curl. curl was not found in your path.") sys.exit(1)