island/tmpsrc/actions/status.java

267 lines
11 KiB
Java

//!/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 os
public void deliver_check(elem, argument_remote_name, id_element, base_display, source_branch, destination_branch):
deliver_availlable = true
Log.debug("deliver-ckeck: " + base_display)
Log.debug(" ==> check repo exist")
// Check the repo exist
git_repo_path = new Path(Env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == false:
Log.warning("deliver-ckeck: " + base_display + " ==> MUST be download")
return false
Log.debug(" ==> check is modify")
// check if the curent repo is modify
is_modify = commands.check_repository_is_modify(git_repo_path)
if is_modify == true:
Log.warning("deliver-ckeck: " + base_display + " ==> MUST not be modify")
return false
Log.debug(" ==> check current branch is '" + source_branch + "'")
// check if we are on source_branch
select_branch = commands.get_current_branch(git_repo_path)
if select_branch != source_branch:
Log.warning("deliver-ckeck: " + base_display + " ==> MUST be on source branch: '" + source_branch + "' and is: '" + select_branch + "'")
return false
Log.debug(" ==> check have tracking branch")
// check if we have a remote traking branch
tracking_remote_branch = commands.get_tracking_branch(git_repo_path, argument_remote_name, select_branch)
if tracking_remote_branch == None:
Log.warning("deliver-ckeck: " + base_display + " ==> MUST have a remote tracking branch")
deliver_availlable = false
// go on destination branch
commands.checkout(git_repo_path, destination_branch)
// TODO: check return value
Log.debug(" ==> check current branch is '" + source_branch + "'")
// check if we are on "master"
select_branch = commands.get_current_branch(git_repo_path)
if select_branch != destination_branch:
Log.warning("deliver-ckeck: " + base_display + " ==> Can not checkout branch: '" + destination_branch + "' and is: '" + select_branch + "'")
deliver_availlable = false
Log.debug(" ==> check have tracking branch")
// check if we have a remote traking branch
tracking_remote_branch = commands.get_tracking_branch(git_repo_path, argument_remote_name, select_branch)
if tracking_remote_branch == None:
Log.warning("deliver-ckeck: " + base_display + " ==> MUST have a remote tracking branch")
deliver_availlable = false
"""
// check if we have a local branch
list_branch_local = commands.get_list_branch_local(git_repo_path)
if destination_branch not in list_branch_local:
Log.warning("deliver-ckeck: " + base_display + " ==> MUST have local branch named '" + destination_branch + "'")
deliver_availlable = false
// TODO: check source_branch is up to date
// TODO: check the remote branch and the local branch are the same
//sha_tracking = get_sha1_for_branch(git_repo_path, tracking_remote_branch)
//sha_current = get_sha1_for_branch(git_repo_path, select_branch)
"""
// check out back the source branch
commands.checkout(git_repo_path, source_branch)
return deliver_availlable
public void get_current_version_repo(git_repo_path):
version_path_file = new Path(git_repo_path, "version.txt")
add_in_version_management = false
version_description = None
if os.path.exists(version_path_file) == false:
Log.info("deliver: ==> No 'version.txt' file ==> not manage release version....")
// Action to do:
valid = false
while valid == false:
Log.info("Create a new version: (0.0.0)")
Log.info(" (1) Add in managing version")
Log.info(" (2) Do NOTHING & continue")
input1 = input()
if input1 in ["1", "2"]:
valid = true
else:
Log.info("!!! Must select in range " + str(["1", "2"]))
if input1.equals("1":
version_description = [0, 0, 0]
add_in_version_management = true
} else if input1.equals("2":
Log.info("Continue Not managing for this repository")
return (None, None)
else:
Log.warning("An error occured for this repository")
return (None, None)
else:
version_description = tools.version_string_to_list(tools.file_read_data(version_path_file))
return (version_description, add_in_version_management)
public void create_new_version_repo(git_repo_path, version_description, add_in_version_management, source_branch, destination_branch):
// get tracking branch
ret_destination_branch_sha1 = commands.get_revision_list_to_branch(git_repo_path, destination_branch)
ret_source_branch_sha1 = commands.get_revision_list_to_branch(git_repo_path, source_branch)
// remove all identical sha1 ==> not needed for this
have_forward = false
for elem_sha1 in ret_destination_branch_sha1:
if elem_sha1 not in ret_source_branch_sha1:
message = commands.get_specific_commit_message(git_repo_path, elem_sha1)
Log.warning("deliver: Forward commit: '" + message + "'")
have_forward = true
if have_forward == true:
Log.error("'" + destination_branch + "' branch must not be forward '" + source_branch + "' branch")
return None
behind_message = ""
behind_count = 0
for elem_sha1 in ret_source_branch_sha1:
if elem_sha1 not in ret_destination_branch_sha1:
message = commands.get_specific_commit_message(git_repo_path, elem_sha1)
behind_count += 1
behind_message = message
if behind_count == 0 and add_in_version_management == false:
Log.info("deliver: ==> Nothing to do (1).")
return None
if behind_count == 1 \
and ( behind_message == default_behind_message
or behind_message == default_update_message):
Log.info("deliver: ==> Nothing to do (2).")
return None
for elem_sha1 in ret_source_branch_sha1:
if elem_sha1 not in ret_destination_branch_sha1:
message = commands.get_specific_commit_message(git_repo_path, elem_sha1)
Log.info("deliver: Behind commit: '" + message + "'")
// Choice of the new version:
valid = false
while valid == false:
Log.info("update version: curent: " + str(version_description))
Log.info(" (1) Major version (change API)")
Log.info(" (2) Medium version (add feature)")
Log.info(" (3) Minor version (Bug fix & doc)")
Log.info(" (4) Do not release & continue")
input1 = input()
if input1 in ["1", "2", "3", "4"]:
valid = true
else:
Log.info("!!! Must select in range " + str(["1", "2", "3", "4"]))
// limit and force at 3 the nuber of variables
version_description_tmp = version_description
version_description = []
if len(version_description_tmp) >= 1:
version_description.append(version_description_tmp[0])
else:
version_description.append(0)
if len(version_description_tmp) >= 2:
version_description.append(version_description_tmp[1])
else:
version_description.append(0)
if len(version_description_tmp) >= 3:
version_description.append(version_description_tmp[2])
else:
version_description.append(0)
Log.info("update version: curent: " + str(version_description))
// increment the version
if input1.equals("1":
version_description[0] += 1
version_description[1] = 0
version_description[2] = 0
} else if input1.equals("2":
version_description[1] += 1
version_description[2] = 0
} else if input1.equals("3":
version_description[2] += 1
} else if input1.equals("4":
Log.info("No release for this repository")
return None
else:
Log.warning("An error occured for this repository")
return None
Log.info("update version: curent: " + str(version_description))
return version_description
public void deliver_push(elem, argument_remote_name, destination_branch, source_branch, base_display):
// Check the repo exist
git_repo_path = new Path(Env.get_island_root_path(), elem.path)
if os.path.exists(git_repo_path) == false:
Log.warning("deliver-push: " + base_display + " ==> MUST be download")
return
// check if we are on destination_branch
select_branch = commands.get_current_branch(git_repo_path)
if select_branch != destination_branch:
Log.warning("deliver-push: " + base_display + " ==> MUST be on '" + destination_branch + "'")
return
// check if we have a local branch
list_branch_local = commands.get_list_branch_local(git_repo_path)
if source_branch not in list_branch_local:
Log.warning("deliver-push: " + base_display + " ==> No '" + source_branch + "' (not managed)")
return
if destination_branch not in list_branch_local:
Log.warning("deliver-push: " + base_display + " ==> No '" + destination_branch + "' (not managed)")
return
list_of_element_to_push = []
// check sha1 of destination_branch
sha_1_destination = commands.get_sha1_for_branch(git_repo_path, destination_branch)
tracking_remote_branch = commands.get_tracking_branch(git_repo_path, argument_remote_name, destination_branch)
if tracking_remote_branch == None:
Log.warning("deliver-push: " + base_display + " ==> '" + destination_branch + "' have no tracking branch")
deliver_availlable = false
sha_1_destination_tracking = commands.get_sha1_for_branch(git_repo_path, tracking_remote_branch)
if sha_1_destination == sha_1_destination_tracking:
Log.info("deliver-push: " + base_display + " ==> '" + destination_branch + "' && '" + tracking_remote_branch + "' have the same sha1")
else:
list_of_element_to_push.append(destination_branch)
// check sha1 of source_branch
sha_1_source = commands.get_sha1_for_branch(git_repo_path, source_branch)
tracking_remote_branch = commands.get_tracking_branch(git_repo_path, argument_remote_name, source_branch)
if tracking_remote_branch == None:
Log.info("deliver-push: " + base_display + " ==> '" + source_branch + "' have no tracking branch")
deliver_availlable = false
sha_1_source_tracking = commands.get_sha1_for_branch(git_repo_path, tracking_remote_branch)
if sha_1_source == sha_1_source_tracking:
Log.info("deliver-push: " + base_display + " ==> '" + source_branch + "' && '" + tracking_remote_branch + "' have the same sha1")
else:
list_of_element_to_push.append(source_branch)
ret_current_tags = commands.get_tags_current(git_repo_path)
if len(ret_current_tags) == 0:
Log.info("deliver-push: " + base_display + " ==> No tag on the current '" + destination_branch + "'")
return
if len(ret_current_tags) > 1:
Log.info("deliver-push: " + base_display + " ==> Too mush tags on the current '" + destination_branch + "' : " + str(ret_current_tags) + " ==> only support 1")
return
list_remote_tags = commands.get_tags_remote(git_repo_path, argument_remote_name)
Log.verbose("remote tags: " + str(list_remote_tags))
if ret_current_tags[0] not in list_remote_tags:
Log.info("deliver-push: " + base_display + " ==> tag already exist.")
list_of_element_to_push.append(ret_current_tags[0])
if len(list_of_element_to_push) == 0:
Log.info("deliver-push: " + base_display + " ==> Everything up-to-date")
return
Log.info("deliver-push: " + base_display + " ==> element to push:" + str(list_of_element_to_push))
//push all on the server:
commands.push(git_repo_path, argument_remote_name, list_of_element_to_push)