[DEV] start review island

This commit is contained in:
Edouard DUPIN 2023-03-06 21:07:52 +01:00
parent fa8f5ec087
commit f05cd3fe51
33 changed files with 4507 additions and 3362 deletions

View File

@ -1,11 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Inland main interface.
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license MPL v2.0 (see license file)
##
import island @author Edouard DUPIN
@copyright 2012, Edouard DUPIN, all right reserved
@license MPL v2.0 (see license file)
"""
import island # Noqa: import

View File

@ -1,222 +1,283 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Inland main().
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
import copy
import fnmatch
import os import os
import sys import sys
import fnmatch from typing import Union
import copy
# Local import
from . import host
from . import tools
from realog import debug
from . import env
from . import actions
import death.Arguments as arguments
import death.ArgElement as arg_element import death.ArgElement as arg_element
import death.Arguments as arguments
from realog import debug
# Local import
from . import (
actions,
env,
host,
tools,
)
is_init = False is_init = False
debug.set_display_on_error(" ==========================\n == Some error occured ==\n ==========================") debug.set_display_on_error(
" ==========================\n == Some error occurred ==\n =========================="
)
def init(): def init():
global is_init; global is_init
if is_init == True: if is_init == True:
return return
# import local island files # 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") list_of_island_files = tools.import_path_local(
actions.init(list_of_island_files) os.path.join(tools.get_current_path(__file__), "actions"),
# import project actions files base_name=env.get_system_base_name() + "*.py",
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) actions.init(list_of_island_files)
is_init = True # 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 ... # initialize the system ...
init() init()
debug.verbose("List of actions: " + str(actions.get_list_of_action())) debug.verbose("List of actions: " + str(actions.get_list_of_action()))
my_args = arguments.Arguments() my_args = arguments.Arguments()
my_args.add_section("option", "Can be set one time in all case") 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("h", "help", desc="Display this help")
my_args.add("v", "verbose", list=[ my_args.add(
["0","None"], "v",
["1","error"], "verbose",
["2","warning"], list=[
["3","info"], ["0", "None"],
["4","debug"], ["1", "error"],
["5","verbose"], ["2", "warning"],
["6","extreme_verbose"], ["3", "info"],
], desc="display debug level (verbose) default =2") ["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("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.add(
my_args.add("F", "filter", haveParam=True, desc="Filter the action on a list of path or subpath: -f library") "n", "no-fetch-manifest", haveParam=False, desc="Disable the fetch of the manifest"
my_args.add("f", "folder", haveParam=False, desc="Display the folder instead of the git repository name") )
my_args.add("w", "wait", haveParam=True, desc="Wait between 2 acces on the server (needed when the server is really slow to remove ssh connection) (default=" + str(env.get_wait_between_sever_command()) + ")") my_args.add(
"F",
"filter",
haveParam=True,
desc="Filter the action on a list of path or subpath: -f library",
)
my_args.add(
"f",
"folder",
haveParam=False,
desc="Display the folder instead of the git repository name",
)
my_args.add(
"w",
"wait",
haveParam=True,
desc="Wait between 2 access on the server (needed when the server is really slow to remove ssh connection) (default="
+ str(env.get_wait_between_sever_command())
+ ")",
)
my_args.set_stop_at(actions.get_list_of_action()) my_args.set_stop_at(actions.get_list_of_action())
local_argument = my_args.parse() local_argument = my_args.parse()
## ##
## @brief Display the help of this makefile. ## @brief Display the help of this makefile.
## ##
def usage(): def usage():
color = debug.get_color_set() color = debug.get_color_set()
# generic argument displayed : # generic argument displayed :
my_args.display() my_args.display()
print(" Action availlable" ) print(" Action available")
list_actions = actions.get_list_of_action(); list_actions = actions.get_list_of_action()
for elem in list_actions: for elem in list_actions:
print(" " + color['green'] + elem + color['default']) print(f" {color['green']}{color['green']}{color['default']}")
print(" " + actions.get_action_help(elem)) print(f" {actions.get_action_help(elem)}")
""" """
print(" " + color['green'] + "init" + color['default']) print(" " + color['green'] + "init" + color['default'])
print(" initialize a 'island' interface with a manifest in a git ") print(" initialize a 'island' interface with a manifest in a git ")
print(" " + color['green'] + "sync" + color['default']) print(" " + color['green'] + "sync" + color['default'])
print(" Syncronise the currect environement") print(" Synchronize the current environnement")
print(" " + color['green'] + "status" + color['default']) print(" " + color['green'] + "status" + color['default'])
print(" Dump the status of the environement") print(" Dump the status of the environnement")
""" """
print(" ex: " + sys.argv[0] + " -c init http://github.com/atria-soft/manifest.git") print(f" ex: {sys.argv[0]} -c init http://github.com/atria-soft/manifest.git")
print(" ex: " + sys.argv[0] + " sync") print(f" ex: {sys.argv[0]} sync")
exit(0) exit(0)
def check_boolean(value: Union[bool, str]) -> bool:
if (
value == ""
or value == "1"
or value == "true"
or value == "True"
or value is True
):
return True
return False
def check_boolean(value):
if value == "" \
or value == "1" \
or value == "true" \
or value == "True" \
or value == True:
return True
return False
# preparse the argument to get the verbose element for debug mode # preparse the argument to get the verbose element for debug mode
def parse_generic_arg(argument, active): def parse_generic_arg(argument, active):
debug.extreme_verbose("parse arg : " + argument.get_option_name() + " " + argument.get_arg() + " active=" + str(active)) debug.extreme_verbose(
if argument.get_option_name() == "help": "parse arg : "
if active == False: + argument.get_option_name()
usage() + " "
return True + argument.get_arg()
elif argument.get_option_name()=="jobs": + " active="
if active == True: + str(active)
#multiprocess.set_core_number(int(argument.get_arg())) )
pass if argument.get_option_name() == "help":
return True if active == False:
elif argument.get_option_name()=="wait": usage()
if active == True: return True
env.set_wait_between_sever_command(int(argument.get_arg())) elif argument.get_option_name() == "jobs":
return True if active == True:
elif argument.get_option_name() == "verbose": # multiprocess.set_core_number(int(argument.get_arg()))
if active == True: pass
debug.set_level(int(argument.get_arg())) return True
return True elif argument.get_option_name() == "wait":
elif argument.get_option_name() == "folder": if active == True:
if active == True: env.set_wait_between_sever_command(int(argument.get_arg()))
env.set_display_folder_instead_of_git_name(True) return True
return True elif argument.get_option_name() == "verbose":
elif argument.get_option_name() == "color": if active == True:
if active == True: debug.set_level(int(argument.get_arg()))
if check_boolean(argument.get_arg()) == True: return True
debug.enable_color() elif argument.get_option_name() == "folder":
else: if active == True:
debug.disable_color() env.set_display_folder_instead_of_git_name(True)
return True return True
elif argument.get_option_name() == "filter": elif argument.get_option_name() == "color":
if active == True: if active == True:
env.set_filter_command(str(argument.get_arg())) if check_boolean(argument.get_arg()) == True:
return True debug.enable_color()
elif argument.get_option_name() == "no-fetch-manifest": else:
if active == False: debug.disable_color()
env.set_fetch_manifest(False) return True
return True elif argument.get_option_name() == "filter":
return False if active == True:
env.set_filter_command(str(argument.get_arg()))
return True
elif argument.get_option_name() == "no-fetch-manifest":
if active == False:
env.set_fetch_manifest(False)
return True
return False
# open configuration of island: # open configuration of island:
config_file = env.get_island_path_user_config() config_file = env.get_island_path_user_config()
if os.path.isfile(config_file) == True: if os.path.isfile(config_file) == True:
sys.path.append(os.path.dirname(config_file)) sys.path.append(os.path.dirname(config_file))
debug.debug("Find basic configuration file: '" + config_file + "'") debug.debug("Find basic configuration file: '" + config_file + "'")
# the file exist, we can open it and get the initial configuration: # the file exist, we can open it and get the initial configuration:
configuration_file = __import__(env.get_system_config_name()[:-3]) configuration_file = __import__(env.get_system_config_name()[:-3])
if "get_exclude_path" in dir(configuration_file): if "get_exclude_path" in dir(configuration_file):
data = configuration_file.get_exclude_path() data = configuration_file.get_exclude_path()
debug.debug(" get default config 'get_exclude_path' val='" + str(data) + "'") debug.debug(" get default config 'get_exclude_path' val='" + str(data) + "'")
env.set_exclude_search_path(data) env.set_exclude_search_path(data)
if "get_default_color" in dir(configuration_file): if "get_default_color" in dir(configuration_file):
data = configuration_file.get_default_color() data = configuration_file.get_default_color()
debug.debug(" get default config 'get_default_color' val='" + str(data) + "'") debug.debug(" get default config 'get_default_color' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("color", str(data)), True) parse_generic_arg(arg_element.ArgElement("color", str(data)), True)
if "get_default_debug_level" in dir(configuration_file): if "get_default_debug_level" in dir(configuration_file):
data = configuration_file.get_default_debug_level() data = configuration_file.get_default_debug_level()
debug.debug(" get default config 'get_default_debug_level' val='" + str(data) + "'") debug.debug(
parse_generic_arg(arg_element.ArgElement("verbose", str(data)), True) " get default config 'get_default_debug_level' val='" + str(data) + "'"
)
if "get_default_folder" in dir(configuration_file): parse_generic_arg(arg_element.ArgElement("verbose", str(data)), True)
data = configuration_file.get_default_folder()
debug.debug(" get default config 'get_default_folder' val='" + str(data) + "'") if "get_default_folder" in dir(configuration_file):
parse_generic_arg(arg_element.ArgElement("folder", str(data)), True) data = configuration_file.get_default_folder()
debug.debug(" get default config 'get_default_folder' val='" + str(data) + "'")
if "get_default_wait" in dir(configuration_file): parse_generic_arg(arg_element.ArgElement("folder", str(data)), True)
data = configuration_file.get_default_wait()
debug.debug(" get default config 'get_default_wait' val='" + str(data) + "'") if "get_default_wait" in dir(configuration_file):
parse_generic_arg(arg_element.ArgElement("wait", str(data)), True) data = configuration_file.get_default_wait()
debug.debug(" get default config 'get_default_wait' val='" + str(data) + "'")
if "get_default_filter" in dir(configuration_file): parse_generic_arg(arg_element.ArgElement("wait", str(data)), True)
data = configuration_file.get_default_filter()
debug.debug(" get default config 'get_default_filter' val='" + str(data) + "'") if "get_default_filter" in dir(configuration_file):
parse_generic_arg(arg_element.ArgElement("filter", str(data)), True) data = configuration_file.get_default_filter()
debug.debug(" get default config 'get_default_filter' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("filter", str(data)), True)
# parse default unique argument: # parse default unique argument:
for argument in local_argument: for argument in local_argument:
parse_generic_arg(argument, True) parse_generic_arg(argument, True)
# remove all generic arguments: # remove all generic arguments:
new_argument_list = [] new_argument_list = []
for argument in local_argument: for argument in local_argument:
if parse_generic_arg(argument, False) == True: if parse_generic_arg(argument, False) == True:
continue continue
new_argument_list.append(argument) new_argument_list.append(argument)
# now the first argument is: the action: # now the first argument is: the action:
if len(new_argument_list) == 0: if len(new_argument_list) == 0:
debug.warning("--------------------------------------") debug.warning("--------------------------------------")
debug.warning("Missing the action to do ...") debug.warning("Missing the action to do ...")
debug.warning("--------------------------------------") debug.warning("--------------------------------------")
usage() usage()
# TODO : move tin in actions ... # TODO : move tin in actions ...
list_actions = actions.get_list_of_action(); list_actions = actions.get_list_of_action()
action_to_do = new_argument_list[0].get_arg() action_to_do = new_argument_list[0].get_arg()
new_argument_list = new_argument_list[1:] new_argument_list = new_argument_list[1:]
if action_to_do not in list_actions: if action_to_do not in list_actions:
debug.warning("--------------------------------------") debug.warning("--------------------------------------")
debug.warning("Wrong action type : '" + str(action_to_do) + "' availlable list: " + str(list_actions) ) debug.warning(
debug.warning("--------------------------------------") "Wrong action type : '"
usage() + str(action_to_do)
+ "' availlable list: "
+ str(list_actions)
)
debug.warning("--------------------------------------")
usage()
# todo : Remove this # todo : Remove this
if action_to_do != "init" \ if action_to_do != "init" and os.path.exists(env.get_island_path()) == False:
and os.path.exists(env.get_island_path()) == False: debug.error(
debug.error("Can not execute a island cmd if we have not initialize a config: '" + str("." + env.get_system_base_name()) + "' in upper 6 parent path") "Can not execute a island cmd if we have not initialize a config: '"
exit(-1) + str("." + env.get_system_base_name())
+ "' in upper 6 parent path"
)
exit(-1)
ret = actions.execute(action_to_do, my_args.get_last_parsed()+1) ret = actions.execute(action_to_do, my_args.get_last_parsed() + 1)
exit (ret) exit(ret)
# stop all started threads; # stop all started threads;
#multiprocess.un_init() # multiprocess.un_init()

View File

@ -1,54 +1,62 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Action interface.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
import os
import sys
import death.Arguments as arguments
# Local import # Local import
from realog import debug from realog import debug
import os
import sys
from . import env from . import env
import death.Arguments as arguments
list_actions = [] list_actions = []
__base_action_name = env.get_system_base_name() + "Action_" __base_action_name = env.get_system_base_name() + "Action_"
def init(files): def init(files):
global list_actions; global list_actions
debug.verbose("List of action for island: " + str(len(files))) debug.verbose("List of action for island: " + str(len(files)))
for elem_path in files : for elem_path in files:
debug.verbose("parse file : " + elem_path) debug.verbose("parse file : " + elem_path)
base_name = os.path.basename(elem_path) base_name = os.path.basename(elem_path)
if len(base_name) <= 3 + len(__base_action_name): if len(base_name) <= 3 + len(__base_action_name):
# reject it, too small # reject it, too small
continue continue
base_name = base_name[:-3] base_name = base_name[:-3]
if base_name[:len(__base_action_name)] != __base_action_name: if base_name[: len(__base_action_name)] != __base_action_name:
# reject it, wrong start file # reject it, wrong start file
continue continue
name_action = base_name[len(__base_action_name):] name_action = base_name[len(__base_action_name) :]
debug.debug(" '" + os.path.basename(elem_path)[:-3] + "' file=" + elem_path) debug.debug(" '" + os.path.basename(elem_path)[:-3] + "' file=" + elem_path)
list_actions.append({ list_actions.append(
"name":name_action, {
"path":elem_path, "name": name_action,
}) "path": elem_path,
}
)
## ##
## @brief Get the wall list of action availlable ## @brief Get the wall list of action availlable
## @return ([string]) the list of action name ## @return ([string]) the list of action name
## ##
def get_list_of_action(): def get_list_of_action():
global list_actions; global list_actions
out = [] out = []
for elem in list_actions: for elem in list_actions:
out.append(elem["name"]) out.append(elem["name"])
return out return out
## ##
## @brief Get a description of an action ## @brief Get a description of an action
@ -57,18 +65,19 @@ def get_list_of_action():
## @param[in] default_value (*) Renurned value of the call if function does not exist ## @param[in] default_value (*) Renurned value of the call if function does not exist
## @return (*) the getted value or the default_value ## @return (*) the getted value or the default_value
## ##
def get_function_value(action_name, function_name, default_value = None): def get_function_value(action_name, function_name, default_value=None):
global list_actions; global list_actions
for elem in list_actions: for elem in list_actions:
if elem["name"] == action_name: if elem["name"] == action_name:
# finish the parsing # finish the parsing
sys.path.append(os.path.dirname(elem["path"])) sys.path.append(os.path.dirname(elem["path"]))
the_action = __import__(__base_action_name + action_name) the_action = __import__(__base_action_name + action_name)
if function_name not in dir(the_action): if function_name not in dir(the_action):
return default_value return default_value
method_to_call = getattr(the_action, function_name) method_to_call = getattr(the_action, function_name)
return method_to_call() return method_to_call()
return default_value return default_value
## ##
## @brief Get the global help value of a module ## @brief Get the global help value of a module
@ -76,65 +85,74 @@ def get_function_value(action_name, function_name, default_value = None):
## @return The first line of description ## @return The first line of description
## ##
def get_action_help(action_name): def get_action_help(action_name):
value = get_function_value(action_name, "help", "---") value = get_function_value(action_name, "help", "---")
return value.split("\n")[0] return value.split("\n")[0]
def usage(arguments, action_name): def usage(arguments, action_name):
color = debug.get_color_set() color = debug.get_color_set()
# generic argument displayed for specific action: # generic argument displayed for specific action:
#print("Specific argument for the command: '" + action_name + "'" ) # print("Specific argument for the command: '" + action_name + "'" )
#print(" " + get_desc(action_name)) # print(" " + get_desc(action_name))
value = get_function_value(action_name, "help") value = get_function_value(action_name, "help")
debug.info("Description:") debug.info("Description:")
debug.info("\t" + str(value)) debug.info("\t" + str(value))
arguments.display(action_name) arguments.display(action_name)
value = get_function_value(action_name, "help_example") value = get_function_value(action_name, "help_example")
if value != None: if value != None:
debug.info("Example:") debug.info("Example:")
for elem in value.split("\n"): for elem in value.split("\n"):
debug.info("\t" + value) debug.info("\t" + value)
exit(0) exit(0)
def execute(action_name, argument_start_id): def execute(action_name, argument_start_id):
global list_actions; global list_actions
# TODO: Move here the check if action is availlable # TODO: Move here the check if action is availlable
for elem in list_actions: for elem in list_actions:
if elem["name"] != action_name: if elem["name"] != action_name:
continue continue
debug.info("action: " + str(elem)); debug.info("action: " + str(elem))
# finish the parsing # finish the parsing
sys.path.append(os.path.dirname(elem["path"])) sys.path.append(os.path.dirname(elem["path"]))
the_action = __import__(__base_action_name + action_name) the_action = __import__(__base_action_name + action_name)
my_under_args_parser = arguments.Arguments() my_under_args_parser = arguments.Arguments()
my_under_args_parser.add("h", "help", desc="Help of this action") my_under_args_parser.add("h", "help", desc="Help of this action")
if "add_specific_arguments" in dir(the_action): if "add_specific_arguments" in dir(the_action):
the_action.add_specific_arguments(my_under_args_parser, elem["name"]) the_action.add_specific_arguments(my_under_args_parser, elem["name"])
have_unknow_argument = False have_unknow_argument = False
if "have_unknow_argument" in dir(the_action): if "have_unknow_argument" in dir(the_action):
have_unknow_argument = the_action.have_unknow_argument() have_unknow_argument = the_action.have_unknow_argument()
my_under_args = my_under_args_parser.parse(argument_start_id, have_unknow_argument) my_under_args = my_under_args_parser.parse(
# search help if needed ==> permit to not duplicating code argument_start_id, have_unknow_argument
for elem in my_under_args: )
if elem.get_option_name() == "help": # search help if needed ==> permit to not duplicating code
usage(my_under_args_parser, action_name) for elem in my_under_args:
return 0 if elem.get_option_name() == "help":
# now we can execute: usage(my_under_args_parser, action_name)
if "execute" not in dir(the_action): return 0
debug.error("execute is not implmented for this action ... '" + str(action_name) + "'") # now we can execute:
return -11 if "execute" not in dir(the_action):
debug.info("execute: " + action_name) debug.error(
for elem in my_under_args: "execute is not implmented for this action ... '"
debug.debug(" " + str(elem.get_option_name()) + "='" + str(elem.get_arg()) + "'") + str(action_name)
ret = the_action.execute(my_under_args) + "'"
if ret == None: )
return 0 return -11
if ret < 0: debug.info("execute: " + action_name)
debug.info(" ==========================") for elem in my_under_args:
debug.info(" == Some error occured ==") debug.debug(
debug.info(" ==========================") " " + str(elem.get_option_name()) + "='" + str(elem.get_arg()) + "'"
return ret )
debug.error("Can not do the action...") ret = the_action.execute(my_under_args)
return -10 if ret == None:
return 0
if ret < 0:
debug.info(" ==========================")
debug.info(" == Some error occured ==")
debug.info(" ==========================")
return ret
debug.error("Can not do the action...")
return -10

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Ckeckout a specific branch in all repository" return "Ckeckout a specific branch in all repository"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,8 +37,13 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") my_args.add("r", "remote", haveParam=True, desc="Name of the remote server")
my_args.add_arg("branch", optionnal=False, desc="Branch to checkout (if '__TAG__' ==> checkout specific repository tags)") my_args.add_arg(
"branch",
optionnal=False,
desc="Branch to checkout (if '__TAG__' ==> checkout specific repository tags)",
)
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -45,44 +55,53 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
branch_to_checkout = "" branch_to_checkout = ""
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "remote": if elem.get_option_name() == "remote":
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
argument_remote_name = elem.get_arg() argument_remote_name = elem.get_arg()
elif elem.get_option_name() == "branch": elif elem.get_option_name() == "branch":
branch_to_checkout = elem.get_arg() branch_to_checkout = elem.get_arg()
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
# update the local configuration file:
configuration.set_branch(branch_to_checkout)
configuration.store()
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("checkout of: " + str(len(all_project)) + " projects")
id_element = 0
have_error = False
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
if status.checkout_elem(elem, argument_remote_name, branch_to_checkout, base_display) == False:
have_error = True
if have_error == True:
return env.ret_action_fail
# check system is OK
manifest.check_lutin_is_init()
configuration = config.get_unique_config()
# update the local configuration file:
configuration.set_branch(branch_to_checkout)
configuration.store()
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("checkout of: " + str(len(all_project)) + " projects")
id_element = 0
have_error = False
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
if (
status.checkout_elem(
elem, argument_remote_name, branch_to_checkout, base_display
)
== False
):
have_error = True
if have_error == True:
return env.ret_action_fail

View File

@ -8,29 +8,35 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import multiprocess
from island import config
from island import manifest
from island import commands
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Write the command you want to be executed in every repository" return "Write the command you want to be executed in every repository"
## ##
## @brief Set the option argument are not able to check if the argument are correct or not ## @brief Set the option argument are not able to check if the argument are correct or not
## @return (boolean) have parameter without arguments ## @return (boolean) have parameter without arguments
## ##
def have_unknow_argument(): def have_unknow_argument():
return True return True
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -42,42 +48,45 @@ def have_unknow_argument():
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
cmd = "" cmd = ""
for elem in _arguments: for elem in _arguments:
debug.info("Get data element: " + str(elem.get_arg())) debug.info("Get data element: " + str(elem.get_arg()))
cmd += elem.get_arg() + " " cmd += elem.get_arg() + " "
# check system is OK # check system is OK
manifest.check_lutin_is_init() manifest.check_lutin_is_init()
configuration = config.get_unique_config() configuration = config.get_unique_config()
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name()) file_source_manifest = os.path.join(
if os.path.exists(file_source_manifest) == False: env.get_island_path_manifest(), configuration.get_manifest_name()
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") )
if os.path.exists(file_source_manifest) == False:
mani = manifest.Manifest(file_source_manifest) debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
all_project = mani.get_all_configs() mani = manifest.Manifest(file_source_manifest)
debug.info("status of: " + str(len(all_project)) + " projects")
id_element = 0 all_project = mani.get_all_configs()
for elem in all_project: debug.info("status of: " + str(len(all_project)) + " projects")
debug.info("------------------------------------------") id_element = 0
id_element += 1 for elem in all_project:
base_display = tools.get_list_base_display(id_element, len(all_project), elem) debug.info("------------------------------------------")
debug.info("execute command : " + base_display) id_element += 1
tools.wait_for_server_if_needed() base_display = tools.get_list_base_display(id_element, len(all_project), elem)
#debug.debug("elem : " + str(elem)) debug.info("execute command : " + base_display)
git_repo_path = os.path.join(env.get_island_root_path(), elem.path) tools.wait_for_server_if_needed()
if os.path.exists(git_repo_path) == False: # debug.debug("elem : " + str(elem))
debug.info("" + base_display + "\r\t\t\t\t\t\t\t\t\t" + " (not download)") git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
continue if os.path.exists(git_repo_path) == False:
debug.info(
debug.verbose("execute : " + cmd) "" + base_display + "\r\t\t\t\t\t\t\t\t\t" + " (not download)"
ret = multiprocess.run_command(cmd, cwd=git_repo_path) )
if ret[0] == 0: continue
debug.info("ret=" + ret[1])
debug.info("err=" + ret[2]) debug.verbose("execute : " + cmd)
else: ret = multiprocess.run_command(cmd, cwd=git_repo_path)
debug.info("Execution ERROR") if ret[0] == 0:
debug.info("ret=" + ret[1])
debug.info("err=" + ret[2])
else:
debug.info("Execution ERROR")

View File

@ -8,22 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Commit in all repository" return "Commit in all repository"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -31,9 +36,10 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("m", "message", haveParam=True, desc="Message to commit data") my_args.add("m", "message", haveParam=True, desc="Message to commit data")
my_args.add("a", "all", desc="Commit all elements") my_args.add("a", "all", desc="Commit all elements")
my_args.add("", "amend", desc="Ammend data at the previous commit") my_args.add("", "amend", desc="Ammend data at the previous commit")
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -45,51 +51,62 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_message = "" argument_message = ""
argument_amend = "" argument_amend = ""
argument_all = "" argument_all = ""
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "message": if elem.get_option_name() == "message":
debug.info("find message: '" + elem.get_arg() + "'") debug.info("find message: '" + elem.get_arg() + "'")
argument_message = " --message \"" + elem.get_arg() + "\" "; argument_message = ' --message "' + elem.get_arg() + '" '
elif elem.get_option_name() == "all": elif elem.get_option_name() == "all":
argument_all = " --all " argument_all = " --all "
elif elem.get_option_name() == "amend": elif elem.get_option_name() == "amend":
argument_amend = " --amend " argument_amend = " --amend "
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == False: # check system is OK
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") manifest.check_lutin_is_init()
mani = manifest.Manifest(file_source_manifest)
configuration = config.get_unique_config()
all_project = mani.get_all_configs()
debug.info("commit : " + str(len(all_project)) + " projects") file_source_manifest = os.path.join(
id_element = 0 env.get_island_path_manifest(), configuration.get_manifest_name()
for elem in all_project: )
id_element += 1 if os.path.exists(file_source_manifest) == False:
base_display = tools.get_list_base_display(id_element, len(all_project), elem) debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
debug.info("commit: " + base_display) mani = manifest.Manifest(file_source_manifest)
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == False: all_project = mani.get_all_configs()
debug.error("can not commit project that not exist") debug.info("commit : " + str(len(all_project)) + " projects")
continue id_element = 0
for elem in all_project:
if os.path.exists(os.path.join(git_repo_path,".git")) == False: id_element += 1
# path already exist but it is not used to as a git repo ==> this is an error base_display = tools.get_list_base_display(id_element, len(all_project), elem)
debug.warning("path '" + git_repo_path + "' is already existing but not used for a git repository. Clean it and restart") debug.info("commit: " + base_display)
continue; git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == False:
# simply update the repository ... debug.error("can not commit project that not exist")
debug.verbose("commit in project:") continue
# fetch the repository
cmd = "git commit " + argument_amend + argument_all + argument_message if os.path.exists(os.path.join(git_repo_path, ".git")) == False:
debug.debug("execute : " + cmd) # path already exist but it is not used to as a git repo ==> this is an error
multiprocess.run_command_direct(cmd, cwd=git_repo_path) debug.warning(
"path '"
+ git_repo_path
+ "' is already existing but not used for a git repository. Clean it and restart"
)
continue
# simply update the repository ...
debug.verbose("commit in project:")
# fetch the repository
cmd = "git commit " + argument_amend + argument_all + argument_message
debug.debug("execute : " + cmd)
multiprocess.run_command_direct(cmd, cwd=git_repo_path)

View File

@ -8,22 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Push a delover (develop & master & tag) on the remotre server" return "Push a delover (develop & master & tag) on the remotre server"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -31,7 +37,8 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") my_args.add("r", "remote", haveParam=True, desc="Name of the remote server")
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -43,38 +50,46 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "remote": if elem.get_option_name() == "remote":
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
argument_remote_name = elem.get_arg() argument_remote_name = elem.get_arg()
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_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)
destination_branch = mani.deliver_master
source_branch = mani.deliver_develop
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
# configure remote name:
if argument_remote_name == "":
argument_remote_name = elem.select_remote["name"]
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
debug.info("deliver-push: " + base_display)
tools.wait_for_server_if_needed()
status.deliver_push(elem, argument_remote_name, destination_branch, source_branch, base_display)
# check system is OK
manifest.check_lutin_is_init()
configuration = config.get_unique_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)
destination_branch = mani.deliver_master
source_branch = mani.deliver_develop
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
# configure remote name:
if argument_remote_name == "":
argument_remote_name = elem.select_remote["name"]
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
debug.info("deliver-push: " + base_display)
tools.wait_for_server_if_needed()
status.deliver_push(
elem, argument_remote_name, destination_branch, source_branch, base_display
)

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import multiprocess
from island import config
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Deliver the current repository (develop & master MUST be up to date and you MUST be on master)" return "Deliver the current repository (develop & master MUST be up to date and you MUST be on master)"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,8 +37,9 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(_my_args, _section): def add_specific_arguments(_my_args, _section):
_my_args.add("f", "from", haveParam=True, desc="source branche to deliver") _my_args.add("f", "from", haveParam=True, desc="source branche to deliver")
_my_args.add("t", "to", haveParam=True, desc="desticantion branche of the deliver") _my_args.add("t", "to", haveParam=True, desc="desticantion branche of the deliver")
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -45,94 +51,140 @@ def add_specific_arguments(_my_args, _section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_from = None argument_from = None
argument_to = None argument_to = None
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "from": if elem.get_option_name() == "from":
debug.info("find source branch name: '" + elem.get_arg() + "'") debug.info("find source branch name: '" + elem.get_arg() + "'")
argument_from = elem.get_arg() argument_from = elem.get_arg()
elif elem.get_option_name() == "to": elif elem.get_option_name() == "to":
debug.info("find destination branch name: '" + elem.get_arg() + "'") debug.info("find destination branch name: '" + elem.get_arg() + "'")
argument_to = elem.get_arg() argument_to = elem.get_arg()
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == False: # check system is OK
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") manifest.check_lutin_is_init()
mani = manifest.Manifest(file_source_manifest) configuration = config.get_unique_config()
destination_branch = mani.deliver_master file_source_manifest = os.path.join(
source_branch = mani.deliver_develop env.get_island_path_manifest(), configuration.get_manifest_name()
if argument_from != None: )
source_branch = argument_from if os.path.exists(file_source_manifest) == False:
if argument_to != None: debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
destination_branch = argument_to
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
debug.info("Check if all project are on master: " + str(len(all_project)) + " projects") destination_branch = mani.deliver_master
id_element = 0 source_branch = mani.deliver_develop
deliver_availlable = True if argument_from != None:
for elem in all_project: source_branch = argument_from
id_element += 1 if argument_to != None:
base_display = tools.get_list_base_display(id_element, len(all_project), elem) destination_branch = argument_to
debug.verbose("deliver-ckeck: " + base_display)
if status.deliver_check(elem, argument_remote_name, id_element, base_display, source_branch, destination_branch) == False: all_project = mani.get_all_configs()
deliver_availlable = False debug.info(
if deliver_availlable == False: "Check if all project are on master: " + str(len(all_project)) + " projects"
debug.error("deliver-ckeck: Correct the warning to validate the Merge") )
return id_element = 0
debug.info("deliver-ckeck: ==> All is OK") deliver_availlable = True
id_element = 0 for elem in all_project:
for elem in all_project: id_element += 1
id_element += 1 base_display = tools.get_list_base_display(id_element, len(all_project), elem)
base_display = tools.get_list_base_display(id_element, len(all_project), elem) debug.verbose("deliver-ckeck: " + base_display)
debug.info("deliver: ========================================================================") if (
debug.info("deliver: == " + base_display) status.deliver_check(
debug.info("deliver: ========================================================================") elem,
argument_remote_name,
git_repo_path = os.path.join(env.get_island_root_path(), elem.path) id_element,
# Check the validity of the version, base_display,
version_description, add_in_version_management = status.get_current_version_repo(git_repo_path) source_branch,
if version_description == None: destination_branch,
continue )
debug.info("deliver: ==> version: " + str(version_description)) == False
):
# go to the dev branch deliver_availlable = False
select_branch = commands.get_current_branch(git_repo_path) if deliver_availlable == False:
debug.error("deliver-ckeck: Correct the warning to validate the Merge")
# Checkout destination branch: return
commands.checkout(git_repo_path, destination_branch) debug.info("deliver-ckeck: ==> All is OK")
id_element = 0
# create new repo tag for elem in all_project:
new_version_description = status.create_new_version_repo(git_repo_path, version_description, add_in_version_management, source_branch, destination_branch) id_element += 1
debug.info("new version: " + str(new_version_description)) base_display = tools.get_list_base_display(id_element, len(all_project), elem)
if new_version_description == None: debug.info(
continue "deliver: ========================================================================"
# merge branch )
if mani.deliver_mode == "merge": debug.info("deliver: == " + base_display)
merge_force = True debug.info(
else: "deliver: ========================================================================"
merge_force = False )
commands.merge_branch_on_master(git_repo_path, source_branch, merge_force, branch_destination=destination_branch)
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
version_path_file = os.path.join(git_repo_path, "version.txt") # Check the validity of the version,
# update version file: (
tools.file_write_data(version_path_file, tools.version_to_string(new_version_description)) version_description,
commands.add_file(git_repo_path, version_path_file) add_in_version_management,
commands.commit_all(git_repo_path, "[RELEASE] Release v" + tools.version_to_string(new_version_description)) ) = status.get_current_version_repo(git_repo_path)
commands.tag(git_repo_path, "v" + tools.version_to_string(new_version_description)) if version_description == None:
commands.checkout(git_repo_path, source_branch) continue
commands.reset_hard(git_repo_path, destination_branch) debug.info("deliver: ==> version: " + str(version_description))
new_version_description.append("dev")
tools.file_write_data(version_path_file, tools.version_to_string(new_version_description)) # go to the dev branch
commands.add_file(git_repo_path, version_path_file) select_branch = commands.get_current_branch(git_repo_path)
commands.commit_all(git_repo_path, status.default_update_message)
commands.checkout(git_repo_path, destination_branch) # Checkout destination branch:
commands.checkout(git_repo_path, destination_branch)
# create new repo tag
new_version_description = status.create_new_version_repo(
git_repo_path,
version_description,
add_in_version_management,
source_branch,
destination_branch,
)
debug.info("new version: " + str(new_version_description))
if new_version_description == None:
continue
# merge branch
if mani.deliver_mode == "merge":
merge_force = True
else:
merge_force = False
commands.merge_branch_on_master(
git_repo_path,
source_branch,
merge_force,
branch_destination=destination_branch,
)
version_path_file = os.path.join(git_repo_path, "version.txt")
# update version file:
tools.file_write_data(
version_path_file, tools.version_to_string(new_version_description)
)
commands.add_file(git_repo_path, version_path_file)
commands.commit_all(
git_repo_path,
"[RELEASE] Release v" + tools.version_to_string(new_version_description),
)
commands.tag(
git_repo_path, "v" + tools.version_to_string(new_version_description)
)
commands.checkout(git_repo_path, source_branch)
commands.reset_hard(git_repo_path, destination_branch)
new_version_description.append("dev")
tools.file_write_data(
version_path_file, tools.version_to_string(new_version_description)
)
commands.add_file(git_repo_path, version_path_file)
commands.commit_all(git_repo_path, status.default_update_message)
commands.checkout(git_repo_path, destination_branch)

View File

@ -8,22 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Fecth all the repository (get all modification on the server)" return "Fecth all the repository (get all modification on the server)"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -31,7 +36,8 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") my_args.add("r", "remote", haveParam=True, desc="Name of the remote server")
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -43,50 +49,61 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "remote": if elem.get_option_name() == "remote":
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
argument_remote_name = elem.get_arg() argument_remote_name = elem.get_arg()
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
debug.info("fetch manifest : '" + str(env.get_island_path_manifest()) + "'") + "'"
commands.fetch(env.get_island_path_manifest(), "origin") )
configuration = config.get_unique_config() # check system is OK
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name()) manifest.check_lutin_is_init()
if os.path.exists(file_source_manifest) == False:
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") debug.info("fetch manifest : '" + str(env.get_island_path_manifest()) + "'")
mani = manifest.Manifest(file_source_manifest) commands.fetch(env.get_island_path_manifest(), "origin")
all_project = mani.get_all_configs() configuration = config.get_unique_config()
debug.info("fetch : " + str(len(all_project)) + " projects") file_source_manifest = os.path.join(
id_element = 0 env.get_island_path_manifest(), configuration.get_manifest_name()
for elem in all_project: )
id_element += 1 if os.path.exists(file_source_manifest) == False:
# configure remote name: debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
if argument_remote_name == "": mani = manifest.Manifest(file_source_manifest)
argument_remote_name = elem.select_remote["name"]
all_project = mani.get_all_configs()
base_display = tools.get_list_base_display(id_element, len(all_project), elem) debug.info("fetch : " + str(len(all_project)) + " projects")
debug.info("fetch: " + base_display) id_element = 0
tools.wait_for_server_if_needed() for elem in all_project:
#debug.debug("elem : " + str(elem)) id_element += 1
git_repo_path = os.path.join(env.get_island_root_path(), elem.path) # configure remote name:
if os.path.exists(git_repo_path) == False: if argument_remote_name == "":
debug.error("can not fetch project that not exist") argument_remote_name = elem.select_remote["name"]
continue
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
if os.path.exists(os.path.join(git_repo_path,".git")) == False: debug.info("fetch: " + base_display)
# path already exist but it is not used to as a git repo ==> this is an error tools.wait_for_server_if_needed()
debug.error("path '" + git_repo_path + "' is already existing but not used for a git repository. Clean it and restart") # debug.debug("elem : " + str(elem))
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
# simply update the repository ... if os.path.exists(git_repo_path) == False:
debug.verbose("Fetching project: ") debug.error("can not fetch project that not exist")
continue
commands.fetch(git_repo_path, argument_remote_name)
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: ")
commands.fetch(git_repo_path, argument_remote_name)

View File

@ -8,21 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import commands
from island import multiprocess
from island import manifest
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Init a island repository (need 'fetch' after)" return "Init a island repository (need 'fetch' after)"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -30,8 +36,9 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("b", "branch", haveParam=True, desc="Select branch to display") my_args.add("b", "branch", haveParam=True, desc="Select branch to display")
my_args.add("m", "manifest", haveParam=True, desc="Name of the manifest") my_args.add("m", "manifest", haveParam=True, desc="Name of the manifest")
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -43,58 +50,80 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
if len(_arguments) == 0: if len(_arguments) == 0:
debug.error("Missing argument to execute the current action ...") debug.error("Missing argument to execute the current action ...")
# the configuration availlable:
branch = "master"
manifest_name = "default.xml"
address_manifest = ""
for elem in _arguments:
if elem.get_option_name() == "branch":
debug.info("find branch name: '" + elem.get_arg() + "'")
branch = elem.get_arg()
elif elem.get_option_name() == "manifest":
debug.info("find mmanifest name: '" + elem.get_arg() + "'")
manifest_name = elem.get_arg()
elif elem.get_option_name() == "":
if address_manifest != "":
debug.error("Manifest adress already set : '" + address_manifest + "' !!! '" + elem.get_arg() + "'")
address_manifest = elem.get_arg()
else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'")
if address_manifest == "":
debug.error("Init: Missing manifest name")
debug.info("Init with: '" + address_manifest + "' branch='" + branch + "' name of manifest='" + manifest_name + "'")
# check if .XXX exist (create it if needed)
if manifest.is_lutin_init() == True:
debug.error("System already init: path already exist: '" + str(env.get_island_path()) + "'")
tools.create_directory(env.get_island_path())
# check if the git of the manifest if availlable
# create the file configuration:
conf = config.get_unique_config()
conf.set_manifest(address_manifest)
conf.set_branch(branch)
conf.set_manifest_name(manifest_name)
conf.store()
debug.info("Clone the manifest")
ret_values = commands.clone(env.get_island_path_manifest(), address_manifest, branch_name=branch)
if ret_values == False:
debug.info("'" + str(ret_values) + "'")
debug.error("Init does not work")
return False
debug.info("Init done correctly ...")
return None
# the configuration availlable:
branch = "master"
manifest_name = "default.xml"
address_manifest = ""
for elem in _arguments:
if elem.get_option_name() == "branch":
debug.info("find branch name: '" + elem.get_arg() + "'")
branch = elem.get_arg()
elif elem.get_option_name() == "manifest":
debug.info("find mmanifest name: '" + elem.get_arg() + "'")
manifest_name = elem.get_arg()
elif elem.get_option_name() == "":
if address_manifest != "":
debug.error(
"Manifest adress already set : '"
+ address_manifest
+ "' !!! '"
+ elem.get_arg()
+ "'"
)
address_manifest = elem.get_arg()
else:
debug.error(
"Wrong argument: '"
+ elem.get_option_name()
+ "' '"
+ elem.get_arg()
+ "'"
)
if address_manifest == "":
debug.error("Init: Missing manifest name")
debug.info(
"Init with: '"
+ address_manifest
+ "' branch='"
+ branch
+ "' name of manifest='"
+ manifest_name
+ "'"
)
# check if .XXX exist (create it if needed)
if manifest.is_lutin_init() == True:
debug.error(
"System already init: path already exist: '"
+ str(env.get_island_path())
+ "'"
)
tools.create_directory(env.get_island_path())
# check if the git of the manifest if availlable
# create the file configuration:
conf = config.get_unique_config()
conf.set_manifest(address_manifest)
conf.set_branch(branch)
conf.set_manifest_name(manifest_name)
conf.store()
debug.info("Clone the manifest")
ret_values = commands.clone(
env.get_island_path_manifest(), address_manifest, branch_name=branch
)
if ret_values == False:
debug.info("'" + str(ret_values) + "'")
debug.error("Init does not work")
return False
debug.info("Init done correctly ...")
return None

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Manifest Ckeckout a specific branch of repository" return "Manifest Ckeckout a specific branch of repository"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,8 +37,13 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") my_args.add("r", "remote", haveParam=True, desc="Name of the remote server")
my_args.add_arg("branch", optionnal=False, desc="Branch to checkout (if '__TAG__' ==> checkout specific repository tags)") my_args.add_arg(
"branch",
optionnal=False,
desc="Branch to checkout (if '__TAG__' ==> checkout specific repository tags)",
)
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -45,28 +55,34 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
branch_to_checkout = "" branch_to_checkout = ""
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "remote": if elem.get_option_name() == "remote":
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
argument_remote_name = elem.get_arg() argument_remote_name = elem.get_arg()
elif elem.get_option_name() == "branch": elif elem.get_option_name() == "branch":
branch_to_checkout = elem.get_arg() branch_to_checkout = elem.get_arg()
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
elem = configuration.get_manifest_config()
base_display = tools.get_list_base_display(0, 0, elem)
if status.checkout_elem(elem, argument_remote_name, branch_to_checkout, base_display) == False:
return env.ret_action_fail
# check system is OK
manifest.check_lutin_is_init()
configuration = config.get_unique_config()
elem = configuration.get_manifest_config()
base_display = tools.get_list_base_display(0, 0, elem)
if (
status.checkout_elem(
elem, argument_remote_name, branch_to_checkout, base_display
)
== False
):
return env.ret_action_fail

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Push the manifest delivery" return "Push the manifest delivery"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,7 +37,8 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
pass pass
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -44,29 +50,34 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
for elem in _arguments: for elem in _arguments:
debug.error("pull Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"pull Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_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) + "'")
elem = configuration.get_manifest_config()
# Check the manifest is up to date ...
base_display = tools.get_list_base_display(0, 0, elem)
mani = manifest.Manifest(file_source_manifest)
destination_branch = mani.deliver_master
source_branch = mani.deliver_develop
status.deliver_push(elem, "origin", destination_branch, source_branch, base_display)
# check system is OK
manifest.check_lutin_is_init()
configuration = config.get_unique_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) + "'")
elem = configuration.get_manifest_config()
# Check the manifest is up to date ...
base_display = tools.get_list_base_display(0, 0, elem)
mani = manifest.Manifest(file_source_manifest)
destination_branch = mani.deliver_master
source_branch = mani.deliver_develop
status.deliver_push(elem, "origin", destination_branch, source_branch, base_display)

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Deliver the manifest (merge develop vertion and create a branch with the specific current tags)" return "Deliver the manifest (merge develop vertion and create a branch with the specific current tags)"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,11 +37,12 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
pass pass
# must be on the branch we choice to merge ... # must be on the branch we choice to merge ...
## ##
## @brief Execute the action required. ## @brief Execute the action required.
## ##
@ -47,134 +53,174 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
for elem in _arguments: for elem in _arguments:
debug.error("pull Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"pull Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == False: # check system is OK
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") manifest.check_lutin_is_init()
elem = configuration.get_manifest_config() configuration = config.get_unique_config()
mani = manifest.Manifest(file_source_manifest) file_source_manifest = os.path.join(
env.get_island_path_manifest(), configuration.get_manifest_name()
destination_branch = mani.deliver_master )
source_branch = mani.deliver_develop if os.path.exists(file_source_manifest) == False:
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
# Check the manifest is up to date ...
base_display = tools.get_list_base_display(0, 0, elem) elem = configuration.get_manifest_config()
debug.verbose("deliver-ckeck: " + base_display)
if status.deliver_check(elem, argument_remote_name, 0, base_display, source_branch, destination_branch) == False: mani = manifest.Manifest(file_source_manifest)
debug.error("Can not deliver a MANIFEST that is not ready to merge", crash=False)
return env.ret_action_fail destination_branch = mani.deliver_master
source_branch = mani.deliver_develop
all_tags = check_all_tags(mani) # Check the manifest is up to date ...
if all_tags == None: base_display = tools.get_list_base_display(0, 0, elem)
debug.error("Need the Tags are set in sub-repository", crash=False) debug.verbose("deliver-ckeck: " + base_display)
return env.ret_action_fail if (
status.deliver_check(
elem,
# deliver the manifest (if Needed ...) argument_remote_name,
base_display = tools.get_list_base_display(0, 0, elem) 0,
base_display,
debug.info("manifest-deliver: ========================================================================") source_branch,
debug.info("manifest-deliver: == " + base_display) destination_branch,
debug.info("manifest-deliver: ========================================================================") )
== False
git_repo_path = os.path.join(env.get_island_root_path(), elem.path) ):
# Check the validity of the version, debug.error(
version_description, add_in_version_management = status.get_current_version_repo(git_repo_path) "Can not deliver a MANIFEST that is not ready to merge", crash=False
if version_description == None: )
return env.ret_action_fail return env.ret_action_fail
debug.info("manifest-deliver: ==> version: " + str(version_description))
all_tags = check_all_tags(mani)
# go to the dev branch if all_tags == None:
select_branch = commands.get_current_branch(git_repo_path) debug.error("Need the Tags are set in sub-repository", crash=False)
return env.ret_action_fail
# create new repo tag # deliver the manifest (if Needed ...)
new_version_description = status.create_new_version_repo(git_repo_path, version_description, add_in_version_management, source_branch, destination_branch) base_display = tools.get_list_base_display(0, 0, elem)
debug.info("new version: " + str(new_version_description))
if new_version_description == None: debug.info(
return "manifest-deliver: ========================================================================"
# merge branch )
commands.checkout(git_repo_path, destination_branch) debug.info("manifest-deliver: == " + base_display)
if mani.deliver_mode == "merge": debug.info(
merge_force = True "manifest-deliver: ========================================================================"
else: )
merge_force = False
commands.merge_branch_on_master(git_repo_path, source_branch, merge_force, branch_destination=destination_branch) git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
# Check the validity of the version,
manifest.tag_manifest(file_source_manifest, all_tags); version_description, add_in_version_management = status.get_current_version_repo(
git_repo_path
version_path_file = os.path.join(git_repo_path, "version.txt") )
# update version file: if version_description == None:
tools.file_write_data(version_path_file, tools.version_to_string(new_version_description)) return env.ret_action_fail
commands.add_file(git_repo_path, version_path_file) debug.info("manifest-deliver: ==> version: " + str(version_description))
commands.commit_all(git_repo_path, "[RELEASE] Release v" + tools.version_to_string(new_version_description))
commands.tag(git_repo_path, "v" + tools.version_to_string(new_version_description)) # go to the dev branch
commands.checkout(git_repo_path, source_branch) select_branch = commands.get_current_branch(git_repo_path)
commands.reset_hard(git_repo_path, destination_branch)
new_version_description.append("dev") # create new repo tag
manifest.tag_clear(file_source_manifest); new_version_description = status.create_new_version_repo(
tools.file_write_data(version_path_file, tools.version_to_string(new_version_description)) git_repo_path,
commands.add_file(git_repo_path, version_path_file) version_description,
commands.commit_all(git_repo_path, status.default_update_message) add_in_version_management,
commands.checkout(git_repo_path, destination_branch) source_branch,
destination_branch,
)
debug.info("manifest-deliver: ==> DONE") debug.info("new version: " + str(new_version_description))
if new_version_description == None:
return
# merge branch
commands.checkout(git_repo_path, destination_branch)
if mani.deliver_mode == "merge":
merge_force = True
else:
merge_force = False
commands.merge_branch_on_master(
git_repo_path, source_branch, merge_force, branch_destination=destination_branch
)
manifest.tag_manifest(file_source_manifest, all_tags)
version_path_file = os.path.join(git_repo_path, "version.txt")
# update version file:
tools.file_write_data(
version_path_file, tools.version_to_string(new_version_description)
)
commands.add_file(git_repo_path, version_path_file)
commands.commit_all(
git_repo_path,
"[RELEASE] Release v" + tools.version_to_string(new_version_description),
)
commands.tag(git_repo_path, "v" + tools.version_to_string(new_version_description))
commands.checkout(git_repo_path, source_branch)
commands.reset_hard(git_repo_path, destination_branch)
new_version_description.append("dev")
manifest.tag_clear(file_source_manifest)
tools.file_write_data(
version_path_file, tools.version_to_string(new_version_description)
)
commands.add_file(git_repo_path, version_path_file)
commands.commit_all(git_repo_path, status.default_update_message)
commands.checkout(git_repo_path, destination_branch)
debug.info("manifest-deliver: ==> DONE")
def check_all_tags(mani): def check_all_tags(mani):
all_project = mani.get_all_configs() all_project = mani.get_all_configs()
debug.info("Check all: " + str(len(all_project)) + " projects have a current tag ...") debug.info(
id_element = 0 "Check all: " + str(len(all_project)) + " projects have a current tag ..."
check_have_error = False )
list_tags = [] id_element = 0
for elem in all_project: check_have_error = False
id_element += 1 list_tags = []
base_display = tools.get_list_base_display(id_element, len(all_project), elem) for elem in all_project:
if elem.volatile == True: id_element += 1
debug.info(base_display + "\r\t\t\t\t\t\t\t\t\t" + " (Not Managed)") base_display = tools.get_list_base_display(id_element, len(all_project), elem)
continue if elem.volatile == True:
tags_comment = "" debug.info(base_display + "\r\t\t\t\t\t\t\t\t\t" + " (Not Managed)")
git_repo_path = os.path.join(env.get_island_root_path(), elem.path) continue
if os.path.exists(git_repo_path) == False: tags_comment = ""
debug.error(base_display + volatile + "\r\t\t\t\t\t\t\t\t\t" + " (not download)", crash=False) git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
check_have_error = True if os.path.exists(git_repo_path) == False:
continue debug.error(
ret_current_tags = commands.get_tags_current(git_repo_path) base_display
debug.verbose("tags found: " + str(ret_current_tags)) + volatile
if len(ret_current_tags) == 0: + "\r\t\t\t\t\t\t\t\t\t"
list_tags.append({ + " (not download)",
"name":elem.name, crash=False,
"tag":"" )
}) check_have_error = True
else: continue
list_tags.append({ ret_current_tags = commands.get_tags_current(git_repo_path)
"name":elem.name, debug.verbose("tags found: " + str(ret_current_tags))
"tag":ret_current_tags[0] if len(ret_current_tags) == 0:
}) list_tags.append({"name": elem.name, "tag": ""})
for elem_tag in ret_current_tags: else:
if len(tags_comment) != 0: list_tags.append({"name": elem.name, "tag": ret_current_tags[0]})
tags_comment += "," for elem_tag in ret_current_tags:
tags_comment += elem_tag if len(tags_comment) != 0:
if len(ret_current_tags) == 0: tags_comment += ","
debug.error(base_display + "\r\t\t\t\t\t\t\t\t\t" + " (NO TAG DETECTED)", crash=False) tags_comment += elem_tag
check_have_error = True if len(ret_current_tags) == 0:
continue debug.error(
else: base_display + "\r\t\t\t\t\t\t\t\t\t" + " (NO TAG DETECTED)",
debug.info(base_display + "\r\t\t\t\t\t\t\t\t\t" + " " + tags_comment) crash=False,
if check_have_error == True: )
return None check_have_error = True
return list_tags continue
else:
debug.info(base_display + "\r\t\t\t\t\t\t\t\t\t" + " " + tags_comment)
if check_have_error == True:
return None
return list_tags

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Display status spécifically of the manifest" return "Display status spécifically of the manifest"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,7 +37,13 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(_my_args, _section): def add_specific_arguments(_my_args, _section):
_my_args.add("t", "tags", haveParam=False, desc="Display if the commit is on a tag (and display it)") _my_args.add(
"t",
"tags",
haveParam=False,
desc="Display if the commit is on a tag (and display it)",
)
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -44,20 +55,28 @@ def add_specific_arguments(_my_args, _section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
argument_display_tag = False argument_display_tag = False
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "tags": if elem.get_option_name() == "tags":
argument_display_tag = True argument_display_tag = True
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
elem = configuration.get_manifest_config() )
base_display = tools.get_list_base_display(0, 0, elem)
ret = status.display_status(elem, argument_remote_name, argument_display_tag, 0, base_display) # check system is OK
if ret != None: manifest.check_lutin_is_init()
return env.ret_action_need_updtate
configuration = config.get_unique_config()
elem = configuration.get_manifest_config()
base_display = tools.get_list_base_display(0, 0, elem)
ret = status.display_status(
elem, argument_remote_name, argument_display_tag, 0, base_display
)
if ret != None:
return env.ret_action_need_updtate

View File

@ -8,22 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Syncronize all the repository referenced" return "Syncronize all the repository referenced"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -31,7 +36,8 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
pass pass
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -43,18 +49,25 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
for elem in _arguments: for elem in _arguments:
debug.error("pull Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"pull Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
is_modify_manifest = commands.check_repository_is_modify(env.get_island_path_manifest()) # check system is OK
if is_modify_manifest == True: manifest.check_lutin_is_init()
commands.fetch(env.get_island_path_manifest(), "origin")
else: configuration = config.get_unique_config()
commands.pull(env.get_island_path_manifest(), "origin")
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
is_modify_manifest = commands.check_repository_is_modify(
env.get_island_path_manifest()
)
if is_modify_manifest == True:
commands.fetch(env.get_island_path_manifest(), "origin")
else:
commands.pull(env.get_island_path_manifest(), "origin")

View File

@ -8,22 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Push all repository to the upper server" return "Push all repository to the upper server"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -31,7 +36,8 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(_my_args, _section): def add_specific_arguments(_my_args, _section):
_my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") _my_args.add("r", "remote", haveParam=True, desc="Name of the remote server")
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -43,72 +49,83 @@ def add_specific_arguments(_my_args, _section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "remote": if elem.get_option_name() == "remote":
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
argument_remote_name = elem.get_arg() argument_remote_name = elem.get_arg()
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == False: # check system is OK
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") manifest.check_lutin_is_init()
mani = manifest.Manifest(file_source_manifest)
configuration = config.get_unique_config()
all_project = mani.get_all_configs()
debug.info("fetch : " + str(len(all_project)) + " projects") file_source_manifest = os.path.join(
id_element = 0 env.get_island_path_manifest(), configuration.get_manifest_name()
for elem in all_project: )
id_element += 1 if os.path.exists(file_source_manifest) == False:
base_display = tools.get_list_base_display(id_element, len(all_project), elem) debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
debug.info("push: " + base_display) mani = manifest.Manifest(file_source_manifest)
tools.wait_for_server_if_needed()
#debug.debug("elem : " + str(elem)) all_project = mani.get_all_configs()
git_repo_path = os.path.join(env.get_island_root_path(), elem.path) debug.info("fetch : " + str(len(all_project)) + " projects")
if os.path.exists(git_repo_path) == False: id_element = 0
debug.error("can not push project that not exist") for elem in all_project:
continue id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
if os.path.exists(os.path.join(git_repo_path,".git")) == False: debug.info("push: " + base_display)
# path already exist but it is not used to as a git repo ==> this is an error tools.wait_for_server_if_needed()
debug.error("path '" + git_repo_path + "' exist but not used for a git repository. Clean it and restart") # debug.debug("elem : " + str(elem))
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
# get the current branch: if os.path.exists(git_repo_path) == False:
# get local branch debug.error("can not push project that not exist")
cmd = "git branch -a" continue
debug.verbose("execute : " + cmd)
ret_branch = multiprocess.run_command(cmd, cwd=git_repo_path) if os.path.exists(os.path.join(git_repo_path, ".git")) == False:
list_branch = ret_branch[1].split('\n') # path already exist but it is not used to as a git repo ==> this is an error
list_branch2 = [] debug.error(
list_branch3 = [] "path '"
select_branch = "" + git_repo_path
for elem_branch in list_branch: + "' exist but not used for a git repository. Clean it and restart"
if len(elem_branch.split(" -> ")) != 1: )
continue
if elem_branch[2:10] == "remotes/": # get the current branch:
elem_branch = elem_branch[:2] + elem_branch[10:] # get local branch
if elem_branch[:2] == "* ": cmd = "git branch -a"
list_branch2.append([elem_branch[2:], True]) debug.verbose("execute : " + cmd)
select_branch = elem_branch[2:] ret_branch = multiprocess.run_command(cmd, cwd=git_repo_path)
else: list_branch = ret_branch[1].split("\n")
list_branch2.append([elem_branch[2:], False]) list_branch2 = []
list_branch3.append(elem_branch[2:]) list_branch3 = []
select_branch = ""
# simply update the repository ... for elem_branch in list_branch:
debug.verbose("Push project: ") if len(elem_branch.split(" -> ")) != 1:
# fetch the repository continue
cmd = "git push" if elem_branch[2:10] == "remotes/":
if argument_remote_name != "": elem_branch = elem_branch[:2] + elem_branch[10:]
cmd += " " + argument_remote_name if elem_branch[:2] == "* ":
else: list_branch2.append([elem_branch[2:], True])
cmd += " " + elem.select_remote["name"] select_branch = elem_branch[2:]
cmd += " " + select_branch + ":" + select_branch else:
debug.info("execute : " + cmd) list_branch2.append([elem_branch[2:], False])
multiprocess.run_command_direct(cmd, cwd=git_repo_path) 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 += " " + select_branch + ":" + select_branch
debug.info("execute : " + cmd)
multiprocess.run_command_direct(cmd, cwd=git_repo_path)

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import multiprocess
from island import config
from island import manifest
from island import commands
import status
import os import os
from realog import debug
import status
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Get the status of all the repositories" return "Get the status of all the repositories"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,8 +37,14 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(_my_args, _section): def add_specific_arguments(_my_args, _section):
_my_args.add("r", "remote", haveParam=True, desc="Name of the remote server") _my_args.add("r", "remote", haveParam=True, desc="Name of the remote server")
_my_args.add("t", "tags", haveParam=False, desc="Display if the commit is on a tag (and display it)") _my_args.add(
"t",
"tags",
haveParam=False,
desc="Display if the commit is on a tag (and display it)",
)
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -45,48 +56,59 @@ def add_specific_arguments(_my_args, _section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
argument_remote_name = "" argument_remote_name = ""
argument_display_tag = False argument_display_tag = False
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "remote": if elem.get_option_name() == "remote":
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
argument_remote_name = elem.get_arg() argument_remote_name = elem.get_arg()
elif elem.get_option_name() == "tags": elif elem.get_option_name() == "tags":
argument_display_tag = True argument_display_tag = True
else: else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
configuration = config.get_unique_config() + elem.get_arg()
+ "'"
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)
is_modify_manifest = commands.check_repository_is_modify(env.get_island_path_manifest())
if is_modify_manifest == True:
debug.info("!!!!!!!!!!!! MANIFEST is modify !!!!!!!!")
all_project = mani.get_all_configs()
debug.info("status of: " + str(len(all_project)) + " projects")
id_element = 0
elem = configuration.get_manifest_config()
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
status.display_status(elem, argument_remote_name, argument_display_tag, id_element, base_display)
is_behind = False
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
ret = status.display_status(elem, argument_remote_name, argument_display_tag, id_element, base_display)
if ret != None:
is_behind = True
if is_behind == True:
return env.ret_action_need_updtate
# check system is OK
manifest.check_lutin_is_init()
configuration = config.get_unique_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)
is_modify_manifest = commands.check_repository_is_modify(
env.get_island_path_manifest()
)
if is_modify_manifest == True:
debug.info("!!!!!!!!!!!! MANIFEST is modify !!!!!!!!")
all_project = mani.get_all_configs()
debug.info("status of: " + str(len(all_project)) + " projects")
id_element = 0
elem = configuration.get_manifest_config()
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
status.display_status(
elem, argument_remote_name, argument_display_tag, id_element, base_display
)
is_behind = False
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
ret = status.display_status(
elem, argument_remote_name, argument_display_tag, id_element, base_display
)
if ret != None:
is_behind = True
if is_behind == True:
return env.ret_action_need_updtate

View File

@ -8,23 +8,28 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import update_links
import os import os
from realog import debug
import update_links
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Update all the branche to the trackin branch in local (no remote access)" return "Update all the branche to the trackin branch in local (no remote access)"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -32,7 +37,13 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("r", "reset", haveParam=False, desc="Rebase the repository instead of 'reset --hard'") my_args.add(
"r",
"reset",
haveParam=False,
desc="Rebase the repository instead of 'reset --hard'",
)
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -46,115 +57,144 @@ def add_specific_arguments(my_args, section):
## -13 : env.ret_action_partial_done : ACTION partially done ## -13 : env.ret_action_partial_done : ACTION partially done
## ##
def execute(_arguments): def execute(_arguments):
reset_instead_of_rebase = False reset_instead_of_rebase = False
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "rebase": if elem.get_option_name() == "rebase":
reset_instead_of_rebase = True reset_instead_of_rebase = True
debug.info("==> Request reset instead of rebase") debug.info("==> Request reset instead of rebase")
else: else:
debug.error("SYNC Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'", ret_value=env.ret_action_wrong_parameters) debug.error(
"SYNC Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'",
ret_value=env.ret_action_wrong_parameters,
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'") )
is_modify_manifest = commands.check_repository_is_modify(env.get_island_path_manifest())
if is_modify_manifest == True:
debug.warning("Manifest is modify")
else:
ret_track = commands.get_current_tracking_branch(env.get_island_path_manifest())
is_forward = commands.is_forward(env.get_island_path_manifest(), ret_track)
if is_forward == True:
# fetch the repository
debug.warning("sync-local: Not update ==> the MANIFEST is forward the remote branch " + str(commands.get_forward(env.get_island_path_manifest(), ret_track)))
else:
debug.verbose("Check behind:")
is_behind = commands.is_behind(env.get_island_path_manifest(), ret_track)
if is_behind == False:
# fetch the repository
debug.info("sync-local: MANIFEST is up-to-date")
else:
if reset_instead_of_rebase == True:
debug.info("sync-local: MANIFEST Reset to " + ret_track)
commands.reset_hard(env.get_island_path_manifest(), ret_track)
else:
debug.info("sync-local: MANIFEST Rebase to " + ret_track)
commands.rebase(env.get_island_path_manifest(), ret_track)
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) + "'", ret_value=env.ret_manifest_is_not_existing)
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
debug.info("synchronize : " + str(len(all_project)) + " projects")
id_element = 0
count_error = 0
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
debug.info("----------------------------------------------------------------")
debug.info("sync-local: " + base_display)
#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:
# The Repository does not exist ==> Nothing to do...
debug.warning("sync-local: ==> Not download")
count_error += 1
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.warning("sync-local: is already existing but not used for a git repository. Remove it and sync")
count_error += 1
continue
# simply update the repository ...
debug.verbose("Check modify:")
is_modify = commands.check_repository_is_modify(git_repo_path)
if is_modify == True:
# fetch the repository
debug.warning("sync-local: Not update ==> the repository is modified (pass through)")
count_error += 1
continue
debug.verbose("Check tracking and local branch:")
# get tracking branch
ret_track = commands.get_current_tracking_branch(git_repo_path)
select_branch = commands.get_current_branch(git_repo_path)
debug.debug("sync-local: check: " + select_branch + " ==> " + ret_track)
debug.verbose("Check forward:")
is_forward = commands.is_forward(git_repo_path, ret_track)
if is_forward == True:
# fetch the repository
debug.warning("sync-local: Not update ==> the repository is forward the remote branch " + str(commands.get_forward(git_repo_path, ret_track)))
count_error += 1
continue
debug.verbose("Check behind:")
is_behind = commands.is_behind(git_repo_path, ret_track)
if is_behind == False:
# fetch the repository
debug.info("sync-local: Nothing to do.")
continue
if reset_instead_of_rebase == True:
debug.info("sync-local: Reset to " + ret_track)
commands.reset_hard(git_repo_path, ret_track)
else:
debug.info("sync-local: Reset to " + ret_track)
commands.rebase(git_repo_path, ret_track)
if count_error != 0:
debug.info(" ***********************************************************")
debug.info(" ** local sync partial warning on " + str(count_error) + " repository")
debug.info(" ***********************************************************")
return env.ret_action_partial_done
## Update the links:
have_error = update_links.update(configuration, mani, "sync-local")
if have_error == True:
return -1
return None
# check system is OK
manifest.check_lutin_is_init()
configuration = config.get_unique_config()
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
is_modify_manifest = commands.check_repository_is_modify(
env.get_island_path_manifest()
)
if is_modify_manifest == True:
debug.warning("Manifest is modify")
else:
ret_track = commands.get_current_tracking_branch(env.get_island_path_manifest())
is_forward = commands.is_forward(env.get_island_path_manifest(), ret_track)
if is_forward == True:
# fetch the repository
debug.warning(
"sync-local: Not update ==> the MANIFEST is forward the remote branch "
+ str(commands.get_forward(env.get_island_path_manifest(), ret_track))
)
else:
debug.verbose("Check behind:")
is_behind = commands.is_behind(env.get_island_path_manifest(), ret_track)
if is_behind == False:
# fetch the repository
debug.info("sync-local: MANIFEST is up-to-date")
else:
if reset_instead_of_rebase == True:
debug.info("sync-local: MANIFEST Reset to " + ret_track)
commands.reset_hard(env.get_island_path_manifest(), ret_track)
else:
debug.info("sync-local: MANIFEST Rebase to " + ret_track)
commands.rebase(env.get_island_path_manifest(), ret_track)
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) + "'",
ret_value=env.ret_manifest_is_not_existing,
)
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
debug.info("synchronize : " + str(len(all_project)) + " projects")
id_element = 0
count_error = 0
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
debug.info("----------------------------------------------------------------")
debug.info("sync-local: " + base_display)
# 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:
# The Repository does not exist ==> Nothing to do...
debug.warning("sync-local: ==> Not download")
count_error += 1
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.warning(
"sync-local: is already existing but not used for a git repository. Remove it and sync"
)
count_error += 1
continue
# simply update the repository ...
debug.verbose("Check modify:")
is_modify = commands.check_repository_is_modify(git_repo_path)
if is_modify == True:
# fetch the repository
debug.warning(
"sync-local: Not update ==> the repository is modified (pass through)"
)
count_error += 1
continue
debug.verbose("Check tracking and local branch:")
# get tracking branch
ret_track = commands.get_current_tracking_branch(git_repo_path)
select_branch = commands.get_current_branch(git_repo_path)
debug.debug("sync-local: check: " + select_branch + " ==> " + ret_track)
debug.verbose("Check forward:")
is_forward = commands.is_forward(git_repo_path, ret_track)
if is_forward == True:
# fetch the repository
debug.warning(
"sync-local: Not update ==> the repository is forward the remote branch "
+ str(commands.get_forward(git_repo_path, ret_track))
)
count_error += 1
continue
debug.verbose("Check behind:")
is_behind = commands.is_behind(git_repo_path, ret_track)
if is_behind == False:
# fetch the repository
debug.info("sync-local: Nothing to do.")
continue
if reset_instead_of_rebase == True:
debug.info("sync-local: Reset to " + ret_track)
commands.reset_hard(git_repo_path, ret_track)
else:
debug.info("sync-local: Reset to " + ret_track)
commands.rebase(git_repo_path, ret_track)
if count_error != 0:
debug.info(
" ***********************************************************"
)
debug.info(
" ** local sync partial warning on "
+ str(count_error)
+ " repository"
)
debug.info(
" ***********************************************************"
)
return env.ret_action_partial_done
## Update the links:
have_error = update_links.update(configuration, mani, "sync-local")
if have_error == True:
return -1
return None

View File

@ -8,29 +8,36 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
from island import commands
import update_links
import os import os
from realog import debug
import update_links
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Syncronize all the repository referenced" return "Syncronize all the repository referenced"
## ##
## @brief at the end of the help wa have the example section ## @brief at the end of the help wa have the example section
## @return (string) the Example description string ## @return (string) the Example description string
## ##
def help_example(): def help_example():
return "island init https://git.heeroyui.org/atria-tools/island.git" return "island init https://git.heeroyui.org/atria-tools/island.git"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -38,7 +45,13 @@ def help_example():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add("d", "download", haveParam=False, desc="Just download the 'not download' repository") my_args.add(
"d",
"download",
haveParam=False,
desc="Just download the 'not download' repository",
)
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -50,141 +63,168 @@ def add_specific_arguments(my_args, section):
## -12 : ACTION Wrong parameters ## -12 : ACTION Wrong parameters
## ##
def execute(_arguments): def execute(_arguments):
just_download = False just_download = False
for elem in _arguments: for elem in _arguments:
if elem.get_option_name() == "download": if elem.get_option_name() == "download":
just_download = True just_download = True
debug.info("find remote name: '" + elem.get_arg() + "'") debug.info("find remote name: '" + elem.get_arg() + "'")
else: else:
debug.error("SYNC Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"SYNC Wrong argument: '"
# check system is OK + elem.get_option_name()
manifest.check_lutin_is_init() + "' '"
+ elem.get_arg()
configuration = config.get_unique_config() + "'"
)
# TODO: Load Old manifect to check diff ...
# check system is OK
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'") manifest.check_lutin_is_init()
is_modify_manifest = commands.check_repository_is_modify(env.get_island_path_manifest())
if is_modify_manifest == True: configuration = config.get_unique_config()
commands.fetch(env.get_island_path_manifest(), "origin")
else: # TODO: Load Old manifect to check diff ...
commands.pull(env.get_island_path_manifest(), "origin")
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name()) is_modify_manifest = commands.check_repository_is_modify(
if os.path.exists(file_source_manifest) == False: env.get_island_path_manifest()
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'") )
if is_modify_manifest == True:
mani = manifest.Manifest(file_source_manifest) commands.fetch(env.get_island_path_manifest(), "origin")
else:
all_project = mani.get_all_configs() commands.pull(env.get_island_path_manifest(), "origin")
debug.info("synchronize : " + str(len(all_project)) + " projects")
id_element = 0 file_source_manifest = os.path.join(
for elem in all_project: env.get_island_path_manifest(), configuration.get_manifest_name()
id_element += 1 )
base_display = tools.get_list_base_display(id_element, len(all_project), elem) if os.path.exists(file_source_manifest) == False:
debug.info("sync : " + base_display) debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
tools.wait_for_server_if_needed()
#debug.debug("elem : " + str(elem)) mani = manifest.Manifest(file_source_manifest)
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
if elem.tag != None: all_project = mani.get_all_configs()
debug.warning("Need to select a specific tag version ... " + elem.tag) debug.info("synchronize : " + str(len(all_project)) + " projects")
if os.path.exists(git_repo_path) == False: id_element = 0
# this is a new clone ==> this is easy ... for elem in all_project:
#clone the manifest repository id_element += 1
address_manifest = "" base_display = tools.get_list_base_display(id_element, len(all_project), elem)
### example git@git.plouf.com:basic_folder debug.info("sync : " + base_display)
address_manifest = elem.select_remote["fetch"] tools.wait_for_server_if_needed()
if elem.select_remote["fetch"][0:4] == "git@" \ # debug.debug("elem : " + str(elem))
and len(elem.select_remote["fetch"][4:].split(":")) <= 1: git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
address_manifest += ":" if elem.tag != None:
else: debug.warning("Need to select a specific tag version ... " + elem.tag)
address_manifest += "/" if os.path.exists(git_repo_path) == False:
address_manifest += elem.name # this is a new clone ==> this is easy ...
debug.info("clone the repo") # clone the manifest repository
ret = commands.clone(git_repo_path, address_manifest, branch_name=elem.branch, origin=elem.select_remote["name"]) address_manifest = ""
if ret[0] != "" \ ### example git@git.plouf.com:basic_folder
and ret[0] != False: address_manifest = elem.select_remote["fetch"]
# all is good, ready to get the system work corectly if (
debug.info("'" + str(ret) + "'") elem.select_remote["fetch"][0:4] == "git@"
debug.error("Clone repository does not work ... ") and len(elem.select_remote["fetch"][4:].split(":")) <= 1
continue ):
# add global mirror list address_manifest += ":"
for mirror in elem.select_remote["mirror"]: else:
debug.verbose("Add global mirror: " + str(mirror)) address_manifest += "/"
cmd = "git remote add " + mirror["name"] + " " + mirror["fetch"] address_manifest += elem.name
if mirror["fetch"][0:4] == "git@": debug.info("clone the repo")
cmd += ":" ret = commands.clone(
else: git_repo_path,
cmd += "/" address_manifest,
cmd += elem.name branch_name=elem.branch,
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path) origin=elem.select_remote["name"],
if ret != "" \ )
and ret != False: if ret[0] != "" and ret[0] != False:
# all is good, ready to get the system work corectly # all is good, ready to get the system work corectly
debug.info("'" + str(ret) + "'") debug.info("'" + str(ret) + "'")
debug.warning("Can not add global mirror ... ") debug.error("Clone repository does not work ... ")
continue continue
debug.verbose("Add global mirror: " + str(mirror) + " (done)") # add global mirror list
#debug.info("plop " + str(elem.select_remote.keys())) for mirror in elem.select_remote["mirror"]:
# check submodule if requested: debug.verbose("Add global mirror: " + str(mirror))
if elem.select_remote["sync"] == True \ cmd = "git remote add " + mirror["name"] + " " + mirror["fetch"]
and os.path.exists(os.path.join(git_repo_path, ".gitmodules")) == True: if mirror["fetch"][0:4] == "git@":
debug.info(" ==> update submodule") cmd += ":"
cmd = "git submodule init" else:
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path) cmd += "/"
if ret != "" \ cmd += elem.name
and ret != False: ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
# all is good, ready to get the system work corectly if ret != "" and ret != False:
debug.info("'" + str(ret) + "'") # all is good, ready to get the system work corectly
debug.error("Can not init submodules ... ") debug.info("'" + str(ret) + "'")
continue debug.warning("Can not add global mirror ... ")
cmd = "git submodule update" continue
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path) debug.verbose("Add global mirror: " + str(mirror) + " (done)")
if ret[:16] == "Submodule path '": # debug.info("plop " + str(elem.select_remote.keys()))
#all is good ... # check submodule if requested:
debug.info(" " + ret) if (
elif ret != "" \ elem.select_remote["sync"] == True
and ret != False: and os.path.exists(os.path.join(git_repo_path, ".gitmodules")) == True
# all is good, ready to get the system work corectly ):
debug.info("'" + str(ret) + "'") debug.info(" ==> update submodule")
debug.error("Can not init submodules ... ") cmd = "git submodule init"
continue ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
continue if ret != "" and ret != False:
# all is good, ready to get the system work corectly
if just_download == True: debug.info("'" + str(ret) + "'")
debug.info("SYNC: Already downloaded") debug.error("Can not init submodules ... ")
continue continue
cmd = "git submodule update"
if os.path.exists(os.path.join(git_repo_path,".git")) == False: ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
# path already exist but it is not used to as a git repo ==> this is an error if ret[:16] == "Submodule path '":
debug.error("path '" + git_repo_path + "' is already existing but not used for a git repository. Clean it and restart") # all is good ...
debug.info(" " + ret)
# simply update the repository ... elif ret != "" and ret != False:
debug.verbose("Fetching project: ") # all is good, ready to get the system work corectly
debug.info("'" + str(ret) + "'")
# get tracking branch debug.error("Can not init submodules ... ")
ret_track = commands.get_current_tracking_branch(git_repo_path) continue
is_modify = commands.check_repository_is_modify(git_repo_path) continue
select_branch = commands.get_current_branch(git_repo_path)
if just_download == True:
if is_modify == True: debug.info("SYNC: Already downloaded")
# fetch the repository continue
commands.fetch(git_repo_path, elem.select_remote["name"])
debug.warning("[" + elem.name + "] Not update ==> the repository is modified (just fetch)") if os.path.exists(os.path.join(git_repo_path, ".git")) == False:
continue # path already exist but it is not used to as a git repo ==> this is an error
commands.pull(git_repo_path, elem.select_remote["name"]) debug.error(
"path '"
debug.verbose("select branch = '" + select_branch + "' track: '" + str(ret_track) + "'") + git_repo_path
# check submodule if requested: + "' is already existing but not used for a git repository. Clean it and restart"
if elem.select_remote["sync"] == True \ )
and os.path.exists(os.path.join(git_repo_path, ".gitmodules")) == True:
debug.info(" ==> sync submodule") # simply update the repository ...
commands.submodule_sync(git_repo_path) debug.verbose("Fetching project: ")
## Update the links: # get tracking branch
have_error = update_links.update(configuration, mani, "sync-local") ret_track = commands.get_current_tracking_branch(git_repo_path)
if have_error == True: is_modify = commands.check_repository_is_modify(git_repo_path)
return -1 select_branch = commands.get_current_branch(git_repo_path)
return None
if is_modify == True:
# fetch the repository
commands.fetch(git_repo_path, elem.select_remote["name"])
debug.warning(
"["
+ elem.name
+ "] Not update ==> the repository is modified (just fetch)"
)
continue
commands.pull(git_repo_path, elem.select_remote["name"])
debug.verbose(
"select branch = '" + select_branch + "' track: '" + str(ret_track) + "'"
)
# check submodule if requested:
if (
elem.select_remote["sync"] == True
and os.path.exists(os.path.join(git_repo_path, ".gitmodules")) == True
):
debug.info(" ==> sync submodule")
commands.submodule_sync(git_repo_path)
## Update the links:
have_error = update_links.update(configuration, mani, "sync-local")
if have_error == True:
return -1
return None

View File

@ -8,21 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import commands
from island import multiprocess
from island import manifest
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "Add a 'volatile' repository with a local path (this element is update as an element in the manifest but is not managed by the manifest)" return "Add a 'volatile' repository with a local path (this element is update as an element in the manifest but is not managed by the manifest)"
## ##
## @brief Add argument to the specific action ## @brief Add argument to the specific action
@ -30,15 +36,21 @@ def help():
## @param[in] section Name of the currect action ## @param[in] section Name of the currect action
## ##
def add_specific_arguments(my_args, section): def add_specific_arguments(my_args, section):
my_args.add_arg("git repository", optionnal=False, desc="Git repositoty to download") my_args.add_arg(
my_args.add_arg("path", optionnal=False, desc="Path to install the new git repository") "git repository", optionnal=False, desc="Git repositoty to download"
)
my_args.add_arg(
"path", optionnal=False, desc="Path to install the new git repository"
)
## ##
## @brief at the end of the help wa have the example section ## @brief at the end of the help wa have the example section
## @return (string) the Example description string ## @return (string) the Example description string
## ##
def help_example(): def help_example():
return "island volatile-add https://git.heeroyui.org/atria-tools/island.git git" return "island volatile-add https://git.heeroyui.org/atria-tools/island.git git"
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -52,35 +64,44 @@ def help_example():
## -13 : env.ret_action_partial_done : ACTION partially done ## -13 : env.ret_action_partial_done : ACTION partially done
## ##
def execute(_arguments): def execute(_arguments):
if len(_arguments) == 0: if len(_arguments) == 0:
debug.error("Missing argument to execute the current action [git repository] [path]") debug.error(
"Missing argument to execute the current action [git repository] [path]"
# the configuration availlable: )
path = ""
address_git = ""
for elem in _arguments:
if elem.get_option_name() == "git repository":
address_git = elem.get_arg()
elif elem.get_option_name() == "path":
path = elem.get_arg()
else:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'")
if address_git == "":
debug.error("volatile-add: Missing git repository address", env.ret_action_wrong_parameters)
debug.info("Add 'volatile' repository: '" + address_git + "' path='" + path + "'")
# check system is OK
manifest.check_lutin_is_init()
# Update the current configuration:
conf = config.get_unique_config()
# TODO: Check if the local path does not exist in the manifest
if False == conf.add_volatile(address_git, path):
return env.ret_action_executing_system_error
conf.store()
return None
# the configuration availlable:
path = ""
address_git = ""
for elem in _arguments:
if elem.get_option_name() == "git repository":
address_git = elem.get_arg()
elif elem.get_option_name() == "path":
path = elem.get_arg()
else:
debug.error(
"Wrong argument: '"
+ elem.get_option_name()
+ "' '"
+ elem.get_arg()
+ "'"
)
if address_git == "":
debug.error(
"volatile-add: Missing git repository address",
env.ret_action_wrong_parameters,
)
debug.info("Add 'volatile' repository: '" + address_git + "' path='" + path + "'")
# check system is OK
manifest.check_lutin_is_init()
# Update the current configuration:
conf = config.get_unique_config()
# TODO: Check if the local path does not exist in the manifest
if False == conf.add_volatile(address_git, path):
return env.ret_action_executing_system_error
conf.store()
return None

View File

@ -8,21 +8,27 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
from island import config
from island import commands
from island import multiprocess
from island import manifest
import os import os
from realog import debug
from island import (
commands,
config,
env,
manifest,
multiprocess,
tools,
)
## ##
## @brief Get the global description of the current action ## @brief Get the global description of the current action
## @return (string) the description string (fist line if reserved for the overview, all is for the specific display) ## @return (string) the description string (fist line if reserved for the overview, all is for the specific display)
## ##
def help(): def help():
return "List all the volatil repository" return "List all the volatil repository"
## ##
## @brief Execute the action required. ## @brief Execute the action required.
@ -36,18 +42,18 @@ def help():
## -13 : env.ret_action_partial_done : ACTION partially done ## -13 : env.ret_action_partial_done : ACTION partially done
## ##
def execute(_arguments): def execute(_arguments):
for elem in _arguments: for elem in _arguments:
debug.error("Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'") debug.error(
"Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'"
# check system is OK )
manifest.check_lutin_is_init()
conf = config.get_unique_config()
volatiles = conf.get_volatile()
debug.info("List of all volatiles repository: ")
for elem in volatiles:
debug.info("\t" + elem["path"] + "\r\t\t\t\t" + elem["git_address"])
return None
# check system is OK
manifest.check_lutin_is_init()
conf = config.get_unique_config()
volatiles = conf.get_volatile()
debug.info("List of all volatiles repository: ")
for elem in volatiles:
debug.info("\t" + elem["path"] + "\r\t\t\t\t" + elem["git_address"])
return None

File diff suppressed because it is too large Load Diff

View File

@ -8,36 +8,43 @@
## @license MPL v2.0 (see license file) ## @license MPL v2.0 (see license file)
## ##
from realog import debug
from island import tools
from island import env
import os import os
from realog import debug
from island import env, tools
## Update the links: ## Update the links:
def update(configuration, mani, type_call): def update(configuration, mani, type_call):
# TODO: do not remove link when not needed # TODO: do not remove link when not needed
if len(configuration.get_links()) != 0 \ if len(configuration.get_links()) != 0 or len(mani.get_links()) != 0:
or len(mani.get_links()) != 0: debug.info(type_call + ": remove old links ...")
debug.info(type_call + ": remove old links ...") for elem in configuration.get_links():
for elem in configuration.get_links(): base_path = os.path.join(env.get_island_root_path(), elem["destination"])
base_path = os.path.join(env.get_island_root_path(), elem["destination"]) debug.info(type_call + ": link: " + str(base_path))
debug.info(type_call + ": link: " + str(base_path)) if os.path.islink(base_path) == True:
if os.path.islink(base_path) == True: os.unlink(base_path)
os.unlink(base_path) else:
else: debug.error(
debug.error(type_call + ": remove link is not authorised ==> not a link", crash=False) type_call + ": remove link is not authorised ==> not a link",
have_error = True crash=False,
configuration.clear_links() )
debug.info(type_call + ": add new links ...") have_error = True
for elem in mani.get_links(): configuration.clear_links()
base_path = os.path.join(env.get_island_root_path(), elem["destination"]) debug.info(type_call + ": add new links ...")
source_path = os.path.join(env.get_island_root_path(), elem["source"]) for elem in mani.get_links():
debug.info(type_call + ": link: " + str(base_path)) base_path = os.path.join(env.get_island_root_path(), elem["destination"])
if os.path.exists(base_path) == True: source_path = os.path.join(env.get_island_root_path(), elem["source"])
debug.error(type_call + ": create link is not possible ==> path already exist", crash=False) debug.info(type_call + ": link: " + str(base_path))
have_error = True if os.path.exists(base_path) == True:
else: debug.error(
tools.create_directory_of_file(base_path) type_call + ": create link is not possible ==> path already exist",
os.symlink(source_path, base_path) crash=False,
configuration.add_link(elem["source"], elem["destination"]) )
configuration.store() have_error = True
else:
tools.create_directory_of_file(base_path)
os.symlink(source_path, base_path)
configuration.add_link(elem["source"], elem["destination"])
configuration.store()

View File

@ -1,342 +1,393 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Command interface.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
import os
import shutil
import errno import errno
import fnmatch import fnmatch
import os
import shutil
import stat import stat
# Local import # Local import
from realog import debug from realog import debug
from . import env
from . import multiprocess
from . import debug
from . import (
debug,
env,
multiprocess,
)
""" """
""" """
def check_repository_is_modify(path_repository): def check_repository_is_modify(path_repository):
# check if the repository is modify # check if the repository is modify
cmd = "git diff --quiet" cmd = "git diff --quiet"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "check_repository_is_modify", error_only=True, availlable_return=[0,1], display_if_nothing=False) multiprocess.generic_display_error(
ret_diff = return_value return_value,
if ret_diff[0] == 0: "check_repository_is_modify",
return False error_only=True,
return True availlable_return=[0, 1],
display_if_nothing=False,
)
ret_diff = return_value
if ret_diff[0] == 0:
return False
return True
def get_list_branch_meta(path_repository): def get_list_branch_meta(path_repository):
# get local branch # get local branch
cmd = "git branch -a" cmd = "git branch -a"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_list_branch_meta", error_only=True) multiprocess.generic_display_error(
ret_branch = return_value return_value, "get_list_branch_meta", error_only=True
list_branch = ret_branch[1].split('\n') )
out = [] ret_branch = return_value
for elem_branch in list_branch: list_branch = ret_branch[1].split("\n")
is_remote = False out = []
branch_name = "" for elem_branch in list_branch:
is_selected = False is_remote = False
if len(elem_branch.split(" -> ")) != 1: branch_name = ""
continue is_selected = False
# separate the remote element if len(elem_branch.split(" -> ")) != 1:
if elem_branch[2:10] == "remotes/": continue
elem_branch = elem_branch[:2] + elem_branch[10:] # separate the remote element
is_remote = True if elem_branch[2:10] == "remotes/":
# separate select branch elem_branch = elem_branch[:2] + elem_branch[10:]
if elem_branch[:2] == "* ": is_remote = True
is_selected = True # separate select branch
branch_name = elem_branch[2:] if elem_branch[:2] == "* ":
else: is_selected = True
branch_name = elem_branch[2:] branch_name = elem_branch[2:]
out.append({ else:
"remote": is_remote, branch_name = elem_branch[2:]
"name": branch_name, out.append({"remote": is_remote, "name": branch_name, "select": is_selected})
"select": is_selected debug.extreme_verbose("List all branch Meta: " + str(out))
}) return out
debug.extreme_verbose("List all branch Meta: " + str(out))
return out
def get_list_branch_all(path_repository): def get_list_branch_all(path_repository):
tmp = get_list_branch_meta(path_repository) tmp = get_list_branch_meta(path_repository)
out = [] out = []
for elem in tmp: for elem in tmp:
out.append(elem["name"]) out.append(elem["name"])
debug.verbose("List all branch: " + str(out)) debug.verbose("List all branch: " + str(out))
return out return out
def get_list_branch_local(path_repository): def get_list_branch_local(path_repository):
tmp = get_list_branch_meta(path_repository) tmp = get_list_branch_meta(path_repository)
out = [] out = []
for elem in tmp: for elem in tmp:
if elem["remote"] == False: if elem["remote"] == False:
out.append(elem["name"]) out.append(elem["name"])
debug.verbose("List local branch: " + str(out)) debug.verbose("List local branch: " + str(out))
return out return out
def get_list_branch_remote(path_repository): def get_list_branch_remote(path_repository):
tmp = get_list_branch_meta(path_repository) tmp = get_list_branch_meta(path_repository)
out = [] out = []
for elem in tmp: for elem in tmp:
if elem["remote"] == True: if elem["remote"] == True:
out.append(elem["name"]) out.append(elem["name"])
debug.verbose("List remote branch: " + str(out)) debug.verbose("List remote branch: " + str(out))
return out return out
def get_current_branch(path_repository): def get_current_branch(path_repository):
tmp = get_list_branch_meta(path_repository) tmp = get_list_branch_meta(path_repository)
for elem in tmp: for elem in tmp:
if elem["select"] == True: if elem["select"] == True:
debug.verbose("List local branch: " + str(elem["name"])) debug.verbose("List local branch: " + str(elem["name"]))
return elem["name"] return elem["name"]
debug.verbose("List local branch: None" ) debug.verbose("List local branch: None")
return None return None
def get_current_tracking_branch(path_repository): def get_current_tracking_branch(path_repository):
# get tracking branch # get tracking branch
cmd = "git rev-parse --abbrev-ref --symbolic-full-name @{u}" cmd = "git rev-parse --abbrev-ref --symbolic-full-name @{u}"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
if return_value[1] == "@{u}": if return_value[1] == "@{u}":
debug.warning("in '" + path_repository + "' no tracking branch is specify") debug.warning("in '" + path_repository + "' no tracking branch is specify")
return None return None
multiprocess.generic_display_error(return_value, "get_current_tracking_branch", error_only=True) multiprocess.generic_display_error(
return return_value[1] return_value, "get_current_tracking_branch", error_only=True
)
return return_value[1]
def get_revision_list_to_branch(path_repository, branch): def get_revision_list_to_branch(path_repository, branch):
cmd = "git rev-list " + branch cmd = "git rev-list " + branch
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_revision_list_to_branch", error_only=True) multiprocess.generic_display_error(
return return_value[1].split('\n') 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): def get_specific_commit_message(path_repository, sha_1):
if sha_1 == None or sha_1 == "": if sha_1 == None or sha_1 == "":
return "" return ""
cmd = "git log --format=%B -n 1 " + sha_1 cmd = "git log --format=%B -n 1 " + sha_1
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_specific_commit_message", error_only=True) multiprocess.generic_display_error(
return return_value[1].split('\n')[0] 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): def get_sha1_for_branch(path_repository, branch_name):
if branch_name == None or branch_name == "": if branch_name == None or branch_name == "":
return None return None
cmd = "git rev-parse " + branch_name cmd = "git rev-parse " + branch_name
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_sha1_for_branch", error_only=True) multiprocess.generic_display_error(
return return_value[1].split('\n')[0] return_value, "get_sha1_for_branch", error_only=True
)
return return_value[1].split("\n")[0]
def get_tags_current(path_repository): def get_tags_current(path_repository):
cmd = "git tag --points-at" cmd = "git tag --points-at"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "get_tags_current", error_only=True) multiprocess.generic_display_error(
list_tags = [] return_value, "get_tags_current", error_only=True
for elem in return_value[1].split('\n'): )
if elem != "": list_tags = []
list_tags.append(elem) for elem in return_value[1].split("\n"):
return list_tags if elem != "":
list_tags.append(elem)
return list_tags
def get_tags(path_repository): def get_tags(path_repository):
cmd = "git tag" cmd = "git tag"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.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') return return_value[1].split("\n")
def get_tags_remote(path_repository, remote_name): def get_tags_remote(path_repository, remote_name):
if remote_name == "" or remote_name == None: if remote_name == "" or remote_name == None:
return get_current_tracking_branch(path_repository) return get_current_tracking_branch(path_repository)
cmd = "git ls-remote --tags " + remote_name cmd = "git ls-remote --tags " + remote_name
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.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') list_element = return_value[1].split("\n")
debug.verbose(" receive: " + str(list_element)) debug.verbose(" receive: " + str(list_element))
#6bc01117e85d00686ae2d423193a161e82df9a44 refs/tags/0.1.0 # 6bc01117e85d00686ae2d423193a161e82df9a44 refs/tags/0.1.0
#7ef9caa51cf3744de0f46352e5aa07bd4980fe89 refs/tags/v0.2.0 # 7ef9caa51cf3744de0f46352e5aa07bd4980fe89 refs/tags/v0.2.0
#870e8e039b0a98370a9d23844f0af66824c57a5f refs/tags/v0.2.0^{} # 870e8e039b0a98370a9d23844f0af66824c57a5f refs/tags/v0.2.0^{}
#16707e17e58f16b3409f8c64df7f595ba7dcf499 refs/tags/v0.3.0 # 16707e17e58f16b3409f8c64df7f595ba7dcf499 refs/tags/v0.3.0
#dfb97c3dfea776e5c4862dc9f60f8c5ad83b55eb refs/tags/v0.3.0^{} # dfb97c3dfea776e5c4862dc9f60f8c5ad83b55eb refs/tags/v0.3.0^{}
out = [] out = []
for elem in list_element: for elem in list_element:
cut = elem.split("\t") cut = elem.split("\t")
if len(cut) != 2: if len(cut) != 2:
continue continue
if cut[1][-3:] == "^{}": if cut[1][-3:] == "^{}":
# specific usage for the annotated commit # specific usage for the annotated commit
continue continue
if cut[1][:10] == "refs/tags/": if cut[1][:10] == "refs/tags/":
out.append(cut[1][10:]) out.append(cut[1][10:])
else: else:
out.append(cut[1]) out.append(cut[1])
return out return out
def get_tracking_branch(path_repository, remote_name, select_branch): def get_tracking_branch(path_repository, remote_name, select_branch):
# get tracking branch # get tracking branch
if remote_name == "" or remote_name == None: if remote_name == "" or remote_name == None:
return get_current_tracking_branch(path_repository) return get_current_tracking_branch(path_repository)
list_branch_remote = get_list_branch_remote(path_repository) list_branch_remote = get_list_branch_remote(path_repository)
debug.extreme_verbose("check if exist " + remote_name + "/" + select_branch + " in " + str(list_branch_remote)) debug.extreme_verbose(
if remote_name + "/" + select_branch not in list_branch_remote: "check if exist "
debug.debug(" ==> can not get remote branch") + remote_name
return None + "/"
return remote_name + "/" + select_branch + select_branch
+ " in "
+ str(list_branch_remote)
)
if remote_name + "/" + select_branch not in list_branch_remote:
debug.debug(" ==> can not get remote branch")
return None
return remote_name + "/" + select_branch
def merge_branch_on_master(path_repository, branch_name, merge_force=True, branch_destination = "master"): def merge_branch_on_master(
if branch_name == None or branch_name == "": path_repository, branch_name, merge_force=True, branch_destination="master"
raise "Missing branch name" ):
cmd = "git merge " if branch_name == None or branch_name == "":
if merge_force == True: raise "Missing branch name"
cmd += "--no-ff " cmd = "git merge "
cmd += branch_name + " --message \"Merge branch '" + branch_name + "' into '" + branch_destination + "'\"" if merge_force == True:
debug.verbose("execute : " + cmd) cmd += "--no-ff "
# TODO: check if the command work correctly cmd += (
return_value = multiprocess.run_command(cmd, cwd=path_repository) branch_name
multiprocess.generic_display_error(return_value, "merge_branch_on_master", error_only=True) + " --message \"Merge branch '"
return return_value + branch_name
+ "' into '"
+ branch_destination
+ "'\""
)
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(
return_value, "merge_branch_on_master", error_only=True
)
return return_value
def add_file(path_repository, file_path): def add_file(path_repository, file_path):
if file_path == None or file_path == "": if file_path == None or file_path == "":
raise "Missing file_path name" raise "Missing file_path name"
cmd = "git add " + file_path cmd = "git add " + file_path
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly # TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "add_file", error_only=True) multiprocess.generic_display_error(return_value, "add_file", error_only=True)
return return_value return return_value
def commit_all(path_repository, comment): def commit_all(path_repository, comment):
if comment == None or comment == "": if comment == None or comment == "":
raise "Missing comment description" raise "Missing comment description"
cmd = 'git commit -a --message "' + comment +'"' cmd = 'git commit -a --message "' + comment + '"'
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly # TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "commit_all", error_only=True) multiprocess.generic_display_error(return_value, "commit_all", error_only=True)
return return_value return return_value
def tag(path_repository, tag_name): def tag(path_repository, tag_name):
if tag_name == None or tag_name == "": if tag_name == None or tag_name == "":
raise "Missing tag name" raise "Missing tag name"
tag_name = tag_name.replace(" ", "_") tag_name = tag_name.replace(" ", "_")
cmd = 'git tag ' + tag_name + ' --message "[TAG] create tag ' + tag_name +'"' cmd = "git tag " + tag_name + ' --message "[TAG] create tag ' + tag_name + '"'
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly # TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "tag", error_only=True) multiprocess.generic_display_error(return_value, "tag", error_only=True)
return return_value return return_value
def checkout(path_repository, branch_name): def checkout(path_repository, branch_name):
if branch_name == None or branch_name == "": if branch_name == None or branch_name == "":
raise "Missing branch name" raise "Missing branch name"
cmd = 'git checkout ' + branch_name cmd = "git checkout " + branch_name
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly # TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "checkout", error_only=True) multiprocess.generic_display_error(return_value, "checkout", error_only=True)
return return_value return return_value
def reset_hard(path_repository, destination): def reset_hard(path_repository, destination):
if destination == None or destination == "": if destination == None or destination == "":
raise "Missing destination 'sha1' or 'branch name'" raise "Missing destination 'sha1' or 'branch name'"
cmd = 'git reset --hard ' + destination cmd = "git reset --hard " + destination
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly # TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "reset_hard", error_only=True) multiprocess.generic_display_error(return_value, "reset_hard", error_only=True)
return return_value return return_value
def rebase(path_repository, destination): def rebase(path_repository, destination):
if destination == None or destination == "": if destination == None or destination == "":
raise "Missing destination 'sha1' or 'branch name'" raise "Missing destination 'sha1' or 'branch name'"
cmd = 'git rebase ' + destination cmd = "git rebase " + destination
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly # TODO: check if the command work correctly
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "rebase", error_only=True) multiprocess.generic_display_error(return_value, "rebase", error_only=True)
return return_value return return_value
def clone(path_repository, address, branch_name = None, origin=None): def clone(path_repository, address, branch_name=None, origin=None):
if address == None or address == "": if address == None or address == "":
raise "Missing address" raise "Missing address"
cmd = 'git clone ' + address cmd = "git clone " + address
if branch_name != None and branch_name == "": if branch_name != None and branch_name == "":
cmd += " --branch " + branch_name cmd += " --branch " + branch_name
if origin != None and origin == "": if origin != None and origin == "":
cmd += " --origin " + origin cmd += " --origin " + origin
if path_repository != None and path_repository != "": if path_repository != None and path_repository != "":
cmd += " " + path_repository cmd += " " + path_repository
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
if os.path.exists(path_repository) == True: if os.path.exists(path_repository) == True:
debug.warning("Can not clone repository path already exist") debug.warning("Can not clone repository path already exist")
return False return False
return_value = multiprocess.run_command(cmd) return_value = multiprocess.run_command(cmd)
multiprocess.generic_display_error(return_value, "clone", error_only=True) multiprocess.generic_display_error(return_value, "clone", error_only=True)
return return_value return return_value
def fetch(path_repository, remote_name, prune=True): def fetch(path_repository, remote_name, prune=True):
cmd = 'git fetch ' + remote_name cmd = "git fetch " + remote_name
if prune == True: if prune == True:
cmd += " --prune" cmd += " --prune"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "fetch") multiprocess.generic_display_error(return_value, "fetch")
return return_value return return_value
def pull(path_repository, remote_name, prune=True): def pull(path_repository, remote_name, prune=True):
if remote_name == None or remote_name == "": if remote_name == None or remote_name == "":
raise "Missing remote_name" raise "Missing remote_name"
cmd = 'git pull ' + remote_name cmd = "git pull " + remote_name
if prune == True: if prune == True:
cmd += " --prune" cmd += " --prune"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "pull") multiprocess.generic_display_error(return_value, "pull")
return return_value return return_value
def push(path_repository, remote_name, elements): def push(path_repository, remote_name, elements):
if remote_name == None or remote_name == "": if remote_name == None or remote_name == "":
raise "Missing remote_name" raise "Missing remote_name"
if len(elements) == 0: if len(elements) == 0:
raise "No elements to push on server" raise "No elements to push on server"
cmd = 'git push ' + remote_name cmd = "git push " + remote_name
for elem in elements: for elem in elements:
cmd += " " + elem cmd += " " + elem
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "push") multiprocess.generic_display_error(return_value, "push")
return return_value return return_value
def submodule_sync(path_repository, remote_name): def submodule_sync(path_repository, remote_name):
cmd = "git submodule sync" cmd = "git submodule sync"
debug.verbose("execute : " + cmd) debug.verbose("execute : " + cmd)
return_value = multiprocess.run_command(cmd, cwd=path_repository) return_value = multiprocess.run_command(cmd, cwd=path_repository)
multiprocess.generic_display_error(return_value, "submodule_sync") multiprocess.generic_display_error(return_value, "submodule_sync")
""" """
if ret[:31] == "Synchronizing submodule url for": if ret[:31] == "Synchronizing submodule url for":
#all is good ... #all is good ...
debug.info(" " + ret) debug.info(" " + ret)
@ -348,41 +399,43 @@ def submodule_sync(path_repository, remote_name):
""" """
def get_forward(path_repository, branch_name): def get_forward(path_repository, branch_name):
if branch_name == None or branch_name == "": if branch_name == None or branch_name == "":
raise "get_fast_forward: Missing branch_name" raise "get_fast_forward: Missing branch_name"
select_branch = get_current_branch(path_repository) select_branch = get_current_branch(path_repository)
# get tracking branch # get tracking branch
ret_current_branch_sha1 = get_revision_list_to_branch(path_repository, select_branch) ret_current_branch_sha1 = get_revision_list_to_branch(
ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name) path_repository, select_branch
# count the number of commit fast forward )
forward_count = 0 ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name)
for elem_sha1 in ret_current_branch_sha1: # count the number of commit fast forward
if elem_sha1 not in ret_track_branch_sha1: forward_count = 0
forward_count += 1 for elem_sha1 in ret_current_branch_sha1:
return forward_count if elem_sha1 not in ret_track_branch_sha1:
forward_count += 1
return forward_count
def is_forward(path_repository, branch_name): def is_forward(path_repository, branch_name):
return get_forward(path_repository, branch_name) != 0; return get_forward(path_repository, branch_name) != 0
def get_behind(path_repository, branch_name): def get_behind(path_repository, branch_name):
if branch_name == None or branch_name == "": if branch_name == None or branch_name == "":
raise "get_fast_forward: Missing branch_name" raise "get_fast_forward: Missing branch_name"
select_branch = get_current_branch(path_repository) select_branch = get_current_branch(path_repository)
# get tracking branch # get tracking branch
ret_current_branch_sha1 = get_revision_list_to_branch(path_repository, select_branch) ret_current_branch_sha1 = get_revision_list_to_branch(
ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name) path_repository, select_branch
# count the number of commit behind )
behind_count = 0 ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name)
for elem_sha1 in ret_track_branch_sha1: # count the number of commit behind
if elem_sha1 not in ret_current_branch_sha1: behind_count = 0
behind_count += 1 for elem_sha1 in ret_track_branch_sha1:
return behind_count if elem_sha1 not in ret_current_branch_sha1:
behind_count += 1
return behind_count
def is_behind(path_repository, branch_name): def is_behind(path_repository, branch_name):
return get_behind(path_repository, branch_name) != 0; return get_behind(path_repository, branch_name) != 0

View File

@ -1,185 +1,187 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Config main interface.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
import platform
import sys
import os
import copy import copy
import json import json
import os
import platform
import sys
# Local import # Local import
from realog import debug from realog import debug
from . import tools
from . import env from . import (
from . import multiprocess env,
from . import repo_config multiprocess,
repo_config,
tools,
)
env.get_island_path_config() env.get_island_path_config()
unique_config = None unique_config = None
def get_unique_config(): def get_unique_config():
global unique_config global unique_config
if unique_config == None: if unique_config == None:
unique_config = Config() unique_config = Config()
return unique_config return unique_config
class Config(): class Config:
def __init__(self): def __init__(self):
self._repo = "" self._repo = ""
self._branch = "master" self._branch = "master"
self._manifest_name = "default.xml" self._manifest_name = "default.xml"
self._volatiles = [] self._volatiles = []
self._curent_link = [] self._curent_link = []
self.load() self.load()
# set it deprecated at 2020/07
def load_old(self):
config_property = tools.file_read_data(env.get_island_path_config_old())
element_config = config_property.split("\n")
for line in element_config:
if len(line) == 0 \
or line[0] == "#":
# simple comment line ==> pass
pass
elif line[:5] == "repo=":
self._repo = line[5:]
elif line[:7] == "branch=":
self._branch = line[7:]
elif line[:5] == "file=":
self._manifest_name = line[5:]
else:
debug.warning("island config error: can not parse: '" + str(line) + "'")
return True
def convert_config_file(self):
debug.warning("INTERNAL: Convert your configuration file: " + str(env.get_island_path_config_old()) + " -> " + str(env.get_island_path_config()))
self.load_old()
self.store()
tools.remove_file(env.get_island_path_config_old())
def load(self):
# transform the old format of configuration (use json now ==> simple
if os.path.exists(env.get_island_path_config_old()) == True:
self.convert_config_file()
if os.path.exists(env.get_island_path_config()) == False:
return True
self._volatiles = []
self._curent_link = []
with open(env.get_island_path_config()) as json_file:
data = json.load(json_file)
if "repo" in data.keys():
self._repo = data["repo"]
if "branch" in data.keys():
self._branch = data["branch"]
if "manifest_name" in data.keys():
self._manifest_name = data["manifest_name"]
if "volatiles" in data.keys():
for elem in data["volatiles"]:
if "git_address" in elem.keys() and "path" in elem.keys():
self.add_volatile(elem["git_address"], elem["path"])
if "link" in data.keys():
for elem in data["link"]:
if "source" in elem.keys() and "destination" in elem.keys():
self.add_link(elem["source"], elem["destination"])
return True
return False
def store(self):
data = {}
data["repo"] = self._repo
data["branch"] = self._branch
data["manifest_name"] = self._manifest_name
data["volatiles"] = self._volatiles
data["link"] = self._curent_link
with open(env.get_island_path_config(), 'w') as outfile:
json.dump(data, outfile, indent=4)
return True
return False
def set_manifest(self, value):
self._repo = value
def get_manifest(self):
return self._repo
def set_branch(self, value):
self._branch = value
def get_branch(self):
return self._branch
def set_manifest_name(self, value):
self._manifest_name = value
def get_manifest_name(self):
return self._manifest_name
def add_volatile(self, git_adress, local_path):
for elem in self._volatiles:
if elem["path"] == local_path:
debug.error("can not have multiple local repositoty on the same PATH", crash=False)
return False
self._volatiles.append( {
"git_address": git_adress,
"path": local_path
})
return True
def get_volatile(self):
return copy.deepcopy(self._volatiles)
def get_links(self):
return self._curent_link
def add_link(self, source, destination):
for elem in self._curent_link:
if elem["destination"] == destination:
debug.error("can not have multiple destination folder in link " + destination, crash=False)
return False
self._curent_link.append( {
"source": source,
"destination": destination
})
return True
def remove_link(self, destination):
for elem in self._curent_link:
if elem["destination"] == destination:
del self._curent_link[elem]
return
debug.warning("Request remove link that does not exist")
def clear_links(self):
self._curent_link = []
def get_manifest_config(self):
conf = repo_config.RepoConfig()
base_volatile, repo_volatile = repo_config.split_repo(self.get_manifest())
conf.name = repo_volatile
conf.path = os.path.join("." + env.get_system_base_name(), "manifest") #env.get_island_path_manifest()
conf.branch = "master"
conf.volatile = False
conf.remotes = [
{
'name': 'origin',
'fetch': base_volatile,
'mirror': []
}
]
conf.select_remote = {
'name': 'origin',
'fetch': base_volatile,
'sync': False,
'mirror': []
}
return conf
# set it deprecated at 2020/07
def load_old(self):
config_property = tools.file_read_data(env.get_island_path_config_old())
element_config = config_property.split("\n")
for line in element_config:
if len(line) == 0 or line[0] == "#":
# simple comment line ==> pass
pass
elif line[:5] == "repo=":
self._repo = line[5:]
elif line[:7] == "branch=":
self._branch = line[7:]
elif line[:5] == "file=":
self._manifest_name = line[5:]
else:
debug.warning("island config error: can not parse: '" + str(line) + "'")
return True
def convert_config_file(self):
debug.warning(
"INTERNAL: Convert your configuration file: "
+ str(env.get_island_path_config_old())
+ " -> "
+ str(env.get_island_path_config())
)
self.load_old()
self.store()
tools.remove_file(env.get_island_path_config_old())
def load(self):
# transform the old format of configuration (use json now ==> simple
if os.path.exists(env.get_island_path_config_old()) == True:
self.convert_config_file()
if os.path.exists(env.get_island_path_config()) == False:
return True
self._volatiles = []
self._curent_link = []
with open(env.get_island_path_config()) as json_file:
data = json.load(json_file)
if "repo" in data.keys():
self._repo = data["repo"]
if "branch" in data.keys():
self._branch = data["branch"]
if "manifest_name" in data.keys():
self._manifest_name = data["manifest_name"]
if "volatiles" in data.keys():
for elem in data["volatiles"]:
if "git_address" in elem.keys() and "path" in elem.keys():
self.add_volatile(elem["git_address"], elem["path"])
if "link" in data.keys():
for elem in data["link"]:
if "source" in elem.keys() and "destination" in elem.keys():
self.add_link(elem["source"], elem["destination"])
return True
return False
def store(self):
data = {}
data["repo"] = self._repo
data["branch"] = self._branch
data["manifest_name"] = self._manifest_name
data["volatiles"] = self._volatiles
data["link"] = self._curent_link
with open(env.get_island_path_config(), "w") as outfile:
json.dump(data, outfile, indent=4)
return True
return False
def set_manifest(self, value):
self._repo = value
def get_manifest(self):
return self._repo
def set_branch(self, value):
self._branch = value
def get_branch(self):
return self._branch
def set_manifest_name(self, value):
self._manifest_name = value
def get_manifest_name(self):
return self._manifest_name
def add_volatile(self, git_adress, local_path):
for elem in self._volatiles:
if elem["path"] == local_path:
debug.error(
"can not have multiple local repositoty on the same PATH",
crash=False,
)
return False
self._volatiles.append({"git_address": git_adress, "path": local_path})
return True
def get_volatile(self):
return copy.deepcopy(self._volatiles)
def get_links(self):
return self._curent_link
def add_link(self, source, destination):
for elem in self._curent_link:
if elem["destination"] == destination:
debug.error(
"can not have multiple destination folder in link " + destination,
crash=False,
)
return False
self._curent_link.append({"source": source, "destination": destination})
return True
def remove_link(self, destination):
for elem in self._curent_link:
if elem["destination"] == destination:
del self._curent_link[elem]
return
debug.warning("Request remove link that does not exist")
def clear_links(self):
self._curent_link = []
def get_manifest_config(self):
conf = repo_config.RepoConfig()
base_volatile, repo_volatile = repo_config.split_repo(self.get_manifest())
conf.name = repo_volatile
conf.path = os.path.join(
"." + env.get_system_base_name(), "manifest"
) # env.get_island_path_manifest()
conf.branch = "master"
conf.volatile = False
conf.remotes = [{"name": "origin", "fetch": base_volatile, "mirror": []}]
conf.select_remote = {
"name": "origin",
"fetch": base_volatile,
"sync": False,
"mirror": [],
}
return conf

View File

@ -1,138 +1,179 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Environment management.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
import os
# Local import # Local import
from realog import debug from realog import debug
import os
system_base_name = "island" system_base_name = "island"
def set_system_base_name(val): def set_system_base_name(val):
global system_base_name global system_base_name
system_base_name = val system_base_name = val
debug.debug("Set basename: '" + str(system_base_name) + "'") debug.debug("Set basename: '" + str(system_base_name) + "'")
def get_system_base_name(): def get_system_base_name():
global system_base_name global system_base_name
return system_base_name return system_base_name
def get_system_config_name(): def get_system_config_name():
global system_base_name global system_base_name
return system_base_name + "Config.py" return system_base_name + "Config.py"
fetch_manifest = True fetch_manifest = True
def set_fetch_manifest(val): def set_fetch_manifest(val):
global fetch_manifest global fetch_manifest
fetch_manifest = val fetch_manifest = val
def get_fetch_manifest(): def get_fetch_manifest():
global fetch_manifest global fetch_manifest
return fetch_manifest return fetch_manifest
wait_between_sever_command = 0 wait_between_sever_command = 0
def set_wait_between_sever_command(val): def set_wait_between_sever_command(val):
global wait_between_sever_command global wait_between_sever_command
wait_between_sever_command = val wait_between_sever_command = val
def get_wait_between_sever_command(): def get_wait_between_sever_command():
global wait_between_sever_command global wait_between_sever_command
return wait_between_sever_command return wait_between_sever_command
filter_command = "" filter_command = ""
def set_filter_command(val): def set_filter_command(val):
global filter_command global filter_command
filter_command = val filter_command = val
def get_filter_command(): def get_filter_command():
global filter_command global filter_command
return filter_command return filter_command
def need_process_with_filter(data): def need_process_with_filter(data):
global filter_command global filter_command
if filter_command == "": if filter_command == "":
return True return True
if len(data) < len(filter_command): if len(data) < len(filter_command):
return False return False
if data[:len(filter_command)] == filter_command: if data[: len(filter_command)] == filter_command:
return True return True
return False return False
display_folder_instead_of_git_name = True display_folder_instead_of_git_name = True
def set_display_folder_instead_of_git_name(val): def set_display_folder_instead_of_git_name(val):
global display_folder_instead_of_git_name global display_folder_instead_of_git_name
display_folder_instead_of_git_name = val display_folder_instead_of_git_name = val
def get_display_folder_instead_of_git_name(): def get_display_folder_instead_of_git_name():
global display_folder_instead_of_git_name global display_folder_instead_of_git_name
return display_folder_instead_of_git_name return display_folder_instead_of_git_name
island_root_path = os.path.join(os.getcwd()) island_root_path = os.path.join(os.getcwd())
if os.path.exists(os.path.join(island_root_path, "." + get_system_base_name())) == True: if os.path.exists(os.path.join(island_root_path, "." + get_system_base_name())) == True:
# all is good ... # all is good ...
pass pass
elif os.path.exists(os.path.join(island_root_path, "..", "." + get_system_base_name())) == True: elif os.path.exists(os.path.join(island_root_path, "..", "." + get_system_base_name())):
island_root_path = os.path.join(os.getcwd(), "..") island_root_path = os.path.join(os.getcwd(), "..")
elif os.path.exists(os.path.join(island_root_path, "..", "..", "." + get_system_base_name())) == True: elif os.path.exists(
island_root_path = os.path.join(os.getcwd(), "..", "..") os.path.join(island_root_path, "..", "..", "." + get_system_base_name())
elif os.path.exists(os.path.join(island_root_path, "..", "..", "..", "." + get_system_base_name())) == True: ):
island_root_path = os.path.join(os.getcwd(), "..", "..", "..") island_root_path = os.path.join(os.getcwd(), "..", "..")
elif os.path.exists(os.path.join(island_root_path, "..", "..", "..", "..", "." + get_system_base_name())) == True: elif os.path.exists(
island_root_path = os.path.join(os.getcwd(), "..", "..", "..", "..") os.path.join(island_root_path, "..", "..", "..", "." + get_system_base_name())
elif os.path.exists(os.path.join(island_root_path, "..", "..", "..", "..", "..", "." + get_system_base_name())) == True: ):
island_root_path = os.path.join(os.getcwd(), "..", "..", "..", "..", "..") island_root_path = os.path.join(os.getcwd(), "..", "..", "..")
elif os.path.exists(os.path.join(island_root_path, "..", "..", "..", "..", "..", "..", "." + get_system_base_name())) == True: elif os.path.exists(
island_root_path = os.path.join(os.getcwd(), "..", "..", "..", "..", "..", "..") os.path.join(island_root_path, "..", "..", "..", "..", "." + get_system_base_name())
):
island_root_path = os.path.join(os.getcwd(), "..", "..", "..", "..")
elif os.path.exists(
os.path.join(
island_root_path, "..", "..", "..", "..", "..", "." + get_system_base_name()
)
):
island_root_path = os.path.join(os.getcwd(), "..", "..", "..", "..", "..")
elif os.path.exists(
os.path.join(
island_root_path,
"..",
"..",
"..",
"..",
"..",
"..",
"." + get_system_base_name(),
)
):
island_root_path = os.path.join(os.getcwd(), "..", "..", "..", "..", "..", "..")
else: else:
#debug.error("the root path of " + get_system_base_name() + " must not be upper that 6 parent path") # debug.error("the root path of " + get_system_base_name() + " must not be upper that 6 parent path")
pass pass
island_path_user_config = os.path.join(island_root_path, get_system_config_name()) island_path_user_config = os.path.join(island_root_path, get_system_config_name())
island_path = os.path.join(island_root_path, "." + get_system_base_name()) island_path = os.path.join(island_root_path, "." + get_system_base_name())
island_path_config_old = os.path.join(island_path, "config.txt") island_path_config_old = os.path.join(island_path, "config.txt")
island_path_config = os.path.join(island_path, "config.json") island_path_config = os.path.join(island_path, "config.json")
island_path_manifest = os.path.join(island_path, "manifest") island_path_manifest = os.path.join(island_path, "manifest")
## ##
## @brief to use later to know where the ".island" parent path is ... ## @brief to use later to know where the ".island" parent path is ...
## @return the parent path of the ".island" ## @return the parent path of the ".island"
## ##
def get_island_root_path(): def get_island_root_path():
global island_root_path global island_root_path
return island_root_path return island_root_path
def get_island_path(): def get_island_path():
global island_path global island_path
return island_path return island_path
def get_island_path_config(): def get_island_path_config():
global island_path_config global island_path_config
return island_path_config return island_path_config
def get_island_path_config_old(): def get_island_path_config_old():
global island_path_config_old global island_path_config_old
return island_path_config_old return island_path_config_old
def get_island_path_manifest(): def get_island_path_manifest():
global island_path_manifest global island_path_manifest
return island_path_manifest return island_path_manifest
def get_island_path_user_config(): def get_island_path_user_config():
global island_path_user_config global island_path_user_config
return island_path_user_config return island_path_user_config
ret_manifest_is_not_existing = -5 ret_manifest_is_not_existing = -5
@ -143,5 +184,3 @@ ret_action_partial_done = -13
ret_action_fail = -14 ret_action_fail = -14
ret_action_need_updtate = 15 ret_action_need_updtate = 15

View File

@ -1,26 +1,26 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Type of host detection.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
import platform import platform
import sys import sys
# Local import # Local import
from realog import debug from realog import debug
# print os.name # ==> 'posix' # print os.name # ==> 'posix'
if platform.system() == "Linux": if platform.system() == "Linux":
OS = "Linux" OS = "Linux"
elif platform.system() == "Windows": elif platform.system() == "Windows":
OS = "Windows" OS = "Windows"
elif platform.system() == "Darwin": elif platform.system() == "Darwin":
OS = "MacOs" OS = "MacOs"
else: else:
debug.error("Unknow the Host OS ... '" + platform.system() + "'") debug.error("Unknow the Host OS ... '" + platform.system() + "'")
debug.debug("host.OS = " + OS) debug.debug("host.OS = " + OS)

View File

@ -1,22 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Link interface.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
from realog import debug
from . import tools
from . import env
class LinkConfig():
def __init__(self):
self.source = ""
self.destination = ""
class LinkConfig:
def __init__(self) -> None:
self.source = ""
self.destination = ""

File diff suppressed because it is too large Load Diff

View File

@ -1,118 +1,134 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """System call Interface.
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license MPL v2.0 (see license file)
##
@author Edouard DUPIN
@copyright 2012, Edouard DUPIN, all right reserved
@license MPL v2.0 (see license file)
"""
import os
import shlex
import subprocess
import sys import sys
import threading import threading
import time import time
import sys
import os
import subprocess
import shlex
# Local import # Local import
from realog import debug from realog import debug
from . import tools
from . import env from . import env, tools
def generic_display_error(return_value, type_name, error_only=False, availlable_return=[0], display_if_nothing=True): def generic_display_error(
debug.verbose(str(return_value)) return_value,
if return_value[0] in availlable_return: type_name,
if error_only == True: error_only=False,
return availlable_return=[0],
display = False display_if_nothing=True,
if return_value[1] != "": ):
debug.info(return_value[1]) debug.verbose(str(return_value))
display = True if return_value[0] in availlable_return:
if return_value[2] != "": if error_only == True:
debug.warning(return_value[2]) return
display = True display = False
if display_if_nothing == False: if return_value[1] != "":
return debug.info(return_value[1])
if display == False: display = True
debug.verbose("GIT(" + type_name + "): All done OK") if return_value[2] != "":
else: debug.warning(return_value[2])
display = False display = True
if return_value[1] != "": if display_if_nothing == False:
debug.warning("ERROR GIT(" + type_name + ") 1:" + return_value[1]) return
display = True if display == False:
if return_value[2] != "": debug.verbose("GIT(" + type_name + "): All done OK")
debug.warning("ERROR GIT(" + type_name + ") 2:" + return_value[2]) else:
display = True display = False
if display == False: if return_value[1] != "":
debug.warning("ERROR GIT(" + type_name + "): Unknow error return_value=" + str(return_value[0])) 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): def run_command_direct_shell(cmd_line, cwd=None, shell=False):
# prepare command line: # prepare command line:
args = shlex.split(cmd_line) args = shlex.split(cmd_line)
debug.verbose("cmd = " + str(args)) debug.verbose("cmd = " + str(args))
subprocess.check_call(args, shell=shell) subprocess.check_call(args, shell=shell)
return "" return ""
## ##
## @brief Execute the command and ruturn generate data ## @brief Execute the command and ruturn generate data
## ##
def run_command_direct(cmd_line, cwd=None): def run_command_direct(cmd_line, cwd=None):
# prepare command line: # prepare command line:
args = shlex.split(cmd_line) args = shlex.split(cmd_line)
debug.verbose("cmd = " + str(args)) debug.verbose("cmd = " + str(args))
""" """
if True: if True:
subprocess.check_call(args) subprocess.check_call(args)
return "" return ""
""" """
try: try:
# create the subprocess # create the subprocess
#p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#p = subprocess.check_call(args) # p = subprocess.check_call(args)
""" """
if cwd != None: if cwd != None:
debug.info("path = " + cwd) debug.info("path = " + cwd)
""" """
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) p = subprocess.Popen(
except subprocess.CalledProcessError as e: args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd
debug.error("subprocess.CalledProcessError : " + str(args)) )
except: except subprocess.CalledProcessError as e:
debug.error("Exception on : " + str(args)) debug.error("subprocess.CalledProcessError : " + str(args))
# launch the subprocess: except:
output, err = p.communicate() debug.error("Exception on : " + str(args))
if sys.version_info >= (3, 0): # launch the subprocess:
output = output.decode("utf-8") output, err = p.communicate()
err = err.decode("utf-8") if sys.version_info >= (3, 0):
# Check errors: output = output.decode("utf-8")
if p.returncode == 0: err = err.decode("utf-8")
if output == None: # Check errors:
return err[:-1]; if p.returncode == 0:
return output[:-1]; if output == None:
else: return err[:-1]
return False return output[:-1]
else:
return False
def run_command(cmd_line, cwd=None): def run_command(cmd_line, cwd=None):
# prepare command line: # prepare command line:
args = shlex.split(cmd_line) args = shlex.split(cmd_line)
debug.verbose("cmd = " + str(args)) debug.verbose("cmd = " + str(args))
try: try:
# create the subprocess # create the subprocess
""" """
if cwd != None: if cwd != None:
debug.info("path = " + cwd) debug.info("path = " + cwd)
""" """
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) p = subprocess.Popen(
except subprocess.CalledProcessError as e: args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd
debug.error("subprocess.CalledProcessError : " + str(args)) )
except: except subprocess.CalledProcessError as e:
debug.error("Exception on : " + str(args)) debug.error("subprocess.CalledProcessError : " + str(args))
# launch the subprocess: except:
output, err = p.communicate() debug.error("Exception on : " + str(args))
if sys.version_info >= (3, 0): # launch the subprocess:
output = output.decode("utf-8") output, err = p.communicate()
err = err.decode("utf-8") if sys.version_info >= (3, 0):
# Check error : output = output.decode("utf-8")
return [p.returncode, output[:-1], err[:-1]] err = err.decode("utf-8")
# Check error :
return [p.returncode, output[:-1], err[:-1]]

View File

@ -1,51 +1,60 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Repository management.
## @author Edouard DUPIN
## @author Edouard DUPIN
## @copyright 2012, Edouard DUPIN, all right reserved @copyright 2012, Edouard DUPIN, all right reserved
## @license MPL v2.0 (see license file)
## @license MPL v2.0 (see license file) """
##
from realog import debug from realog import debug
from . import tools from . import env, tools
from . import env
class RepoConfig(): class RepoConfig:
def __init__(self): def __init__(self):
self.name = "" self.name = ""
self.path = "" self.path = ""
self.remotes = [] # list of all remotes, with the upstream elements (needed for third party integrations) self.remotes = (
self.select_remote = "" []
self.branch = "" ) # list of all remotes, with the upstream elements (needed for third party integrations)
self.tag = None self.select_remote = ""
self.volatile = False self.branch = ""
self.tag = None
self.volatile = False
def split_repo(git_repo): def split_repo(git_repo):
debug.verbose("parse git repo in RAW: " + str(git_repo)) debug.verbose("parse git repo in RAW: " + str(git_repo))
if len(git_repo) > 4 \ if len(git_repo) > 4 and git_repo[:4] == "http":
and git_repo[:4] == "http": # http://wdfqsdfqs@qsdfqsdf/qsdfqsdf/qsdfqsdf/qsdfqs.git find the 3rd '/' and cut at this point
# http://wdfqsdfqs@qsdfqsdf/qsdfqsdf/qsdfqsdf/qsdfqs.git find the 3rd '/' and cut at this point elements = git_repo.split("/")
elements = git_repo.split('/') if len(elements) < 4:
if len(elements) < 4: debug.error(
debug.error("Can not parse the git repository : '" + str(git_repo) + "' wrong format http?://xxx@xxx.xxx/****") "Can not parse the git repository : '"
base = elements[0] + "/" + elements[1] + "/" + elements[2] + str(git_repo)
repo = git_repo[len(base)+1:] + "' wrong format http?://xxx@xxx.xxx/****"
elif len(git_repo) > 3 \ )
and git_repo[:3] == "git": base = elements[0] + "/" + elements[1] + "/" + elements[2]
# git@qsdfqsdf:qsdfqsdf/qsdfqsdf/qsdfqs.git find the 1st ':' and cut at this point repo = git_repo[len(base) + 1 :]
elements = git_repo.split(':') elif len(git_repo) > 3 and git_repo[:3] == "git":
if len(elements) < 2: # git@qsdfqsdf:qsdfqsdf/qsdfqsdf/qsdfqs.git find the 1st ':' and cut at this point
debug.error("Can not parse the git repository : '" + str(git_repo) + "' wrong format git@xxx.xxx:****") elements = git_repo.split(":")
base = elements[0] if len(elements) < 2:
repo = git_repo[len(base)+1:] debug.error(
else: "Can not parse the git repository : '"
debug.error("Can not parse the git repository : '" + str(git_repo) + "' does not start with ['http', 'git']") + str(git_repo)
debug.verbose(" base: " + str(base)) + "' wrong format git@xxx.xxx:****"
debug.verbose(" repo: " + str(repo)) )
return (base, repo) base = elements[0]
repo = git_repo[len(base) + 1 :]
else:
debug.error(
"Can not parse the git repository : '"
+ str(git_repo)
+ "' does not start with ['http', 'git']"
)
debug.verbose(" base: " + str(base))
debug.verbose(" repo: " + str(repo))
return (base, repo)

