diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2015-06-30 22:15:35 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-06-30 22:15:35 -0400 |
commit | 8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f (patch) | |
tree | 165b052003e580934854a5e9da1182cde1312d62 /utils | |
download | grss-8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f.tar.gz grss-8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f.tar.bz2 grss-8885d6a5b9035f2eb0c02e697dc0bfb45c8b5a7f.zip |
Initial commit.
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/make-worldconf | 138 | ||||
-rwxr-xr-x | utils/most-dependant | 142 |
2 files changed, 280 insertions, 0 deletions
diff --git a/utils/make-worldconf b/utils/make-worldconf new file mode 100755 index 0000000..29cf5b8 --- /dev/null +++ b/utils/make-worldconf @@ -0,0 +1,138 @@ +#!/usr/bin/env python + +import configparser +import copy +import os +import re +import sys + +from _emerge.main import parse_opts +from _emerge.actions import load_emerge_config, create_depgraph_params +from _emerge.depgraph import backtrack_depgraph + +PORTAGE_CONFIGDIR = '/etc/portage' + + +def useflags(config, p): + # Get all IUSE, enabled USE and EXPAND_HIDDEN flags. + try: + iuse = list(p.iuse.all) + use = list(p.use.enabled) + expand_hidden = list(p.use._expand_hidden) + except AttributeError: + return + except TypeError: + return + + # Remove any EXPAND_HIDDEN flags from IUSE flags + my_iuse = copy.deepcopy(iuse) + for u in iuse: + for e in expand_hidden: + while re.match(e, u): + try: + my_iuse.remove(u) + except ValueError: + break + + # Remove any EXPAND_HIDDEN flags from the enabled USE flags + my_use = copy.deepcopy(use) + for u in use: + for e in expand_hidden: + while re.match(e, u): + try: + my_use.remove(u) + except ValueError: + break + + # Remove the arch flag - this needs to be generalized + my_use.remove('amd64') + + # Go through all the IUSE flags and put a - in front + # of all the disabled USE flags. + flags = [] + for i in my_iuse: + if i in my_use: + flags.append(i) + else: + flags.append('-%s' % i) + + # Insert nicely sorted flags. + if len(flags) > 0: + flags.sort() + config[p.slot_atom]['package.use/%s' % re.sub('[/:]', '_', p.slot_atom)] = \ + p.slot_atom + ' ' + ' '.join(flags) + + +def keywords(config, p): + # Stable means there is no keyword is needed. + keyword = None + try: + if not p.stable: + keyword = "??" # Something went wrong! + if p.get_keyword_mask() == 'missing': + keyword = '**' + if p.get_keyword_mask() == 'unstable': + keyword = '~amd64' + except AttributeError: + pass + if keyword: + config[p.slot_atom]['package.accept_keywords/%s' % re.sub('[/:]', '_', p.slot_atom)] = \ + '=%s %s' % (p.cpv, keyword) + + +def envvars(config, p): + try: + fpath = os.path.join(PORTAGE_CONFIGDIR, 'package.env') + with open(fpath, 'r') as g: + for l in g.readlines(): + # This matching needs to be made more strick. + if re.search('%s' % re.escape(p.cpv_split[1]), l): + config[p.slot_atom]['+package.env'] = '%s %s' % (p.slot_atom, + re.sub('[/:]', '_', p.slot_atom)) + m = re.search('(\S+)\s+(\S+)', l) + env_file = os.path.join(PORTAGE_CONFIGDIR, 'env') + env_file = os.path.join(env_file, m.group(2)) + with open(env_file, 'r') as h: + config[p.slot_atom]['env/%s' % re.sub('[/:]', '_', p.slot_atom)] = h.read() + except FileNotFoundError: + pass + + +def main(): + args = sys.argv[1:] + if len(args) == 0: + args = [ '-e', '@world' ] + + myaction, myopts, myfiles = parse_opts(args, silent=True) + emerge_config = load_emerge_config(action=myaction, args=myfiles, opts=myopts) + mysettings, mytrees = emerge_config.target_config.settings, emerge_config.trees + myparams = create_depgraph_params(myopts, myaction) + success, mydepgraph, favorites = backtrack_depgraph(mysettings, mytrees, myopts, \ + myparams, myaction, myfiles, spinner=None) + + config = configparser.RawConfigParser(delimiters=':', allow_no_value=True, comment_prefixes=None) + + for p in mydepgraph.altlist(): + # Prepare a section for this atom + try: + config[p.slot_atom] = {} + except AttributeError: + continue + + # Populate package.use + useflags(config, p) + + # Populate package.accept_keywords + keywords(config, p) + + # Populate package.env and env/* + envvars(config, p) + + if config[p.slot_atom] == {}: + config.remove_section(p.slot_atom) + + with open('world.conf', 'w') as configfile: + config.write(configfile) + +if __name__ == "__main__": + main() diff --git a/utils/most-dependant b/utils/most-dependant new file mode 100755 index 0000000..4ca432b --- /dev/null +++ b/utils/most-dependant @@ -0,0 +1,142 @@ +#!/usr/bin/env python + +import portage +import getopt, re +import os, shlex, shutil, sys, subprocess +from copy import deepcopy + +try: + opts, args = getopt.getopt(sys.argv[1:], 'ea:pv') +except getopt.GetoptError as e: + print(e) + sys.exit(1) + +arch = None +emerge = False +pause = False +verbose = False +for o, a in opts: + if o == '-e': + emerge = True + elif o == '-a': + arch = a + elif o == '-p': + pause = True + elif o == '-v': + verbose = True + else: + print('option %s unknown' % o) +if not arch: + print('no arch privided') + sys.exit(1) +if not verbose and pause: + print('can\'t pause without verbose') + sys.exit(1) + +portdb = portage.db["/"]["porttree"].dbapi +gentoo_repo_location = portdb.repositories["gentoo"].location + +cp_all = [] +if os.path.isfile('desp-1.log'): + if verbose: print('skipping desp-1.log\n', flush=True) + with open('desp-1.log', 'r') as f: + cp_all = [cp.strip() for cp in f.readlines()] + if pause: input('pause\n') +else: + if verbose: print('All packages:', flush=True) + for cp in portdb.cp_all(trees=[gentoo_repo_location]): + if not cp in cp_all: + cp_all.append(cp) + if verbose: print(cp, flush=True) + with open('desp-1.log', 'w') as f: + for cp in cp_all: + f.write('%s\n' % cp) + if verbose: print('\n', flush=True) + if pause: input('pause\n') + +if os.path.isfile('deps-2.log'): + if verbose: print('skipping deps-2.log\n', flush=True) + with open('deps-2.log', 'r') as f: + cp_all = [cp.strip() for cp in f.readlines()] + if pause: input('pause\n') +else: + if verbose: print('Unstable packages:', flush=True) + cp_copy = deepcopy(cp_all) + for cp in cp_copy: + for cpv in portdb.cp_list(cp, mytree=gentoo_repo_location): + keywords = portdb.aux_get(cpv, ["KEYWORDS"])[0] + if arch in re.split('\s+', keywords): + break + else: + cp_all.remove(cp) + if verbose: print(cp, flush=True) + with open('deps-2.log', 'w') as f: + for cp in cp_all: + f.write('%s\n' % cp) + if verbose: print('\n', flush=True) + if pause: input('pause\n') + +if os.path.isfile('deps-3.log'): + if verbose: print('skipping deps-3.log\n', flush=True) + with open('deps-3.log', 'r') as f: + cp_all = [cp.strip() for cp in f.readlines()] + if pause: input('pause\n') +else: + if verbose: print('Dependee packages:', flush=True) + cp_copy = deepcopy(cp_all) + for cp in cp_copy: + for cpv in portdb.cp_list(cp, mytree=gentoo_repo_location): + deps = portdb.aux_get(cpv, ["DEPEND", "RDEPEND"], myrepo="gentoo") + deps = portage.dep.use_reduce(deps, matchall=True, flat=True) + for d in deps: + try: + cp = portage.dep.Atom(d).cp + cp_all.remove(cp) + if verbose: print(cp, flush=True) + except portage.exception.InvalidAtom: + pass + except ValueError: + pass + with open('deps-3.log', 'w') as f: + for cp in cp_all: + f.write('%s\n' % cp) + if verbose: print('\n', flush=True) + if pause: input('pause\n') +if not emerge: + sys.exit(0) + +if os.path.isfile('deps-4.log'): + if verbose: print('skipping deps-4.log\n', flush=True) + with open('deps-4.log', 'r') as f: + cp_all = [cp.strip() for cp in f.readlines()] + if pause: input('pause\n') +else: + if verbose: print('Building dependant packages:', flush=True) + cp_copy = deepcopy(cp_all) + for cp in cp_copy: + outdir = os.path.join('packages', cp) + logfile = os.path.join(outdir, 'emerge.log') + try: + os.makedirs(outdir) + except OSError: + pass + cmd = 'emerge -vp %s' % cp + args = shlex.split(cmd) + with open(logfile, encoding='utf-8', mode='w') as f: + proc = subprocess.Popen(args, stdout=f, stderr=f) + try: + proc.wait(600) + except subprocess.TimeoutExpired: + f.write('TIME OUT\n') + with open(logfile, encoding='utf-8', mode='r') as f: + lines=f.readlines() + if re.search('^Total: ', lines[-1], re.M | re.S): + os.remove(logfile) + else: + cp_all.remove(cp) + if verbose: print(cp, flush=True) + with open('deps-4.log', 'w') as f: + for cp in cp_all: + f.write('%s\n' % cp) + if verbose: print('\n', flush=True) + if pause: input('pause\n') |