update utils to class

This commit is contained in:
Dimitris Zlatanidis 2015-01-31 02:47:36 +02:00
parent 7b8e2a3ddb
commit 70ce59db9c
17 changed files with 88 additions and 101 deletions

View file

@ -23,7 +23,7 @@
import sys
from slpkg.utils import package_name
from slpkg.utils import Utils
from slpkg.toolbar import status
from slpkg.blacklist import BlackList
@ -35,7 +35,7 @@ class Dependencies(object):
def __init__(self, PACKAGES_TXT, repo):
self.repo = repo
self.dep_results = []
self.packages = package_name(PACKAGES_TXT, repo)
self.packages = Utils().package_name(PACKAGES_TXT, repo)
def binary(self, name):
'''

View file

@ -23,8 +23,8 @@
import os
from slpkg.utils import Utils
from slpkg.toolbar import status
from slpkg.utils import read_file
from slpkg.splitting import split_package
from slpkg.slack.slack_version import slack_ver
from slpkg.__metadata__ import MetaData as _m
@ -162,7 +162,7 @@ def fix_slackers_pkg(name):
name in PACKAGES.TXT file use FILELIST.TXT to
get.
'''
FILELIST_TXT = read_file(_m.lib_path + 'slackr_repo/FILELIST.TXT')
FILELIST_TXT = Utils().read_file(_m.lib_path + 'slackr_repo/FILELIST.TXT')
for line in FILELIST_TXT.splitlines():
if name in line and line.endswith(".txz"):
return line.split("/")[-1].strip()
@ -198,7 +198,7 @@ class Requires(object):
else:
return ""
else:
PACKAGES_TXT = read_file('{0}{1}_repo/PACKAGES.TXT'.format(
PACKAGES_TXT = Utils().read_file('{0}{1}_repo/PACKAGES.TXT'.format(
_m.lib_path, self.repo))
for line in PACKAGES_TXT.splitlines():
if line.startswith("PACKAGE NAME:"):

View file

@ -24,6 +24,7 @@
import os
import sys
from slpkg.utils import Utils
from slpkg.sizes import units
from slpkg.messages import Msg
from slpkg.remove import delete
@ -33,10 +34,6 @@ from slpkg.blacklist import BlackList
from slpkg.downloader import Download
from slpkg.grep_md5 import pkg_checksum
from slpkg.splitting import split_package
from slpkg.utils import (
remove_dbs,
dimensional_list
)
from slpkg.__metadata__ import MetaData as _m
from slpkg.pkg.find import find_package
@ -149,7 +146,7 @@ class BinaryInstall(object):
or if added to install two or more times
'''
packages = []
for mas in remove_dbs(self.packages):
for mas in Utils().remove_dbs(self.packages):
if mas not in self.dependencies:
packages.append(mas)
return packages
@ -205,11 +202,11 @@ class BinaryInstall(object):
Msg().resolving()
for dep in self.packages:
dependencies = []
dependencies = dimensional_list(Dependencies(self.PACKAGES_TXT,
self.repo).binary(dep))
dependencies = Utils().dimensional_list(Dependencies(
self.PACKAGES_TXT, self.repo).binary(dep))
requires += dependencies
self.deps_dict[dep] = remove_dbs(dependencies)
return remove_dbs(requires)
self.deps_dict[dep] = Utils().remove_dbs(dependencies)
return Utils().remove_dbs(requires)
def view_version(self, packages):
'''

View file

@ -23,7 +23,7 @@
import os
from slpkg.utils import read_file
from slpkg.utils import Utils
from slpkg.repositories import Repo
from slpkg.__metadata__ import MetaData as _m
@ -46,7 +46,7 @@ class RepoInit(object):
else:
exec('self._init_custom()')
self.lib = _m.lib_path + "{0}_repo/PACKAGES.TXT".format(self.repo)
PACKAGES_TXT = read_file(self.lib)
PACKAGES_TXT = Utils().read_file(self.lib)
return PACKAGES_TXT, self.mirror
def _init_custom(self):

View file

@ -23,12 +23,10 @@
import sys
from slpkg.utils import Utils
from slpkg.toolbar import status
from slpkg.blacklist import BlackList
from slpkg.splitting import split_package
from slpkg.utils import (
read_file
)
from slpkg.__metadata__ import MetaData as _m
@ -40,8 +38,8 @@ def search_pkg(name, repo):
try:
blacklist = BlackList().packages()
toolbar_width, index = 2, 0
PACKAGES_TXT = read_file(_m.lib_path + '{0}_repo/PACKAGES.TXT'.format(
repo))
PACKAGES_TXT = Utils().read_file(_m.lib_path + '{0}_repo/'
'PACKAGES.TXT'.format(repo))
for line in PACKAGES_TXT.splitlines():
index += 1
toolbar_width = status(index, toolbar_width, 1400)

View file

@ -21,7 +21,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from utils import read_file
from utils import Utils
from __metadata__ import MetaData as _m
@ -33,7 +33,7 @@ class BlackList(object):
def __init__(self):
self.quit = False
self.blackfile = "/etc/slpkg/blacklist"
self.black_conf = read_file(self.blackfile)
self.black_conf = Utils().read_file(self.blackfile)
def packages(self):
'''

View file

@ -23,7 +23,7 @@
import subprocess
from utils import read_file
from utils import Utils
from __metadata__ import MetaData as _m
@ -54,7 +54,7 @@ class Config(object):
'USE_COLORS',
'WGET_OPTION'
]
read_conf = read_file(self.config_file)
read_conf = Utils().read_file(self.config_file)
for line in read_conf.splitlines():
if not line.startswith("#") and line.split("=")[0] in conf_args:
print(line)

View file

@ -22,8 +22,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from utils import Utils
from messages import Msg
from utils import read_file
from __metadata__ import MetaData as _m
@ -51,7 +51,7 @@ class PkgDesc(object):
self.repo)
def view(self):
PACKAGES_TXT = read_file(self.lib)
PACKAGES_TXT = Utils().read_file(self.lib)
print("") # new line at start
count = 0
if self.repo != "sbo":

View file

@ -25,8 +25,8 @@ import os
import sys
import subprocess
from slpkg.utils import Utils
from slpkg.messages import Msg
from slpkg.utils import read_file
from slpkg.__metadata__ import MetaData as _m
from slpkg.pkg.find import find_package
@ -160,7 +160,7 @@ class PackageManager(object):
'''
View dependencies for before remove
'''
dependencies = read_file(path + package)
dependencies = Utils().read_file(path + package)
print("") # new line at start
Msg().template(78)
print("| Found dependencies for package {0}:".format(package))
@ -224,7 +224,7 @@ class PackageManager(object):
matching += 1
print("[ {0}installed{1} ] - {2}".format(
_m.color['GREEN'], _m.color['ENDC'], match))
data = read_file(_m.pkg_path + match)
data = Utils().read_file(_m.pkg_path + match)
for line in data.splitlines():
if line.startswith("UNCOMPRESSED PACKAGE SIZE:"):
if "M" in line[26:]:
@ -252,7 +252,7 @@ class PackageManager(object):
for pkg in self.binary:
find = find_package(pkg + _m.sp, _m.pkg_path)
if find:
package = read_file(_m.pkg_path + "".join(find))
package = Utils().read_file(_m.pkg_path + "".join(find))
for line in package.splitlines():
print(line).strip()
print("") # new line per file
@ -275,13 +275,13 @@ class PackageManager(object):
if repo == 'sbo':
if (os.path.isfile(
_m.lib_path + '{0}_repo/SLACKBUILDS.TXT'.format(repo))):
r = read_file(_m.lib_path + '{0}_repo/'
'SLACKBUILDS.TXT'.format(repo))
r = Utils().read_file(_m.lib_path + '{0}_repo/'
'SLACKBUILDS.TXT'.format(repo))
else:
if os.path.isfile(_m.lib_path + '{0}_repo/PACKAGES.TXT'.format(
repo)):
r = read_file(_m.lib_path + '{0}_repo/PACKAGES.TXT'.format(
repo))
r = Utils().read_file(_m.lib_path + '{0}_repo/'
'PACKAGES.TXT'.format(repo))
for line in r.splitlines():
if repo == 'sbo':
if line.startswith("SLACKBUILD NAME: "):

View file

@ -24,7 +24,7 @@
import os
from collections import OrderedDict
from utils import read_file
from utils import Utils
from downloader import Download
from __metadata__ import MetaData as _m
@ -59,7 +59,7 @@ class QueuePkgs(object):
for line in queue_file:
queue.write(line)
queue.close()
self.queued = read_file(self.queue_list)
self.queued = Utils().read_file(self.queue_list)
def packages(self):
'''

View file

@ -25,7 +25,7 @@ import os
import sys
from sizes import units
from utils import read_file
from utils import Utils
from repositories import Repo
from repolist import RepoList
from __metadata__ import MetaData as _m
@ -77,11 +77,11 @@ class RepoInfo(object):
'SLACKBUILDS.TXT'.format(repo))):
status = '{0}enabled{1}'.format(_m.color['GREEN'], _m.color['ENDC'])
sum_sbo_pkgs = 0
for line in (read_file(
for line in (Utils().read_file(
_m.lib_path + 'sbo_repo/SLACKBUILDS.TXT').splitlines()):
if line.startswith('SLACKBUILD NAME: '):
sum_sbo_pkgs += 1
changelog_txt = read_file(_m.log_path + 'sbo/ChangeLog.txt')
changelog_txt = Utils().read_file(_m.log_path + 'sbo/ChangeLog.txt')
last_upd = changelog_txt.split('\n', 1)[0]
self.form['Repo id:'] = repo
self.form['Repo url:'] = self.all_repos[repo]
@ -101,7 +101,7 @@ class RepoInfo(object):
Grap data packages
'''
sum_pkgs, size, unsize, last_upd = 0, [], [], ''
for line in (read_file(
for line in (Utils().read_file(
_m.lib_path + repo + '_repo/PACKAGES.TXT').splitlines()):
if line.startswith('PACKAGES.TXT;'):
last_upd = line[14:].strip()
@ -112,6 +112,7 @@ class RepoInfo(object):
if line.startswith('PACKAGE SIZE (uncompressed): '):
unsize.append(line[30:-2].strip())
if repo in ['salix', 'slackl']:
log = read_file(_m.log_path + '{0}/ChangeLog.txt'.format(repo))
log = Utils().read_file(_m.log_path + '{0}/ChangeLog.txt'.format(
repo))
last_upd = log.split('\n', 1)[0]
return [sum_pkgs, size, unsize, last_upd]

View file

@ -25,7 +25,7 @@
import os
import sys
from utils import read_file
from utils import Utils
from __metadata__ import MetaData as _m
@ -33,7 +33,7 @@ class Repo(object):
def __init__(self):
self.repo_file = "/etc/slpkg/custom-repositories"
self.repositories_list = read_file(self.repo_file)
self.repositories_list = Utils().read_file(self.repo_file)
def add(self, repo, url):
'''
@ -102,7 +102,7 @@ class Repo(object):
'''
default = "http://mirrors.slackware.com/slackware/"
if os.path.isfile("/etc/slpkg/slackware-mirrors"):
mirrors = read_file(_m.conf_path + 'slackware-mirrors')
mirrors = Utils().read_file(_m.conf_path + 'slackware-mirrors')
for line in mirrors.splitlines():
line = line.rstrip()
if not line.startswith("#") and line:

View file

@ -21,7 +21,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from slpkg.utils import read_file
from slpkg.utils import Utils
from slpkg.__metadata__ import MetaData as _m
@ -43,7 +43,7 @@ class SBoGrep(object):
self.sbo_txt = _m.lib_path + "sbo_repo/SLACKBUILDS.TXT"
self.answer = ['y', 'Y']
self.unst = ['UNSUPPORTED', 'UNTESTED']
self.SLACKBUILDS_TXT = read_file(self.sbo_txt)
self.SLACKBUILDS_TXT = Utils().read_file(self.sbo_txt)
def source(self):
'''

View file

@ -23,12 +23,10 @@
import sys
from slpkg.utils import Utils
from slpkg.repositories import Repo
from slpkg.blacklist import BlackList
from slpkg.__metadata__ import MetaData as _m
from slpkg.utils import (
read_file
)
from slpkg.slack.slack_version import slack_ver
@ -41,7 +39,8 @@ def sbo_search_pkg(name):
repo = Repo().sbo()
blacklist = BlackList().packages()
sbo_url = "{0}{1}/".format(repo, slack_ver())
SLACKBUILDS_TXT = read_file(_m.lib_path + "sbo_repo/SLACKBUILDS.TXT")
SLACKBUILDS_TXT = Utils().read_file(
_m.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()

View file

@ -25,15 +25,12 @@ import os
import sys
from slpkg.utils import Utils
from slpkg.messages import Msg
from slpkg.toolbar import status
from slpkg.log_deps import write_deps
from slpkg.downloader import Download
from slpkg.splitting import split_package
from slpkg.utils import (
dimensional_list,
remove_dbs
)
from slpkg.messages import Msg
from slpkg.__metadata__ import MetaData as _m
from slpkg.pkg.find import find_package
@ -144,7 +141,7 @@ class SBoInstall(object):
or if added to install two or more times
'''
slackbuilds = []
for mas in remove_dbs(self.master_packages):
for mas in Utils().remove_dbs(self.master_packages):
if mas not in self.dependencies:
slackbuilds.append(mas)
return slackbuilds
@ -183,11 +180,11 @@ class SBoInstall(object):
Thus creating this loop create one-dimensional list.
'''
requires, dependencies = [], []
requires = dimensional_list(deps)
requires = Utils().dimensional_list(deps)
# Inverting the list brings the
# dependencies in order to be installed.
requires.reverse()
dependencies = remove_dbs(requires)
dependencies = Utils().remove_dbs(requires)
return dependencies
def top_view(self):

View file

@ -22,11 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from utils import (
read_file,
remove_dbs,
dimensional_list
)
from utils import Utils
from messages import Msg
from __metadata__ import MetaData as _m
@ -51,16 +47,16 @@ def track_dep(name, repo):
dependencies_list = Requires().sbo(name)
find_pkg = sbo_search_pkg(name)
else:
PACKAGES_TXT = read_file(_m.lib_path + '{0}_repo/PACKAGES.TXT'.format(
repo))
PACKAGES_TXT = Utils().read_file(_m.lib_path + '{0}_repo/'
'PACKAGES.TXT'.format(repo))
dependencies_list = Dependencies(PACKAGES_TXT, repo).binary(name)
find_pkg = search_pkg(name, repo)
Msg().done()
if find_pkg:
requires, dependencies = [], []
requires = dimensional_list(dependencies_list)
requires = Utils().dimensional_list(dependencies_list)
requires.reverse()
dependencies = remove_dbs(requires)
dependencies = Utils().remove_dbs(requires)
if dependencies == []:
dependencies = ["No dependencies"]
pkg_len = len(name) + 24

View file

@ -25,40 +25,39 @@
from splitting import split_package
def dimensional_list(lists):
""" Create one dimensional list """
one_list = []
for lst in lists:
one_list += lst
return one_list
class Utils(object):
def dimensional_list(self, lists):
""" Create one dimensional list """
one_list = []
for lst in lists:
one_list += lst
return one_list
def remove_dbs(double):
""" Remove douuble item from list """
one = []
for dup in double:
if dup not in one:
one.append(dup)
return one
def remove_dbs(self, double):
""" Remove douuble item from list """
one = []
for dup in double:
if dup not in one:
one.append(dup)
return one
def read_file(self, registry):
""" Return reading file """
with open(registry, "r") as file_txt:
read_file = file_txt.read()
file_txt.close()
return read_file
def read_file(registry):
""" Return reading file """
with open(registry, "r") as file_txt:
read_file = file_txt.read()
file_txt.close()
return read_file
def package_name(PACKAGES_TXT, repo):
""" Return PACKAGE NAME """
packages = []
for line in PACKAGES_TXT.splitlines():
# index += 1
# toolbar_width = status(index, toolbar_width, step)
if line.startswith("PACKAGE NAME:"):
if repo == "slackr":
packages.append(line[14:].strip())
else:
packages.append(split_package(line[14:].strip())[0])
return packages
def package_name(self, PACKAGES_TXT, repo):
""" Return PACKAGE NAME """
packages = []
for line in PACKAGES_TXT.splitlines():
# index += 1
# toolbar_width = status(index, toolbar_width, step)
if line.startswith("PACKAGE NAME:"):
if repo == "slackr":
packages.append(line[14:].strip())
else:
packages.append(split_package(line[14:].strip())[0])
return packages