From 3b2c888fad400793127c43ec7b35055155826fe3 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 9 Feb 2016 22:32:33 +0100 Subject: [PATCH] [DEV] add run and multiple action in taget --- lutin/multiprocess.py | 16 ++++ lutin/target.py | 129 +++++++++++++++++--------- lutin/z_target/lutinTarget_Android.py | 2 +- lutin/z_target/lutinTarget_Linux.py | 15 ++- lutin/z_target/lutinTarget_MacOs.py | 14 ++- 5 files changed, 127 insertions(+), 49 deletions(-) diff --git a/lutin/multiprocess.py b/lutin/multiprocess.py index c518a40..29da80b 100644 --- a/lutin/multiprocess.py +++ b/lutin/multiprocess.py @@ -42,6 +42,22 @@ exit_flag = False # resuest stop of the thread is_init = False # the thread are initialized error_occured = False # a thread have an error processor_availlable = 1 # number of CPU core availlable +## +## @brief Execute the command with no get of output +## +def run_command_no_lock_out(cmd_line): + # prepare command line: + args = shlex.split(cmd_line) + debug.verbose("cmd = " + str(args)) + try: + # create the subprocess + p = subprocess.Popen(args) + except subprocess.CalledProcessError as e: + debug.error("subprocess.CalledProcessError : " + str(args)) + except: + debug.error("Exception on : " + str(args)) + # launch the subprocess: + p.communicate() ## ## @brief Execute the command and ruturn generate data diff --git a/lutin/target.py b/lutin/target.py index 7731db0..456012e 100644 --- a/lutin/target.py +++ b/lutin/target.py @@ -155,6 +155,9 @@ class Target: # special case for IOS (example) no build dynamicly ... self.support_dynamic_link = True + def __repr__(self): + return "{lutin.Target}" + def add_flag(self, type, list): tools.list_append_to_2(self.global_flags, type, list) @@ -460,7 +463,7 @@ class Target: def build(self, name, packagesName=None, optionnal=False): if name == "gcov": debug.info("gcov all") - debug.error("must set the gcov parsig on a specific library or binary ==> not supported now for all") + debug.error("must set the gcov parsing on a specific library or binary ==> not supported now for all") if name == "dump": debug.info("dump all") self.load_all() @@ -488,49 +491,87 @@ class Target: name2 = name.replace("@", "?") gettedElement = name2.split("?") module_name = gettedElement[0] - if len(gettedElement)>=3: - sub_action_name = gettedElement[2] - else: - sub_action_name = "" - if len(gettedElement)>=2: - actionName = gettedElement[1] - else : - actionName = "build" - debug.verbose("requested : " + module_name + "?" + actionName) - if actionName == "install": - self.build(module_name + "?build") - self.install_package(module_name) - elif actionName == "uninstall": - self.un_install_package(module_name) - elif actionName == "log": - self.Log(module_name) - else: - present = self.load_if_needed(module_name, optionnal=optionnal) - if present == False \ - and optionnal == True: - return [heritage.HeritageList(), False] - # clean requested - for mod in self.module_list: - if mod.name == module_name: - if actionName == "dump": - debug.info("dump module '" + module_name + "'") - return mod.display(self) - elif actionName == "clean": - debug.info("clean module '" + module_name + "'") - return mod.clean(self) - elif actionName == "gcov": - debug.debug("gcov on module '" + module_name + "'") - if sub_action_name == "output": - return mod.gcov(self, generate_output=True) - return mod.gcov(self, generate_output=False) - elif actionName == "build": - debug.debug("build module '" + module_name + "'") - if optionnal == True: - return [mod.build(self, None), True] - return mod.build(self, None) - if optionnal == True: - return [heritage.HeritageList(), False] - debug.error("not know module name : '" + module_name + "' to '" + actionName + "' it") + action_list = gettedElement[1:] + if len(action_list) == 0: + action_list = ["build"] + debug.verbose("requested : " + module_name + " ? actions:" + str(action_list)) + for action_name in action_list: + debug.verbose("requested : " + module_name + "?" + action_name + " [START]") + ret = None; + if action_name == "install": + try: + self.install_package(module_name) + except AttributeError: + debug.error("target have no 'install_package' instruction") + elif action_name == "uninstall": + try: + self.un_install_package(module_name) + except AttributeError: + debug.error("target have no 'un_install_package' instruction") + elif action_name == "run": + try: + self.run(module_name) + except AttributeError: + debug.error("target have no 'run' instruction") + elif action_name == "log": + try: + self.show_log(module_name) + except AttributeError: + debug.error("target have no 'show_log' instruction") + else: + present = self.load_if_needed(module_name, optionnal=optionnal) + if present == False \ + and optionnal == True: + ret = [heritage.HeritageList(), False] + else: + # clean requested + for mod in self.module_list: + if mod.name == module_name: + if action_name[:4] == "dump": + debug.info("dump module '" + module_name + "'") + if len(action_name) > 4: + debug.warning("action 'dump' does not support options ... : '" + action_name + "'") + ret = mod.display(self) + break + elif action_name[:5] == "clean": + debug.info("clean module '" + module_name + "'") + if len(action_name) > 5: + debug.warning("action 'clean' does not support options ... : '" + action_name + "'") + ret = mod.clean(self) + break + elif action_name[:4] == "gcov": + debug.debug("gcov on module '" + module_name + "'") + if len(action_name) > 4: + # we have option: + option_list = action_name.split(":") + if len(option_list) == 0: + debug.warning("action 'gcov' wrong options options ... : '" + action_name + "' might be separate with ':'") + option_list = [] + else: + option_list = option_list[1:] + if "output" in option_list: + ret = mod.gcov(self, generate_output=True) + else: + ret = mod.gcov(self, generate_output=False) + break + elif action_name[:5] == "build": + if len(action_name) > 5: + debug.warning("action 'build' does not support options ... : '" + action_name + "'") + debug.debug("build module '" + module_name + "'") + if optionnal == True: + ret = [mod.build(self, None), True] + else: + ret = mod.build(self, None) + break + if optionnal == True \ + and ret == None: + ret = [heritage.HeritageList(), False] + break + if ret == None: + debug.error("not know module name : '" + module_name + "' to '" + action_name + "' it") + debug.verbose("requested : " + module_name + "?" + action_name + " [STOP]") + if len(action_list) == 1: + return ret def add_action(self, name_of_state="PACKAGE", level=5, name="no-name", action=None): debug.verbose("add action : " + name) diff --git a/lutin/z_target/lutinTarget_Android.py b/lutin/z_target/lutinTarget_Android.py index e4beeb9..e55d945 100644 --- a/lutin/z_target/lutinTarget_Android.py +++ b/lutin/z_target/lutinTarget_Android.py @@ -512,7 +512,7 @@ class Target(target.Target): cmdLine = self.path_sdk + "/platform-tools/adb uninstall " + pkg_name_application_name Rmultiprocess.run_command(cmdLine) - def Log(self, pkg_name): + def show_log(self, pkg_name): debug.debug("------------------------------------------------------------------------") debug.info("logcat of android board") debug.debug("------------------------------------------------------------------------") diff --git a/lutin/z_target/lutinTarget_Linux.py b/lutin/z_target/lutinTarget_Linux.py index d699cb4..bc0b5e0 100644 --- a/lutin/z_target/lutinTarget_Linux.py +++ b/lutin/z_target/lutinTarget_Linux.py @@ -73,7 +73,7 @@ class Target(target.Target): """ def make_package_binary(self, pkg_name, pkg_properties, base_pkg_path, heritage_list, static): debug.debug("------------------------------------------------------------------------") - debug.info("Generate generic '" + pkg_name + "' v" + tools.version_to_string(pkg_properties["VERSION"])) + debug.info("-- Generate generic '" + pkg_name + "' v" + tools.version_to_string(pkg_properties["VERSION"])) debug.debug("------------------------------------------------------------------------") #output path target_outpath = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app") @@ -100,7 +100,7 @@ class Target(target.Target): def install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") - debug.info("Install package '" + pkg_name + "'") + debug.info("-- Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") # this is temporary ... Will call: if False: @@ -123,7 +123,7 @@ class Target(target.Target): def un_install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") - debug.info("Un-Install package '" + pkg_name + "'") + debug.info("-- Un-Install package '" + pkg_name + "'") debug.debug("------------------------------------------------------------------------") # this is temporary ... Will call: if False: @@ -137,5 +137,14 @@ class Target(target.Target): # remove executable link version: tools.remove_file(target_bin_link) + def run(self, pkg_name): + debug.debug("------------------------------------------------------------------------") + debug.info("-- Run package '" + pkg_name + "'") + debug.debug("------------------------------------------------------------------------") + appl_path = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app", "bin", pkg_name) + multiprocess.run_command_no_lock_out(appl_path) + debug.debug("------------------------------------------------------------------------") + debug.info("-- Run package '" + pkg_name + "' Finished") + debug.debug("------------------------------------------------------------------------") diff --git a/lutin/z_target/lutinTarget_MacOs.py b/lutin/z_target/lutinTarget_MacOs.py index 337d95b..249f1f6 100644 --- a/lutin/z_target/lutinTarget_MacOs.py +++ b/lutin/z_target/lutinTarget_MacOs.py @@ -136,7 +136,7 @@ class Target(target.Target): if os.path.exists("/Applications/" + pkg_name + ".app") == True: shutil.rmtree("/Applications/" + pkg_name + ".app") # copy the application in the basic application path : /Applications/xxx.app - shutil.copytree(tools.get_run_path() + self.path_out + self.path_staging + "/" + pkg_name + ".app", "/Applications/" + pkg_name + ".app") + shutil.copytree(os.path.join(tools.get_run_path(),self.path_out,self.path_staging,pkg_name + ".app"), os.path.join("/Applications", pkg_name + ".app")) def un_install_package(self, pkg_name): debug.debug("------------------------------------------------------------------------") @@ -146,6 +146,18 @@ class Target(target.Target): # Remove the application in the basic application path : /Applications/xxx.app if os.path.exists("/Applications/" + pkg_name + ".app") == True: shutil.rmtree("/Applications/" + pkg_name + ".app") + + def run(self, pkg_name): + debug.debug("------------------------------------------------------------------------") + debug.info("-- Run package '" + pkg_name + "'") + debug.debug("------------------------------------------------------------------------") + appl_path = os.path.join(tools.get_run_path(),self.path_out,self.path_staging,pkg_name + ".app", "bin", pkg_name) + multiprocess.run_command_no_lock_out(appl_path) + debug.debug("------------------------------------------------------------------------") + debug.info("-- Run package '" + pkg_name + "' Finished") + debug.debug("------------------------------------------------------------------------") + +