diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2010-06-10 19:35:16 -0300 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2010-06-10 19:35:16 -0300 |
commit | 73e23779dd68549642c54e9bcfc0ca4d50c05a0f (patch) | |
tree | 4415025c2fc9d5fad9c52cc13177f8b5e3c44d25 /scripts | |
parent | fixes to the requirements.py script (diff) | |
download | g-octave-73e23779dd68549642c54e9bcfc0ca4d50c05a0f.tar.gz g-octave-73e23779dd68549642c54e9bcfc0ca4d50c05a0f.tar.bz2 g-octave-73e23779dd68549642c54e9bcfc0ca4d50c05a0f.zip |
changes to fix the requirements.py script; lots of trailling spaces
removed.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/requirements.py | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/scripts/requirements.py b/scripts/requirements.py index bc892ca..03b90b9 100755 --- a/scripts/requirements.py +++ b/scripts/requirements.py @@ -4,11 +4,11 @@ """ requirements.py ~~~~~~~~~~~~~~~ - + a simple script that creates a JSON file with the list of dependencies that are not from octave-forge package (SystemRequirements and BuildRequires). It writes the JSON content to the stdout. - + :copyright: (c) 2010 by Rafael Goncalves Martins :license: GPL-2, see LICENSE for more details. """ @@ -28,80 +28,84 @@ if os.path.exists(os.path.join(current_dir, '..', 'g_octave')): from g_octave import description, description_tree, exception def main(argv): - + if len(argv) <= 1: print >> sys.stderr, 'one argument required: the json file.' return 1 - + # init portage stuff settings, trees, mtimedb = load_emerge_config() root_config = trees[settings['ROOT']]['root_config'] s = search(root_config, False, False, False, False, False) - + desc_tree = description_tree.DescriptionTree(parse_sysreq = False) - - dependencies = [] - + + # identifier => list of dependencies + dependencies = dict() + for pkg in desc_tree.packages(): try: desc = desc_tree[pkg] except exception.DescriptionTreeException, err: print >> sys.stderr, 'DescriptionTree error: %s' % err return 1 - + deps = [] - + if desc.systemrequirements is not None: deps += [i.strip() for i in desc.systemrequirements.split(',')] - + if desc.buildrequires is not None: deps += [i.strip() for i in desc.buildrequires.split(',')] - - dep_aux = [] + for dep in deps: match = description.re_depends.match(dep) if match is not None: - my_match = match.group(1).split('-')[0] - if my_match not in dep_aux: - dependencies.append((match.group(1), my_match)) - dep_aux.append(my_match) - + my_dep = match.group(1) + my_match = my_dep.split('-')[0] + if my_match not in dependencies: + dependencies[my_match] = [my_dep] + else: + dependencies[my_match].append(my_dep) + json_dict = dict(dependencies=dict()) - + try: with open(argv[1], 'r') as fp: json_dict = json.load(fp) except: pass - - for dep_name, dep in dependencies: + + for dep in dependencies: s.execute(dep) - print dep_name + print dep temp = [] for i in range(len(s.matches['pkg'])): print ' %i: %s' % (i, s.matches['pkg'][i][0]) temp.append(s.matches['pkg'][i][0]) - - if dep_name in json_dict['dependencies']: + + if dependencies[dep][0] in json_dict['dependencies']: select = raw_input('Select a package [%s]: ' % \ - json_dict['dependencies'][dep_name]) + json_dict['dependencies'][dependencies[dep][0]]) else: select = raw_input('Select a package: ') try: - json_dict['dependencies'][dep_name] = temp[int(select)] + for dep_name in dependencies[dep]: + json_dict['dependencies'][dep_name] = temp[int(select)] except: - if select != '' or dep_name not in json_dict['dependencies']: - json_dict['dependencies'][dep_name] = select - print 'Selected: %s' % json_dict['dependencies'][dep_name] - print - + if select != '' or dependencies[dep][0] not in json_dict['dependencies']: + for dep_name in dependencies[dep]: + json_dict['dependencies'][dep_name] = select + print 'Selected: %s' % json_dict['dependencies'][dependencies[dep][0]] + print + try: with open(argv[1], 'w') as fp: json.dump(json_dict, fp, sort_keys=True, indent=4) except: print >> sys.stderr, 'failed to save the json file.' return 1 - + return 0 if __name__ == '__main__': |