[DEV] strop the rework on generic asign

This commit is contained in:
Edouard DUPIN 2019-08-22 22:14:33 +02:00
parent a9e1685d8d
commit 59341b9b00
7 changed files with 131 additions and 80 deletions

View File

@ -23,37 +23,17 @@ is_init = False
debug.set_display_on_error(" ==========================\n == Some error occured ==\n ==========================")
def filter_name_and_file(root, list_files, filter):
# filter elements:
tmp_list = fnmatch.filter(list_files, filter)
out = []
for elem in tmp_list:
if os.path.isfile(os.path.join(root, elem)) == True:
out.append(elem);
return out;
def import_path_local(path):
out = []
debug.verbose("island files: " + str(path) + " [START]")
list_files = os.listdir(path)
# filter elements:
tmp_list_island_file = filter_name_and_file(path, list_files, env.get_system_base_name() + "*.py")
debug.verbose("island files: " + str(path) + " : " + str(tmp_list_island_file))
# Import the module:
for filename in tmp_list_island_file:
out.append(os.path.join(path, filename))
debug.verbose(" Find a file : '" + str(out[-1]) + "'")
return out
def init():
global is_init;
if is_init == True:
return
list_of_island_files = import_path_local(os.path.join(tools.get_current_path(__file__), 'actions'))
# import local island files
list_of_island_files = tools.import_path_local(os.path.join(tools.get_current_path(__file__), 'actions'), base_name = env.get_system_base_name() + "*.py")
actions.init(list_of_island_files)
# import project actions files
list_of_island_files = tools.import_path_local(env.get_island_root_path(), 2, [".island", ".git", "archive"], base_name = env.get_system_base_name() + "*.py")
actions.init(list_of_island_files)
is_init = True
# initialize the system ...

View File

@ -21,8 +21,9 @@ __base_action_name = env.get_system_base_name() + "Action_"
def init(files):
global list_actions;
debug.debug("List of action for island: ")
debug.verbose("List of action for island: " + str(len(files)))
for elem_path in files :
debug.verbose("parse file : " + elem_path)
base_name = os.path.basename(elem_path)
if len(base_name) <= 3 + len(__base_action_name):
# reject it, too small

View File

@ -72,9 +72,17 @@ def execute(_arguments):
all_project = mani.get_all_configs()
debug.info("status of: " + str(len(all_project)) + " projects")
id_element = 0
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
display_status(elem, argument_remote_name, argument_display_tag, id_element, base_display)
def display_status(elem, argument_remote_name, argument_display_tag, id_element, base_display):
volatile = ""
if elem.volatile == True:
volatile = " (volatile)"
@ -83,7 +91,7 @@ def execute(_arguments):
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == False:
debug.info(base_display + volatile + "\r\t\t\t\t\t\t\t\t\t" + " (not download)")
continue
return
is_modify = commands.check_repository_is_modify(git_repo_path)
list_branch = commands.get_list_branch_all(git_repo_path)
@ -93,7 +101,7 @@ def execute(_arguments):
tracking_remote_branch = commands.get_tracking_branch(git_repo_path, argument_remote_name, select_branch)
if tracking_remote_branch == None:
debug.info(base_display + volatile + "\r\t\t\t\t\t\t\t (NO BRANCH)")
continue
return
modify_status = " "
if is_modify == True:

View File

