mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 12:03:31 +01:00
166 lines
5.4 KiB
Python
166 lines
5.4 KiB
Python
#!/usr/bin/python -u
|
|
|
|
import sys
|
|
import argparse
|
|
from sets import Set
|
|
from os.path import expanduser
|
|
import re
|
|
|
|
def re_section(name):
|
|
return re.compile('[' + name + ']'
|
|
'.*?'
|
|
'(?=[)',
|
|
re.DOTALL)
|
|
|
|
# --------------------------------------------------------------------- helpers
|
|
def strip_module_from_spec(mod):
|
|
return re.sub(r'-devel$|-run$', '', re.split('([=><]+)', mod)[0].strip())
|
|
|
|
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(name, section, key):
|
|
proj_root = 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
|
|
|
|
path = proj_root + '/doc/share/project.txt'
|
|
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 None
|
|
|
|
def add_modules_from_project_txt(buf, spec, section, key, add_self, recursive,
|
|
names_only):
|
|
name = strip_module_from_spec(spec)
|
|
if names_only:
|
|
spec = name
|
|
if spec in buf:
|
|
return
|
|
if recursive:
|
|
deps = get_value(name, section, key)
|
|
if deps:
|
|
deps = deps.split(',')
|
|
for dep in deps:
|
|
add_modules_from_project_txt(buf, dep,
|
|
section, key, add_self=True, recursive=True,
|
|
names_only=names_only)
|
|
if add_self:
|
|
buf.append(name)
|
|
|
|
def get_modules_from_project_txt(names, section, key, add_self, recursive,
|
|
names_only = True):
|
|
#r = Set()
|
|
r = []
|
|
for name in names:
|
|
add_modules_from_project_txt(r, name, section, key, add_self, recursive,
|
|
names_only)
|
|
return r
|
|
|
|
# --------------------------------------------------------------------- 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 = get_modules_from_project_txt(args.module, 'pkg.required', 'run',
|
|
recursive=True, add_self=True, names_only=True)
|
|
r = ''
|
|
for m in deps:
|
|
r = r + ':' + projs_root + '/' + m + '/lib'
|
|
print r[1:]
|
|
|
|
def cmd_path(args_):
|
|
parser = argparse.ArgumentParser(description='path')
|
|
parser.add_argument('module', nargs='*', help='Modules')
|
|
args=parser.parse_args(args_)
|
|
deps = get_modules_from_project_txt(args.module, 'pkg.required', 'run',
|
|
recursive=True, add_self=True, names_only=True)
|
|
r = ''
|
|
for m in deps:
|
|
r = r + ':' + projs_root + '/' + m + '/bin'
|
|
print r[1:]
|
|
|
|
def cmd_pkg_requires(args_):
|
|
parser = argparse.ArgumentParser(description='pkg-requires')
|
|
parser.add_argument('flavour', help='Flavour')
|
|
parser.add_argument('module', nargs='*', help='Modules')
|
|
args=parser.parse_args(args_)
|
|
r = []
|
|
for m in args.module:
|
|
deps = get_value(m, 'pkg.required', args.flavour).split(',')
|
|
for spec in deps:
|
|
dep = re.split('([=><]+)', spec)
|
|
for i, item in enumerate(dep):
|
|
dep[i] = item.strip()
|
|
if len(dep) == 3:
|
|
dep_project = re.sub(r'-devel$|-run$', '', dep[0])
|
|
version = get_value(dep_project, 'version', '')
|
|
if dep[2] == 'VERSION':
|
|
dep[2] = version.split('-')[0]
|
|
elif dep[2] == 'VERSION-REVISION':
|
|
dep[2] = version
|
|
else:
|
|
raise Exception("Unknown version specifier in " + spec)
|
|
r.append(' '.join(dep))
|
|
print ', '.join(r)
|
|
|
|
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('--prefix', '-p', nargs='?', default = expanduser("~") + '/local/src/cvs.stable/proj', help='Project Path Prefix')
|
|
parser.add_argument('arg', nargs='*', help='Command arguments')
|
|
args=parser.parse_args(global_args)
|
|
projs_root = args.prefix
|
|
cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd.replace('-', '_'))
|
|
cmd(sys.argv[(len(global_args) + 1)::])
|
|
|