def build_install(self): """Build and install packages if not already installed """ slackbuilds = self.dependencies + self.master_packages installs, upgraded, = [], [] if not os.path.exists(self.build_folder): os.makedirs(self.build_folder) if not os.path.exists(self._SOURCES): os.makedirs(self._SOURCES) os.chdir(self.build_folder) for prgnam in slackbuilds: if (self.meta.not_downgrade == "on" and self.not_downgrade(prgnam) is True): continue pkg = "-".join(prgnam.split("-")[:-1]) installed = "".join(find_package(prgnam, self.meta.pkg_path)) src_link = SBoGrep(pkg).source().split() if (installed and "--download-only" not in self.flag and "--rebuild" not in self.flag): self.msg.template(78) self.msg.pkg_found(prgnam) self.msg.template(78) elif self.unst[0] in src_link or self.unst[1] in src_link: self.msg.template(78) print("| Package {0} {1}{2}{3}".format( prgnam, self.meta.color["RED"], "".join(src_link), self.meta.color["ENDC"])) self.msg.template(78) else: sbo_url = sbo_search_pkg(pkg) sbo_link = SBoLink(sbo_url).tar_gz() script = sbo_link.split("/")[-1] if self.meta.sbosrcarch in ["on", "ON"]: src_link = self.sbosrcarsh(prgnam, sbo_link, src_link) Download(self.build_folder, sbo_link.split(), repo="sbo").start() Download(self._SOURCES, src_link, repo="sbo").start() if "--download-only" in self.flag: continue sources = self.filenames(src_link) BuildPackage(script, sources, self.build_folder, auto=False).build() binary = slack_package(prgnam) if os.path.isfile("".join(binary)): if GetFromInstalled(pkg).name() == pkg: print("[ {0}Upgrading{1} ] --> {2}".format( self.meta.color["YELLOW"], self.meta.color["ENDC"], prgnam)) upgraded.append(prgnam) else: print("[ {0}Installing{1} ] --> {2}".format( self.meta.color["GREEN"], self.meta.color["ENDC"], prgnam)) installs.append(prgnam) if ("--rebuild" in self.flag and GetFromInstalled(pkg).name() == pkg): PackageManager(binary).upgrade(flag="--reinstall") else: PackageManager(binary).upgrade(flag="--install-new") return installs, upgraded
def find(self, pkg, flag): """Start to find packages and print """ print("\nPackages with name matching [ {0}{1}{2} ]\n".format( self.cyan, ", ".join(pkg), self.endc)) Msg().template(78) print("| {0} {1}{2}{3}".format("Repository", "Package", " " * 54, "Size")) Msg().template(78) for repo in _meta_.repositories: PACKAGES_TXT = PackageManager(pkg).list_lib(repo) packages, sizes = PackageManager(pkg).list_greps( repo, PACKAGES_TXT) for find, size in zip(packages, sizes): for p in pkg: if "--case-ins" in flag: self.p_cache = p.lower() self.find_cache = find.lower() else: self.p_cache = p self.find_cache = find if self.p_cache in self.find_cache: if self.cache != repo: self.count_repo += 1 self.cache = repo self.count_pkg += 1 ver = self.sbo_version(repo, find) print(" {0}{1}{2}{3}{4} {5}{6:>11}".format( self.cyan, repo, self.endc, " " * (12 - len(repo)), find + ver, " " * (53 - len(find + ver)), size)) print("\nFound summary") print("=" * 79) print("{0}Total found {1} packages in {2} repositories.{3}\n".format( self.grey, self.count_pkg, self.count_repo, self.endc))
def upgrade(self): """ Upgrade packages """ for pkg in self.upgrade_all: check_md5(pkg_checksum(pkg, "slack_patches"), self.patch_path + pkg) pkg_ver = "{0}-{1}".format( split_package(pkg)[0], split_package(pkg)[1]) if find_package( split_package(pkg)[0] + self.meta.sp, self.meta.pkg_path): print("[ {0}upgrading{1} ] --> {2}".format( self.meta.color["YELLOW"], self.meta.color["ENDC"], pkg[:-4])) PackageManager( (self.patch_path + pkg).split()).upgrade("--install-new") self.upgraded.append(pkg_ver) else: print("[ {0}installing{1} ] --> {2}".format( self.meta.color["GREEN"], self.meta.color["ENDC"], pkg[:-4])) PackageManager( (self.patch_path + pkg).split()).upgrade("--install-new") self.installed.append(pkg_ver)
def execute(self): """Execute Slackware command """ if self.choice in self.commands.keys(): if self.choice == "i": PackageManager(self.packages).install("") elif self.choice in ["u", "r"]: PackageManager(self.packages).upgrade( self.commands[self.choice][11:])
def install(tmp_path, install_all): ''' Install or upgrade packages ''' for install in install_all: package = (tmp_path + install).split() if os.path.isfile(pkg_path + install[:-4]): print("[ {0}reinstalling{1} ] --> {2}".format( GREEN, ENDC, install)) PackageManager(package).reinstall() elif find_package(split_package(install)[0] + "-", pkg_path): print("[ {0}upgrading{1} ] --> {2}".format(YELLOW, ENDC, install)) PackageManager(package).upgrade() else: print("[ {0}installing{1} ] --> {2}".format(GREEN, ENDC, install)) PackageManager(package).upgrade()
def bin_remove(self): """Remove Slackware packages """ packages = self.args[1:] options = ["-r", "--removepkg"] additional_options = ["--deps", "--check-deps", "--tag", "--checklist"] flag, extra = "", [] flags = ["-warn", "-preserve", "-copy", "-keep"] # merge --check-deps and --deps options if (additional_options[1] in self.args and additional_options[0] not in self.args): self.args.append(additional_options[0]) if len(self.args) > 1 and self.args[0] in options: for additional in additional_options: if additional in self.args: extra.append(additional) self.args.remove(additional) packages = self.args[1:] for fl in flags: if fl in self.args: flag = self.args[1] packages = self.args[2:] PackageManager(packages).remove(flag, extra) else: usage("")
def pkg_list(self): """List of packages by repository """ options = ["-l", "--list"] flag = ["--index", "--installed", "--name"] name = INDEX = installed = False for arg in self.args[2:]: if flag[0] == arg: INDEX = True if flag[1] in arg: installed = True if flag[2] == arg: name = True if arg not in flag: usage("") raise SystemExit() if (len(self.args) > 1 and len(self.args) <= 5 and self.args[0] in options): if self.args[1] in self.meta.repositories: PackageManager(binary=None).package_list( self.args[1], name, INDEX, installed) else: usage(self.args[1]) else: usage("")
def bin_install(self): """Install Slackware binary packages """ packages = self.args[1:] options = [ "-i", "--installpkg" ] flag = "" flags = [ "--warn", "--md5sum", "--root", "--infobox", "--menu", "--terse", "--ask", "--priority", "--tagfile" ] if len(self.args) > 1 and self.args[0] in options: if self.args[1] in flags: flag = self.args[1] packages = self.args[2:] PackageManager(packages).install(flag) else: usage("")
def upgrade(patch_path, upgrade_all): ''' Upgrade packages ''' for pkg in upgrade_all: print("[ {0}upgrading{1} ] --> {2}".format(YELLOW, ENDC, pkg[:-4])) PackageManager((patch_path + pkg).split()).upgrade()
def install(self): """Install SBo package found in /tmp directory. """ binary = slack_package(self.prgnam) print("[ {0}Installing{1} ] --> {2}".format(self.green, self.endc, self.name)) PackageManager(binary).upgrade(flag="--install-new")
def pkg_contents(self): """Print packages contents """ packages = self.args[1:] options = ["-d", "--display"] if len(self.args) > 1 and self.args[0] in options: PackageManager(packages).display() else: usage("")
def bin_upgrade(self): """Install-upgrade Slackware binary packages """ packages = self.args[1:] options = ["-u", "--upgradepkg"] flag = "" flags = ["--dry-run", "--install-new", "--reinstall", "--verbose"] if len(self.args) > 1 and self.args[0] in options: if self.args[1] in flags: flag = self.args[1] packages = self.args[2:] PackageManager(packages).upgrade(flag) else: usage("")
def install_packages(self): """Install or upgrade packages """ installs, upgraded = [], [] for inst in (self.dep_install + self.install): package = (self.tmp_path + inst).split() pkg_ver = "{0}-{1}".format(split_package(inst)[0], split_package(inst)[1]) self.checksums(inst) if GetFromInstalled(split_package(inst)[0]).name(): print("[ {0}upgrading{1} ] --> {2}".format( self.meta.color["YELLOW"], self.meta.color["ENDC"], inst)) upgraded.append(pkg_ver) if "--reinstall" in self.flag: PackageManager(package).upgrade("--reinstall") else: PackageManager(package).upgrade("--install-new") else: print("[ {0}installing{1} ] --> {2}".format( self.meta.color["GREEN"], self.meta.color["ENDC"], inst)) installs.append(pkg_ver) PackageManager(package).upgrade("--install-new") return [installs, upgraded]
def bin_find(self): """Find installed packages """ flag = [] options = ["-f", "--find"] additional_options = ["--case-ins"] for arg in self.args: if arg in additional_options: flag.append(arg) self.args.remove(arg) packages = self.args[1:] if len(self.args) > 1 and self.args[0] in options: PackageManager(packages).find(flag) else: usage("")
def install(name, prgnam, sbo_url): ''' Install Slackware package found in /tmp directory. ''' binary_list = [] for search in find_package(prgnam, tmp): if "_SBo" in search: binary_list.append(search) try: binary = (tmp + max(binary_list)).split() except ValueError: build_FAILED(sbo_url, prgnam) sys.exit() print("[ {0}Installing{1} ] --> {2}".format(GREEN, ENDC, name)) PackageManager(binary).upgrade()
def install(self): """Install packages from queue """ packages = self.packages() if packages: print("") # new line at start for pkg in packages: ver = SBoGrep(pkg).version() prgnam = "{0}-{1}".format(pkg, ver) if find_package(prgnam, self.meta.output): binary = slack_package(prgnam) PackageManager(binary).upgrade(flag="--install-new") else: print("\nPackage {0} not found in the {1} for " "installation\n".format(prgnam, self.meta.output)) else: print("\nPackages not found in the queue for installation\n") raise SystemExit(1)
def build_install(dependencies, sbo_versions, packages_arch): ''' Searches the package name and version in /tmp to install. If find two or more packages e.g. to build tag 2 or 3 will fit most ''' installs, upgraded, versions = [], [], [] create_build_path() os.chdir(build_path) for pkg, ver, ar in zip(dependencies, sbo_versions, packages_arch): prgnam = ("{0}-{1}".format(pkg, ver)) sbo_file = "".join(find_package(prgnam, pkg_path)) if sbo_file: sbo_file_version = sbo_file[len(pkg) + 1:-len(ar) - 7] template(78) pkg_found(pkg, sbo_file_version) template(78) else: sbo_url = sbo_search_pkg(pkg) sbo_link = SBoLink(sbo_url).tar_gz() src_link = SBoGrep(pkg).source().split() script = sbo_link.split("/")[-1] Download(build_path, sbo_link).start() sources = dwn_sources(src_link) BuildPackage(script, sources, build_path).build() binary_list = search_in_tmp(prgnam) try: binary = (tmp + max(binary_list)).split() except ValueError: build_FAILED(sbo_url, prgnam) sys.exit() if find_package(pkg + sp, pkg_path): print("{0}[ Upgrading ] --> {1}{2}".format(GREEN, ENDC, pkg)) upgraded.append(pkg) else: print("{0}[ Installing ] --> {1}{2}".format(GREEN, ENDC, pkg)) PackageManager(binary).upgrade() installs.append(pkg) versions.append(ver) return [installs, upgraded, versions]
def start(self): ''' Upgrade all slackbuilds packages from slackbuilds.org repository. NOTE: This functions check packages by version not by build tag because build tag not reported the SLACKBUILDS.TXT file, but install the package with maximum build tag if find the some version in /tmp directory. ''' try: if sbo_list(): upg_name = exists(self.index, self.toolbar_width) sys.stdout.write(self.done) data = [] if upg_name: sys.stdout.write("{0}Resolving dependencies ...{1}".format( GREY, ENDC)) sys.stdout.flush() dependencies = deps(upg_name) requires = one_for_all(dependencies) dependencies_list = order_list(upg_name, remove_dbs(requires)) # upgrade name = data[0] # package for upgrade = data[1] # upgrade version = data[2] # upgrade arch = data[3] data = store(dependencies_list) sys.stdout.write(self.done) if data: # count installed = count[0] # count upgraded = count[1] # message install = msg[0] # message upgrade = msg[1] count, msg = view_packages(data[1], data[2], data[3]) read = raw_input("Would you like to upgrade [Y/n]? ") if read == "Y" or read == "y": create_build_path() os.chdir(build_path) for name, version in zip(data[0], data[2]): prgnam = ("{0}-{1}".format(name, version)) sbo_url = sbo_search_pkg(name) sbo_dwn = SBoLink(sbo_url).tar_gz() src_dwn = SBoGrep(name).source().split() script = sbo_dwn.split("/")[-1] Download(build_path, sbo_dwn).start() sources = dwn_sources(src_dwn) BuildPackage(script, sources, build_path).build() # Searches the package name and version in /tmp to # install.If find two or more packages e.g. to build # tag 2 or 3 will fit most. binary_list = search_in_tmp(prgnam) try: binary = (tmp + max(binary_list)).split() except ValueError: build_FAILED(sbo_url, prgnam) sys.exit() if find_package(name + sp, pkg_path): print("[ {0}Upgrading{1} ] --> {2}".format( YELLOW, ENDC, name)) else: print("[ {0}Installing{1} ] --> {2}".format( GREEN, ENDC, name)) # Use this list to pick out what # packages will be installed self.installed.append(name) PackageManager(binary).upgrade() reference(data[0], data[1], data[2], count[0], count[1], msg[0], msg[1], self.installed) else: print("\nTotal {0} SBo packages are up to date\n".format( len(sbo_list()))) else: sys.stdout.write(self.done) print("\nNo SBo packages found\n") except KeyboardInterrupt: print # new line at exit sys.exit()