def run_command(self, options, args): if options.default: # create only one instance as default of an application. pythons = self._get_pythons([options.default]) for pkgname in pythons: if args: bin = args[0] self._symlink(bin, bin, pkgname) else: self._symlink('python', 'py', pkgname) else: pythons = self._get_pythons(options.pythons) for pkgname in pythons: if options.remove: # remove symlinks for bin in os.listdir(PATH_BIN): path = os.path.join(PATH_BIN, bin) if os.path.islink(path): unlink(path) else: # create symlinks if args: bin = args[0] self._symlink_version_suffix(bin, bin, pkgname) else: self._symlink_version_suffix('python', 'py', pkgname)
def run_command(self, options, args): if args: # Uninstall pythonidae for arg in args: pkg = Package(arg) pkgname = pkg.name pkgpath = os.path.join(PATH_PYTHONS, pkgname) venvpath = os.path.join(PATH_VENVS, pkgname) if not is_installed(pkgname): logger.error("`%s` is not installed." % pkgname) continue if get_using_python_pkgname() == pkgname: off() for d in os.listdir(PATH_BIN): # remove symlink path = os.path.join(PATH_BIN, d) if os.path.islink(path): basename = os.path.basename(os.path.realpath(path)) tgtpath = os.path.join(pkgpath, "bin", basename) if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath): unlink(path) rm_r(pkgpath) rm_r(venvpath) else: self.parser.print_help()
def download_unpack(self): content_type = self.content_type if is_html(content_type): logger.error("Invalid content-type: `%s`" % content_type) sys.exit(1) if is_file(self.download_url): path = fileurl_to_path(self.download_url) if os.path.isdir(path): logger.info('Copying %s into %s' % (path, self.build_dir)) if os.path.isdir(self.build_dir): shutil.rmtree(self.build_dir) shutil.copytree(path, self.build_dir) return if os.path.isfile(self.download_file): logger.info("Use the previously fetched %s" % (self.download_file)) else: msg = Link(self.download_url).show_msg try: dl = Downloader() dl.download(msg, self.download_url, self.download_file) except: unlink(self.download_file) logger.info("\nInterrupt to abort. `%s`" % (self.download_url)) sys.exit(1) # unpack if not unpack_downloadfile(self.content_type, self.download_file, self.build_dir): sys.exit(1)
def run_command(self, options, args): if args: # Uninstall pythons for arg in args: pkg = Package(arg) pkgname = pkg.name pkgpath = os.path.join(PATH_PYTHONS, pkgname) venvpath = os.path.join(PATH_VENVS, pkgname) if not is_installed(pkgname): logger.error("`%s` is not installed." % pkgname) continue if get_using_python_pkgname() == pkgname: off() for d in os.listdir(PATH_BIN): # remove symlink path = os.path.join(PATH_BIN, d) if os.path.islink(path): basename = os.path.basename(os.path.realpath(path)) tgtpath = os.path.join(pkgpath, 'bin', basename) if os.path.isfile(tgtpath) and os.path.samefile( path, tgtpath): unlink(path) rm_r(pkgpath) rm_r(venvpath) else: self.parser.print_help()
def run_command(self, options, args): if options.default: # create only one instance as default of an application. pythons = self._get_pythons([options.default]) for pkgname in pythons: if args: bin = args[0] self._symlink(bin, bin, pkgname) else: self._symlink('python', 'py', pkgname) elif options.venv: if options.pythons: pkgname = Package(options.pythons[0]).name else: pkgname = get_using_python_pkgname() if not is_installed(pkgname): logger.error('`%s` is not installed.') sys.exit(1) venv_pkgdir = os.path.join(PATH_VENVS, pkgname) venv_dir = os.path.join(venv_pkgdir, options.venv) if not os.path.isdir(venv_dir): logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir)) sys.exit(1) pkg = Package(pkgname) if args: bin = args[0] dstbin = '%s%s-%s' % (bin, pkg.version, options.venv) self._symlink(bin, dstbin, pkgname) else: dstbin = 'py%s-%s' % (pkg.version, options.venv) self._symlink('python', dstbin, pkgname) else: pythons = self._get_pythons(options.pythons) for pkgname in pythons: if options.remove: # remove symlinks for bin in os.listdir(PATH_BIN): path = os.path.join(PATH_BIN, bin) if os.path.islink(path): unlink(path) else: # create symlinks if args: bin = args[0] self._symlink_version_suffix(bin, bin, pkgname) else: self._symlink_version_suffix('python', 'py', pkgname)
def download(self): content_type = self.content_type if is_html(content_type): logger.error("Invalid content-type: `%s`" % content_type) sys.exit(1) if os.path.isfile(self.download_file): logger.info("Use the previously fetched %s" % (self.download_file)) return msg = Link(self.download_url).show_msg try: dl = Downloader() dl.download( msg, self.download_url, self.download_file ) except: unlink(self.download_file) logger.info("\nInterrupt to abort. `%s`" % (self.download_url)) sys.exit(1)
def download_and_extract(self): if is_file(self.download_url): path = fileurl_to_path(self.download_url) if os.path.isdir(path): logger.info('Copying %s into %s' % (path, self.build_dir)) shutil.copytree(path, self.build_dir) return if os.path.isfile(self.download_file): logger.info("Use the previously fetched %s" % (self.download_file)) else: base_url = Link(self.download_url).base_url try: dl = Downloader() dl.download(base_url, self.download_url, self.download_file) except: unlink(self.download_file) logger.error("Failed to download.\n%s" % (sys.exc_info()[1])) sys.exit(1) # extracting if not extract_downloadfile(self.content_type, self.download_file, self.build_dir): sys.exit(1)
def run_command(self, options, args): if args: # Uninstall pythons for arg in args: pkg = Package(arg) pkgname = pkg.name pkgpath = os.path.join(PATH_PYTHONS, pkgname) if not os.path.isdir(pkgpath): logger.info("`%s` is not installed." % pkgname) continue if get_current_python_path() == os.path.join(pkgpath,'bin','python'): off() for d in os.listdir(PATH_BIN): # remove symlink path = os.path.join(PATH_BIN, d) if os.path.islink(path): basename = os.path.basename(os.path.realpath(path)) tgtpath = os.path.join(pkgpath, 'bin', basename) if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath): unlink(path) rm_r(pkgpath) else: self.parser.print_help()