aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-06-09 00:49:39 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-06-09 00:49:39 -0300
commitc2f43afea101c56fb41048d8a39739ab396820ae (patch)
tree4d7a6441c34a7755326c4b1cb183487d94ddaf59 /scripts
parentinitial import of the script to improve the management of dependencies. (diff)
downloadg-octave-c2f43afea101c56fb41048d8a39739ab396820ae.tar.gz
g-octave-c2f43afea101c56fb41048d8a39739ab396820ae.tar.bz2
g-octave-c2f43afea101c56fb41048d8a39739ab396820ae.zip
finished scripts/requirements.py
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/requirements.py51
1 files changed, 48 insertions, 3 deletions
diff --git a/scripts/requirements.py b/scripts/requirements.py
index 3d46b27..3fd7513 100755
--- a/scripts/requirements.py
+++ b/scripts/requirements.py
@@ -16,6 +16,10 @@
import json
import sys
import os
+import portage
+
+from _emerge.actions import load_emerge_config
+from _emerge.search import search
current_dir = os.path.dirname(os.path.realpath(__file__))
if os.path.exists(os.path.join(current_dir, '..', 'g_octave')):
@@ -24,6 +28,16 @@ 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 = []
@@ -46,14 +60,45 @@ def main(argv):
for dep in deps:
match = description.re_depends.match(dep)
if match is not None:
- dependencies.append(match.group(1))
+ my_match = match.group(1).split('-')[0]
+ if my_match not in dependencies:
+ dependencies.append(my_match)
json_dict = dict(dependencies=dict())
+ try:
+ with open(argv[1], 'r') as fp:
+ json_dict = json.load(fp)
+ except:
+ pass
+
for dep in dependencies:
- json_dict['dependencies'][dep] = ''
+ s.execute(dep)
+ 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 in json_dict['dependencies']:
+ select = raw_input('Select a package [%s]: ' % \
+ json_dict['dependencies'][dep])
+ else:
+ select = raw_input('Select a package: ')
+ try:
+ json_dict['dependencies'][dep] = temp[int(select)]
+ except:
+ if select != '' or dep not in json_dict['dependencies']:
+ json_dict['dependencies'][dep] = select
+ print 'Selected: %s' % json_dict['dependencies'][dep]
+ print
- json.dump(json_dict, sys.stdout, sort_keys=True, indent=4)
+ 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