diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index db3a5883..f6011572 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -77,7 +77,7 @@ class BinaryInstall(object): msg_reading() self.PACKAGES_TXT, self.mirror = RepoInit(self.repo).fetch() num_lines = sum(1 for line in self.PACKAGES_TXT) - self.step = (num_lines / 700) + self.step = (num_lines / (100 * len(self.packages))) def start(self, if_upgrade): ''' diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 734b56f1..1c55a0e5 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -21,6 +21,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from utils import read_file from __metadata__ import color @@ -32,9 +33,7 @@ class BlackList(object): def __init__(self): self.quit = False self.blackfile = "/etc/slpkg/blacklist" - f = open(self.blackfile, "r") - self.black_conf = f.read() - f.close() + self.black_conf = read_file(self.blackfile) def packages(self): ''' diff --git a/slpkg/queue.py b/slpkg/queue.py index 6bc648ba..d417b80f 100644 --- a/slpkg/queue.py +++ b/slpkg/queue.py @@ -24,6 +24,7 @@ import os from collections import OrderedDict +from utils import read_file from downloader import Download from __metadata__ import ( lib_path, @@ -63,10 +64,7 @@ class QueuePkgs(object): for line in queue_file: queue.write(line) queue.close() - - f = open(self.queue_list, "r") - self.queued = f.read() - f.close() + self.queued = read_file(self.queue_list) def packages(self): ''' diff --git a/slpkg/repositories.py b/slpkg/repositories.py index 9d1bb3f4..872e0ff9 100644 --- a/slpkg/repositories.py +++ b/slpkg/repositories.py @@ -25,6 +25,7 @@ import os import sys +from utils import read_file from __metadata__ import ( default_repositories, repositories @@ -35,9 +36,7 @@ class Repo(object): def __init__(self): self.repo_file = "/etc/slpkg/custom-repositories" - f = open(self.repo_file, "r") - self.repositories_list = f.read() - f.close() + self.repositories_list = read_file(self.repo_file) def add(self, repo, url): ''' diff --git a/slpkg/sbo/search.py b/slpkg/sbo/search.py index 4098570e..a7bbac56 100644 --- a/slpkg/sbo/search.py +++ b/slpkg/sbo/search.py @@ -26,6 +26,9 @@ import sys from slpkg.repositories import Repo from slpkg.blacklist import BlackList from slpkg.__metadata__ import lib_path +from utils import ( + read_file +) from slpkg.slack.slack_version import slack_ver @@ -38,15 +41,12 @@ def sbo_search_pkg(name): repo = Repo().sbo() blacklist = BlackList().packages() sbo_url = "{0}{1}/".format(repo, slack_ver()) - with open(lib_path + "sbo_repo/SLACKBUILDS.TXT", - "r") as SLACKBUILDS_TXT: - for line in SLACKBUILDS_TXT: - if line.startswith("SLACKBUILD LOCATION"): - sbo_name = (line[23:].split("/")[-1].replace("\n", "") - ).strip() - if name == sbo_name and name not in blacklist: - SLACKBUILDS_TXT.close() - return (sbo_url + line[23:].strip() + "/") + SLACKBUILDS_TXT = read_file(lib_path + "sbo_repo/SLACKBUILDS.TXT") + for line in SLACKBUILDS_TXT.splitlines(): + if line.startswith("SLACKBUILD LOCATION"): + sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip() + if name == sbo_name and name not in blacklist: + return (sbo_url + line[23:].strip() + "/") except KeyboardInterrupt: print("") # new line at exit sys.exit(0)