@ -21,33 +21,6 @@ from . import debug
def generic_display_error(return_value, type_name, error_only=False, availlable_return=[0], display_if_nothing=True):
debug.verbose(str(return_value))
if return_value[0] in availlable_return:
if error_only == True:
return
display = False
if return_value[1] != "":
debug.info(return_value[1])
display = True
if return_value[2] != "":
debug.warning(return_value[2])
display = True
if display_if_nothing == False:
return
if display == False:
debug.verbose("GIT(" + type_name + "): All done OK")
else:
display = False
if return_value[1] != "":
debug.warning("ERROR GIT(" + type_name + ") 1:" + return_value[1])
display = True
if return_value[2] != "":
debug.warning("ERROR GIT(" + type_name + ") 2:" + return_value[2])
display = True
if display == False:
debug.warning("ERROR GIT(" + type_name + "): Unknow error return_value=" + str(return_value[0]))
"""
@ -58,7 +31,7 @@ def check_repository_is_modify(path_repository):
cmd = "git diff --quiet"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "check_repository_is_modify", error_only=True, availlable_return=[0,1], display_if_nothing=False)
multiprocess.generic_display_error(return_value, "check_repository_is_modify", error_only=True, availlable_return=[0,1], display_if_nothing=False)
ret_diff = return_value
if ret_diff[0] == 0:
return False
@ -69,7 +42,7 @@ def get_list_branch_meta(path_repository):
cmd = "git branch -a"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_list_branch_meta", error_only=True)
multiprocess.generic_display_error(return_value, "get_list_branch_meta", error_only=True)
ret_branch = return_value
list_branch = ret_branch[1].split('\n')
out = []
@ -141,14 +114,14 @@ def get_current_tracking_branch(path_repository):
if return_value[1] == "@{u}":
debug.warning("in '" + path_repository + "' no tracking branch is specify")
return None
generic_display_error(return_value, "get_current_tracking_branch", error_only=True)
multiprocess.generic_display_error(return_value, "get_current_tracking_branch", error_only=True)
return return_value[1]
def get_revision_list_to_branch(path_repository, branch):
cmd = "git rev-list " + branch
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_revision_list_to_branch", error_only=True)
multiprocess.generic_display_error(return_value, "get_revision_list_to_branch", error_only=True)
return return_value[1].split('\n')
def get_specific_commit_message(path_repository, sha_1):
@ -157,7 +130,7 @@ def get_specific_commit_message(path_repository, sha_1):
cmd = "git log --format=%B -n 1 " + sha_1
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_specific_commit_message", error_only=True)
multiprocess.generic_display_error(return_value, "get_specific_commit_message", error_only=True)
return return_value[1].split('\n')[0]
def get_sha1_for_branch(path_repository, branch_name):
@ -166,7 +139,7 @@ def get_sha1_for_branch(path_repository, branch_name):
cmd = "git rev-parse " + branch_name
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_sha1_for_branch", error_only=True)
multiprocess.generic_display_error(return_value, "get_sha1_for_branch", error_only=True)
return return_value[1].split('\n')[0]
@ -174,14 +147,14 @@ def get_tags_current(path_repository):
cmd = "git tag --points-at"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_tags_current", error_only=True)
multiprocess.generic_display_error(return_value, "get_tags_current", error_only=True)
return return_value[1].split('\n')
def get_tags(path_repository):
cmd = "git tag"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_tags", error_only=True)
multiprocess.generic_display_error(return_value, "get_tags", error_only=True)
return return_value[1].split('\n')
def get_tags_remote(path_repository, remote_name):
@ -190,7 +163,7 @@ def get_tags_remote(path_repository, remote_name):
cmd = "git ls-remote --tags " + remote_name
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_tags_remote", error_only=True)
multiprocess.generic_display_error(return_value, "get_tags_remote", error_only=True)
list_element = return_value[1].split('\n')
debug.verbose(" receive: " + str(list_element))
#6bc01117e85d00686ae2d423193a161e82df9a44 refs/tags/0.1.0
@ -231,7 +204,7 @@ def merge_branch_on_master(path_repository, branch_name):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "merge_branch_on_master", error_only=True)
multiprocess.generic_display_error(return_value, "merge_branch_on_master", error_only=True)
return return_value
@ -242,7 +215,7 @@ def add_file(path_repository, file_path):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "add_file", error_only=True)
multiprocess.generic_display_error(return_value, "add_file", error_only=True)
return return_value
@ -253,7 +226,7 @@ def commit_all(path_repository, comment):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "commit_all", error_only=True)
multiprocess.generic_display_error(return_value, "commit_all", error_only=True)
return return_value
def tag(path_repository, tag_name):
@ -264,7 +237,7 @@ def tag(path_repository, tag_name):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "tag", error_only=True)
multiprocess.generic_display_error(return_value, "tag", error_only=True)
return return_value
def checkout(path_repository, branch_name):
@ -274,7 +247,7 @@ def checkout(path_repository, branch_name):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "checkout", error_only=True)
multiprocess.generic_display_error(return_value, "checkout", error_only=True)
return return_value
def reset_hard(path_repository, destination):
@ -284,7 +257,7 @@ def reset_hard(path_repository, destination):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "reset_hard", error_only=True)
multiprocess.generic_display_error(return_value, "reset_hard", error_only=True)
return return_value
def rebase(path_repository, destination):
@ -294,7 +267,7 @@ def rebase(path_repository, destination):
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "rebase", error_only=True)
multiprocess.generic_display_error(return_value, "rebase", error_only=True)
return return_value
@ -313,7 +286,7 @@ def clone(path_repository, address, branch_name = None, origin=None):
debug.warning("Can not clone repository path already exist")
return False
return_value = multiprocess.run_command(cmd)
generic_display_error(return_value, "clone", error_only=True)
multiprocess.generic_display_error(return_value, "clone", error_only=True)
return return_value
@ -323,7 +296,7 @@ def fetch(path_repository, remote_name, prune=True):
cmd += " --prune"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "fetch")
multiprocess.generic_display_error(return_value, "fetch")
return return_value
def pull(path_repository, remote_name, prune=True):
@ -334,7 +307,7 @@ def pull(path_repository, remote_name, prune=True):
cmd += " --prune"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "pull")
multiprocess.generic_display_error(return_value, "pull")
return return_value
def push(path_repository, remote_name, elements):
@ -347,7 +320,7 @@ def push(path_repository, remote_name, elements):
cmd += " " + elem
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "push")
multiprocess.generic_display_error(return_value, "push")
return return_value
@ -355,7 +328,7 @@ def submodule_sync(path_repository, remote_name):
cmd = "git submodule sync"
debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "submodule_sync")
multiprocess.generic_display_error(return_value, "submodule_sync")
"""
if ret[:31] == "Synchronizing submodule url for":
#all is good ...