View File

@ -1,111 +1,117 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## """Toolbox.
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license MPL v2.0 (see license file)
##
@author Edouard DUPIN
@copyright 2012, Edouard DUPIN, all right reserved
@license MPL v2.0 (see license file)
"""
import fnmatch
import os import os
import shutil import shutil
import errno
import fnmatch
import stat
import time import time
# Local import # Local import
from realog import debug from realog import debug
from . import env from . import env
"""
"""
def get_run_path():
return os.getcwd()
""" def get_run_path() -> str:
return os.getcwd()
"""
def get_current_path(file):
return os.path.dirname(os.path.realpath(file)) def get_current_path(file) -> str:
return os.path.dirname(os.path.realpath(file))
def create_directory(path): def create_directory(path):
try: try:
os.stat(path) os.stat(path)
except: except:
os.makedirs(path) os.makedirs(path)
def create_directory_of_file(file): def create_directory_of_file(file):
path = os.path.dirname(file) path = os.path.dirname(file)
create_directory(path) create_directory(path)
def get_list_sub_path(path): def get_list_sub_path(path):
# TODO : os.listdir(path) # TODO : os.listdir(path)
for dirname, dirnames, filenames in os.walk(path): for dirname, dirnames, filenames in os.walk(path):
return dirnames return dirnames
return [] return []
def get_list_sub_files(path): def get_list_sub_files(path):
# TODO : os.listdir(path) # TODO : os.listdir(path)
for dirname, dirnames, filenames in os.walk(path): for dirname, dirnames, filenames in os.walk(path):
return filenames return filenames
return [] return []
def remove_path_and_sub_path(path): def remove_path_and_sub_path(path):
if os.path.isdir(path): if os.path.isdir(path):
debug.verbose("remove path : '" + path + "'") debug.verbose("remove path : '" + path + "'")
shutil.rmtree(path) shutil.rmtree(path)
def remove_file(path): def remove_file(path):
if os.path.isfile(path): if os.path.isfile(path):
os.remove(path) os.remove(path)
elif os.path.islink(path): elif os.path.islink(path):
os.remove(path) os.remove(path)
def file_size(path): def file_size(path):
if not os.path.isfile(path): if not os.path.isfile(path):
return 0 return 0
statinfo = os.stat(path) statinfo = os.stat(path)
return statinfo.st_size return statinfo.st_size
def file_read_data(path, binary=False): def file_read_data(path, binary=False):
if not os.path.isfile(path): if not os.path.isfile(path):
return "" return ""
if binary == True: if binary == True:
file = open(path, "rb") file = open(path, "rb")
else: else:
file = open(path, "r") file = open(path, "r")
data_file = file.read() data_file = file.read()
file.close() file.close()
return data_file return data_file
def version_to_string(version): def version_to_string(version):
version_ID = "" version_ID = ""
for id in version: for id in version:
if len(version_ID) != 0: if len(version_ID) != 0:
if type(id) == str: if type(id) == str:
version_ID += "-" version_ID += "-"
else: else:
version_ID += "." version_ID += "."
version_ID += str(id) version_ID += str(id)
return version_ID return version_ID
def version_string_to_list(version): def version_string_to_list(version):
debug.verbose("parse version string '" + version +"'") debug.verbose("parse version string '" + version + "'")
out = [] out = []
if version == "": if version == "":
return [0, 0, 0] return [0, 0, 0]
elems = version.split("-") elems = version.split("-")
if len(elems[0].split(".")) <= 1: if len(elems[0].split(".")) <= 1:
debug.error("Can not parde a version with wrong version model '" + version +"'") debug.error(
for elem in elems[0].split("."): "Can not parde a version with wrong version model '" + version + "'"
out.append(int(elem)) )
if len(elems) >= 2: for elem in elems[0].split("."):
out.append(elems[1]) out.append(int(elem))
return out if len(elems) >= 2:
out.append(elems[1])
return out
## ##
## @brief Write data in a specific path. ## @brief Write data in a specific path.
@ -115,98 +121,106 @@ def version_string_to_list(version):
## @return True Something has been copied ## @return True Something has been copied
## @return False Nothing has been copied ## @return False Nothing has been copied
## ##
def file_write_data(path, data, only_if_new=False): def file_write_data(path, data: str, only_if_new: bool = False):
if only_if_new == True: if only_if_new is True:
if os.path.exists(path) == True: if os.path.exists(path) is True:
old_data = file_read_data(path) old_data = file_read_data(path)
if old_data == data: if old_data == data:
return False return False
#real write of data: # real write of data:
create_directory_of_file(path) create_directory_of_file(path)
file = open(path, "w") file = open(path, "w")
file.write(data) file.write(data)
file.close() file.close()
return True return True
def list_to_str(list): def list_to_str(list):
if type(list) == type(str()): if type(list) == type(str()):
return list + " " return list + " "
else: else:
result = "" result = ""
# mulyiple imput in the list ... # mulyiple imput in the list ...
for elem in list: for elem in list:
result += list_to_str(elem) result += list_to_str(elem)
return result return result
def add_prefix(prefix, list):
if type(list) == type(None):
return ""
if type(list) == type(str()):
return prefix + list
else:
if len(list) == 0:
return ""
else:
result = []
for elem in list:
result.append(prefix + elem)
return result
def add_prefix(prefix,list):
if type(list) == type(None):
return ""
if type(list) == type(str()):
return prefix+list
else:
if len(list)==0:
return ''
else:
result=[]
for elem in list:
result.append(prefix+elem)
return result
def store_command(cmd_line, file): def store_command(cmd_line, file):
# write cmd line only after to prevent errors ... # write cmd line only after to prevent errors ...
if file == "" \ if file == "" or file == None:
or file == None: return
return; debug.verbose("create cmd file: " + file)
debug.verbose("create cmd file: " + file) # Create directory:
# Create directory: create_directory_of_file(file)
create_directory_of_file(file) # Store the command Line:
# Store the command Line: file2 = open(file, "w")
file2 = open(file, "w") file2.write(cmd_line)
file2.write(cmd_line) file2.flush()
file2.flush() file2.close()
file2.close()
def get_type_string(in_type): def get_type_string(in_type):
if type(in_type) == str: if type(in_type) == str:
return "string" return "string"
elif type(in_type) == list: elif type(in_type) == list:
return "list" return "list"
elif type(in_type) == dict: elif type(in_type) == dict:
return "dict" return "dict"
return "unknow" return "unknow"
## List tools: ## List tools:
def list_append_and_check(listout, newElement, order): def list_append_and_check(listout, newElement, order):
for element in listout: for element in listout:
if element==newElement: if element == newElement:
return return
listout.append(newElement) listout.append(newElement)
if order == True: if order == True:
if type(newElement) is not dict: if type(newElement) is not dict:
listout.sort() listout.sort()
def list_append_to(out_list, in_list, order=False): def list_append_to(out_list, in_list, order=False):
if type(in_list) == str: if type(in_list) == str:
list_append_and_check(out_list, in_list, order) list_append_and_check(out_list, in_list, order)
elif type(in_list) == list: elif type(in_list) == list:
# mulyiple imput in the list ... # mulyiple imput in the list ...
for elem in in_list: for elem in in_list:
list_append_and_check(out_list, elem, order) list_append_and_check(out_list, elem, order)
elif type(in_list) == dict: elif type(in_list) == dict:
list_append_and_check(out_list, in_list, order) list_append_and_check(out_list, in_list, order)
else: else:
debug.warning("can not add in list other than {list/dict/str} : " + str(type(in_list))) debug.warning(
"can not add in list other than {list/dict/str} : " + str(type(in_list))
)
def list_append_to_2(listout, module, in_list, order=False): def list_append_to_2(listout, module, in_list, order=False):
# sepcial cse of bool # sepcial cse of bool
if type(in_list) == bool: if type(in_list) == bool:
listout[module] = in_list listout[module] = in_list
return return
# add list in the Map # add list in the Map
if module not in listout: if module not in listout:
listout[module] = [] listout[module] = []
# add elements... # add elements...
list_append_to(listout[module], in_list, order) list_append_to(listout[module], in_list, order)
## ##
@ -216,36 +230,55 @@ def list_append_to_2(listout, module, in_list, order=False):
## @return (list) List of version number ## @return (list) List of version number
## ##
def get_version_from_file_or_direct(path_module, filename_or_version): def get_version_from_file_or_direct(path_module, filename_or_version):
# check case of iser set the version directly # check case of iser set the version directly
if type(filename_or_version) == list: if type(filename_or_version) == list:
return filename_or_version return filename_or_version
# this use a version file # this use a version file
file_data = file_read_data(os.path.join(path_module, filename_or_version)) file_data = file_read_data(os.path.join(path_module, filename_or_version))
if len(file_data) == 0: if len(file_data) == 0:
debug.warning("not enought data in the file version size=0 " + path_module + " / " + filename_or_version) debug.warning(
return [0,0,0] "not enought data in the file version size=0 "
lines = file_data.split("\n") + path_module
if len(lines) != 1: + " / "
debug.warning("More thatn one line in the file version ==> bas case use mode: 'XX', XX.YYY', 'XX.Y.ZZZ' or 'XX.Y-dev' : " + path_module + " / " + filename_or_version) + filename_or_version
return [0,0,0] )
line = lines[0] return [0, 0, 0]
debug.debug("Parse line: '" + line + "'") lines = file_data.split("\n")
#check if we have "-dev" if len(lines) != 1:
dev_mode = "" debug.warning(
list_tiret = line.split('-') "More thatn one line in the file version ==> bas case use mode: 'XX', XX.YYY', 'XX.Y.ZZZ' or 'XX.Y-dev' : "
if len(list_tiret) > 2: + path_module
debug.warning("more than one '-' in version file " + str(filename_or_version) + " : '" + str(list_tiret) + "' in '" + path_module + "'") + " / "
if len(list_tiret) >= 2: + filename_or_version
dev_mode = list_tiret[1] )
line = list_tiret[0] return [0, 0, 0]
out = [] line = lines[0]
list_elem = line.split('.') debug.debug("Parse line: '" + line + "'")
for elem in list_elem: # check if we have "-dev"
out.append(int(elem)) dev_mode = ""
if dev_mode != "": list_tiret = line.split("-")
out.append(dev_mode) if len(list_tiret) > 2:
debug.debug(" ==> " + str(out)) debug.warning(
return out "more than one '-' in version file "
+ str(filename_or_version)
+ " : '"
+ str(list_tiret)
+ "' in '"
+ path_module
+ "'"
)
if len(list_tiret) >= 2:
dev_mode = list_tiret[1]
line = list_tiret[0]
out = []
list_elem = line.split(".")
for elem in list_elem:
out.append(int(elem))
if dev_mode != "":
out.append(dev_mode)
debug.debug(" ==> " + str(out))
return out
## ##
## @brief Get the list of the authors frim an input list or a file ## @brief Get the list of the authors frim an input list or a file
@ -254,120 +287,133 @@ def get_version_from_file_or_direct(path_module, filename_or_version):
## @return (list) List of authors ## @return (list) List of authors
## ##
def get_maintainer_from_file_or_direct(path_module, filename_or_author): def get_maintainer_from_file_or_direct(path_module, filename_or_author):
# check case of iser set the version directly # check case of iser set the version directly
if type(filename_or_author) == list: if type(filename_or_author) == list:
return filename_or_author return filename_or_author
# this use a version file # this use a version file
file_data = file_read_data(os.path.join(path_module, filename_or_author)) file_data = file_read_data(os.path.join(path_module, filename_or_author))
if len(file_data) == 0: if len(file_data) == 0:
debug.warning("not enought data in the file author size=0 " + path_module + " / " + filename_or_author) debug.warning(
return [] "not enought data in the file author size=0 "
# One user by line and # for comment line + path_module
out = [] + " / "
for elem in file_data.split('\n'): + filename_or_author
if len(elem) == 0: )
continue return []
if elem[0] == "#": # One user by line and # for comment line
# comment ... out = []
continue for elem in file_data.split("\n"):
out.append(elem) if len(elem) == 0:
return out continue
if elem[0] == "#":
# comment ...
continue
out.append(elem)
return out
def remove_element(data, to_remove): def remove_element(data, to_remove):
base_data = [] base_data = []
for elem in data: for elem in data:
if type(elem) == list: if type(elem) == list:
for elem2 in elem: for elem2 in elem:
base_data.append(elem2) base_data.append(elem2)
else: else:
base_data.append(elem) base_data.append(elem)
base_remove = [] base_remove = []
for elem in to_remove: for elem in to_remove:
if type(elem) == list: if type(elem) == list:
for elem2 in elem: for elem2 in elem:
base_remove.append(elem2) base_remove.append(elem2)
else: else:
base_remove.append(elem) base_remove.append(elem)
out = [] out = []
for elem in base_data: for elem in base_data:
if elem not in base_remove: if elem not in base_remove:
out.append(elem) out.append(elem)
return out; return out
def get_list_base_display(id, count, elem): def get_list_base_display(id, count, elem):
if env.get_display_folder_instead_of_git_name() == False: if env.get_display_folder_instead_of_git_name() == False:
return str(id) + "/" + str(count) + " : " + str(elem.name) return str(id) + "/" + str(count) + " : " + str(elem.name)
return str(id) + "/" + str(count) + " : " + str(elem.path) return str(id) + "/" + str(count) + " : " + str(elem.path)
is_first_time_sleep = True is_first_time_sleep = True
def wait_for_server_if_needed(): def wait_for_server_if_needed():
global is_first_time_sleep global is_first_time_sleep
if is_first_time_sleep == False: if is_first_time_sleep == False:
is_first_time_sleep = True; is_first_time_sleep = True
return return
if env.get_wait_between_sever_command() != 0: if env.get_wait_between_sever_command() != 0:
debug.info("Wait for server contrition (" + str(env.get_wait_between_sever_command()) + " s)") debug.info(
time.sleep(env.get_wait_between_sever_command()) "Wait for server contrition ("
+ str(env.get_wait_between_sever_command())
+ " s)"
)
time.sleep(env.get_wait_between_sever_command())
def filter_name_and_file(root, list_files, filter): def filter_name_and_file(root, list_files, filter):
# filter elements: # filter elements:
tmp_list = fnmatch.filter(list_files, filter) tmp_list = fnmatch.filter(list_files, filter)
out = [] out = []
for elem in tmp_list: for elem in tmp_list:
if os.path.isfile(os.path.join(root, elem)) == True: if os.path.isfile(os.path.join(root, elem)) == True:
out.append(elem); out.append(elem)
return out; return out
def filter_name(list_files, filter): def filter_name(list_files, filter):
# filter elements: # filter elements:
return fnmatch.filter(list_files, filter) return fnmatch.filter(list_files, filter)
def exclude_list(list_elements, filter): def exclude_list(list_elements, filter):
out = [] out = []
for elem in list_elements: for elem in list_elements:
if elem not in filter: if elem not in filter:
out.append(elem) out.append(elem)
return out return out
def import_path_local(path, limit_sub_folder = 1, exclude_path = [], base_name = "*"):
out = [] def import_path_local(path, limit_sub_folder=1, exclude_path=[], base_name="*"):
debug.debug("island files: " + str(path) + " [START] " + str(limit_sub_folder)) out = []
if limit_sub_folder == 0: debug.debug("island files: " + str(path) + " [START] " + str(limit_sub_folder))
debug.verbose("Subparsing limitation append ...") if limit_sub_folder == 0:
return [] debug.verbose("Subparsing limitation append ...")
list_files = get_list_sub_files(path) return []
# filter elements: list_files = get_list_sub_files(path)
debug.debug("island files: " + str(path) + " : " + str(list_files)) # filter elements:
tmp_list_island_file = filter_name_and_file(path, list_files, base_name) debug.debug("island files: " + str(path) + " : " + str(list_files))
debug.debug("island files (filtered): " + str(path) + " : " + str(tmp_list_island_file)) tmp_list_island_file = filter_name_and_file(path, list_files, base_name)
# Import the module: debug.debug(
for filename in tmp_list_island_file: "island files (filtered): " + str(path) + " : " + str(tmp_list_island_file)
out.append(os.path.join(path, filename)) )
debug.debug(" Find a file : '" + str(out[-1]) + "'") # Import the module:
list_folders_full = get_list_sub_path(path) for filename in tmp_list_island_file:
list_folders = [] out.append(os.path.join(path, filename))
for elem in list_folders_full: debug.debug(" Find a file : '" + str(out[-1]) + "'")
if elem in exclude_path: list_folders_full = get_list_sub_path(path)
debug.verbose("find '" + str(elem) + "' in exclude_path=" + str(exclude_path)) list_folders = []
continue for elem in list_folders_full:
list_folders.append(os.path.join(path,elem)) if elem in exclude_path:
# check if we need to parse sub_folder debug.verbose(
if len(list_folders) != 0: "find '" + str(elem) + "' in exclude_path=" + str(exclude_path)
debug.debug(" Find a folder : " + str(list_folders)) )
for folder in list_folders: continue
tmp_out = import_path_local(folder, list_folders.append(os.path.join(path, elem))
limit_sub_folder - 1, # check if we need to parse sub_folder
exclude_path, if len(list_folders) != 0:
base_name) debug.debug(" Find a folder : " + str(list_folders))
# add all the elements: for folder in list_folders:
for elem in tmp_out: tmp_out = import_path_local(
out.append(elem) folder, limit_sub_folder - 1, exclude_path, base_name
return out )
# add all the elements:
for elem in tmp_out:
out.append(elem)
return out

View File

@ -11,57 +11,59 @@
from setuptools import setup from setuptools import setup
import os import os
def readme(): def readme():
with open('README.rst') as f: with open("README.rst") as f:
return f.read() return f.read()
def read_version_file(): def read_version_file():
if not os.path.isfile("version.txt"): if not os.path.isfile("version.txt"):
return "" return ""
file = open("version.txt", "r") file = open("version.txt", "r")
data_file = file.read() data_file = file.read()
file.close() file.close()
if len(data_file) > 4 and data_file[-4:] == "-dev": if len(data_file) > 4 and data_file[-4:] == "-dev":
data_file = data_file[:-4] data_file = data_file[:-4]
return data_file return data_file
# https://pypi.python.org/pypi?%3Aaction=list_classifiers # https://pypi.python.org/pypi?%3Aaction=list_classifiers
setup(name='island', setup(
version=read_version_file(), name="island",
description='island generic source manager (like repo in simple mode)', version=read_version_file(),
long_description=readme(), description="island generic source manager (like repo in simple mode)",
url='http://github.com/HeeroYui/island', long_description=readme(),
author='Edouard DUPIN', url="http://github.com/HeeroYui/island",
author_email='yui.heero@gmail.com', author="Edouard DUPIN",
license='MPL-2', author_email="yui.heero@gmail.com",
packages=['island', license="MPL-2",
'island/actions'], packages=["island", "island/actions"],
classifiers=[ classifiers=[
'Development Status :: 2 - Pre-Alpha', "Development Status :: 2 - Pre-Alpha",
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
'Programming Language :: Python', "Programming Language :: Python",
'Topic :: Software Development :: Build Tools' "Topic :: Software Development :: Build Tools",
], ],
keywords='source manager repo qisrc lutin', keywords="source manager repo qisrc lutin",
scripts=['bin/island'], scripts=["bin/island"],
# Does not work on MacOs # Does not work on MacOs
#data_file=[ # data_file=[
# ('/etc/bash_completion.d', ['bash-autocompletion/lutin']), # ('/etc/bash_completion.d', ['bash-autocompletion/lutin']),
#], # ],
install_requires=[ install_requires=[
'lxml', "lxml",
'realog', "realog",
'death', "death",
], ],
include_package_data = True, include_package_data=True,
zip_safe=False) zip_safe=False,
)
#To developp: sudo ./setup.py install # To developp: sudo ./setup.py install
# sudo ./setup.py develop # sudo ./setup.py develop
#TO register all in pip: use external tools: # TO register all in pip: use external tools:
# pip install twine # pip install twine
# # create the archive # # create the archive
# ./setup.py sdist # ./setup.py sdist
# twine upload dist/* # twine upload dist/*