[DEV] checkout submodule correct and basic status
This commit is contained in:
parent
d3a542a957
commit
910016f978
@ -0,0 +1,101 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
##
|
||||
## @author Edouard DUPIN
|
||||
##
|
||||
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||
##
|
||||
## @license MPL v2.0 (see license file)
|
||||
##
|
||||
|
||||
from island import debug
|
||||
from island import tools
|
||||
from island import env
|
||||
from island import multiprocess
|
||||
from island import manifest
|
||||
import os
|
||||
|
||||
|
||||
def help():
|
||||
return "plop"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def execute(arguments):
|
||||
debug.info("execute:")
|
||||
for elem in arguments:
|
||||
debug.info(" '" + str(elem.get_arg()) + "'")
|
||||
if len(arguments) != 0:
|
||||
debug.error("Sync have not parameter")
|
||||
|
||||
# check if .XXX exist (create it if needed)
|
||||
if os.path.exists(env.get_island_path()) == False \
|
||||
or os.path.exists(env.get_island_path_config()) == False \
|
||||
or os.path.exists(env.get_island_path_manifest()) == False:
|
||||
debug.error("System already init have an error: missing data: '" + str(env.get_island_path()) + "'")
|
||||
|
||||
configuration = manifest.load_config()
|
||||
|
||||
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration["file"])
|
||||
if os.path.exists(file_source_manifest) == False:
|
||||
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
|
||||
|
||||
mani = manifest.Manifest(file_source_manifest)
|
||||
|
||||
all_project = mani.get_all_configs()
|
||||
debug.info("status of: " + str(len(all_project)) + " projects")
|
||||
id_element = 0
|
||||
for elem in all_project:
|
||||
id_element += 1
|
||||
debug.verbose("status : " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name))
|
||||
#debug.debug("elem : " + str(elem))
|
||||
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
|
||||
if os.path.exists(git_repo_path) == False:
|
||||
debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t\t\t" + " (not download)")
|
||||
continue
|
||||
|
||||
# check if the repository is modify
|
||||
cmd = "git diff --quiet"
|
||||
debug.verbose("execute : " + cmd)
|
||||
ret_diff = multiprocess.run_command(cmd, cwd=git_repo_path)
|
||||
# get local branch
|
||||
cmd = "git branch"
|
||||
debug.verbose("execute : " + cmd)
|
||||
ret_branch = multiprocess.run_command(cmd, cwd=git_repo_path)
|
||||
|
||||
# get tracking branch
|
||||
cmd = "git rev-parse --abbrev-ref --symbolic-full-name @{u}"
|
||||
debug.verbose("execute : " + cmd)
|
||||
ret_track = multiprocess.run_command(cmd, cwd=git_repo_path)
|
||||
|
||||
is_modify = True
|
||||
if ret_diff[0] == 0:
|
||||
is_modify = False
|
||||
|
||||
list_branch = ret_branch[1].split('\n')
|
||||
list_branch2 = []
|
||||
select_branch = ""
|
||||
for elem_branch in list_branch:
|
||||
if elem_branch[:2] == "* ":
|
||||
list_branch2.append([elem_branch[2:], True])
|
||||
select_branch = elem_branch[2:]
|
||||
else:
|
||||
list_branch2.append([elem_branch[2:], False])
|
||||
|
||||
modify_status = " "
|
||||
if is_modify == True:
|
||||
modify_status = " *** "
|
||||
|
||||
debug.verbose("select branch = '" + select_branch + "' is modify : " + str(is_modify) + " track: '" + str(ret_track[1]) + "'")
|
||||
|
||||
#debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + ret_track[1] + " -> " + elem.select_remote["name"] + "/" + elem.branch + ")")
|
||||
debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + ret_track[1] + ")")
|
||||
if is_modify == True:
|
||||
cmd = "git status --short"
|
||||
debug.verbose("execute : " + cmd)
|
||||
ret_diff = multiprocess.run_command(cmd, cwd=git_repo_path)
|
||||
tmp_color_red = "\033[31m"
|
||||
tmp_color_default= "\033[00m"
|
||||
debug.info(tmp_color_red + ret_diff[1] + tmp_color_default)
|
@ -66,13 +66,37 @@ def execute(arguments):
|
||||
cmd = "git clone " + elem.select_remote["fetch"] + "/" + elem.name + " --branch " + elem.branch + " --origin " + elem.select_remote["name"] + " " + git_repo_path
|
||||
debug.info("clone the repo")
|
||||
ret = multiprocess.run_command_direct(cmd)
|
||||
if ret == "":
|
||||
continue
|
||||
if ret == False:
|
||||
if ret != "" \
|
||||
and ret != False:
|
||||
# all is good, ready to get the system work corectly
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Clone repository does not work ... ")
|
||||
continue
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Clone repository does not work ... ")
|
||||
#debug.info("plop " + str(elem.select_remote.keys()))
|
||||
# check submodule if requested:
|
||||
if elem.select_remote["sync"] == True \
|
||||
and os.path.exists(os.path.join(git_repo_path, ".gitmodules")) == True:
|
||||
debug.info(" ==> update submodule")
|
||||
cmd = "git submodule init"
|
||||
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
|
||||
if ret != "" \
|
||||
and ret != False:
|
||||
# all is good, ready to get the system work corectly
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Can not init submodules ... ")
|
||||
continue
|
||||
cmd = "git submodule update"
|
||||
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
|
||||
if ret[:16] == "Submodule path '":
|
||||
#all is good ...
|
||||
debug.info(" " + ret)
|
||||
elif ret != "" \
|
||||
and ret != False:
|
||||
# all is good, ready to get the system work corectly
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Can not init submodules ... ")
|
||||
continue
|
||||
|
||||
continue
|
||||
|
||||
if os.path.exists(os.path.join(git_repo_path,".git")) == False:
|
||||
@ -123,4 +147,36 @@ def execute(arguments):
|
||||
continue
|
||||
|
||||
debug.info("select branch = '" + select_branch + "' is modify : " + str(is_modify) + " track: '" + str(ret_track[1]) + "'")
|
||||
|
||||
# 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")
|
||||
cmd = "git submodule sync"
|
||||
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
|
||||
if ret != "" \
|
||||
and ret != False:
|
||||
# all is good, ready to get the system work corectly
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Can not sync submodules ... ")
|
||||
continue
|
||||
"""
|
||||
cmd = "git submodule init"
|
||||
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
|
||||
if ret != "" \
|
||||
and ret != False:
|
||||
# all is good, ready to get the system work corectly
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Can not init submodules ... ")
|
||||
continue
|
||||
cmd = "git submodule update"
|
||||
ret = multiprocess.run_command_direct(cmd, cwd=git_repo_path)
|
||||
if ret[:16] == "Submodule path '":
|
||||
#all is good ...
|
||||
debug.info(" " + ret)
|
||||
elif ret != "" \
|
||||
and ret != False:
|
||||
# all is good, ready to get the system work corectly
|
||||
debug.info("'" + ret + "'")
|
||||
debug.error("Can not init submodules ... ")
|
||||
continue
|
||||
"""
|
@ -83,6 +83,10 @@ class Manifest():
|
||||
name = child.attrib[attr]
|
||||
elif attr == "fetch":
|
||||
fetch = child.attrib[attr]
|
||||
while len(fetch) > 1 \
|
||||
and ( fetch[-1] == "\\" \
|
||||
or fetch[-1] == "/") :
|
||||
fetch = fetch[:-1]
|
||||
else:
|
||||
debug.error("(l:" + str(child.sourceline) + ") Parsing the manifest : Unknow '" + child.tag + "' attibute : '" + attr + "', availlable:[name,fetch]")
|
||||
debug.debug("(l:" + str(child.sourceline) + ") find '" + child.tag + "' : name='" + name + "' fetch='" + fetch + "'");
|
||||
@ -118,7 +122,7 @@ class Manifest():
|
||||
remote = child.attrib[attr]
|
||||
elif attr == "revision":
|
||||
revision = child.attrib[attr]
|
||||
elif attr == "sync-s":
|
||||
elif attr == "sync-s": # synchronize submodule ... automaticaly
|
||||
sync = child.attrib[attr]
|
||||
if sync.lower() == "true" \
|
||||
or sync == "1" \
|
||||
@ -218,8 +222,12 @@ class Manifest():
|
||||
debug.debug(" remotes count: " + str(len(conf.remotes)))
|
||||
for remote in conf.remotes:
|
||||
debug.debug(" Ckeck remote : " + remote["name"] + " == " + default["remote"])
|
||||
debug.verbose(" remote=" + str(remote))
|
||||
debug.verbose(" default=" + str(default))
|
||||
if remote["name"] == default["remote"]:
|
||||
conf.select_remote = remote
|
||||
conf.select_remote = copy.deepcopy(remote)
|
||||
# copy the submodule synchronisation
|
||||
conf.select_remote["sync"] = default["sync"]
|
||||
break
|
||||
if conf.select_remote == None:
|
||||
debug.error("missing remote for project: " + str(conf.name))
|
||||
|
2
setup.py
2
setup.py
@ -16,7 +16,7 @@ def readme():
|
||||
|
||||
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
|
||||
setup(name='island',
|
||||
version='0.1.0',
|
||||
version='0.2.0',
|
||||
description='island generic source manager (like repo in simple mode)',
|
||||
long_description=readme(),
|
||||
url='http://github.com/HeeroYui/island',
|
||||
|
Loading…
x
Reference in New Issue
Block a user