def _get_removed(self): """Manage removed packages by extra options """ removed, packages = [], [] if "--tag" in self.extra: for pkg in find_package("", self.meta.pkg_path): for tag in self.binary: if pkg.endswith(tag): removed.append(split_package(pkg)[0]) packages.append(pkg) if not removed: self.msg.pkg_not_found("", "'tag'", "Can't remove", "\n") raise SystemExit(1) else: for pkg in self.binary: name = GetFromInstalled(pkg).name() ver = GetFromInstalled(pkg).version() package = find_package("{0}{1}{2}".format( name, ver, self.meta.sp), self.meta.pkg_path) if pkg and name == pkg: removed.append(pkg) packages.append(package[0]) else: self.msg.pkg_not_found("", pkg, "Can't remove", "\n") raise SystemExit(1) return removed, packages
def views(self, install, comp_sum): """Views packages """ pkg_sum = uni_sum = upg_sum = 0 # fix repositories align repo = self.repo + (" " * (6 - (len(self.repo)))) for pkg, comp in zip(install, comp_sum): pkg_repo = split_package(pkg[:-4]) if find_package(pkg[:-4], self.meta.pkg_path): pkg_sum += 1 COLOR = self.meta.color["GREEN"] elif pkg_repo[0] == GetFromInstalled(pkg_repo[0]).name(): COLOR = self.meta.color["YELLOW"] upg_sum += 1 else: COLOR = self.meta.color["RED"] uni_sum += 1 ver = GetFromInstalled(pkg_repo[0]).version() print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>11}{12}".format( COLOR, pkg_repo[0] + ver, self.meta.color["ENDC"], " " * (23-len(pkg_repo[0] + ver)), pkg_repo[1], " " * (18-len(pkg_repo[1])), pkg_repo[2], " " * (8-len(pkg_repo[2])), pkg_repo[3], " " * (7-len(pkg_repo[3])), repo, comp, " K")).rstrip() return [pkg_sum, upg_sum, uni_sum]
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 choose_upg(packages): """Create checklist to choose packages for upgrade """ selected_packages, data = [], [] if packages: for pkg in packages: name = GetFromInstalled(pkg).name() ver = GetFromInstalled(pkg).version() binary = "{0}{1}".format(name, ver) installed = find_package(binary + _meta_.sp, _meta_.pkg_path)[0] data.append(installed) text = "Press 'spacebar' to unchoose packages from upgrade" title = " Upgrade " backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__) status = True pkgs = DialogUtil(data, text, title, backtitle, status).checklist() pkgs = [] if pkgs is None else pkgs for pkg in pkgs: name = split_package(pkg)[0] if name in packages: selected_packages.append(name) if not selected_packages: raise SystemExit() print("") return selected_packages
def _rmv_pkg(self, package): """Remove one signle package """ removes = [] if GetFromInstalled(package).name() and package not in self.skip: ver = GetFromInstalled(package).version() removes.append(package + ver) self._removepkg(package) return removes
def _rmv_deps(self, dependencies, package): """Remove dependencies """ removes = [] dependencies.append(package) self._check_if_used(dependencies) for dep in dependencies: if dep not in self.skip and GetFromInstalled(dep).name(): ver = GetFromInstalled(dep).version() removes.append(dep + ver) self._removepkg(dep) return removes
def views(self): """ Views packages """ for upg, size in sorted(zip(self.upgrade_all, self.comp_sum)): pkg_repo = split_package(upg[:-4]) color = self.meta.color["RED"] pkg_inst = GetFromInstalled(pkg_repo[0]).name() if pkg_repo[0] == pkg_inst: color = self.meta.color["YELLOW"] ver = GetFromInstalled(pkg_repo[0]).version() print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>12}{12}".format( color, pkg_repo[0] + ver, self.meta.color["ENDC"], " " * (23 - len(pkg_repo[0] + ver)), pkg_repo[1], " " * (18 - len(pkg_repo[1])), pkg_repo[2], " " * (8 - len(pkg_repo[2])), pkg_repo[3], " " * (7 - len(pkg_repo[3])), "Slack", size, " K")).rstrip()
def display(self): """Print the Slackware packages contents """ for pkg in self.binary: name = GetFromInstalled(pkg).name() ver = GetFromInstalled(pkg).version() find = find_package("{0}{1}{2}".format(name, ver, self.meta.sp), self.meta.pkg_path) if find: package = Utils().read_file(self.meta.pkg_path + "".join(find)) print(package) else: message = "Can't dislpay" if len(self.binary) > 1: bol = eol = "" else: bol = eol = "\n" self.msg.pkg_not_found(bol, pkg, message, eol) raise SystemExit(1)
def _view_deps(self, path, package): """View dependencies before remove """ self.size = 0 packages = [] dependencies = (Utils().read_file(path + package)).splitlines() for dep in dependencies: if GetFromInstalled(dep).name(): ver = GetFromInstalled(dep).version() packages.append(dep + ver) else: dependencies.remove(dep) if packages: if "--checklist" in self.extra: deps, dependencies = [], [] text = "Found dependencies for the package {0}".format(package) backtitle = "{0} {1}".format(self.meta.__all__, self.meta.__version__) status = True deps = DialogUtil(packages, text, " Remove ", backtitle, status).checklist() for d in deps: dependencies.append("-".join(d.split("-")[:-1])) self.meta.remove_deps_answer = "y" else: print("") # new line at start self.msg.template(78) print("| Found dependencies for the package {0}:".format( package)) self.msg.template(78) for pkg in packages: find = find_package(pkg + self.meta.sp, self.meta.pkg_path) self._sizes(find[0]) print("| {0}{1}{2}".format(self.meta.color["RED"], pkg, self.meta.color["ENDC"])) self.msg.template(78) self._calc_sizes() print("| {0}Size of removed dependencies {1} {2}{3}".format( self.meta.color["GREY"], round(self.size, 2), self.unit, self.meta.color["ENDC"])) self.msg.template(78) return dependencies
def list_color_tag(self, pkg): """Tag with color installed packages """ name = GetFromInstalled(pkg).name() find = name + self.meta.sp if pkg.endswith(".txz") or pkg.endswith(".tgz"): find = pkg[:-4] if find_package(find, self.meta.pkg_path): pkg = "{0}{1}{2}".format(self.meta.color["GREEN"], pkg, self.meta.color["ENDC"]) return pkg
def view_packages(self, *args): """:View slackbuild packages with version and arch args[0] package color args[1] package args[2] version args[3] arch """ ver = GetFromInstalled(args[1]).version() print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>11}{12}".format( args[0], args[1] + ver, self.meta.color["ENDC"], " " * (23 - len(args[1] + ver)), args[2], " " * (18 - len(args[2])), args[3], " " * (15 - len(args[3])), "", "", "SBo", "", "")).rstrip()
def not_downgrade(self, package): """Don't downgrade packages if repository version is lower than installed""" name = split_package(package)[0] rep_ver = split_package(package)[1] ins_ver = GetFromInstalled(name).version()[1:] if not ins_ver: ins_ver = "0" if LooseVersion(rep_ver) < LooseVersion(ins_ver): self.msg.template(78) print("| Package {0} don't downgrade, " "setting by user".format(name)) self.msg.template(78) return True
def not_downgrade(self, prgnam): """Don't downgrade packages if sbo version is lower than installed""" name = "-".join(prgnam.split("-")[:-1]) sbo_ver = prgnam.split("-")[-1] ins_ver = GetFromInstalled(name).version()[1:] if not ins_ver: ins_ver = "0" if LooseVersion(sbo_ver) < LooseVersion(ins_ver): self.msg.template(78) print("| Package {0} don't downgrade, " "setting by user".format(name)) self.msg.template(78) return True
def _reference_rmvs(self, removes): """Prints all removed packages """ print("") self.msg.template(78) msg_pkg = "package" if len(removes) > 1: msg_pkg = "packages" print("| Total {0} {1} removed".format(len(removes), msg_pkg)) self.msg.template(78) for pkg in removes: if not GetFromInstalled(pkg).name(): print("| Package {0} removed".format(pkg)) else: print("| Package {0} not found".format(pkg)) self.msg.template(78) print("") # new line at end
def tag(self, sbo): """Tag with color green if package already installed, color yellow for packages to upgrade and color red if not installed. """ # split sbo name with version and get name sbo_name = "-".join(sbo.split("-")[:-1]) find = GetFromInstalled(sbo_name).name() if find_package(sbo, self.meta.pkg_path): paint = self.meta.color["GREEN"] self.count_ins += 1 if "--rebuild" in self.flag: self.count_upg += 1 elif sbo_name == find: paint = self.meta.color["YELLOW"] self.count_upg += 1 else: paint = self.meta.color["RED"] self.count_uni += 1 return paint
def _check_if_used(self, removes): """Check package if dependencies for another package before removed""" if "--check-deps" in self.extra: package, dependency, pkg_dep = [], [], [] for pkg in find_package("", self.dep_path): deps = Utils().read_file(self.dep_path + pkg) for rmv in removes: if GetFromInstalled(rmv).name() and rmv in deps.split(): pkg_dep.append( "{0} is dependency of the package --> {1}".format( rmv, pkg)) package.append(pkg) dependency.append(rmv) if package: if "--checklist" in self.extra: text = ("Press 'spacebar' to choose packages for the remove" " exception") backtitle = "{0} {1}".format(self.meta.__all__, self.meta.__version__) status = False choose = DialogUtil(pkg_dep, text, " !!! WARNING !!! ", backtitle, status).checklist() for pkg in choose: self.skip.append(pkg.split()[0]) else: self.msg.template(78) print("| {0}{1}{2}".format( self.meta.color["RED"], " " * 30 + "!!! WARNING !!!", self.meta.color["ENDC"])) self.msg.template(78) for p, d in zip(package, dependency): print("| {0}{1}{2} is dependency of the package --> " "{3}{4}{5}".format(self.meta.color["YELLOW"], d, self.meta.color["ENDC"], self.meta.color["GREEN"], p, self.meta.color["ENDC"])) self.msg.template(78) self._skip_remove()
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]