projects.py: Introduced -t topdir

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-01-29 12:20:51 +00:00
commit e015fcfa51

View file

@ -37,40 +37,53 @@ def get_section(path, section):
def get_value(name, section, key): def get_value(name, section, key):
proj_root = proj_dir(name) proj_root = proj_dir(name)
dirs = []
if topdir:
dirs.append(topdir)
dirs.append(projs_root + '/' + name)
if section == 'version': if section == 'version':
with open(proj_root + '/VERSION', 'r') as file: for d in dirs:
r=file.read().replace('\n', '').replace('-dev', '') with open(d + '/VERSION', 'r') as file:
file.close() r=file.read().replace('\n', '').replace('-dev', '')
return r 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' ]: for conf in [ '/make/project.conf', '/doc/share/project.txt' ]:
path = proj_root + conf for d in dirs:
r = () path = d + conf
try: r = ()
file = open(path) try:
except: file = open(path)
continue except:
if not len(section): continue
for line in file: if not len(section):
r = re.findall('^ *' + key + ' *= *(.*)', line) for line in file:
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
r = re.findall('^ *' + key + ' *= *(.*)', line) r = re.findall('^ *' + key + ' *= *(.*)', line)
if (len(r) > 0): if (len(r) > 0):
break break
file.close() else:
if len(r): in_section = False
return r[0] 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 return None
# scope 0: no children # scope 0: no children
@ -220,7 +233,7 @@ global_args = []
skip = 0 skip = 0
for a in sys.argv[1::]: for a in sys.argv[1::]:
global_args.append(a) global_args.append(a)
if a in [ '--prefix', '-p' ]: if a in [ '--prefix', '-p', '--topdir', '-t' ]:
skip = 1 skip = 1
continue continue
if skip > 0: if skip > 0:
@ -231,10 +244,13 @@ for a in sys.argv[1::]:
parser = argparse.ArgumentParser(description='Project metadata evaluation') parser = argparse.ArgumentParser(description='Project metadata evaluation')
parser.add_argument('cmd', default='', help='Command') 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') parser.add_argument('arg', nargs='*', help='Command arguments')
args=parser.parse_args(global_args) args=parser.parse_args(global_args)
projs_root = args.prefix projs_root = args.prefix
topdir = args.topdir
cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd.replace('-', '_')) cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd.replace('-', '_'))
cmd(sys.argv[(len(global_args) + 1)::]) cmd(sys.argv[(len(global_args) + 1)::])