diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-01 12:08:34 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-01 12:08:34 -0500 |
commit | f26b3563614940347748c296d74b1071e9de4d2a (patch) | |
tree | 3b7c70d5a9b9034609005d7d46c90f62f9924cb2 | |
parent | ceb1c3496fd69cbff37a12e634c8baf7fc38f581 (diff) |
volk: modifying volk_modtool.
1. Better handling of initial config cases.
2. Don't over-write an existing directory when using -i.
-rw-r--r-- | volk/python/volk_modtool/README | 4 | ||||
-rw-r--r-- | volk/python/volk_modtool/cfg.py | 28 | ||||
-rwxr-xr-x | volk/python/volk_modtool/volk_modtool | 7 | ||||
-rw-r--r-- | volk/python/volk_modtool/volk_modtool_generate.py | 2 |
4 files changed, 34 insertions, 7 deletions
diff --git a/volk/python/volk_modtool/README b/volk/python/volk_modtool/README index 2532e1a86a..5413ff1f1a 100644 --- a/volk/python/volk_modtool/README +++ b/volk/python/volk_modtool/README @@ -49,6 +49,10 @@ Run the command "volk_modtool -i". This will ask you three questions: // It will create <directory>/volk_<name> base: // the directory containing the original VOLK source code +The name provided must be alphanumeric (and cannot start with a +number). No special characters including dashes and underscores are +allowed. + This will build a new skeleton directory in the destination provided with the name volk_<name>. It will contain the necessary structure to build: diff --git a/volk/python/volk_modtool/cfg.py b/volk/python/volk_modtool/cfg.py index c5cfb919c0..c58dc59091 100644 --- a/volk/python/volk_modtool/cfg.py +++ b/volk/python/volk_modtool/cfg.py @@ -28,21 +28,41 @@ import re class volk_modtool_config: + def key_val_sub(self, num, stuff, section): + return re.sub('\$' + 'k' + str(num), stuff[num][0], (re.sub('\$' + str(num), stuff[num][1], section[1][num]))); + def verify(self): for i in self.verification: self.verify_section(i) - + def remap(self): + for i in self.remapification: + self.verify_section(i) + def verify_section(self, section): stuff = self.cfg.items(section[0]) for i in range(len(section[1])): - if not eval(re.sub('\$' + str(i), stuff[i][1], section[1][i])): + eval(self.key_val_sub(i, stuff, section)) + try: + val = eval(self.key_val_sub(i, stuff, section)) + if val == False: + raise exceptions.ValueError + except ValueError: + raise exceptions.ValueError('Verification function returns False... key:%s, val:%s'%(stuff[i][0], stuff[i][1])) + except: raise exceptions.IOError('bad configuration... key:%s, val:%s'%(stuff[i][0], stuff[i][1])) + def __init__(self, cfg=None): self.config_name = 'config' self.config_defaults = ['name', 'destination', 'base'] + self.config_defaults_remap = ['1', + 'self.cfg.set(self.config_name, \'$k1\', os.path.realpath(os.path.expanduser(\'$1\')))', + 'self.cfg.set(self.config_name, \'$k2\', os.path.realpath(os.path.expanduser(\'$2\')))'] + self.config_defaults_verify = ['re.match(\'[a-zA-Z0-9]+$\', \'$0\')', - 'os.path.exists(\'$1\')', 'os.path.exists(\'$2\')'] + 'os.path.exists(\'$1\')', + 'os.path.exists(\'$2\')'] + self.remapification = [(self.config_name, self.config_defaults_remap)] self.verification = [(self.config_name, self.config_defaults_verify)] default = os.path.join(os.getcwd(), 'volk_modtool.cfg') icfg = ConfigParser.RawConfigParser() @@ -57,7 +77,9 @@ class volk_modtool_config: rv = raw_input("%s: "%(kn)) icfg.set(self.config_name, kn, rv) self.cfg = icfg + self.remap() self.verify() + def read_map(self, name, inp): diff --git a/volk/python/volk_modtool/volk_modtool b/volk/python/volk_modtool/volk_modtool index fbacc7139b..74b71adde2 100755 --- a/volk/python/volk_modtool/volk_modtool +++ b/volk/python/volk_modtool/volk_modtool @@ -25,6 +25,7 @@ from optparse import OptionParser, OptionGroup import exceptions import os +import sys if __name__ == '__main__': parser = OptionParser(); @@ -54,8 +55,10 @@ if __name__ == '__main__': parser.add_option_group(actions) (options, args) = parser.parse_args(); + if len(sys.argv) < 2: + parser.print_help() - if options.moo: + elif options.moo: print " (__) " print " (oo) " print " /------\/ " @@ -123,5 +126,3 @@ if __name__ == '__main__': kernelset = my_modtool.get_current_kernels(base); for i in kernelset: print i; - - diff --git a/volk/python/volk_modtool/volk_modtool_generate.py b/volk/python/volk_modtool/volk_modtool_generate.py index 2e10e7b00c..80c2aed598 100644 --- a/volk/python/volk_modtool/volk_modtool_generate.py +++ b/volk/python/volk_modtool/volk_modtool_generate.py @@ -94,7 +94,7 @@ class volk_modtool: dest = os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name']) if os.path.exists(dest): - shutil.rmtree(dest) + raise exceptions.IOError("Destination %s already exits!"%(dest)); if not os.path.exists(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'kernels/volk_' + self.my_dict['name'])): os.makedirs(os.path.join(self.my_dict['destination'], 'volk_' + self.my_dict['name'], 'kernels/volk_' + self.my_dict['name'])) |