Commit c5a1e0b5 authored by Steve Goering's avatar Steve Goering

add shortcut way for modules

parent ea291102
......@@ -51,6 +51,7 @@ main() {
sudo ln -s "$webiscmdrootpath/webis.py" "/usr/bin/webis"
}
#
......
......@@ -65,6 +65,9 @@ def get_submodule_description(modulepath):
extract submodul description based on modulepath
:return description
"""
if not os.path.isfile(modulepath):
return os.path.basename(modulepath)
f = open(modulepath)
lines = f.readlines()
f.close()
......@@ -96,6 +99,14 @@ def handle_script(submodul, scriptfile, params=[]):
return return_value
def get_keys_startswith(dictionary, searchkey):
"""
extract keys that have a prefix match
"""
needed_keys = [x for x in dictionary.keys() if x.startswith(searchkey)]
return needed_keys
def main(args):
lInfo("read config")
# read config file
......@@ -119,10 +130,13 @@ def main(args):
parser.add_argument('submodul', type=str, nargs='?', default="help", help='submodul')
parser.add_argument('parameter', type=str, nargs='*', help='parameters for submodul command')
argsdict = vars(parser.parse_args(sys.argv[1:3])) # using sys.arv[..] is necessary because of unknown arguments in the parameters for submoduls
if len(args) > 0 and len(get_keys_startswith(modules, args[0])) == 1:
args[0] = get_keys_startswith(modules, args[0])[0]
argsdict = vars(parser.parse_args(args[0:2])) # using args[..] is necessary because of unknown arguments in the parameters for submoduls
# set parameters
argsdict["parameter"] = sys.argv[3:]
argsdict["parameter"] = args[2:]
lInfo("available moduls: " + str(len(modules)))
......@@ -132,6 +146,11 @@ def main(args):
lInfo("selected modul: " + argsdict["modul"])
submodules = get_submodules(config, modules[argsdict["modul"]])
submodules["help"] = "integrated help"
if len(get_keys_startswith(submodules, argsdict["submodul"])) == 1:
argsdict["submodul"] = get_keys_startswith(submodules, argsdict["submodul"])[0]
if argsdict["submodul"] == "help":
lHelp("submodules of " + argsdict["modul"])
max_size = len(max(submodules.keys(), key=len))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment