//!/usr/bin/python // -*- coding: utf-8 -*- //# //# @author Edouard DUPIN //# //# @copyright 2012, Edouard DUPIN, all right reserved //# //# @license MPL v2.0 (see license file) //# from realog import Log 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 //# //# @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) //# public void help(): return "Update all the branche to the trackin branch in local (no remote access)" //# //# @brief Add argument to the specific action //# @param[in,out] my_args (death.Arguments) Argument manager //# @param[in] section Name of the currect action //# public void add_specific_arguments(my_args, section): my_args.add("r", "reset", haveParam=false, desc="Rebase the repository instead of 'reset --hard'") //# //# @brief Execute the action required. //# //# @return error value [0 .. 50] the <0 value is reserved system ==> else, what you want. //# None : No error (return program out 0) //# -5 : Env.ret_manifest_is_not_existing : Manifest does not exit //# -10 : Env.ret_action_is_not_existing : ACTION is not existing //# -11 : Env.ret_action_executing_system_error : ACTION execution system error //# -12 : Env.ret_action_wrong_parameters : ACTION Wrong parameters //# -13 : Env.ret_action_partial_done : ACTION partially done //# public void execute(_arguments): reset_instead_of_rebase = false for elem in _arguments: if elem.getOptionName().equals("rebase": reset_instead_of_rebase = true Log.info("==> Request reset instead of rebase") else: Log.error("SYNC Wrong argument: '" + elem.getOptionName() + "' '" + elem.getArg() + "'", ret_value=Env.ret_action_wrong_parameters) // check system is OK Manifest.checkIsInit(); ConfigManifest configuration = Config.getUniqueConfig(); Log.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: Log.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 Log.warning("sync-local: Not update ==> the MANIFEST is forward the remote branch " + str(commands.get_forward(Env.get_island_path_manifest(), ret_track))) else: Log.verbose("Check behind:") is_behind = commands.is_behind(Env.get_island_path_manifest(), ret_track) if is_behind == false: // fetch the repository Log.info("sync-local: MANIFEST is up-to-date") else: if reset_instead_of_rebase == true: Log.info("sync-local: MANIFEST Reset to " + ret_track) commands.reset_hard(Env.get_island_path_manifest(), ret_track) else: Log.info("sync-local: MANIFEST Rebase to " + ret_track) commands.rebase(Env.get_island_path_manifest(), ret_track) file_source_manifest = new Path(Env.get_island_path_manifest(), configuration.get_manifest_name()) if os.path.exists(file_source_manifest) == false: Log.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() Log.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) Log.info("----------------------------------------------------------------") Log.info("sync-local: " + base_display) //Log.debug("elem : " + str(elem)) git_repo_path = new Path(Env.get_island_root_path(), elem.path) if os.path.exists(git_repo_path) == false: // The Repository does not exist ==> Nothing to do... Log.warning("sync-local: ==> Not download") count_error += 1 continue if os.path.exists(new Path(git_repo_path,".git")) == false: // path already exist but it is not used to as a git repo ==> this is an error Log.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 ... Log.verbose("Check modify:") is_modify = commands.check_repository_is_modify(git_repo_path) if is_modify == true: // fetch the repository Log.warning("sync-local: Not update ==> the repository is modified (pass through)") count_error += 1 continue Log.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) Log.debug("sync-local: check: " + select_branch + " ==> " + ret_track) Log.verbose("Check forward:") is_forward = commands.is_forward(git_repo_path, ret_track) if is_forward == true: // fetch the repository Log.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 Log.verbose("Check behind:") is_behind = commands.is_behind(git_repo_path, ret_track) if is_behind == false: // fetch the repository Log.info("sync-local: Nothing to do.") continue if reset_instead_of_rebase == true: Log.info("sync-local: Reset to " + ret_track) commands.reset_hard(git_repo_path, ret_track) else: Log.info("sync-local: Reset to " + ret_track) commands.rebase(git_repo_path, ret_track) if count_error != 0: Log.info(" ***********************************************************") Log.info(" ** local sync partial warning on " + str(count_error) + " repository") Log.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