From 12d50f5040d8cc0a5564ba7dc328aa58b595eac6 Mon Sep 17 00:00:00 2001 From: necoro <> Date: Mon, 9 Oct 2006 19:16:29 +0000 Subject: bla - prepared 0.4.0 ; added dialogs.py; extended some comments --- geneticone/backend/flags.py | 55 ++++++++++++++++++++++++++---------- geneticone/backend/package.py | 20 ++++++++++--- geneticone/backend/portage_helper.py | 52 ++++++++++++++++++++++++++-------- 3 files changed, 97 insertions(+), 30 deletions(-) (limited to 'geneticone/backend') diff --git a/geneticone/backend/flags.py b/geneticone/backend/flags.py index 2da0a94..1d2f321 100644 --- a/geneticone/backend/flags.py +++ b/geneticone/backend/flags.py @@ -23,7 +23,10 @@ from portage_util import unique_array CONFIG = { "usefile" : "geneticone", "maskfile" : "geneticone", - "usePerVersion" : True + "testingfile" : "geneticone", + "usePerVersion" : True, + "maskPerVersion" : True, + "testingPerVersion" : True } ### GENERAL PART ### @@ -41,7 +44,7 @@ def grep (pkg, path): if not isinstance(pkg, package.Package): pkg = package.Package(pkg) # assume it is a cpv or a gentoolkit.Package - command = "egrep -x -n -r -H '^[<>!=~]{0,2}%s(-[0-9].*)?[[:space:]]?.*$' %s" + command = "egrep -x -n -r -H '^[<>!=~]{0,2}%s(-[0-9].*)?[[:space:]]?.*$' %s" # %s is replaced in the next line ;) return Popen((command % (pkg.get_cp(), path)), shell = True, stdout = PIPE).communicate()[0].splitlines() def get_data(pkg, path): @@ -66,7 +69,7 @@ def get_data(pkg, path): fl = fl[1:] # stop after first comment for i in range(len(fl)): - if fl[i][0] == "#": #comment - stop here + if fl[i][0] == "#": # comment - stop here fl = fl[:i] break flags.append((file,line,crit,fl)) @@ -74,7 +77,7 @@ def get_data(pkg, path): return flags def set_config (cfg): - """This function sets the CONFIG-variable for the whole module. Use this instead of modifying CONFIG directly. + """This function sets the CONFIG-variable for the whole module. Use this instead of modifying L{CONFIG} directly. @param cfg: a dictionary with at least all the keys of the CONFIG-var @type cfg: dict @raises KeyError: if a keyword is missing in the new cfg""" @@ -87,11 +90,27 @@ def set_config (cfg): CONFIG[i] = cfg[i] def generate_path (cpv, exp): + """Generates the correct path out of given wildcards. + These wildcards can be: + - $(cat) : category + - $(cat-1): first part of the category (e.g. "app") + - $(cat-2): second part of the category + - $(pkg) : name of the package + + @param cpv: the cpv of the current package + @type cpv: string (cat/pkg-ver) + @param exp: the expression to render the path from + @type exp: string + @returns: rendered path + @rtype string""" cat, pkg, ver, rev = split_package_name(cpv) if exp.find("$(") != -1: - exp = exp.replace("$(cat)",cat).replace("$(pkg)",pkg).replace("$(cat-1)",cat.split("-")[0]).replace("$(cat-2)",cat.split("-")[1]) + exp = exp.replace("$(cat)",cat).\ + replace("$(pkg)",pkg).\ + replace("$(cat-1)",cat.split("-")[0]).\ + replace("$(cat-2)",cat.split("-")[1]) return exp ### USE FLAG PART ### @@ -284,9 +303,9 @@ def write_use_flags (): # write new lines msg = "\n#geneticone update#\n" - if CONFIG["usePerVersion"]: + if CONFIG["usePerVersion"]: # add on a per-version-base msg += "=%s %s\n" % (cpv, ' '.join(flagsToAdd)) - else: + else: # add on a per-package-base list = split_package_name(cpv) msg += "%s/%s %s\n" % (list[0], list[1], ' '.join(flagsToAdd)) if not file in file_cache: @@ -305,11 +324,6 @@ def write_use_flags (): useFlags = {} newUseFlags = {} -# -# -# NOTHING IS WORKING / IN USE BELOW THIS LINE -# -# ### MASKING PART ### MASK_PATH = os.path.join(portage.USER_CONFIG_PATH,"package.mask") UNMASK_PATH = os.path.join(portage.USER_CONFIG_PATH,"package.unmask") @@ -321,6 +335,7 @@ new_unmasked = {} def set_masked (pkg, masked = True): global new_masked, newunmasked + if not isinstance(pkg, package.Package): pkg = package.Package(pkg) @@ -411,7 +426,12 @@ def write_masked (): line = int(line) # add new line if line == -1: - msg = "\n#geneticone update#\n=%s\n" % cpv + msg = "\n#geneticone update#\n" + if CONFIG["maskPerVersion"]: + msg += "=%s\n" % cpv + else: + list = split_package_name(cpv) + msg += "%s/%s\n" % (list[0],list[1]) if not file in file_cache: f = open(file, "a") f.write(msg) @@ -519,7 +539,7 @@ def set_testing (pkg, enable): newTesting[cpv].append((file, line)) else: if TESTING_PATH_IS_DIR: - file = os.path.join(TESTING_PATH, "geneticone") + file = os.path.join(TESTING_PATH, CONFIG["testingfile"]) else: file = TESTING_PATH newTesting[cpv].append((file, "-1")) @@ -536,7 +556,12 @@ def write_testing (): line = int(line) # add new line if line == -1: - msg = "\n#geneticone update#\n=%s ~%s\n" % (cpv, arch) + msg = "\n#geneticone update#\n" + if CONFIG["testingPerVersion"]: + msg += "=%s ~%s\n" % (cpv, arch) + else: + list = split_package_name(cpv) + msg += "%s/%s ~%s\n" % (list[0],list[1],arch) if not file in file_cache: f = open(file, "a") f.write(msg) diff --git a/geneticone/backend/package.py b/geneticone/backend/package.py index 7b917a8..522ca08 100644 --- a/geneticone/backend/package.py +++ b/geneticone/backend/package.py @@ -14,8 +14,7 @@ from geneticone.helper import * from portage_helper import * import flags -import gentoolkit -import portage +import portage, gentoolkit from portage_util import unique_array class Package (gentoolkit.Package): @@ -182,8 +181,21 @@ class Package (gentoolkit.Package): continue pkg = find_best_match(dep) - if not dep: - raise PackageNotFoundException, dep + if not pkg: # try to find masked ones + list = find_packages(dep, masked = True) + if not list: + raise PackageNotFoundException, dep + + list = sort_package_list(list) + done = False + for i in range(len(list)-1,0,-1): + p = list[i] + if not p.is_masked(): + dep_pkgs.append(p.get_cpv()) + done = True + break + if not done: + dep_pkgs.append(list[-1].get_cpv()) else: dep_pkgs.append(pkg.get_cpv()) diff --git a/geneticone/backend/portage_helper.py b/geneticone/backend/portage_helper.py index aae7c19..23172e5 100644 --- a/geneticone/backend/portage_helper.py +++ b/geneticone/backend/portage_helper.py @@ -7,14 +7,11 @@ # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. # -# Written by Necoro d.M. et.al. +# Written by Necoro d.M. -import re -import os -import copy +import re, os, copy -import gentoolkit -import portage +import portage, gentoolkit from portage_util import unique_array from geneticone.backend import * @@ -42,7 +39,16 @@ def geneticize_list (list_of_packages): return [package.Package(x) for x in list_of_packages] def find_best_match (search_key, only_installed = False): - """Finds the best match in the portage tree.""" + """Finds the best match in the portage tree. It does not find masked packages! + + @param search_key: the key to find in the portage tree + @type search_key: string + @param only_installed: if True, only installed packages are searched + @type only_installed: boolean + + @returns: the package found or None + @rtype: backend.Package or None""" + t = None if not only_installed: t = porttree.dep_bestmatch(search_key) @@ -53,14 +59,28 @@ def find_best_match (search_key, only_installed = False): return None def find_packages (search_key, masked=False): - """This returns a list of packages which have to fit exactly. Additionally ranges like '<,>,=,~,!' et. al. are possible.""" + """This returns a list of packages which have to fit exactly. Additionally ranges like '<,>,=,~,!' et. al. are possible. + @param search_key: the key to look for + @type search_key: string + @param masked: if True, also look for masked packages + @type masked: boolean + @returns: list of found packages + @rtype: list of backend.Package""" + return geneticize_list(gentoolkit.find_packages(search_key, masked)) def find_installed_packages (search_key, masked=False): - """This returns a list of installed packages which have to fit exactly. Additionally ranges like '<,>,=,~,!' et. al. are possible.""" + """This returns a list of packages which have to fit exactly. Additionally ranges like '<,>,=,~,!' et. al. are possible. + @param search_key: the key to look for + @type search_key: string + @param masked: if True, also look for masked packages + @type masked: boolean + @returns: list of found packages + @rtype: list of backend.Package""" + return geneticize_list(gentoolkit.find_installed_packages(search_key, masked)) -def find_system_packages (name=None): +def find_system_packages (): """Returns a list-tuple (resolved_packages, unresolved_packages) for all system packages.""" list = gentoolkit.find_system_packages() return (geneticize_list(list[0]), geneticize_list(list[1])) @@ -114,12 +134,22 @@ def find_all_system_packages (name=None): return [package.Package(x) for x in sys] def get_all_versions (cp): + """Returns all versions of a certain package. + @param cp: the package + @type cp: string (cat/pkg) + @returns: the list of found packages + @rtype: list of backend.Package""" t = porttree.dbapi.cp_list(cp) t += vartree.dbapi.cp_list(cp) t = unique_array(t) return geneticize_list(t) def get_all_installed_versions (cp): + """Returns all installed versions of a certain package. + @param cp: the package + @type cp: string (cat/pkg) + @returns: the list of found packages + @rtype: list of backend.Package""" return geneticize_list(vartree.dbapi.cp_list(cp)) def list_categories (name=None): @@ -138,7 +168,7 @@ def sort_package_list(pkglist): return gentoolkit.sort_package_list(pkglist) def reload_settings (): - # XXX: what the hack are we doing here Oo + """Reloads portage.""" gentoolkit.settings = portage.config(config_incrementals = copy.deepcopy(gentoolkit.settings.incrementals)) use_descs = {} -- cgit v1.2.3-70-g09d2