class SBoNetwork(object): """View SBo site in terminal and also read, build or install packages """ def __init__(self, name, flag): self.name = name self.flag = flag self.meta = _meta_ self.msg = Msg() self.arch = SBoArch().get() self.comp_tar = ".tar.gz" self.choice = "" self.FAULT = "" self.green = self.meta.color["GREEN"] self.red = self.meta.color["RED"] self.yellow = self.meta.color["YELLOW"] self.cyan = self.meta.color["CYAN"] self.grey = self.meta.color["GREY"] self.endc = self.meta.color["ENDC"] self.build_folder = self.meta.build_path self._SOURCES = self.meta._SBo_SOURCES self.msg.reading() self.data = SBoGrep(name="").names() self.case_insensitive() if "--checklist" in self.flag: self.with_checklist() grep = SBoGrep(self.name) self.sbo_files = grep.files() self.blacklist = BlackList().packages(pkgs=self.data, repo="sbo") self.sbo_url = sbo_search_pkg(self.name) if self.sbo_url: self.sbo_desc = grep.description()[len(self.name) + 2:-1] self.source_dwn = grep.source().split() self.sbo_req = grep.requires() self.sbo_dwn = SBoLink(self.sbo_url).tar_gz() self.sbo_version = grep.version() self.dwn_srcs = self.sbo_dwn.split() + self.source_dwn if "--checklist" not in self.flag or not self.sbo_url and self.name: self.msg.done() def view(self): """View SlackBuild package, read or install them from slackbuilds.org """ if self.sbo_url and self.name not in self.blacklist: self.prgnam = ("{0}-{1}".format(self.name, self.sbo_version)) self.view_sbo() while True: self.read_choice() choice = { "r": self.choice_README, "R": self.choice_README, "s": self.choice_SlackBuild, "S": self.choice_SlackBuild, "f": self.choice_info, "F": self.choice_info, "o": self.choice_doinst, "O": self.choice_doinst, "d": self.choice_download, "D": self.choice_download, "download": self.choice_download, "b": self.choice_build, "B": self.choice_build, "build": self.choice_build, "i": self.choice_install, "I": self.choice_install, "install": self.choice_install, "c": self.choice_clear_screen, "C": self.choice_clear_screen, "clear": self.choice_clear_screen, "q": self.choice_quit, "quit": self.choice_quit, "Q": self.choice_quit } try: choice[self.choice]() except KeyError: pass else: self.msg.pkg_not_found("\n", self.name, "Can't view", "\n") def case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.data) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value def read_choice(self): """Return choice """ commands = { "r": "README", "R": "README", "s": "{0}.SlackBuild".format(self.name), "S": "{0}.SlackBuild".format(self.name), "f": "{0}.info".format(self.name), "F": "{0}.info".format(self.name), "o": "doinst.sh", "O": "doinst.sh", "d": "download", "D": "download", "download": "download", "b": "build", "B": "build", "build": "build", "i": "install", "I": "install", "install": "install", "c": "clear", "C": "clear", "clear": "clear", "q": "quit", "quit": "quit", "Q": "quit" } try: message = " Choose an option > " self.choice = raw_input("{0}{1}{2}".format(self.grey, message, self.endc)) except EOFError: print("") raise SystemExit() try: sys.stdout.write("{0}\x1b[1A{1}{2}{3}\n".format( " " * len(message), self.cyan, commands[self.choice], self.endc)) sys.stdout.flush() except KeyError: pass def choice_README(self): """View README file """ README = ReadSBo(self.sbo_url).readme("README") fill = self.fill_pager(README) self.pager(README + fill) def choice_SlackBuild(self): """View .SlackBuild file """ SlackBuild = ReadSBo(self.sbo_url).slackbuild(self.name, ".SlackBuild") fill = self.fill_pager(SlackBuild) self.pager(SlackBuild + fill) def choice_info(self): """View .info file """ info = ReadSBo(self.sbo_url).info(self.name, ".info") fill = self.fill_pager(info) self.pager(info + fill) def choice_doinst(self): """View doinst.sh file """ if "doinst.sh" in self.sbo_files.split(): doinst_sh = ReadSBo(self.sbo_url).doinst("doinst.sh") fill = self.fill_pager(doinst_sh) self.pager(doinst_sh + fill) def choice_download(self): """Download script.tar.gz and sources """ Download(path="", url=self.dwn_srcs, repo="sbo").start() raise SystemExit() def choice_build(self): """Build package """ self.build() delete(self.build_folder) raise SystemExit() def choice_install(self): """Download, build and install package """ if not find_package(self.prgnam, self.meta.pkg_path): self.build() self.install() delete(self.build_folder) raise SystemExit() else: self.msg.template(78) self.msg.pkg_found(self.prgnam) self.msg.template(78) raise SystemExit() def choice_clear_screen(self): """Clear screen """ os.system("clear") self.view() def choice_quit(self): """Quit from choices """ raise SystemExit() def view_sbo(self): """View slackbuild.org """ sbo_url = self.sbo_url.replace("/slackbuilds/", "/repository/") br1, br2, fix_sp = "", "", " " if self.meta.use_colors in ["off", "OFF"]: br1 = "(" br2 = ")" fix_sp = "" print("") # new line at start self.msg.template(78) print("| {0}{1}SlackBuilds Repository{2}".format(" " * 28, self.grey, self.endc)) self.msg.template(78) print("| {0} > {1} > {2}{3}{4}".format(slack_ver(), sbo_url.split("/")[-3].title(), self.cyan, self.name, self.endc)) self.msg.template(78) print("| {0}Package url{1}: {2}".format(self.green, self.endc, sbo_url)) self.msg.template(78) print("| {0}Description: {1}{2}".format(self.green, self.endc, self.sbo_desc)) print("| {0}SlackBuild: {1}{2}".format(self.green, self.endc, self.sbo_dwn.split("/")[-1])) print("| {0}Sources: {1}{2}".format( self.green, self.endc, (", ".join([src.split("/")[-1] for src in self.source_dwn])))) print("| {0}Requirements: {1}{2}".format(self.yellow, self.endc, ", ".join(self.sbo_req))) self.msg.template(78) print("| {0}R{1}{2}EADME View the README file".format( self.red, self.endc, br2)) print("| {0}S{1}{2}lackBuild View the .SlackBuild " "file".format(self.red, self.endc, br2)) print("| In{0}{1}f{2}{3}o{4} View the .info " "file".format(br1, self.red, self.endc, br2, fix_sp)) if "doinst.sh" in self.sbo_files.split(): print("| D{0}{1}o{2}{3}inst.sh{4} View the doinst.sh " "file".format(br1, self.red, self.endc, br2, fix_sp)) print("| {0}D{1}{2}ownload Download this package".format( self.red, self.endc, br2)) print("| {0}B{1}{2}uild Download and build".format( self.red, self.endc, br2)) print("| {0}I{1}{2}nstall Download/Build/Install".format( self.red, self.endc, br2)) print("| {0}C{1}{2}lear Clear screen".format(self.red, self.endc, br2)) print("| {0}Q{1}{2}uit Quit".format(self.red, self.endc, br2)) self.msg.template(78) def with_checklist(self): """Using dialog and checklist option """ data = [] if self.name == "ALL": data = self.data else: for name in self.data: if self.name in name: data.append(name) if data: text = "Press 'spacebar' to choose SlackBuild for view" title = " SlackBuilds.org " backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__) status = False pkg = DialogUtil(data, text, title, backtitle, status).checklist() if pkg and len(pkg) > 1: print("\nslpkg: Error: Choose only one package") raise SystemExit() if pkg is None: raise SystemExit() self.name = "".join(pkg) os.system("clear") def pager(self, text): """Read text """ pydoc.pager(text) def fill_pager(self, page): """Fix pager spaces """ tty_size = os.popen("stty size", "r").read().split() rows = int(tty_size[0]) - 1 lines = sum(1 for line in page.splitlines()) diff = rows - lines fill = "\n" * diff if diff > 0: return fill else: return "" def error_uns(self): """Check if package supported by arch before proceed to install """ self.FAULT = "" UNST = ["UNSUPPORTED", "UNTESTED"] if "".join(self.source_dwn) in UNST: self.FAULT = "".join(self.source_dwn) def build(self): """Only build and create Slackware package """ self.error_uns() if self.FAULT: print("") self.msg.template(78) print("| Package {0} {1} {2} {3}".format(self.prgnam, self.red, self.FAULT, self.endc)) self.msg.template(78) else: sources = [] if not os.path.exists(self.meta.build_path): os.makedirs(self.meta.build_path) if not os.path.exists(self._SOURCES): os.makedirs(self._SOURCES) os.chdir(self.meta.build_path) Download(self.meta.build_path, self.sbo_dwn.split(), repo="sbo").start() Download(self._SOURCES, self.source_dwn, repo="sbo").start() script = self.sbo_dwn.split("/")[-1] for src in self.source_dwn: sources.append(src.split("/")[-1]) BuildPackage(script, sources, self.meta.build_path, auto=False).build() slack_package(self.prgnam) # check if build 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")
class Patches(object): """Upgrade distribution from official Slackware mirrors """ def __init__(self, skip, flag): self.skip = skip self.flag = flag self.meta = _meta_ self.msg = Msg() self.version = self.meta.slack_rel self.patch_path = self.meta.slpkg_tmp_patches self.pkg_for_upgrade = [] self.dwn_links = [] self.upgrade_all = [] self.count_added = 0 self.count_upg = 0 self.upgraded = [] self.installed = [] self.comp_sum = [] self.uncomp_sum = [] self.utils = Utils() self.msg.checking() if self.version == "stable": self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "patches/")).reading() else: self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "")).reading() def start(self): """ Install new patches from official Slackware mirrors """ self.store() self.msg.done() if self.upgrade_all: if "--checklist" in self.flag: self.dialog_checklist() print("\nThese packages need upgrading:\n") self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New Version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) print("Upgrading:") self.views() unit, size = units(self.comp_sum, self.uncomp_sum) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2} will be upgraded and {3} will be " "installed.".format(self.meta.color["GREY"], self.count_upg, self.msg.pkg(self.upgrade_all), self.count_added)) print("Need to get {0} {1} of archives.".format(size[0], unit[0])) print("After this process, {0} {1} of additional disk space " "will be used.{2}".format(size[1], unit[1], self.meta.color["ENDC"])) print("") if self.msg.answer() in ["y", "Y"]: Download(self.patch_path, self.dwn_links, repo="slack").start() self.upgrade_all = self.utils.check_downloaded( self.patch_path, self.upgrade_all) self.upgrade() self.kernel() if self.meta.slackpkg_log in ["on", "ON"]: self.slackpkg_update() self.msg.reference(self.installed, self.upgraded) delete_package(self.patch_path, self.upgrade_all) self.update_lists() else: slack_arch = "" if self.meta.arch == "x86_64": slack_arch = "64" print("\nSlackware{0} '{1}' v{2} distribution is up to " "date\n".format(slack_arch, self.version, slack_ver())) def store(self): """ Store and return packages for upgrading """ data = repo_data(self.PACKAGES_TXT, "slack", self.flag) black = BlackList().packages(pkgs=data[0], repo="slack") for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]): status(0.0003) repo_pkg_name = split_package(name)[0] if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and repo_pkg_name not in black and repo_pkg_name not in self.skip): self.dwn_links.append("{0}{1}/{2}".format( mirrors("", ""), loc, name)) self.comp_sum.append(comp) self.uncomp_sum.append(uncomp) self.upgrade_all.append(name) self.count_upg += 1 if not find_package(repo_pkg_name + self.meta.sp, self.meta.pkg_path): self.count_added += 1 self.count_upg -= 1 return self.count_upg def dialog_checklist(self): """Create checklist to choose packages for upgrade """ data = [] for upg in self.upgrade_all: data.append(upg[:-4]) text = "Press 'spacebar' to unchoose packages from upgrade" title = " Upgrade " backtitle = "{0} {1}".format(self.meta.__all__, self.meta.__version__) status = True pkgs = DialogUtil(data, text, title, backtitle, status).checklist() index = 0 for pkg, comp, uncomp in zip(self.upgrade_all, self.comp_sum, self.uncomp_sum): if pkg[:-4] not in pkgs: self.dwn_links.pop(index) self.upgrade_all.pop(index) self.comp_sum.pop(index) self.uncomp_sum.pop(index) self.count_upg -= 1 del comp, uncomp index -= 1 index += 1 if not self.upgrade_all: raise SystemExit() 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 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 kernel(self): """ Check if kernel upgraded if true then reinstall "lilo" """ for core in self.upgrade_all: if "kernel" in core: if self.meta.default_answer in ["y", "Y"]: answer = self.meta.default_answer else: print("") self.msg.template(78) print("| {0}*** HIGHLY recommended reinstall 'LILO' " "***{1}".format(self.meta.color["RED"], self.meta.color["ENDC"])) self.msg.template(78) try: answer = raw_input("\nThe kernel has been upgraded, " "reinstall `LILO` [y/N]? ") except EOFError: print("") raise SystemExit() if answer in ["y", "Y"]: subprocess.call("lilo", shell=True) break def slackpkg_update(self): """This replace slackpkg ChangeLog.txt file with new from Slackware official mirrors after update distribution. """ NEW_ChangeLog_txt = URL(mirrors("ChangeLog.txt", "")).reading() if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt.old"): os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt.old") if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt"): shutil.copy2(self.meta.slackpkg_lib_path + "ChangeLog.txt", self.meta.slackpkg_lib_path + "ChangeLog.txt.old") os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt") with open(self.meta.slackpkg_lib_path + "ChangeLog.txt", "w") as log: log.write(NEW_ChangeLog_txt) log.close() def update_lists(self): """Update packages list and ChangeLog.txt file after upgrade distribution """ print("{0}Update the package lists ?{1}".format( self.meta.color["GREEN"], self.meta.color["ENDC"])) print("=" * 79) if self.msg.answer() in ["y", "Y"]: Update().repository(["slack"])
class TrackingDeps(object): """View tree of dependencies and also highlight packages with color green if already installed and color red if not installed. """ def __init__(self, name, repo, flag): self.name = name self.repo = repo self.flag = flag self.meta = _meta_ self.msg = Msg() self.green = self.meta.color["GREEN"] self.yellow = self.meta.color["YELLOW"] self.cyan = self.meta.color["CYAN"] self.red = self.meta.color["RED"] self.endc = self.meta.color["ENDC"] self.requires = [] self.dependencies = [] self.dependencies_list = [] self.deps_dict = {} for i in range(0, len(self.flag)): if self.flag[i].startswith("--graph="): self.image = self.flag[i].split("=")[1] self.flag[i] = "--graph=" def run(self): """Run tracking dependencies """ self.msg.resolving() self.repositories() if self.find_pkg: self.dependencies_list.reverse() self.requires = Utils().dimensional_list(self.dependencies_list) self.dependencies = Utils().remove_dbs(self.requires) if self.dependencies == []: self.dependencies = ["No dependencies"] if "--graph=" in self.flag: self.deps_tree() self.msg.done() pkg_len = len(self.name) + 24 print("") # new line at start self.msg.template(pkg_len) print("| Package {0}{1}{2} dependencies :".format( self.cyan, self.name, self.endc)) self.msg.template(pkg_len) print("\\") print(" +---{0}[ Tree of dependencies ]{1}".format(self.yellow, self.endc)) index = 0 for pkg in self.dependencies: if "--check-deps" in self.flag: used = self.check_used(pkg) self.deps_used(pkg, used) used = "{0} {1}{2}{3}".format( "is dependency -->", self.cyan, ", ".join(used), self.endc) else: used = "" index += 1 installed = "" if find_package(pkg + self.meta.sp, self.meta.pkg_path): if self.meta.use_colors in ["off", "OFF"]: installed = "* " print(" |") print(" {0}{1}: {2}{3}{4} {5}{6}".format( "+--", index, self.green, pkg, self.endc, installed, used)) else: print(" |") print(" {0}{1}: {2}{3}{4} {5}".format( "+--", index, self.red, pkg, self.endc, installed)) if self.meta.use_colors in ["off", "OFF"]: print("\n * = Installed\n") else: print("") # new line at end if "--graph=" in self.flag: self.graph() else: self.msg.done() print("\nNo package was found to match\n") def repositories(self): """Get dependencies by repositories """ if self.repo == "sbo": self.sbo_case_insensitive() self.find_pkg = sbo_search_pkg(self.name) if self.find_pkg: self.dependencies_list = Requires(self.flag).sbo(self.name) else: PACKAGES_TXT = Utils().read_file( self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(self.repo)) self.names = Utils().package_name(PACKAGES_TXT) self.bin_case_insensitive() self.find_pkg = search_pkg(self.name, self.repo) if self.find_pkg: self.black = BlackList().packages(self.names, self.repo) self.dependencies_list = Dependencies( self.names, self.repo, self.black).binary(self.name, self.flag) def sbo_case_insensitive(self): """Matching packages distinguish between uppercase and lowercase for sbo repository """ if "--case-ins" in self.flag: data = SBoGrep(name="").names() data_dict = Utils().case_sensitive(data) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value def bin_case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.names) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value def graph(self): """Drawing image dependencies map """ Graph(self.image).dependencies(self.deps_dict) def check_used(self, pkg): """Check if dependencies used """ used = [] dep_path = self.meta.log_path + "dep/" logs = find_package("", dep_path) for log in logs: deps = Utils().read_file(dep_path + log) for dep in deps.splitlines(): if pkg == dep: used.append(log) return used def deps_tree(self): """Package dependencies image map file """ dependencies = self.dependencies + [self.name] if self.repo == "sbo": for dep in dependencies: deps = Requires(flag="").sbo(dep) if dep not in self.deps_dict.values(): self.deps_dict[dep] = Utils().dimensional_list(deps) else: for dep in dependencies: deps = Dependencies(self.names, self.repo, self.black).binary(dep, flag="") if dep not in self.deps_dict.values(): self.deps_dict[dep] = Utils().dimensional_list(deps) def deps_used(self, pkg, used): """Create dependencies dictionary """ if find_package(pkg + self.meta.sp, self.meta.pkg_path): if pkg not in self.deps_dict.values(): self.deps_dict[pkg] = used else: self.deps_dict[pkg] += used
class SBoInstall(object): """Build and install SBo packages with all dependencies """ def __init__(self, slackbuilds, flag): self.slackbuilds = slackbuilds pkg_security(self.slackbuilds) self.flag = flag self.meta = _meta_ self.msg = Msg() self.arch = SBoArch().get() self.build_folder = self.meta.build_path self._SOURCES = self.meta.SBo_SOURCES for fl in self.flag: if fl.startswith("--directory-prefix="): self.build_folder = fl.split("=")[1] if not self.build_folder.endswith("/"): self.build_folder += "/" self.unst = ["UNSUPPORTED", "UNTESTED"] self.master_packages = [] self.deps = [] self.dependencies = [] self.package_not_found = [] self.package_found = [] self.deps_dict = {} self.answer = "" self.match = False self.count_ins = 0 self.count_upg = 0 self.count_uni = 0 self.msg.reading() self.data = SBoGrep(name="").names() self.blacklist = BlackList().packages(pkgs=self.data, repo="sbo") def start(self, is_upgrade): """Start view, build and install SBo packages """ tagc = "" self.is_upgrade = is_upgrade self.case_insensitive() for _sbo in self.slackbuilds: status(0.03) if _sbo in self.data and _sbo not in self.blacklist: sbo_deps = Requires(self.flag).sbo(_sbo) self.deps += sbo_deps self.deps_dict[_sbo] = self.one_for_all(sbo_deps) self.package_found.append(_sbo) else: self.package_not_found.append(_sbo) self.update_deps() if not self.package_found: self.match = True self.matching() self.master_packages, mas_src = self.sbo_version_source( self.package_found) self.msg.done() if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off" and not self.match): self.msg.resolving() self.dependencies, dep_src = self.sbo_version_source( self.one_for_all(self.deps)) if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off" and not self.match): self.msg.done() self.clear_masters() if self.package_found: print("\nThe following packages will be automatically " "installed or upgraded \nwith new version:\n") self.top_view() self.msg.upg_inst(self.is_upgrade) # view master packages for sbo, arch in zip(self.master_packages, mas_src): tagc = self.tag(sbo) name = "-".join(sbo.split("-")[:-1]) self.view_packages(tagc, name, sbo.split("-")[-1], self.select_arch(arch)) self.view_installing_for_deps() # view dependencies for dep, arch in zip(self.dependencies, dep_src): tagc = self.tag(dep) name = "-".join(dep.split("-")[:-1]) self.view_packages(tagc, name, dep.split("-")[-1], self.select_arch(arch)) count_total = sum([self.count_ins, self.count_upg, self.count_uni]) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(self.meta.color["GREY"], count_total, self.msg.pkg(count_total))) print("{0} {1} will be installed, {2} already installed and " "{3} {4}".format(self.count_uni, self.msg.pkg(self.count_uni), self.count_ins, self.count_upg, self.msg.pkg(self.count_upg))) print("will be upgraded.{0}\n".format(self.meta.color["ENDC"])) self.continue_to_install() else: self.msg.not_found(self.is_upgrade) raise SystemExit(1) def case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.data) for name in self.slackbuilds: index = self.slackbuilds.index(name) for key, value in data_dict.iteritems(): if key == name.lower(): self.slackbuilds[index] = value def update_deps(self): """Update dependencies dictionary with all package """ onelist, dependencies = [], [] onelist = Utils().dimensional_list(self.deps) dependencies = Utils().remove_dbs(onelist) for dep in dependencies: deps = Requires(self.flag).sbo(dep) self.deps_dict[dep] = self.one_for_all(deps) def continue_to_install(self): """Continue to install ? """ if (self.count_uni > 0 or self.count_upg > 0 or "--download-only" in self.flag or "--rebuild" in self.flag): if self.master_packages and self.msg.answer() in ["y", "Y"]: installs, upgraded = self.build_install() if "--download-only" in self.flag: raise SystemExit() self.msg.reference(installs, upgraded) write_deps(self.deps_dict) delete(self.build_folder) def view_installing_for_deps(self): """View installing message for dependencies """ if not self.match and self.dependencies: print("Installing for dependencies:") def clear_masters(self): """Clear master slackbuilds if already exist in dependencies or if added to install two or more times """ self.master_packages = Utils().remove_dbs(self.master_packages) for mas in self.master_packages: if mas in self.dependencies: self.master_packages.remove(mas) def matching(self): """Return found matching SBo packages """ for sbo in self.package_not_found: for pkg in self.data: if sbo in pkg and pkg not in self.blacklist: self.package_found.append(pkg) def sbo_version_source(self, slackbuilds): """Create sbo name with version """ sbo_versions, sources = [], [] for sbo in slackbuilds: status(0.02) sbo_ver = "{0}-{1}".format(sbo, SBoGrep(sbo).version()) sbo_versions.append(sbo_ver) sources.append(SBoGrep(sbo).source()) return [sbo_versions, sources] def one_for_all(self, deps): """Because there are dependencies that depend on other dependencies are created lists into other lists. Thus creating this loop create one-dimensional list and remove double packages from dependencies. """ requires, dependencies = [], [] deps.reverse() # Inverting the list brings the # dependencies in order to be installed. requires = Utils().dimensional_list(deps) dependencies = Utils().remove_dbs(requires) return dependencies def top_view(self): """View top template """ self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) 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 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 select_arch(self, src): """Looks if sources unsupported or untested from arch else select arch. """ arch = self.arch for item in self.unst: if item in src: arch = item return arch def filenames(self, sources): """Return filenames from sources links """ filename = [] for src in sources: filename.append(src.split("/")[-1]) return filename 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 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 sbosrcarsh(self, prgnam, sbo_link, src_link): """Alternative repository for sbo sources""" sources = [] name = "-".join(prgnam.split("-")[:-1]) category = "{0}/{1}/".format(sbo_link.split("/")[-2], name) for link in src_link: source = link.split("/")[-1] sources.append("{0}{1}{2}".format(self.meta.sbosrcarch_link, category, source)) return sources
class TrackingDeps(object): """View tree of dependencies and also highlight packages with color green if already installed and color red if not installed. """ def __init__(self, name, repo, flag): self.name = name self.repo = repo self.flag = flag self.meta = _meta_ self.msg = Msg() self.green = self.meta.color["GREEN"] self.yellow = self.meta.color["YELLOW"] self.cyan = self.meta.color["CYAN"] self.red = self.meta.color["RED"] self.endc = self.meta.color["ENDC"] self.requires = [] self.dependencies = [] self.dependencies_list = [] self.deps_dict = {} for i in range(0, len(self.flag)): if self.flag[i].startswith("--graph="): self.image = self.flag[i].split("=")[1] self.flag[i] = "--graph=" def run(self): """Run tracking dependencies """ self.msg.resolving() self.repositories() if self.find_pkg: self.dependencies_list.reverse() self.requires = Utils().dimensional_list(self.dependencies_list) self.dependencies = Utils().remove_dbs(self.requires) if self.dependencies == []: self.dependencies = ["No dependencies"] if "--graph=" in self.flag: self.deps_tree() self.msg.done() pkg_len = len(self.name) + 24 print("") # new line at start self.msg.template(pkg_len) print("| Package {0}{1}{2} dependencies :".format( self.cyan, self.name, self.endc)) self.msg.template(pkg_len) print("\\") print(" +---{0}[ Tree of dependencies ]{1}".format( self.yellow, self.endc)) index = 0 for pkg in self.dependencies: if "--check-deps" in self.flag: used = self.check_used(pkg) self.deps_used(pkg, used) used = "{0} {1}{2}{3}".format("is dependency -->", self.cyan, ", ".join(used), self.endc) else: used = "" index += 1 installed = "" if find_package(pkg + self.meta.sp, self.meta.pkg_path): if self.meta.use_colors in ["off", "OFF"]: installed = "* " print(" |") print(" {0}{1}: {2}{3}{4} {5}{6}".format( "+--", index, self.green, pkg, self.endc, installed, used)) else: print(" |") print(" {0}{1}: {2}{3}{4} {5}".format( "+--", index, self.red, pkg, self.endc, installed)) if self.meta.use_colors in ["off", "OFF"]: print("\n * = Installed\n") else: print("") # new line at end if "--graph=" in self.flag: self.graph() else: self.msg.done() print("\nNo package was found to match\n") raise SystemExit(1) def repositories(self): """Get dependencies by repositories """ if self.repo == "sbo": self.sbo_case_insensitive() self.find_pkg = sbo_search_pkg(self.name) if self.find_pkg: self.dependencies_list = Requires(self.flag).sbo(self.name) else: PACKAGES_TXT = Utils().read_file( self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(self.repo)) self.names = Utils().package_name(PACKAGES_TXT) self.bin_case_insensitive() self.find_pkg = search_pkg(self.name, self.repo) if self.find_pkg: self.black = BlackList().packages(self.names, self.repo) self.dependencies_list = Dependencies(self.repo, self.black).binary( self.name, self.flag) def sbo_case_insensitive(self): """Matching packages distinguish between uppercase and lowercase for sbo repository """ if "--case-ins" in self.flag: data = SBoGrep(name="").names() data_dict = Utils().case_sensitive(data) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value def bin_case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.names) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value def graph(self): """Drawing image dependencies map """ Graph(self.image).dependencies(self.deps_dict) def check_used(self, pkg): """Check if dependencies used """ used = [] dep_path = self.meta.log_path + "dep/" logs = find_package("", dep_path) for log in logs: deps = Utils().read_file(dep_path + log) for dep in deps.splitlines(): if pkg == dep: used.append(log) return used def deps_tree(self): """Package dependencies image map file """ dependencies = self.dependencies + [self.name] if self.repo == "sbo": for dep in dependencies: deps = Requires(flag="").sbo(dep) if dep not in self.deps_dict.values(): self.deps_dict[dep] = Utils().dimensional_list(deps) else: for dep in dependencies: deps = Dependencies(self.repo, self.black).binary(dep, flag="") if dep not in self.deps_dict.values(): self.deps_dict[dep] = Utils().dimensional_list(deps) def deps_used(self, pkg, used): """Create dependencies dictionary """ if find_package(pkg + self.meta.sp, self.meta.pkg_path): if pkg not in self.deps_dict.values(): self.deps_dict[pkg] = used else: self.deps_dict[pkg] += used
class SBoInstall(object): """Build and install SBo packages with all dependencies """ def __init__(self, slackbuilds, flag): self.slackbuilds = slackbuilds self.flag = flag self.meta = _meta_ self.msg = Msg() self.arch = SBoArch().get() self.build_folder = self.meta.build_path for fl in self.flag: if fl.startswith("--directory-prefix="): self.build_folder = fl.split("=")[1] if not self.build_folder.endswith("/"): self.build_folder += "/" self.unst = ["UNSUPPORTED", "UNTESTED"] self.master_packages = [] self.deps = [] self.dependencies = [] self.package_not_found = [] self.package_found = [] self.deps_dict = {} self.answer = "" self.match = False self.count_ins = 0 self.count_upg = 0 self.count_uni = 0 self.msg.reading() self.data = SBoGrep(name="").names() self.blacklist = BlackList().packages(pkgs=self.data, repo="sbo") def start(self, if_upgrade): """Start view, build and install SBo packages """ tagc = "" self.if_upgrade = if_upgrade self.case_insensitive() for _sbo in self.slackbuilds: status(0.03) if _sbo in self.data and _sbo not in self.blacklist: sbo_deps = Requires(self.flag).sbo(_sbo) self.deps += sbo_deps self.deps_dict[_sbo] = self.one_for_all(sbo_deps) self.package_found.append(_sbo) else: self.package_not_found.append(_sbo) self.update_deps() if not self.package_found: self.match = True self.matching() self.master_packages, mas_src = self.sbo_version_source( self.package_found) self.msg.done() if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off" and not self.match): self.msg.resolving() self.dependencies, dep_src = self.sbo_version_source( self.one_for_all(self.deps)) if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off" and not self.match): self.msg.done() self.clear_masters() if self.package_found: print("\nThe following packages will be automatically " "installed or upgraded \nwith new version:\n") self.top_view() self.msg.upg_inst(self.if_upgrade) # view master packages for sbo, arch in zip(self.master_packages, mas_src): tagc = self.tag(sbo) name = "-".join(sbo.split("-")[:-1]) self.view_packages(tagc, name, sbo.split("-")[-1], self.select_arch(arch)) self.view_installing_for_deps() # view dependencies for dep, arch in zip(self.dependencies, dep_src): tagc = self.tag(dep) name = "-".join(dep.split("-")[:-1]) self.view_packages(tagc, name, dep.split("-")[-1], self.select_arch(arch)) count_total = sum([self.count_ins, self.count_upg, self.count_uni]) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format( self.meta.color["GREY"], count_total, self.msg.pkg(count_total))) print("{0} {1} will be installed, {2} already installed and " "{3} {4}".format(self.count_uni, self.msg.pkg(self.count_uni), self.count_ins, self.count_upg, self.msg.pkg(self.count_upg))) print("will be upgraded.{0}\n".format(self.meta.color["ENDC"])) self.continue_to_install() else: self.msg.not_found(self.if_upgrade) def case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.data) for name in self.slackbuilds: index = self.slackbuilds.index(name) for key, value in data_dict.iteritems(): if key == name.lower(): self.slackbuilds[index] = value def update_deps(self): """Update dependencies dictionary with all package """ onelist, dependencies = [], [] onelist = Utils().dimensional_list(self.deps) dependencies = Utils().remove_dbs(onelist) for dep in dependencies: deps = Requires(self.flag).sbo(dep) self.deps_dict[dep] = self.one_for_all(deps) def continue_to_install(self): """Continue to install ? """ if (self.count_uni > 0 or self.count_upg > 0 or "--download-only" in self.flag): if self.master_packages and self.msg.answer() in ["y", "Y"]: installs, upgraded = self.build_install() if "--download-only" in self.flag: raise SystemExit() self.msg.reference(installs, upgraded) write_deps(self.deps_dict) delete(self.build_folder) def view_installing_for_deps(self): """View installing message for dependencies """ if not self.match and self.dependencies: print("Installing for dependencies:") def clear_masters(self): """Clear master slackbuilds if already exist in dependencies or if added to install two or more times """ self.master_packages = Utils().remove_dbs(self.master_packages) for mas in self.master_packages: if mas in self.dependencies: self.master_packages.remove(mas) def matching(self): """Return found matching SBo packages """ for sbo in self.package_not_found: for pkg in self.data: if sbo in pkg and pkg not in self.blacklist: self.package_found.append(pkg) def sbo_version_source(self, slackbuilds): """Create sbo name with version """ sbo_versions, sources = [], [] for sbo in slackbuilds: status(0.02) sbo_ver = "{0}-{1}".format(sbo, SBoGrep(sbo).version()) sbo_versions.append(sbo_ver) sources.append(SBoGrep(sbo).source()) return [sbo_versions, sources] def one_for_all(self, deps): """Because there are dependencies that depend on other dependencies are created lists into other lists. Thus creating this loop create one-dimensional list and remove double packages from dependencies. """ requires, dependencies = [], [] deps.reverse() # Inverting the list brings the # dependencies in order to be installed. requires = Utils().dimensional_list(deps) dependencies = Utils().remove_dbs(requires) return dependencies def top_view(self): """View top template """ self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) 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 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 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 select_arch(self, src): """Looks if sources unsupported or untested from arch else select arch. """ arch = self.arch for item in self.unst: if item in src: arch = item return arch def filenames(self, sources): """Return filenames from sources links """ filename = [] for src in sources: filename.append(src.split("/")[-1]) return filename 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) os.chdir(self.build_folder) for prgnam in slackbuilds: 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: 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] dwn_srcs = sbo_link.split() + src_link Download(self.build_folder, dwn_srcs, 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 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) PackageManager(binary).upgrade(flag="--install-new") return installs, upgraded
class BinaryInstall(object): """Install binaries packages with all dependencies from repository """ def __init__(self, packages, repo, flag): self.packages = packages self.repo = repo self.flag = flag self.meta = _meta_ self.msg = Msg() self.version = self.meta.slack_rel self.tmp_path = self.meta.slpkg_tmp_packages for fl in self.flag: if fl.startswith("--directory-prefix="): self.tmp_path = fl.split("=")[1] if not self.tmp_path.endswith("/"): self.tmp_path += "/" self.dwn, self.dep_dwn = [], [] self.install, self.dep_install = [], [] self.comp_sum, self.dep_comp_sum = [], [] self.uncomp_sum, self.dep_uncomp_sum = [], [] self.dependencies = [] self.deps_dict = {} self.answer = "" self.msg.reading() self.PACKAGES_TXT, self.mirror = RepoInit(self.repo).fetch() self.data = repo_data(self.PACKAGES_TXT, self.repo, self.flag) self.blacklist = BlackList().packages(self.data[0], self.repo) def start(self, if_upgrade): """ Install packages from official Slackware distribution """ self.case_insensitive() # fix if packages is for upgrade self.if_upgrade = if_upgrade mas_sum = dep_sum = sums = [0, 0, 0] self.msg.done() self.dependencies = self.resolving_deps() self.update_deps() (self.dep_dwn, self.dep_install, self.dep_comp_sum, self.dep_uncomp_sum) = self.store(self.dependencies) self.clear_masters() (self.dwn, self.install, self.comp_sum, self.uncomp_sum) = self.store(self.packages) if (self.meta.rsl_deps in ["on", "ON"] and "--resolve-off" not in self.flag): self.msg.done() if self.install: print("\nThe following packages will be automatically " "installed or upgraded \nwith new version:\n") self.top_view() self.msg.upg_inst(self.if_upgrade) mas_sum = self.views(self.install, self.comp_sum) if self.dependencies: print("Installing for dependencies:") dep_sum = self.views(self.dep_install, self.dep_comp_sum) # sums[0] --> installed # sums[1] --> upgraded # sums[2] --> uninstall sums = [sum(i) for i in zip(mas_sum, dep_sum)] unit, size = units(self.comp_sum + self.dep_comp_sum, self.uncomp_sum + self.dep_uncomp_sum) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(self.meta.color["GREY"], sum(sums), self.msg.pkg(sum(sums)))) print("{0} {1} will be installed, {2} will be upgraded and " "{3} will be reinstalled.".format(sums[2], self.msg.pkg(sums[2]), sums[1], sums[0])) print("Need to get {0} {1} of archives.".format(size[0], unit[0])) print("After this process, {0} {1} of additional disk " "space will be used.{2}".format(size[1], unit[1], self.meta.color["ENDC"])) print("") if self.msg.answer() in ["y", "Y"]: self.install.reverse() Download(self.tmp_path, self.dep_dwn + self.dwn, self.repo).start() if "--download-only" in self.flag: raise SystemExit() self.dep_install = Utils().check_downloaded( self.tmp_path, self.dep_install) self.install = Utils().check_downloaded( self.tmp_path, self.install) ins, upg = self.install_packages() self.msg.reference(ins, upg) write_deps(self.deps_dict) delete_package(self.tmp_path, self.install) else: self.msg.not_found(self.if_upgrade) def case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data = [] data = Utils().package_name(self.PACKAGES_TXT) data_dict = Utils().case_sensitive(data) for pkg in self.packages: index = self.packages.index(pkg) for key, value in data_dict.iteritems(): if key == pkg.lower(): self.packages[index] = value def update_deps(self): """Update dependencies dictionary with all package """ for dep in self.dependencies: deps = Utils().dimensional_list(Dependencies( self.PACKAGES_TXT, self.repo, self.blacklist).binary( dep, self.flag)) self.deps_dict[dep] = deps def clear_masters(self): """Clear master packages if already exist in dependencies or if added to install two or more times """ packages = [] for mas in Utils().remove_dbs(self.packages): if mas not in self.dependencies: packages.append(mas) self.packages = packages 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 os.path.isfile(self.meta.pkg_path + inst[:-4]): print("[ {0}reinstalling{1} ] --> {2}".format( self.meta.color["GREEN"], self.meta.color["ENDC"], inst)) installs.append(pkg_ver) PackageManager(package).upgrade("--reinstall") elif 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) 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 checksums(self, install): """Checksums before install """ check_md5(pkg_checksum(install, self.repo), self.tmp_path + install) def resolving_deps(self): """Return package dependencies """ requires = [] if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off"): self.msg.resolving() for dep in self.packages: status(0.05) dependencies = [] dependencies = Utils().dimensional_list(Dependencies( self.PACKAGES_TXT, self.repo, self.blacklist).binary( dep, self.flag)) requires += dependencies self.deps_dict[dep] = Utils().remove_dbs(dependencies) return Utils().remove_dbs(requires) 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 top_view(self): """Print packages status bar """ self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New Version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) def store(self, packages): """Store and return packages for install """ dwn, install, comp_sum, uncomp_sum = ([] for i in range(4)) # name = data[0] # location = data[1] # size = data[2] # unsize = data[3] for pkg in packages: for pk, loc, comp, uncomp in zip(self.data[0], self.data[1], self.data[2], self.data[3]): if (pk and pkg == split_package(pk)[0] and pk not in install and split_package(pk)[0] not in self.blacklist): dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk)) install.append(pk) comp_sum.append(comp) uncomp_sum.append(uncomp) if not install: for pkg in packages: for pk, loc, comp, uncomp in zip(self.data[0], self.data[1], self.data[2], self.data[3]): name = split_package(pk)[0] if (pk and pkg in name and name not in self.blacklist): dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk)) install.append(pk) comp_sum.append(comp) uncomp_sum.append(uncomp) dwn.reverse() install.reverse() comp_sum.reverse() uncomp_sum.reverse() return [dwn, install, comp_sum, uncomp_sum]
class Patches(object): """Upgrade distribution from official Slackware mirrors """ def __init__(self, skip, flag): self.skip = skip self.flag = flag self.meta = _meta_ self.msg = Msg() self.version = self.meta.slack_rel self.patch_path = self.meta.slpkg_tmp_patches self.pkg_for_upgrade = [] self.dwn_links = [] self.upgrade_all = [] self.count_added = 0 self.count_upg = 0 self.upgraded = [] self.installed = [] self.comp_sum = [] self.uncomp_sum = [] self.utils = Utils() self.msg.checking() if self.version == "stable": self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "patches/")).reading() else: self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "")).reading() def start(self): """ Install new patches from official Slackware mirrors """ self.store() self.msg.done() if self.upgrade_all: if "--checklist" in self.flag: self.dialog_checklist() print("\nThese packages need upgrading:\n") self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New Version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) print("Upgrading:") self.views() unit, size = units(self.comp_sum, self.uncomp_sum) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2} will be upgraded and {3} will be " "installed.".format(self.meta.color["GREY"], self.count_upg, self.msg.pkg(self.upgrade_all), self.count_added)) print("Need to get {0} {1} of archives.".format(size[0], unit[0])) print("After this process, {0} {1} of additional disk space " "will be used.{2}".format(size[1], unit[1], self.meta.color["ENDC"])) print("") if self.msg.answer() in ["y", "Y"]: Download(self.patch_path, self.dwn_links, repo="slack").start() self.upgrade_all = self.utils.check_downloaded( self.patch_path, self.upgrade_all) self.upgrade() self.kernel() if self.meta.slackpkg_log in ["on", "ON"]: self.slackpkg_update() self.msg.reference(self.installed, self.upgraded) delete_package(self.patch_path, self.upgrade_all) self.update_lists() else: slack_arch = "" if self.meta.arch == "x86_64": slack_arch = "64" print("\nSlackware{0} '{1}' v{2} distribution is up to " "date\n".format(slack_arch, self.version, slack_ver())) def store(self): """ Store and return packages for upgrading """ data = repo_data(self.PACKAGES_TXT, "slack", self.flag) black = BlackList().packages(pkgs=data[0], repo="slack") for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]): status(0.0003) repo_pkg_name = split_package(name)[0] if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and repo_pkg_name not in black and repo_pkg_name not in self.skip): self.dwn_links.append("{0}{1}/{2}".format(mirrors("", ""), loc, name)) self.comp_sum.append(comp) self.uncomp_sum.append(uncomp) self.upgrade_all.append(name) self.count_upg += 1 if not find_package(repo_pkg_name + self.meta.sp, self.meta.pkg_path): self.count_added += 1 self.count_upg -= 1 return self.count_upg def dialog_checklist(self): """Create checklist to choose packages for upgrade """ data = [] for upg in self.upgrade_all: data.append(upg[:-4]) text = "Press 'spacebar' to unchoose packages from upgrade" title = "Upgrade" backtitle = "{0} {1}".format(self.meta.__all__, self.meta.__version__) status = True pkgs = DialogUtil(data, text, title, backtitle, status).checklist() index = 0 for pkg, comp, uncomp in zip(self.upgrade_all, self.comp_sum, self.uncomp_sum): if pkg[:-4] not in pkgs: self.dwn_links.pop(index) self.upgrade_all.pop(index) self.comp_sum.pop(index) self.uncomp_sum.pop(index) self.count_upg -= 1 index -= 1 index += 1 if not self.upgrade_all: raise SystemExit() 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 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 kernel(self): """ Check if kernel upgraded if true then reinstall "lilo" """ for core in self.upgrade_all: if "kernel" in core: if self.meta.default_answer in ["y", "Y"]: answer = self.meta.default_answer else: print("") self.msg.template(78) print("| {0}*** HIGHLY recommended reinstall 'LILO' " "***{1}".format(self.meta.color["RED"], self.meta.color["ENDC"])) self.msg.template(78) try: answer = raw_input("\nThe kernel has been upgraded, " "reinstall `LILO` [y/N]? ") except EOFError: print("") raise SystemExit() if answer in ["y", "Y"]: subprocess.call("lilo", shell=True) break def slackpkg_update(self): """This replace slackpkg ChangeLog.txt file with new from Slackware official mirrors after update distribution. """ NEW_ChangeLog_txt = URL(mirrors("ChangeLog.txt", "")).reading() if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt.old"): os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt.old") if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt"): shutil.copy2(self.meta.slackpkg_lib_path + "ChangeLog.txt", self.meta.slackpkg_lib_path + "ChangeLog.txt.old") os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt") with open(self.meta.slackpkg_lib_path + "ChangeLog.txt", "w") as log: log.write(NEW_ChangeLog_txt) log.close() def update_lists(self): """Update packages list and ChangeLog.txt file after upgrade distribution """ print("{0}Update package lists ?{1}".format(self.meta.color["GREEN"], self.meta.color["ENDC"])) print("=" * 79) if self.msg.answer() in ["y", "Y"]: Update().repository(["slack"])
class BinaryInstall(object): """Install binaries packages with all dependencies from repository """ def __init__(self, packages, repo, flag): self.packages = packages pkg_security(packages) self.repo = repo self.flag = flag self.meta = _meta_ self.msg = Msg() self.version = self.meta.slack_rel self.tmp_path = self.meta.slpkg_tmp_packages for fl in self.flag: if fl.startswith("--directory-prefix="): self.tmp_path = fl.split("=")[1] if not self.tmp_path.endswith("/"): self.tmp_path += "/" self.dwn, self.dep_dwn = [], [] self.install, self.dep_install = [], [] self.comp_sum, self.dep_comp_sum = [], [] self.uncomp_sum, self.dep_uncomp_sum = [], [] self.dependencies = [] self.deps_dict = {} self.answer = "" self.msg.reading() self.PACKAGES_TXT, self.mirror = RepoInit(self.repo).fetch() self.data = repo_data(self.PACKAGES_TXT, self.repo, self.flag) self.repo_pkg_names = [] for name in self.data[0]: self.repo_pkg_names.append(split_package(name)[0]) self.blacklist = BlackList().packages(self.data[0], self.repo) self.matching = False def start(self, is_upgrade): """ Install packages from official Slackware distribution """ self.case_insensitive() # fix if packages is for upgrade self.is_upgrade = is_upgrade mas_sum = dep_sum = sums = [0, 0, 0] self.msg.done() self.dependencies = self.resolving_deps() self.update_deps() (self.dep_dwn, self.dep_install, self.dep_comp_sum, self.dep_uncomp_sum) = self.store(self.dependencies) self.clear_masters() (self.dwn, self.install, self.comp_sum, self.uncomp_sum) = self.store(self.packages) if (self.meta.rsl_deps in ["on", "ON"] and "--resolve-off" not in self.flag): self.msg.done() if self.install: print("\nThe following packages will be automatically " "installed or upgraded \nwith new version:\n") if self.matching: self.msg.matching(self.packages) self.top_view() self.msg.upg_inst(self.is_upgrade) mas_sum = self.views(self.install, self.comp_sum) if self.dependencies: print("Installing for dependencies:") dep_sum = self.views(self.dep_install, self.dep_comp_sum) # sums[0] --> installed # sums[1] --> upgraded # sums[2] --> uninstall sums = [sum(i) for i in zip(mas_sum, dep_sum)] unit, size = units(self.comp_sum + self.dep_comp_sum, self.uncomp_sum + self.dep_uncomp_sum) print("\nInstalling summary") print("=" * 79) print("{0}Total {1} {2}.".format(self.meta.color["GREY"], sum(sums), self.msg.pkg(sum(sums)))) print("{0} {1} will be installed, {2} will be upgraded and " "{3} will be reinstalled.".format(sums[2], self.msg.pkg(sums[2]), sums[1], sums[0])) print("Need to get {0} {1} of archives.".format(size[0], unit[0])) print("After this process, {0} {1} of additional disk " "space will be used.{2}".format(size[1], unit[1], self.meta.color["ENDC"])) print("") self.if_all_installed() if self.msg.answer() in ["y", "Y"]: for inst, dwn in zip(self.dep_install + self.install, self.dep_dwn + self.dwn): if (self.meta.not_downgrade == "on" and self.not_downgrade(inst) is True): continue if (not os.path.isfile(self.meta.pkg_path + inst[:-4]) or "--download-only" in self.flag or "--reinstall" in self.flag): Download(self.tmp_path, dwn.split(), self.repo).start() else: self.msg.template(78) self.msg.pkg_found(inst) self.msg.template(78) if "--download-only" in self.flag: raise SystemExit() self.dep_install = Utils().check_downloaded( self.tmp_path, self.dep_install) self.install = Utils().check_downloaded( self.tmp_path, self.install) ins, upg = self.install_packages() self.msg.reference(ins, upg) write_deps(self.deps_dict) delete_package(self.tmp_path, self.dep_install + self.install) else: self.msg.not_found(self.is_upgrade) raise SystemExit(1) def if_all_installed(self): """Check if all packages is already installed """ count_inst = 0 for inst in (self.dep_install + self.install): if (os.path.isfile(self.meta.pkg_path + inst[:-4]) and "--download-only" not in self.flag): count_inst += 1 if (count_inst == len(self.dep_install + self.install) and "--reinstall" not in self.flag): raise SystemExit() def case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data = [] data = Utils().package_name(self.PACKAGES_TXT) data_dict = Utils().case_sensitive(data) for pkg in self.packages: index = self.packages.index(pkg) for key, value in data_dict.iteritems(): if key == pkg.lower(): self.packages[index] = value def update_deps(self): """Update dependencies dictionary with all package """ for dep in self.dependencies: deps = Utils().dimensional_list(Dependencies( self.repo, self.blacklist).binary( dep, self.flag)) self.deps_dict[dep] = deps def clear_masters(self): """Clear master packages if already exist in dependencies or if added to install two or more times """ packages = [] for mas in Utils().remove_dbs(self.packages): if mas not in self.dependencies: packages.append(mas) self.packages = packages 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 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 checksums(self, install): """Checksums before install """ check_md5(pkg_checksum(install, self.repo), self.tmp_path + install) def resolving_deps(self): """Return package dependencies """ requires = [] if (self.meta.rsl_deps in ["on", "ON"] and self.flag != "--resolve-off"): self.msg.resolving() for dep in self.packages: status(0.05) dependencies = [] dependencies = Utils().dimensional_list(Dependencies( self.repo, self.blacklist).binary(dep, self.flag)) requires += self._fix_deps_repos(dependencies) self.deps_dict[dep] = Utils().remove_dbs(requires) return Utils().remove_dbs(requires) def _fix_deps_repos(self, dependencies): """Fix store deps include in repository """ requires = [] for dep in dependencies: if dep in self.repo_pkg_names: requires.append(dep) return requires 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 top_view(self): """Print packages status bar """ self.msg.template(78) print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( "| Package", " " * 17, "New Version", " " * 8, "Arch", " " * 4, "Build", " " * 2, "Repos", " " * 10, "Size")) self.msg.template(78) def store(self, packages): """Store and return packages for install """ dwn, install, comp_sum, uncomp_sum = ([] for i in range(4)) # name = data[0] # location = data[1] # size = data[2] # unsize = data[3] for pkg in packages: for pk, loc, comp, uncomp in zip(self.data[0], self.data[1], self.data[2], self.data[3]): if (pk and pkg == split_package(pk)[0] and pk not in install and split_package(pk)[0] not in self.blacklist): dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk)) install.append(pk) comp_sum.append(comp) uncomp_sum.append(uncomp) if not install: for pkg in packages: for pk, loc, comp, uncomp in zip(self.data[0], self.data[1], self.data[2], self.data[3]): name = split_package(pk)[0] if (pk and pkg in name and name not in self.blacklist): self.matching = True dwn.append("{0}{1}/{2}".format(self.mirror, loc, pk)) install.append(pk) comp_sum.append(comp) uncomp_sum.append(uncomp) dwn.reverse() install.reverse() comp_sum.reverse() uncomp_sum.reverse() if self.repo == "slack": dwn, install, comp_sum, uncomp_sum = self.patches(dwn, install, comp_sum, uncomp_sum) return [dwn, install, comp_sum, uncomp_sum] def patches(self, dwn, install, comp_sum, uncomp_sum): """Seperates packages from patches/ directory """ dwnp, installp, comp_sump, uncomp_sump = ([] for i in range(4)) for d, i, c, u in zip(dwn, install, comp_sum, uncomp_sum): if "_slack" + slack_ver() in i: dwnp.append(d) dwn.remove(d) installp.append(i) install.remove(i) comp_sump.append(c) comp_sum.remove(c) uncomp_sump.append(u) uncomp_sum.remove(u) if "--patches" in self.flag: return dwnp, installp, comp_sump, uncomp_sump return dwn, install, comp_sum, uncomp_sum
class SBoNetwork(object): """View SBo site in terminal and also read, build or install packages """ def __init__(self, name, flag): self.name = name self.flag = flag self.meta = _meta_ self.msg = Msg() self.arch = SBoArch().get() self.comp_tar = ".tar.gz" self.choice = "" self.FAULT = "" self.green = self.meta.color["GREEN"] self.red = self.meta.color["RED"] self.yellow = self.meta.color["YELLOW"] self.cyan = self.meta.color["CYAN"] self.grey = self.meta.color["GREY"] self.endc = self.meta.color["ENDC"] self.build_folder = self.meta.build_path self._SOURCES = self.meta.SBo_SOURCES self.msg.reading() self.data = SBoGrep(name="").names() self.case_insensitive() if "--checklist" in self.flag: self.with_checklist() grep = SBoGrep(self.name) self.sbo_files = grep.files() self.blacklist = BlackList().packages(pkgs=self.data, repo="sbo") self.sbo_url = sbo_search_pkg(self.name) if self.sbo_url: self.sbo_desc = grep.description()[len(self.name) + 2:-1] self.source_dwn = grep.source().split() self.sbo_req = grep.requires() self.sbo_dwn = SBoLink(self.sbo_url).tar_gz() self.sbo_version = grep.version() self.dwn_srcs = self.sbo_dwn.split() + self.source_dwn if "--checklist" not in self.flag or not self.sbo_url and self.name: self.msg.done() def view(self): """View SlackBuild package, read or install them from slackbuilds.org """ if self.sbo_url and self.name not in self.blacklist: self.prgnam = ("{0}-{1}".format(self.name, self.sbo_version)) self.view_sbo() while True: self.read_choice() choice = { "r": self.choice_README, "R": self.choice_README, "s": self.choice_SlackBuild, "S": self.choice_SlackBuild, "f": self.choice_info, "F": self.choice_info, "o": self.choice_doinst, "O": self.choice_doinst, "d": self.choice_download, "D": self.choice_download, "download": self.choice_download, "b": self.choice_build, "B": self.choice_build, "build": self.choice_build, "i": self.choice_install, "I": self.choice_install, "install": self.choice_install, "c": self.choice_clear_screen, "C": self.choice_clear_screen, "clear": self.choice_clear_screen, "q": self.choice_quit, "quit": self.choice_quit, "Q": self.choice_quit } try: choice[self.choice]() except KeyError: pass else: self.msg.pkg_not_found("\n", self.name, "Can't view", "\n") raise SystemExit(1) def case_insensitive(self): """Matching packages distinguish between uppercase and lowercase """ if "--case-ins" in self.flag: data_dict = Utils().case_sensitive(self.data) for key, value in data_dict.iteritems(): if key == self.name.lower(): self.name = value def read_choice(self): """Return choice """ commands = { "r": "README", "R": "README", "s": "{0}.SlackBuild".format(self.name), "S": "{0}.SlackBuild".format(self.name), "f": "{0}.info".format(self.name), "F": "{0}.info".format(self.name), "o": "doinst.sh", "O": "doinst.sh", "d": "download", "D": "download", "download": "download", "b": "build", "B": "build", "build": "build", "i": "install", "I": "install", "install": "install", "c": "clear", "C": "clear", "clear": "clear", "q": "quit", "quit": "quit", "Q": "quit" } try: message = " Choose an option > " self.choice = raw_input("{0}{1}{2}".format(self.grey, message, self.endc)) except EOFError: print("") raise SystemExit() try: sys.stdout.write("{0}\x1b[1A{1}{2}{3}\n".format( " " * len(message), self.cyan, commands[self.choice], self.endc)) sys.stdout.flush() except KeyError: pass def choice_README(self): """View README file """ README = ReadSBo(self.sbo_url).readme("README") fill = self.fill_pager(README) self.pager(README + fill) def choice_SlackBuild(self): """View .SlackBuild file """ SlackBuild = ReadSBo(self.sbo_url).slackbuild(self.name, ".SlackBuild") fill = self.fill_pager(SlackBuild) self.pager(SlackBuild + fill) def choice_info(self): """View .info file """ info = ReadSBo(self.sbo_url).info(self.name, ".info") fill = self.fill_pager(info) self.pager(info + fill) def choice_doinst(self): """View doinst.sh file """ if "doinst.sh" in self.sbo_files.split(): doinst_sh = ReadSBo(self.sbo_url).doinst("doinst.sh") fill = self.fill_pager(doinst_sh) self.pager(doinst_sh + fill) def choice_download(self): """Download script.tar.gz and sources """ Download(path="", url=self.dwn_srcs, repo="sbo").start() raise SystemExit() def choice_build(self): """Build package """ self.build() delete(self.build_folder) raise SystemExit() def choice_install(self): """Download, build and install package """ pkg_security([self.name]) if not find_package(self.prgnam, self.meta.pkg_path): self.build() self.install() delete(self.build_folder) raise SystemExit() else: self.msg.template(78) self.msg.pkg_found(self.prgnam) self.msg.template(78) raise SystemExit() def choice_clear_screen(self): """Clear screen """ os.system("clear") self.view() def choice_quit(self): """Quit from choices """ raise SystemExit() def view_sbo(self): """View slackbuild.org """ sbo_url = self.sbo_url.replace("/slackbuilds/", "/repository/") br1, br2, fix_sp = "", "", " " if self.meta.use_colors in ["off", "OFF"]: br1 = "(" br2 = ")" fix_sp = "" print("") # new line at start self.msg.template(78) print("| {0}{1}SlackBuilds Repository{2}".format( " " * 28, self.grey, self.endc)) self.msg.template(78) print("| {0} > {1} > {2}{3}{4}".format(slack_ver(), sbo_url.split("/")[-3].title(), self.cyan, self.name, self.endc)) self.msg.template(78) print("| {0}Package url{1}: {2}".format(self.green, self.endc, sbo_url)) self.msg.template(78) print("| {0}Description: {1}{2}".format(self.green, self.endc, self.sbo_desc)) print("| {0}SlackBuild: {1}{2}".format(self.green, self.endc, self.sbo_dwn.split("/")[-1])) print("| {0}Sources: {1}{2}".format( self.green, self.endc, (", ".join([src.split("/")[-1] for src in self.source_dwn])))) print("| {0}Requirements: {1}{2}".format(self.yellow, self.endc, ", ".join(self.sbo_req))) self.msg.template(78) print("| {0}R{1}{2}EADME View the README file".format( self.red, self.endc, br2)) print("| {0}S{1}{2}lackBuild View the .SlackBuild " "file".format(self.red, self.endc, br2)) print("| In{0}{1}f{2}{3}o{4} View the .info " "file".format(br1, self.red, self.endc, br2, fix_sp)) if "doinst.sh" in self.sbo_files.split(): print("| D{0}{1}o{2}{3}inst.sh{4} View the doinst.sh " "file".format(br1, self.red, self.endc, br2, fix_sp)) print("| {0}D{1}{2}ownload Download this package".format( self.red, self.endc, br2)) print("| {0}B{1}{2}uild Download and build".format( self.red, self.endc, br2)) print("| {0}I{1}{2}nstall Download/Build/Install".format( self.red, self.endc, br2)) print("| {0}C{1}{2}lear Clear screen".format( self.red, self.endc, br2)) print("| {0}Q{1}{2}uit Quit".format( self.red, self.endc, br2)) self.msg.template(78) def with_checklist(self): """Using dialog and checklist option """ data = [] if self.name == "ALL": data = self.data else: for name in self.data: if self.name in name: data.append(name) if data: text = "Press 'spacebar' to choose SlackBuild for view" title = " SlackBuilds.org " backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__) status = False pkg = DialogUtil(data, text, title, backtitle, status).checklist() if pkg and len(pkg) > 1: print("\nslpkg: Error: Choose only one package") raise SystemExit() if pkg is None: raise SystemExit() self.name = "".join(pkg) os.system("clear") def pager(self, text): """Read text """ pydoc.pager(text) def fill_pager(self, page): """Fix pager spaces """ tty_size = os.popen("stty size", "r").read().split() rows = int(tty_size[0]) - 1 lines = sum(1 for line in page.splitlines()) diff = rows - lines fill = "\n" * diff if diff > 0: return fill else: return "" def error_uns(self): """Check if package supported by arch before proceed to install """ self.FAULT = "" UNST = ["UNSUPPORTED", "UNTESTED"] if "".join(self.source_dwn) in UNST: self.FAULT = "".join(self.source_dwn) def build(self): """Only build and create Slackware package """ pkg_security([self.name]) self.error_uns() if self.FAULT: print("") self.msg.template(78) print("| Package {0} {1} {2} {3}".format(self.prgnam, self.red, self.FAULT, self.endc)) self.msg.template(78) else: sources = [] if not os.path.exists(self.meta.build_path): os.makedirs(self.meta.build_path) if not os.path.exists(self._SOURCES): os.makedirs(self._SOURCES) os.chdir(self.meta.build_path) Download(self.meta.build_path, self.sbo_dwn.split(), repo="sbo").start() Download(self._SOURCES, self.source_dwn, repo="sbo").start() script = self.sbo_dwn.split("/")[-1] for src in self.source_dwn: sources.append(src.split("/")[-1]) BuildPackage(script, sources, self.meta.build_path, auto=False).build() slack_package(self.prgnam) # check if build 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")