diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index eac5d011..ff7a98b6 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -68,11 +68,7 @@ class BinaryInstall: 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.init_flags() self.dwn, self.dep_dwn = [], [] self.install, self.dep_install = [], [] self.comp_sum, self.dep_comp_sum = [], [] @@ -89,6 +85,15 @@ class BinaryInstall: self.blacklist = BlackList().packages(self.data[0], self.repo) self.matching = False + def init_flags(self): + """Flags initiliazation + """ + 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 += "/" + def start(self, is_upgrade): """ Install packages from official Slackware distribution @@ -186,8 +191,7 @@ class BinaryInstall: lowercase """ if "--case-ins" in self.flag: - data = [] - data = Utils().package_name(self.PACKAGES_TXT) + data = list(Utils().package_name(self.PACKAGES_TXT)) data_dict = Utils().case_sensitive(data) for pkg in self.packages: index = self.packages.index(pkg) @@ -266,18 +270,16 @@ class BinaryInstall: dependencies = [] dependencies = Utils().dimensional_list(Dependencies( self.repo, self.blacklist).binary(dep, self.flag)) - requires += self._fix_deps_repos(dependencies) + requires += list(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 + yield dep def views(self, install, comp_sum): """Views packages diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py index a0a012e1..5673d967 100644 --- a/slpkg/binary/search.py +++ b/slpkg/binary/search.py @@ -23,9 +23,7 @@ from slpkg.utils import Utils -from slpkg.toolbar import status from slpkg.blacklist import BlackList -from slpkg.splitting import split_package from slpkg.__metadata__ import MetaData as _meta_ @@ -34,11 +32,7 @@ def search_pkg(name, repo): and return the name. """ PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT") - names = Utils().package_name(PACKAGES_TXT) + names = list(Utils().package_name(PACKAGES_TXT)) blacklist = BlackList().packages(pkgs=names, repo=repo) - for line in PACKAGES_TXT.splitlines(): - status(0) - if line.startswith("PACKAGE NAME: ") and len(line) > 16: - pkg_name = split_package(line[15:])[0].strip() - if name == pkg_name and name not in blacklist: - return pkg_name + if name in names and name not in blacklist: + return name \ No newline at end of file diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 59eb4058..e074b674 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -75,7 +75,6 @@ class BlackList: print(f"{self.green}{pkg}{self.endc}") black_conf.write(pkg + "\n") self.quit = True - black_conf.close() if self.quit: print() # new line at exit @@ -90,7 +89,6 @@ class BlackList: else: print(f"{self.red}{line}{self.endc}") self.quit = True - remove.close() if self.quit: print() # new line at exit diff --git a/slpkg/pkg/build.py b/slpkg/pkg/build.py index ad61e537..81eeb46b 100644 --- a/slpkg/pkg/build.py +++ b/slpkg/pkg/build.py @@ -108,7 +108,7 @@ class BuildPackage: log_end(self.build_logs, self.log_file, sum_time) print(f"Total build time for the package {self.prgnam} : {sum_time}\n") else: - subprocess.call(f"{' '.join(pass_ver)} ./{self.prgnam}.SlackBuild", shell=True) + subprocess.call(f"{' '.join(pass_var)} ./{self.prgnam}.SlackBuild", shell=True) os.chdir(self.path) except KeyboardInterrupt: # (OSError, IOError): self.msg.pkg_not_found("\n", self.prgnam, "Wrong file", "\n") @@ -171,7 +171,6 @@ def log_head(path, log_file, log_time): log.write("Date : " + time.strftime("%d/%m/%Y") + "\n") log.write("Time : " + log_time + "\n\n") log.write("#" * 79 + "\n\n") - log.close() def log_end(path, log_file, sum_time): @@ -185,7 +184,6 @@ def log_end(path, log_file, sum_time): log.write(f"Total build time : {sum_time}\n") log.write(" " * 38 + "E N D\n\n") log.write("#" * 79 + "\n\n") - log.close() def build_time(start_time): diff --git a/slpkg/pkg/find.py b/slpkg/pkg/find.py index 0bacbaa1..c75f5d13 100644 --- a/slpkg/pkg/find.py +++ b/slpkg/pkg/find.py @@ -27,16 +27,20 @@ from slpkg.blacklist import BlackList from slpkg.splitting import split_package -def find_package(find_pkg, directory): +def searching(find_pkg, directory): """Find packages """ - pkgs = [] if os.path.isdir(directory): - installed = sorted(os.listdir(directory)) + installed = os.listdir(directory) blacklist = BlackList().packages(pkgs=installed, repo="local") if os.path.exists(directory): for pkg in installed: if (not pkg.startswith(".") and pkg.startswith(find_pkg) and split_package(pkg)[0] not in blacklist): - pkgs.append(pkg) - return pkgs + yield pkg + + +def find_package(pkg, path): + """Generator allias + """ + return list(searching(pkg, path)) \ No newline at end of file diff --git a/slpkg/repositories.py b/slpkg/repositories.py index c4d4f1ed..5a77b726 100644 --- a/slpkg/repositories.py +++ b/slpkg/repositories.py @@ -82,7 +82,6 @@ class Repo: print("\nRepository '{0}' successfully " "removed\n".format(repo)) rem_repo = True - repos.close() if not rem_repo: print("\nRepository '{0}' doesn't exist\n".format(repo)) raise SystemExit() diff --git a/slpkg/sbo/dependency.py b/slpkg/sbo/dependency.py index afb5b1dd..e6e428a7 100644 --- a/slpkg/sbo/dependency.py +++ b/slpkg/sbo/dependency.py @@ -58,10 +58,15 @@ class Requires: # if require in blacklist if "%README%" not in req and req not in self.blacklist: dependencies.append(req) - if dependencies: - self.dep_results.append(dependencies) - for dep in dependencies: - self.sbo(dep) + self.deep_check(dependencies) return self.dep_results else: return [] + + def deep_check(self, dependencies): + """Checking if dependencies are finnished + """ + if dependencies: + self.dep_results.append(dependencies) + for dep in dependencies: + self.sbo(dep) \ No newline at end of file diff --git a/slpkg/sbo/greps.py b/slpkg/sbo/greps.py index 09dbf4c4..21be0426 100644 --- a/slpkg/sbo/greps.py +++ b/slpkg/sbo/greps.py @@ -47,14 +47,18 @@ class SBoGrep: self.unst = ["UNSUPPORTED", "UNTESTED"] self.SLACKBUILDS_TXT = Utils().read_file(self.sbo_txt) - def names(self): - """Grab all packages name + def _names_grabbing(self): + """Generator that collecting all packages names """ - pkg_names = [] for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): - pkg_names.append(line[17:].strip()) - return pkg_names + yield line[17:].strip() + + def names(self): + """Alias method convert generator and return + a list + """ + return list(self._names_grabbing()) def source(self): """Grab sources downloads links @@ -138,7 +142,7 @@ class SBoGrep: return md5sum64 def description(self): - """Grab package verion + """Grab package version """ for line in self.SLACKBUILDS_TXT.splitlines(): if line.startswith(self.line_name): diff --git a/slpkg/sbo/queue.py b/slpkg/sbo/queue.py index 4e888aef..fd7547cb 100644 --- a/slpkg/sbo/queue.py +++ b/slpkg/sbo/queue.py @@ -65,7 +65,6 @@ class QueuePkgs: with open(self.queue_list, "w") as queue: for line in queue_file: queue.write(line) - queue.close() self.queued = Utils().read_file(self.queue_list) def packages(self): @@ -106,7 +105,6 @@ class QueuePkgs: else: print(f"{self.red}{pkg}{self.endc}") self.quit = True - queue.close() if self.quit: print() # new line at exit @@ -121,7 +119,6 @@ class QueuePkgs: else: print(f"{self.red}{line}{self.endc}") self.quit = True - queue.close() if self.quit: print() # new line at exit diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py index 2643c1be..6cc1071a 100644 --- a/slpkg/sbo/slackbuild.py +++ b/slpkg/sbo/slackbuild.py @@ -65,11 +65,7 @@ class SBoInstall: 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.init_flags() self.unst = ["UNSUPPORTED", "UNTESTED"] self.master_packages = [] self.deps = [] @@ -86,6 +82,15 @@ class SBoInstall: self.data = SBoGrep(name="").names() self.blacklist = BlackList().packages(pkgs=self.data, repo="sbo") + def init_flags(self): + """Flags initialization + """ + 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 += "/" + def start(self, is_upgrade): """Start view, build and install SBo packages """ @@ -307,10 +312,8 @@ class SBoInstall: def filenames(self, sources): """Return filenames from sources links """ - filename = [] for src in sources: - filename.append(src.split("/")[-1]) - return filename + yield src.split("/")[-1] def build_install(self): """Build and install packages if not already installed @@ -343,13 +346,14 @@ class SBoInstall: 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) + src_link = list(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) + sources = list(self.filenames(src_link)) + print(sources) BuildPackage(script, sources, self.build_folder, auto=False).build() binary = slack_package(prgnam) @@ -384,10 +388,8 @@ class SBoInstall: def sbosrcarsh(self, prgnam, sbo_link, src_link): """Alternative repository for sbo sources""" - sources = [] name = "-".join(prgnam.split("-")[:-1]) category = f"{sbo_link.split('/')[-2]}/{name}/" for link in src_link: source = link.split("/")[-1] - sources.append(f"{self.meta.sbosrcarch_link}{category}{source}") - return sources + yield f"{self.meta.sbosrcarch_link}{category}{source}" diff --git a/slpkg/tracking.py b/slpkg/tracking.py index 92440ac2..c9a51743 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -125,7 +125,7 @@ class TrackingDeps: else: PACKAGES_TXT = Utils().read_file( self.meta.lib_path + f"{self.repo}_repo/PACKAGES.TXT") - self.names = Utils().package_name(PACKAGES_TXT) + self.names = list(Utils().package_name(PACKAGES_TXT)) self.bin_case_insensitive() self.find_pkg = search_pkg(self.name, self.repo) if self.find_pkg: diff --git a/slpkg/utils.py b/slpkg/utils.py index bde618f4..acca1a5d 100644 --- a/slpkg/utils.py +++ b/slpkg/utils.py @@ -66,11 +66,9 @@ class Utils: def package_name(self, PACKAGES_TXT): """Returns list with all the names of packages repository """ - packages = [] for line in PACKAGES_TXT.splitlines(): if line.startswith("PACKAGE NAME:"): - packages.append(split_package(line[14:].strip())[0]) - return packages + yield split_package(line[14:].strip())[0] def check_downloaded(self, path, maybe_downloaded): """Check if files downloaded and return downloaded