Use another script to update local git tree
authorLin Yang <lin.a.yang@intel.com>
Mon, 10 Dec 2012 06:18:03 +0000 (14:18 +0800)
committerLin Yang <lin.a.yang@intel.com>
Thu, 28 Feb 2013 07:23:25 +0000 (15:23 +0800)
Change-Id: Icc682744e0c4c26e17f52c32d94fc6b14fe8bc25
Signed-off-by: Lin Yang <lin.a.yang@intel.com>
job_submitobs.py
job_update_local_git.py [new file with mode: 0755]

index 75d1dfd..11fab21 100755 (executable)
@@ -296,12 +296,11 @@ def main():
 
     # update local git tree from remote
     try:
-        if utils.retry(git.update_git_project, (GIT_CACHE_DIR, GERRIT_PROJECT, GIT_URL)):
-            if os.path.exists(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT)):
-                print '\nuse local repo as reference to clone'
-                if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
-                    print 'use local repo as reference to clone: Failed.'
-                    shutil.rmtree(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT))
+        if os.path.exists(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT)):
+            print '\nuse local repo as reference to clone'
+            if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+                print 'use local repo as reference to clone: Failed.'
+                shutil.rmtree(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT))
     except Exception, ex:
         print '\nExcept occur when use reference repo to clone code'
         print ex
diff --git a/job_update_local_git.py b/job_update_local_git.py
new file mode 100755 (executable)
index 0000000..bdb4b80
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+"""This script will pull latest change to local when remote ref updated..
+"""
+
+# internal module
+from common import utils
+from common import git
+from common.envparas import export
+
+envparas = ['GERRIT_PROJECT',
+            'GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME',
+            'GIT_CACHE_DIR']
+export(envparas, locals())
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+
+if __name__ == '__main__':
+    print '---[JOB STARTED]----------------------------------------'
+
+    # update local git tree from remote
+    try:
+        if not utils.retry(git.update_git_project, (GIT_CACHE_DIR, GERRIT_PROJECT, GIT_URL)):
+            print '\nUpdate local git failed!'
+            exit(1)
+    except Exception, ex:
+        print '\nExcept occur when updating local git tree'
+        print ex
+        exit(1)