From e015fcfa51e4f8ea015d06509591af176b5aebea Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 29 Jan 2016 12:20:51 +0000 Subject: [PATCH] projects.py: Introduced -t topdir Signed-off-by: Jan Lindemann --- scripts/projects.py | 76 +++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/scripts/projects.py b/scripts/projects.py index 4409c847..fac2b00e 100644 --- a/scripts/projects.py +++ b/scripts/projects.py @@ -37,40 +37,53 @@ def get_section(path, section): def get_value(name, section, key): proj_root = proj_dir(name) + dirs = [] + if topdir: + dirs.append(topdir) + dirs.append(projs_root + '/' + name) if section == 'version': - with open(proj_root + '/VERSION', 'r') as file: - r=file.read().replace('\n', '').replace('-dev', '') - file.close() - return r + for d in dirs: + with open(d + '/VERSION', 'r') as file: + r=file.read().replace('\n', '').replace('-dev', '') + file.close() + return r + raise Exception("failed to find version of " + name) + dirs = [] + if topdir: + dirs.append(topdir) + dirs.append(projs_root + '/' + name) for conf in [ '/make/project.conf', '/doc/share/project.txt' ]: - path = proj_root + conf - r = () - try: - file = open(path) - except: - continue - if not len(section): - for line in file: - r = re.findall('^ *' + key + ' *= *(.*)', line) - if (len(r) > 0): - break - else: - in_section = False - pat = '[' + section + ']' - for line in file: - if (line.rstrip() == pat): - in_section = True - continue - if in_section: - if len(line) and line[0] == '[': - break + for d in dirs: + path = d + conf + r = () + try: + file = open(path) + except: + continue + if not len(section): + for line in file: r = re.findall('^ *' + key + ' *= *(.*)', line) if (len(r) > 0): break - file.close() - if len(r): - return r[0] + else: + in_section = False + pat = '[' + section + ']' + for line in file: + if (line.rstrip() == pat): + in_section = True + continue + if in_section: + if len(line) and line[0] == '[': + break + r = re.findall('^ *' + key + ' *= *(.*)', line) + if (len(r) > 0): + break + file.close() + if len(r): + return r[0] + return '' + return None # scope 0: no children @@ -220,7 +233,7 @@ global_args = [] skip = 0 for a in sys.argv[1::]: global_args.append(a) - if a in [ '--prefix', '-p' ]: + if a in [ '--prefix', '-p', '--topdir', '-t' ]: skip = 1 continue if skip > 0: @@ -231,10 +244,13 @@ for a in sys.argv[1::]: parser = argparse.ArgumentParser(description='Project metadata evaluation') parser.add_argument('cmd', default='', help='Command') -parser.add_argument('--prefix', '-p', nargs='?', default = expanduser("~") + '/local/src/cvs.stable/proj', help='Project Path Prefix') +parser.add_argument('--topdir', '-t', nargs='?', help='Project Path') +parser.add_argument('--prefix', '-p', nargs='?', default = expanduser("~") + + '/local/src/cvs.stable/proj', help='Projects Path Prefix') parser.add_argument('arg', nargs='*', help='Command arguments') args=parser.parse_args(global_args) projs_root = args.prefix +topdir = args.topdir cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd.replace('-', '_')) cmd(sys.argv[(len(global_args) + 1)::])