View File

@ -254,7 +254,7 @@ class Manifest():
"source":source,
"destination":destination,
})
debug.warning("Add link: '" + str(destination) + "' ==> '" + str(source) + "'")
debug.debug("Add link: '" + str(destination) + "' ==> '" + str(source) + "'")
continue
debug.info("(l:" + str(child.sourceline) + ") '" + str(child.tag) + "' values=" + str(child.attrib));
debug.error("(l:" + str(child.sourceline) + ") Parsing error Unknow NODE : '" + str(child.tag) + "' availlable:[remote,include,default,project,option,link]")

View File

@ -21,6 +21,33 @@ from . import tools
from . import env
def generic_display_error(return_value, type_name, error_only=False, availlable_return=[0], display_if_nothing=True):
debug.verbose(str(return_value))
if return_value[0] in availlable_return:
if error_only == True:
return
display = False
if return_value[1] != "":
debug.info(return_value[1])
display = True
if return_value[2] != "":
debug.warning(return_value[2])
display = True
if display_if_nothing == False:
return
if display == False:
debug.verbose("GIT(" + type_name + "): All done OK")
else:
display = False
if return_value[1] != "":
debug.warning("ERROR GIT(" + type_name + ") 1:" + return_value[1])
display = True
if return_value[2] != "":
debug.warning("ERROR GIT(" + type_name + ") 2:" + return_value[2])
display = True
if display == False:
debug.warning("ERROR GIT(" + type_name + "): Unknow error return_value=" + str(return_value[0]))
def run_command_direct_shell(cmd_line, cwd=None, shell=False):
# prepare command line:
args = shlex.split(cmd_line)

View File

@ -48,6 +48,12 @@ def get_list_sub_path(path):
return dirnames
return []
def get_list_sub_files(path):
# TODO : os.listdir(path)
for dirname, dirnames, filenames in os.walk(path):
return filenames
return []
def remove_path_and_sub_path(path):
if os.path.isdir(path):
debug.verbose("remove path : '" + path + "'")
@ -111,9 +117,10 @@ def version_string_to_list(version):
##
def file_write_data(path, data, only_if_new=False):
if only_if_new == True:
old_data = file_read_data(path)
if old_data == data:
return False
if os.path.exists(path) == True:
old_data = file_read_data(path)
if old_data == data:
return False
#real write of data:
create_directory_of_file(path)
file = open(path, "w")
@ -309,3 +316,58 @@ def wait_for_server_if_needed():
def filter_name_and_file(root, list_files, filter):
# filter elements:
tmp_list = fnmatch.filter(list_files, filter)
out = []
for elem in tmp_list:
if os.path.isfile(os.path.join(root, elem)) == True:
out.append(elem);
return out;
def filter_name(list_files, filter):
# filter elements:
return fnmatch.filter(list_files, filter)
def exclude_list(list_elements, filter):
out = []
for elem in list_elements:
if elem not in filter:
out.append(elem)
return out
def import_path_local(path, limit_sub_folder = 1, exclude_path = [], base_name = "*"):
out = []
debug.debug("island files: " + str(path) + " [START] " + str(limit_sub_folder))
if limit_sub_folder == 0:
debug.verbose("Subparsing limitation append ...")
return []
list_files = get_list_sub_files(path)
# filter elements:
debug.debug("island files: " + str(path) + " : " + str(list_files))
tmp_list_island_file = filter_name_and_file(path, list_files, base_name)
debug.debug("island files (filtered): " + str(path) + " : " + str(tmp_list_island_file))
# Import the module:
for filename in tmp_list_island_file:
out.append(os.path.join(path, filename))
debug.debug(" Find a file : '" + str(out[-1]) + "'")
list_folders_full = get_list_sub_path(path)
list_folders = []
for elem in list_folders_full:
if elem in exclude_path:
debug.verbose("find '" + str(elem) + "' in exclude_path=" + str(exclude_path))
continue
list_folders.append(os.path.join(path,elem))
# check if we need to parse sub_folder
if len(list_folders) != 0:
debug.debug(" Find a folder : " + str(list_folders))
for folder in list_folders:
tmp_out = import_path_local(folder,
limit_sub_folder - 1,
exclude_path,
base_name)
# add all the elements:
for elem in tmp_out:
out.append(elem)
return out