root/releases/pkgcore-checks/0.3/pkgcore_checks/util.py @ ferringb%2540gmail.com-20070127120900-op2rn4z1ozpp167n

Revision ferringb%2540gmail.com-20070127120900-op2rn4z1ozpp167n, 2.0 KB (checked in by Brian Harring <ferringb@…>, 2 years ago)

use pjoin instead of os.path.join

Line 
1# Copyright: 2006 Brian Harring <ferringb@gmail.com>
2# License: GPL2
3
4from pkgcore.util.demandload import demandload
5demandload(globals(),
6    "logging "
7    "pkgcore.util.packages:get_raw_pkg "
8    "pkgcore.ebuild.atom:atom "
9    "pkgcore.util.file:iter_read_bash "
10    "pkgcore.util.osutils:pjoin ")
11
12
13def get_profiles_desc(repo, ignore_dev=False):
14    fp = pjoin(repo, "profiles.desc")
15
16    arches_dict = {}
17    for line_no, line in enumerate(iter_read_bash(fp)):
18        l = line.split()
19        try:
20            key, profile, status = l
21        except ValueError:
22            logging.error("%s: line number %i isn't of 'key profile status' "
23                "form" % (fp, line_no))
24            continue
25        if ignore_dev and status.lower().strip() == "dev":
26            continue
27        # yes, we're ignoring status.
28        # it's a silly feature anyways.
29        arches_dict.setdefault(key, []).append(profile)
30
31    return arches_dict
32
33def get_repo_known_arches(profiles_path):
34    """Takes the path to the dir with arch.list in it (repo/profiles)."""
35    fp = pjoin(profiles_path, "arch.list")
36    return set(open(fp, "r").read().split())
37
38def get_cpvstr(pkg):
39    pkg = get_raw_pkg(pkg)
40    s = getattr(pkg, "cpvstr", None)
41    if s is not None:
42        return s
43    return str(pkg)     
44
45def get_use_desc(profiles_path):
46    """Takes the path to the dir with use*desc in it (repo/profiles)."""
47    fp = pjoin(profiles_path, "use.desc")
48    l = []
49    for line in iter_read_bash(fp):
50        l.append(line.split()[0])
51    return tuple(l)
52
53def get_use_local_desc(profiles_path):
54    """Takes the path to the dir with use*desc in it (repo/profiles)."""
55    fp = pjoin(profiles_path, "use.local.desc")
56    d = {}
57    for line in iter_read_bash(fp):
58        key, val = line.split(":", 1)
59        a = atom(key.strip())
60        flag = val.split()[0]
61        d.setdefault(a.key, {}).setdefault(a, []).append(flag)
62
63    for v in d.itervalues():
64        v.update((k, frozenset(v)) for k, v in v.items())
65    return d
Note: See TracBrowser for help on using the browser.