mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 12:03:31 +01:00
100 lines
2.8 KiB
Python
100 lines
2.8 KiB
Python
#!/usr/bin/python -u
|
|
|
|
import sys
|
|
import argparse
|
|
from sets import Set
|
|
from os.path import expanduser
|
|
import re
|
|
|
|
proj_root = expanduser("~") + '/local/src/cvs.stable/proj'
|
|
|
|
def re_section(name):
|
|
return re.compile('[' + name + ']'
|
|
'.*?'
|
|
'(?=[)',
|
|
re.DOTALL)
|
|
|
|
# --------------------------------------------------------------------- helpers
|
|
def get_section(path, section):
|
|
r = ''
|
|
file = open(path)
|
|
pat = '[' + section + ']'
|
|
in_section = False
|
|
for line in file:
|
|
if (line.rstrip() == pat):
|
|
in_section = True
|
|
continue
|
|
if in_section:
|
|
if len(line) and line[0] == '[':
|
|
break
|
|
r = r + line
|
|
file.close()
|
|
return r.rstrip()
|
|
|
|
def get_value(path, section, key):
|
|
r = ()
|
|
file = open(path)
|
|
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
|
|
r = re.findall(key + ' *= *(.*)', line)
|
|
if (len(r) > 0):
|
|
break
|
|
file.close()
|
|
if len(r):
|
|
return r[0]
|
|
return ""
|
|
|
|
def add_module_from_projects_txt(buf, name, section, key):
|
|
if name in buf:
|
|
return
|
|
buf.add(name)
|
|
deps = get_value(proj_root + '/' + name + '/doc/share/project.txt', section, key).split()
|
|
for dep in deps:
|
|
add_module_from_projects_txt(buf, dep, section, key)
|
|
|
|
# --------------------------------------------------------------------- commands
|
|
|
|
def cmd_test(args_):
|
|
parser = argparse.ArgumentParser(description='Test')
|
|
parser.add_argument('blah', default='', help='The blah argument')
|
|
args=parser.parse_args(args_)
|
|
print "blah = " + args.blah
|
|
|
|
def cmd_ldlibpath(args_):
|
|
parser = argparse.ArgumentParser(description='ldlibpath')
|
|
parser.add_argument('module', nargs='*', help='Modules')
|
|
args=parser.parse_args(args_)
|
|
deps = Set()
|
|
for m in args.module:
|
|
add_module_from_projects_txt(deps, m, 'dependencies', 'ldlibpath')
|
|
for m in deps:
|
|
print m
|
|
|
|
global_args = []
|
|
for a in sys.argv[1::]:
|
|
global_args.append(a)
|
|
if a[0] != '-':
|
|
break
|
|
|
|
# -------------------------------------------------------------------- here we go
|
|
|
|
parser = argparse.ArgumentParser(description='Project metadata evaluation')
|
|
parser.add_argument('cmd', default='', help='Command')
|
|
parser.add_argument('arg', nargs='*', help='Command arguments')
|
|
args=parser.parse_args(global_args)
|
|
cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd);
|
|
cmd(sys.argv[(len(global_args) + 1)::])
|
|
|