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