diff --git a/island/__init__.py b/island/__init__.py index 80f0826..a7e053d 100755 --- a/island/__init__.py +++ b/island/__init__.py @@ -54,36 +54,33 @@ def init(): is_init = True - -myArgs = arguments.islandArg() -myArgs.add_section("option", "Can be set one time in all case") -myArgs.add("h", "help", desc="Display this help") -myArgs.add("v", "verbose", list=[["0","None"],["1","error"],["2","warning"],["3","info"],["4","debug"],["5","verbose"],["6","extreme_verbose"]], desc="display debug level (verbose) default =2") -myArgs.add("c", "color", desc="Display message in color") -# for init only -#myArgs.add("h", "help", desc="Help of this action") -myArgs.add("b", "branch", haveParam=True, desc="Select branch to display") -myArgs.add("m", "manifest", haveParam=True, desc="Name of the manifest") -myArgs.add("N", "no-fetch-manifest", haveParam=False, desc="Disable the fetch of the manifest") -""" -myArgs.add("j", "jobs", haveParam=True, desc="Specifies the number of jobs (commands) to run simultaneously") -myArgs.add("d", "depth", haveParam=True, desc="Depth to clone all the repository") - -""" -localArgument = myArgs.parse() +# initialize the system ... +init() -""" - display the help of this makefile -""" +debug.verbose("List of actions: " + str(actions.get_list_of_action())) + +my_args = arguments.islandArg() +my_args.add_section("option", "Can be set one time in all case") +my_args.add("h", "help", desc="Display this help") +my_args.add("v", "verbose", list=[["0","None"],["1","error"],["2","warning"],["3","info"],["4","debug"],["5","verbose"],["6","extreme_verbose"]], desc="display debug level (verbose) default =2") +my_args.add("c", "color", desc="Display message in color") +my_args.add("n", "no-fetch-manifest", haveParam=False, desc="Disable the fetch of the manifest") +my_args.set_stop_at(actions.get_list_of_action()) +local_argument = my_args.parse() + +## +## @brief Display the help of this makefile. +## def usage(): color = debug.get_color_set() # generic argument displayed : - myArgs.display() + my_args.display() print(" Action availlable" ) list_actions = actions.get_list_of_action(); for elem in list_actions: - print(" " + color['green'] + elem + color['default']) + print(" " + color['green'] + elem + color['default']) + print(" " + actions.get_action_help(elem)) """ print(" " + color['green'] + "init" + color['default']) print(" initialize a 'island' interface with a manifest in a git ") @@ -191,15 +188,12 @@ if os.path.isfile(config_file) == True: """ # parse default unique argument: -for argument in localArgument: +for argument in local_argument: parseGenericArg(argument, True) -# initialize the system ... -init() - # remove all generic arguments: new_argument_list = [] -for argument in localArgument: +for argument in local_argument: if parseGenericArg(argument, False) == True: continue new_argument_list.append(argument) @@ -230,7 +224,7 @@ if action_to_do != "init" \ exit(-1) -actions.execute(action_to_do, new_argument_list) +actions.execute(action_to_do, my_args.get_last_parsed()+1) # stop all started threads; #multiprocess.un_init() diff --git a/island/actions.py b/island/actions.py index 475da38..f594522 100644 --- a/island/actions.py +++ b/island/actions.py @@ -13,6 +13,7 @@ from . import debug import os import sys from . import env +from . import arguments list_actions = [] @@ -61,25 +62,58 @@ def get_desc(action_name): sys.path.append(os.path.dirname(elem["path"])) the_action = __import__(__base_action_name + action_name) if "get_desc" not in dir(the_action): - debug.error("execute is not implmented for this action ... '" + str(action_name) + "'") - return None + return "" return the_action.get_desc() - return None + return "" -def execute(action_name, argument_list): +def usage(arguments, action_name): + color = debug.get_color_set() + # generic argument displayed for specific action: + print("Specific argument for the command: '" + action_name + "'" ) + print(" " + get_desc(action_name)) + arguments.display(action_name) + exit(0) + +def execute(action_name, argument_start_id): global list_actions; # TODO: Move here the check if action is availlable for elem in list_actions: - if elem["name"] == action_name: - debug.info("action: " + str(elem)); - # finish the parsing - sys.path.append(os.path.dirname(elem["path"])) - the_action = __import__(__base_action_name + action_name) - if "execute" not in dir(the_action): - debug.error("execute is not implmented for this action ... '" + str(action_name) + "'") + if elem["name"] != action_name: + continue + debug.info("action: " + str(elem)); + # finish the parsing + sys.path.append(os.path.dirname(elem["path"])) + the_action = __import__(__base_action_name + action_name) + my_under_args_parser = arguments.islandArg() + my_under_args_parser.add("h", "help", desc="Help of this action") + if "add_specific_arguments" in dir(the_action): + the_action.add_specific_arguments(my_under_args_parser, elem["name"]) + my_under_args = my_under_args_parser.parse(argument_start_id) + # search help if needed ==> permit to not duplicating code + for elem in my_under_args: + if elem.get_option_name() == "help": + usage(my_under_args_parser, action_name) return False - return the_action.execute(argument_list) + # now we can execute: + if "execute" not in dir(the_action): + debug.error("execute is not implmented for this action ... '" + str(action_name) + "'") + return False + debug.info("execute: " + action_name) + for elem in my_under_args: + debug.info(" " + str(elem.get_option_name()) + "='" + str(elem.get_arg()) + "'") + return the_action.execute(my_under_args) debug.error("Can not do the action...") return False + +def get_action_help(action_name): + global list_actions; + for elem in list_actions: + if elem["name"] != action_name: + continue + sys.path.append(os.path.dirname(elem["path"])) + the_action = __import__(__base_action_name + action_name) + if "help" in dir(the_action): + return the_action.help() + return "---" diff --git a/island/actions/islandAction_checkout.py b/island/actions/islandAction_checkout.py index 20c4a67..3004eab 100644 --- a/island/actions/islandAction_checkout.py +++ b/island/actions/islandAction_checkout.py @@ -20,21 +20,18 @@ import os def help(): return "plop" - - - +def add_specific_arguments(my_args, section): + my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") + my_args.add_arg("branch", optionnal=False, desc="Branch to checkout") def execute(arguments): - debug.info("execute:") - for elem in arguments: - debug.info(" '" + str(elem.get_arg()) + "'") - if len(arguments) != 1: - debug.error("checkout: missing argument to select the new branch ...") + argument_remote_name = "" branch_to_checkout = "" for elem in arguments: - if elem.get_option_name() == "": - if branch_to_checkout != "": - debug.error("checkout branch already set : '" + branch_to_checkout + "' !!! '" + elem.get_arg() + "'") + if elem.get_option_name() == "remote": + debug.info("find remote name: '" + elem.get_arg() + "'") + argument_remote_name = elem.get_arg() + if elem.get_option_name() == "branch": branch_to_checkout = elem.get_arg() else: debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") diff --git a/island/actions/islandAction_commit.py b/island/actions/islandAction_commit.py new file mode 100644 index 0000000..c797260 --- /dev/null +++ b/island/actions/islandAction_commit.py @@ -0,0 +1,94 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## + +from island import debug +from island import tools +from island import env +from island import config +from island import multiprocess +from island import manifest +import os + + +def help(): + return "commit in all repository" + + + + +def add_specific_arguments(my_args, section): + my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") + my_args.add("m", "comment", haveParam=True, desc="Comment to commit data") + + +def execute(arguments): + argument_remote_name = "" + argument_comment = "" + for elem in arguments: + if elem.get_option_name() == "remote": + debug.info("find remote name: '" + elem.get_arg() + "'") + argument_remote_name = elem.get_arg() + if elem.get_option_name() == "comment": + debug.info("find comment: '" + elem.get_arg() + "'") + argument_comment = elem.get_arg() + else: + debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") + + debug.info("commit with argument: "); + if argument_comment != "": + debug.info(" comment: '" + str(argument_comment) + "'"); + exit(0); + + # check if .XXX exist (create it if needed) + if os.path.exists(env.get_island_path()) == False \ + or os.path.exists(env.get_island_path_config()) == False \ + or os.path.exists(env.get_island_path_manifest()) == False: + debug.error("System already init have an error: missing data: '" + str(env.get_island_path()) + "'") + + + configuration = config.Config() + + if env.get_fetch_manifest() == True: + debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'") + # update manifest + cmd = "git fetch --all" + multiprocess.run_command_direct(cmd, cwd=env.get_island_path_manifest()) + + file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name()) + if os.path.exists(file_source_manifest) == False: + debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") + mani = manifest.Manifest(file_source_manifest) + + all_project = mani.get_all_configs() + debug.info("fetch : " + str(len(all_project)) + " projects") + id_element = 0 + for elem in all_project: + id_element += 1 + debug.info("fetch: " + str(id_element) + "/" + str(len(all_project)) + ": " + str(elem.name)) + #debug.debug("elem : " + str(elem)) + git_repo_path = os.path.join(env.get_island_root_path(), elem.path) + if os.path.exists(git_repo_path) == False: + debug.error("can not fetch project that not exist") + continue + + if os.path.exists(os.path.join(git_repo_path,".git")) == False: + # path already exist but it is not used to as a git repo ==> this is an error + debug.error("path '" + git_repo_path + "' is already existing but not used for a git repository. Clean it and restart") + + # simply update the repository ... + debug.verbose("Fetching project: ") + # fetch the repository + if argument_remote_name == "": + cmd = "git fetch " + elem.select_remote["name"] + else: + cmd = "git fetch " + argument_remote_name + debug.verbose("execute : " + cmd) + multiprocess.run_command_direct(cmd, cwd=git_repo_path) + diff --git a/island/actions/islandAction_fetch.py b/island/actions/islandAction_fetch.py index d46f12d..4204ac2 100644 --- a/island/actions/islandAction_fetch.py +++ b/island/actions/islandAction_fetch.py @@ -22,20 +22,18 @@ def help(): +def add_specific_arguments(my_args, section): + my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") def execute(arguments): - debug.info("execute:") - origin_name = "" + argument_remote_name = "" for elem in arguments: - debug.info(" '" + str(elem.get_arg()) + "'") - if len(arguments) == 0: - pass - elif len(arguments) == 1: - origin_name = arguments[0].get_arg() - debug.info("try fetch remote if exist: '" + str(origin_name) + "'") - else: - debug.error("Sync have not parameter") + if elem.get_option_name() == "remote": + debug.info("find remote name: '" + elem.get_arg() + "'") + argument_remote_name = elem.get_arg() + else: + debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") # check if .XXX exist (create it if needed) if os.path.exists(env.get_island_path()) == False \ @@ -62,7 +60,7 @@ def execute(arguments): id_element = 0 for elem in all_project: id_element += 1 - debug.info("fetch : " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name)) + debug.info("fetch: " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name)) #debug.debug("elem : " + str(elem)) git_repo_path = os.path.join(env.get_island_root_path(), elem.path) if os.path.exists(git_repo_path) == False: @@ -76,10 +74,11 @@ def execute(arguments): # simply update the repository ... debug.verbose("Fetching project: ") # fetch the repository - if origin_name == "": - cmd = "git fetch " + elem.select_remote["name"] + cmd = "git fetch" + if argument_remote_name != "": + cmd += " " + argument_remote_name else: - cmd = "git fetch " + origin_name + cmd += " " + elem.select_remote["name"] debug.verbose("execute : " + cmd) multiprocess.run_command_direct(cmd, cwd=git_repo_path) diff --git a/island/actions/islandAction_init.py b/island/actions/islandAction_init.py index db4d489..e3f1235 100644 --- a/island/actions/islandAction_init.py +++ b/island/actions/islandAction_init.py @@ -16,12 +16,14 @@ from island import multiprocess import os def help(): - return "plop" + return "Init a island repository (need 'fetch' after)" + +def add_specific_arguments(my_args, section): + my_args.add("b", "branch", haveParam=True, desc="Select branch to display") + my_args.add("m", "manifest", haveParam=True, desc="Name of the manifest") + def execute(arguments): - debug.info("execute:") - for elem in arguments: - debug.info(" '" + str(elem.get_arg()) + "'") if len(arguments) == 0: debug.error("Missing argument to execute the current action ...") diff --git a/island/actions/islandAction_push.py b/island/actions/islandAction_push.py new file mode 100644 index 0000000..e736ceb --- /dev/null +++ b/island/actions/islandAction_push.py @@ -0,0 +1,107 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license MPL v2.0 (see license file) +## + +from island import debug +from island import tools +from island import env +from island import config +from island import multiprocess +from island import manifest +import os + + +def help(): + return "Push all repository to the upper server" + + + + +def add_specific_arguments(my_args, section): + my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") + + +def execute(arguments): + argument_remote_name = "" + for elem in arguments: + if elem.get_option_name() == "remote": + debug.info("find remote name: '" + elem.get_arg() + "'") + argument_remote_name = elem.get_arg() + else: + debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") + + # check if .XXX exist (create it if needed) + if os.path.exists(env.get_island_path()) == False \ + or os.path.exists(env.get_island_path_config()) == False \ + or os.path.exists(env.get_island_path_manifest()) == False: + debug.error("System already init have an error: missing data: '" + str(env.get_island_path()) + "'") + + + configuration = config.Config() + + if env.get_fetch_manifest() == True: + debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'") + # update manifest + cmd = "git fetch --all" + multiprocess.run_command_direct(cmd, cwd=env.get_island_path_manifest()) + + file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name()) + if os.path.exists(file_source_manifest) == False: + debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") + mani = manifest.Manifest(file_source_manifest) + + all_project = mani.get_all_configs() + debug.info("fetch : " + str(len(all_project)) + " projects") + id_element = 0 + for elem in all_project: + id_element += 1 + debug.info("push: " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name)) + #debug.debug("elem : " + str(elem)) + git_repo_path = os.path.join(env.get_island_root_path(), elem.path) + if os.path.exists(git_repo_path) == False: + debug.error("can not push project that not exist") + continue + + if os.path.exists(os.path.join(git_repo_path,".git")) == False: + # path already exist but it is not used to as a git repo ==> this is an error + debug.error("path '" + git_repo_path + "' exist but not used for a git repository. Clean it and restart") + + # get the current branch: + # get local branch + cmd = "git branch -a" + debug.verbose("execute : " + cmd) + ret_branch = multiprocess.run_command(cmd, cwd=git_repo_path) + list_branch = ret_branch[1].split('\n') + list_branch2 = [] + list_branch3 = [] + select_branch = "" + for elem_branch in list_branch: + if len(elem_branch.split(" -> ")) != 1: + continue + if elem_branch[2:10] == "remotes/": + elem_branch = elem_branch[:2] + elem_branch[10:] + if elem_branch[:2] == "* ": + list_branch2.append([elem_branch[2:], True]) + select_branch = elem_branch[2:] + else: + list_branch2.append([elem_branch[2:], False]) + list_branch3.append(elem_branch[2:]) + + # simply update the repository ... + debug.verbose("Push project: ") + # fetch the repository + cmd = "git push" + if argument_remote_name != "": + cmd += " " + argument_remote_name + else: + cmd += " " + elem.select_remote["name"] + cmd += " " + elem_branch + ":" + elem_branch + debug.verbose("execute : " + cmd) + multiprocess.run_command_direct(cmd, cwd=git_repo_path) + diff --git a/island/actions/islandAction_status.py b/island/actions/islandAction_status.py index 390b1d2..a3ca665 100644 --- a/island/actions/islandAction_status.py +++ b/island/actions/islandAction_status.py @@ -21,18 +21,18 @@ def help(): return "plop" +def add_specific_arguments(my_args, section): + my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") + + def execute(arguments): - debug.info("execute:") - origin_name = "" + argument_remote_name = "" for elem in arguments: - debug.info(" '" + str(elem.get_arg()) + "'") - if len(arguments) == 0: - pass - elif len(arguments) == 1: - origin_name = arguments[0].get_arg() - debug.info("try fetch remote if exist: '" + str(origin_name) + "'") - else: - debug.error("Sync have not parameter") + if elem.get_option_name() == "remote": + debug.info("find remote name: '" + elem.get_arg() + "'") + argument_remote_name = elem.get_arg() + else: + debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") # check if .XXX exist (create it if needed) if os.path.exists(env.get_island_path()) == False \ @@ -90,17 +90,17 @@ def execute(arguments): list_branch3.append(elem_branch[2:]) debug.verbose("List all branch: " + str(list_branch3)) # get tracking branch - if origin_name == "": + if argument_remote_name == "": cmd = "git rev-parse --abbrev-ref --symbolic-full-name @{u}" debug.verbose("execute : " + cmd) ret_track = multiprocess.run_command(cmd, cwd=git_repo_path) else: - debug.extreme_verbose("check if exist " + origin_name + "/" + select_branch + " in " + str(list_branch3)) - if origin_name + "/" + select_branch not in list_branch3: + debug.extreme_verbose("check if exist " + argument_remote_name + "/" + select_branch + " in " + str(list_branch3)) + if argument_remote_name + "/" + select_branch not in list_branch3: debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t (NO BRANCH)") continue; else: - ret_track = [True, origin_name + "/" + select_branch] + ret_track = [True, argument_remote_name + "/" + select_branch] modify_status = " " if is_modify == True: diff --git a/island/actions/islandAction_sync.py b/island/actions/islandAction_sync.py index 9679be9..20117dc 100644 --- a/island/actions/islandAction_sync.py +++ b/island/actions/islandAction_sync.py @@ -23,11 +23,7 @@ def help(): - def execute(arguments): - debug.info("execute:") - for elem in arguments: - debug.info(" '" + str(elem.get_arg()) + "'") if len(arguments) != 0: debug.error("Sync have not parameter") diff --git a/island/arguments.py b/island/arguments.py index 680faaf..daae3f9 100644 --- a/island/arguments.py +++ b/island/arguments.py @@ -83,6 +83,8 @@ class ArgDefine: self.have_param = False self.description = desc; + def is_parsable(self): + return True ## ## @brief Get the small name of the option ex: '-v' ## @param[in] self Class handle @@ -165,6 +167,88 @@ class ArgDefine: print(" { " + tmpElementPrint + " }") +## +## @brief Declare an argument value and store it in a parameter +## +class ArgVolatile: + ## + ## @brief Contructor. + ## @param[in] self Class handle + ## @param[in] dest_option (string) Where to store the option name + ## @param[in] optionnal (bool) this element can be not present + ## @param[in] desc (string) user friendly description with this parameter (default "") + ## + def __init__(self, + dest_option="", + optionnal=False, + desc=""): + self.dest_option = dest_option; + if dest_option == "": + debug.error("volatil argument must be store in an argument name") + self.optionnal = optionnal; + self.description = desc; + self.count = 0; + + def is_parsable(self): + return False + ## + ## @brief Get the small name of the option ex: '-v' + ## @param[in] self Class handle + ## @return (string) Small name value + ## + def get_option_small(self): + return "" + + ## + ## @brief Get the big name of the option ex: '--verbose' + ## @param[in] self Class handle + ## @return (string) Big name value + ## + def get_option_big(self): + return self.dest_option + + ## + ## @brief Get the status of getting user parameter value + ## @param[in] self Class handle + ## @return True The user must write a value + ## @return False The user must NOT write a value + ## + def need_parameters(self): + if self.count == 0: + self.count += 1 + return True + return False + + ## + ## @brief Compatibility with @ref ArgSection class + ## @param[in] self Class handle + ## @return (string) empty string + ## + def get_porperties(self): + return "???? WHAT the fuck ????" + + ## + ## @brief Check if the user added value is correct or not with the list of availlable value + ## @param[in] self Class handle + ## @param[in] argument (string) User parameter value (string) + ## @return True The parameter is OK + ## @return False The parameter is NOT Availlable + ## + def check_availlable(self, argument): + return True + + ## + ## @brief Display the argument property when user request help + ## @param[in] self Class handle + ## + def display(self): + color = debug.get_color_set() + print(" " + color['red'] + "[" + self.dest_option + "]" + color['default']) + if self.optionnal == True: + print("(OPTIONNAL)") + if self.description != "": + print(" " + self.description) + ## ## @brief Section Class definition (permit to add a comment when requesting help ## @@ -181,6 +265,9 @@ class ArgSection: self.section = sectionName; self.description = desc; + def is_parsable(self): + return False + ## ## @brief Compatibility with @ref ArgDefine class ## @param[in] self Class handle @@ -215,6 +302,9 @@ class ArgSection: print(" [" + color['blue'] + self.section + color['default'] + "] : " + self.description) + + + ## ## @brief Class to define the agmument list availlable for a program ## @@ -225,6 +315,8 @@ class islandArg: ## def __init__(self): self.list_properties = [] + self._list_element_stop = [] + self._last_element_parsed = 0 ## ## @brief Add a new argument possibilities... @@ -238,6 +330,9 @@ class islandArg: def add(self, smallOption="", bigOption="", list=[], desc="", haveParam=False): self.list_properties.append(ArgDefine(smallOption, bigOption, list, desc, haveParam)) + def add_arg(self, destOption="", optionnal=False, desc=""): + self.list_properties.append(ArgVolatile(destOption, optionnal, desc)) + ## ## @brief Add section on argument list ## @param[in] self Class handle @@ -250,17 +345,24 @@ class islandArg: ## ## @brief Parse the argument set in the command line ## @param[in] self Class handle + ## @param[in] start_position_parsing position to start the parsing in the arguments ## - def parse(self): - listArgument = [] # composed of list element - NotparseNextElement=False - for iii in range(1, len(sys.argv)): + def parse(self, start_position_parsing=1): + list_argument = [] # composed of list element + not_parse_next_element=False + for iii in range(start_position_parsing, len(sys.argv)): + self._last_element_parsed = iii # special case of parameter in some elements - if NotparseNextElement==True: - NotparseNextElement = False + if not_parse_next_element == True: + not_parse_next_element = False continue debug.verbose("parse [" + str(iii) + "]=" + sys.argv[iii]) argument = sys.argv[iii] + # check if we get a stop parsing element: + if argument in self._list_element_stop: + debug.warning("stop at position: " + str(iii)) + list_argument.append(ArgElement("", argument)) + break; optionList = argument.split("=") debug.verbose(str(optionList)) if type(optionList) == type(str()): @@ -269,10 +371,12 @@ class islandArg: option = optionList[0] optionParam = argument[len(option)+1:] debug.verbose(option) - argumentFound=False; - if option[:2]=="--": + argument_found=False; + if option[:2] == "--": # big argument for prop in self.list_properties: + if prop.is_parsable()==False: + continue if prop.get_option_big()=="": continue if prop.get_option_big() == option[2:]: @@ -291,7 +395,7 @@ class islandArg: #Get the next parameters if len(sys.argv) > iii+1: optionParam = sys.argv[iii+1] - NotparseNextElement=True + not_parse_next_element=True else : # missing arguments debug.warning("parsing argument error : '" + prop.get_option_big() + "' Missing : subParameters ... cmdLine='" + argument + "'") @@ -301,20 +405,22 @@ class islandArg: debug.warning("argument error : '" + prop.get_option_big() + "' SubParameters not availlable ... cmdLine='" + argument + "' option='" + optionParam + "'") prop.display() exit(-1) - listArgument.append(ArgElement(prop.get_option_big(),optionParam)) - argumentFound = True + list_argument.append(ArgElement(prop.get_option_big(),optionParam)) + argument_found = True else: if len(optionParam)!=0: debug.warning("parsing argument error : '" + prop.get_option_big() + "' need no subParameters : '" + optionParam + "' cmdLine='" + argument + "'") prop.display() - listArgument.append(ArgElement(prop.get_option_big())) - argumentFound = True + list_argument.append(ArgElement(prop.get_option_big())) + argument_found = True break; - if False==argumentFound: + if argument_found == False: debug.error("UNKNOW argument : '" + argument + "'") elif option[:1]=="-": # small argument for prop in self.list_properties: + if prop.is_parsable()==False: + continue if prop.get_option_small()=="": continue if prop.get_option_small() == option[1:1+len(prop.get_option_small())]: @@ -333,7 +439,7 @@ class islandArg: #Get the next parameters if len(sys.argv) > iii+1: optionParam = sys.argv[iii+1] - NotparseNextElement=True + not_parse_next_element=True else : # missing arguments debug.warning("parsing argument error : '" + prop.get_option_big() + "' Missing : subParameters cmdLine='" + argument + "'") @@ -343,36 +449,69 @@ class islandArg: debug.warning("argument error : '" + prop.get_option_big() + "' SubParameters not availlable ... cmdLine='" + argument + "' option='" + optionParam + "'") prop.display() exit(-1) - listArgument.append(ArgElement(prop.get_option_big(),optionParam)) - argumentFound = True + list_argument.append(ArgElement(prop.get_option_big(),optionParam)) + argument_found = True else: if len(optionParam)!=0: debug.warning("parsing argument error : '" + prop.get_option_big() + "' need no subParameters : '" + optionParam + "' cmdLine='" + argument + "'") prop.display() - listArgument.append(ArgElement(prop.get_option_big())) - argumentFound = True + list_argument.append(ArgElement(prop.get_option_big())) + argument_found = True break; - if argumentFound==False: + if argument_found==False: + # small argument + for prop in self.list_properties: + if prop.is_parsable() == True \ + or prop.get_option_big() == "": + continue + if prop.need_parameters() == True: + list_argument.append(ArgElement(prop.get_option_big(), argument)) + argument_found = True + break + if argument_found==False: #unknow element ... ==> just add in the list ... debug.verbose("unknow argument : " + argument) - listArgument.append(ArgElement("", argument)) + list_argument.append(ArgElement("", argument)) - #for argument in listArgument: + for prop in self.list_properties: + if prop.is_parsable() == True \ + or prop.get_option_big() == "": + continue + if prop.need_parameters() == True \ + and prop.optionnal == False: + debug.error("Missing argument:" + prop.get_option_big()) + #for argument in list_argument: # argument.display() #exit(0) - return listArgument; + return list_argument; + + ## + ## @brief Stop parsing at a specific position + ## @param[in] self Class handle + ## @param[in] list_of_element List of element that stop the parsing + ## + def set_stop_at(self, list_of_element): + self._list_element_stop = list_of_element + + ## + ## @brief get the last element parsed. + ## @param[in] self Class handle + ## + def get_last_parsed(self): + return self._last_element_parsed ## ## @brief Display help on console output ## @param[in] self Class handle + ## @param[in] action_name opation to set at the end of the application name ## - def display(self): + def display(self, action_name=""): print("usage:") listOfPropertiesArg = ""; for element in self.list_properties : listOfPropertiesArg += element.get_porperties() - print(" " + sys.argv[0] + listOfPropertiesArg + " ...") + print(" " + sys.argv[0] + listOfPropertiesArg + " " + action_name + " ...") for element in self.list_properties : element.display()