mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-02-01 09:18:40 +01:00
build.Cmd: Add module
Cmd is meant as a base class for classes representing commands currently still implemented as methods of the Project class. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
fbc9e3a001
commit
17bf98cb7a
3 changed files with 79 additions and 1 deletions
|
|
@ -715,7 +715,7 @@ class App(object):
|
|||
r = r + ':' + pd + '/lib'
|
||||
print(r[1:])
|
||||
|
||||
def cmd_pythonpath(self, args_):
|
||||
def cmd_pythonpath_orig(self, args_):
|
||||
parser = argparse.ArgumentParser(description='pythonpath')
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
args = parser.parse_args(args_)
|
||||
|
|
@ -959,6 +959,18 @@ class App(object):
|
|||
args = parser.parse_args(args_)
|
||||
print(self.get_value(args.project, args.section, args.key))
|
||||
|
||||
def run_from_cmd_module(self, name: str, args_) -> None:
|
||||
import importlib
|
||||
name = name.replace('-', '_')
|
||||
cc_name = 'Cmd' + ''.join(x.capitalize() for x in name.lower().split("_"))
|
||||
module = importlib.import_module('jw.build.cmds.' + cc_name)
|
||||
cmd = getattr(module, cc_name)()
|
||||
cmd.app = self
|
||||
parser = argparse.ArgumentParser(description=name)
|
||||
cmd.add_arguments(parser)
|
||||
args = parser.parse_args(args_)
|
||||
return cmd.run(args)
|
||||
|
||||
# -------------------------------------------------------------------- here we go
|
||||
def run(self):
|
||||
|
||||
|
|
@ -1003,6 +1015,10 @@ class App(object):
|
|||
if not self.top_name:
|
||||
self.top_name = re.sub('-[0-9.-]*$', '', basename(realpath(self.topdir)))
|
||||
|
||||
try:
|
||||
return self.run_from_cmd_module(args.cmd, sys.argv[(len(self.global_args) + 1)::])
|
||||
except:
|
||||
pass
|
||||
cmd_name = 'cmd_' + args.cmd.replace('-', '_')
|
||||
cmd = getattr(self, cmd_name)
|
||||
cmd(sys.argv[(len(self.global_args) + 1)::])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue