From 8d7fd3271465068093e84c55f213d7970fef38d0 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 16 Apr 2019 23:29:44 +0200 Subject: [PATCH] [DEV] add command actions --- island/actions/islandAction_command.py | 63 ++++++++++++++++++++++++++ island/multiprocess.py | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 island/actions/islandAction_command.py diff --git a/island/actions/islandAction_command.py b/island/actions/islandAction_command.py new file mode 100644 index 0000000..73ab212 --- /dev/null +++ b/island/actions/islandAction_command.py @@ -0,0 +1,63 @@ +#!/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 multiprocess +from island import config +from island import manifest +import os + + +def help(): + return "write the command you want to be executed in every repository" + +def execute(arguments): + cmd = "" + for elem in arguments: + debug.info("Get data element: " + str(elem.get_arg())) + cmd += 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() + + 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("status of: " + str(len(all_project)) + " projects") + id_element = 0 + for elem in all_project: + debug.info("------------------------------------------") + id_element += 1 + debug.verbose("execute command : " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name)) + debug.info("in: " + 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.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t\t\t" + " (not download)") + continue + + debug.verbose("execute : " + cmd) + ret = multiprocess.run_command(cmd, cwd=git_repo_path) + if ret[0] == 0: + debug.info(ret[1]) + else: + debug.info("Execution ERROR") + \ No newline at end of file diff --git a/island/multiprocess.py b/island/multiprocess.py index a4196bf..3f21d0b 100644 --- a/island/multiprocess.py +++ b/island/multiprocess.py @@ -57,7 +57,7 @@ def run_command_direct(cmd_line, cwd=None): if sys.version_info >= (3, 0): output = output.decode("utf-8") err = err.decode("utf-8") - # Check error : + # Check errors: if p.returncode == 0: if output == None: return err[:-1];