move all submodules to common directory
authorLin Yang <lin.a.yang@intel.com>
Thu, 9 Aug 2012 08:18:13 +0000 (16:18 +0800)
committerLin Yang <lin.a.yang@intel.com>
Thu, 9 Aug 2012 08:18:13 +0000 (16:18 +0800)
15 files changed:
aiaiaicheck.py
buildcheck.py
common/buildservice.py [moved from buildservice.py with 100% similarity]
common/envparas.py
common/errors.py [moved from errors.py with 100% similarity]
common/git.py [moved from git.py with 96% similarity]
common/msger.py [moved from msger.py with 100% similarity]
common/mysql.py [moved from mysql.py with 100% similarity]
common/obspkg.py [moved from obspkg.py with 92% similarity]
common/runner.py [moved from runner.py with 100% similarity]
common/utils.py [moved from utils.py with 95% similarity]
policycheck.py
rpmlint_wapper.py [deleted file]
submitobs.py
submitobs_orig.py

index 32b8ea0..f7f407c 100755 (executable)
@@ -8,13 +8,18 @@ import os
 import tempfile
 import shutil
 
-import runner
-import utils
-import git
-from envparas import *
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common.envparas import * 
 
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+envparas = ['GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
 
 def end(rc = 0):
     shutil.rmtree(tmpdir)
@@ -33,17 +38,17 @@ if __name__ == '__main__':
     try:
         if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
             print '\nuse local repo as reference to clone'
-            if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+            if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
                 print 'use local repo as reference to clone: Failed.'
                 shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
     except Exception, ex:
         print '\nExcept occur when use reference repo to clone code'
         print ex
-    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
         end(1)
 
     mygit = git.Git(prjdir)
-    mygit.fetch('%s/%s' % (giturl, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
+    mygit.fetch('%s/%s' % (GIT_URL, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
     mygit.checkout('FETCH_HEAD')
     patch = mygit.format_patch('-n1 -o %s' % tmpdir)[0]
     basecommit = mygit.get_base_commit(GERRIT_PATCHSET_REVISION)
@@ -59,5 +64,5 @@ if __name__ == '__main__':
         if line:
             msg.append(line)
     if msg:
-        runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, 'aiaiai check result:\n- '+'\n'.join(msg)))
+        runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, 'aiaiai check result:\n- '+'\n'.join(msg)))
     end()
index 15882bf..eee5582 100755 (executable)
@@ -10,21 +10,37 @@ import tempfile
 import glob
 import shutil
 import time
-import runner
-import utils
-import git
 import gzip
-import obspkg
 
-from envparas import *
+# internal
+from common import obspkg
+from common import utils
+from common import git
+from common import runner
+from common.envparas import *
+from common import buildservice
+from common.send_mail import sendmail
 
 import gbp.rpm
 import gbp
-import buildservice
-from send_mail import sendmail
 
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+envparas = ['JENKINS_HOME',
+            'WORKSPACE',
+            'GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME',
+            'GERRIT_PROJECT',
+            'GERRIT_CHANGE_NUMBER',
+            'GERRIT_REFSPEC',
+            'GERRIT_PATCHSET_NUMBER',
+            'GERRIT_BRANCH',
+            'BUILD_NUMBER',
+            'OBS_USERNAME',
+            'OBS_API_URL',
+            'OBS_OSCRC_PATH']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
 
 def end(rc = 0):
     shutil.rmtree(tmpdir)
@@ -37,30 +53,30 @@ if __name__ == '__main__':
     prjdir = os.path.join(tmpdir, GERRIT_PROJECT)
     prjpath, prj = os.path.split(GERRIT_PROJECT)
 
-    if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
-        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+    if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
             end(1)
 
     # update local git tree from remote
     try:
         if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
             print '\nuse local repo as reference to clone'
-            if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+            if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
                 print 'use local repo as reference to clone: Failed.'
                 shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
     except Exception, ex:
         print '\nExcept occur when use reference repo to clone code'
         print ex
-    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
         end(1)
 
     mygit = git.Git(prjdir)
-    mygit.fetch('%s/%s' % (giturl, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
+    mygit.fetch('%s/%s' % (GIT_URL, GERRIT_PROJECT), GERRIT_REFSPEC, '-t')
     mygit.checkout('FETCH_HEAD')
 
     packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
 
-    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
 
     print "Project Mapping info: %s" %mapping
 
@@ -120,11 +136,11 @@ if __name__ == '__main__':
                     print 'The log file %s is deleted' %(buildlog_gz)
                     os.remove(buildlog_gz)
         if not status:
-            runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, "[BUILD CHECK RESULT] The project %s is not ready for build, please contact the build systerm administrator"))
+            runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, "[BUILD CHECK RESULT] The project %s is not ready for build, please contact the build systerm administrator"))
             end(1)
             
         print 'The project %s is deleted on OBS' %(buildcheck_project)
         bs.deleteProject(buildcheck_project)
         print msg
-        runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, msg))
+        runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, msg))
     end()
similarity index 100%
rename from buildservice.py
rename to common/buildservice.py
index 4de1362..4b8c00b 100644 (file)
@@ -11,12 +11,16 @@ def export(envargs, local_env):
     for element in envargs:
         if element in os.environ.keys():
             local_env[element]=os.getenv(element)
-            print element
+            print element, local_env[element]
         else:
             print "WARN: %s doesn't exist" %(element)
             local_env[element]=''
     return local_env
-    
+
+MAPPING_PRJ = 'scm/git-obs-mapping'
+RPMLINT_PRJ = 'scm/rpmlint-configi'
+OBS_URL = 'https://tz-testing-obs.bj.intel.com'    
+FROM_EMAIL = 'no-replay@tz-testing-jenkins.bj.intel.com'
 #envargs = [# General parameters
 #           'OBS_DEST_PROJECT',
 #           'OBS_STAGING_PROJECT',
similarity index 100%
rename from errors.py
rename to common/errors.py
similarity index 96%
rename from git.py
rename to common/git.py
index ed835e2..c7eebe0 100644 (file)
--- a/git.py
@@ -240,14 +240,18 @@ class Git:
     def get_commit_info(self, commit):
         """Given a commit name, return a dictionary of its components,
         including id, author, email, subject, and body."""
-        out = self._exec_git('log',
+        ret, outs = self._exec_git('log',
                              ['--pretty=format:%h%n%an%n%ae%n%s%n%b%n',
-                              '-n1', commit])[1].split('\n')
-        return {'id' : out[0].strip(),
-                'author' : out[1].strip(),
-                'email' : out[2].strip(),
-                'subject' : out[3].rstrip(),
-                'body' : [line.rstrip() for line in  out[4:]]}
+                              '-n1', commit])
+        if ret:
+            return None
+        else:
+            out = outs.splitlines()
+            return {'id' : out[0].strip(),
+                    'author' : out[1].strip(),
+                    'email' : out[2].strip(),
+                    'subject' : out[3].rstrip(),
+                    'body' : [line.rstrip() for line in  out[4:]]}
 
     def get_tagger(self, tag):
         ret, outs = self._exec_git('show',
similarity index 100%
rename from msger.py
rename to common/msger.py
similarity index 100%
rename from mysql.py
rename to common/mysql.py
similarity index 92%
rename from obspkg.py
rename to common/obspkg.py
index 77f889c..95c4995 100644 (file)
--- a/obspkg.py
@@ -39,7 +39,7 @@ class ObsPackage(object):
           oscrc: optional, the path of customized oscrc
                  if not specified, ~/.oscrc will be used
         """
-
+        print "Init obs package %s %s %s %s %s" % (basedir, prj, pkg, apiurl, oscrc)
         if oscrc:
             self._oscrc = oscrc
         else:
@@ -64,7 +64,7 @@ class ObsPackage(object):
         with Workdir(self._bdir):
             shutil.rmtree(prj, ignore_errors = True)
 
-        if self._bs.isNewPackage(prj, pkg):
+        if self.is_new_pkg():
             # to init new package in local dir
             self._mkpac()
         else:
@@ -72,6 +72,7 @@ class ObsPackage(object):
             self._checkout_latest()
 
     def _mkpac(self):
+        print "mkpac %s %s" % (self._prj, self._pkg)
         with Workdir(self._bdir):
             self._bs.mkPac(self._prj, self._pkg)
 
@@ -79,7 +80,7 @@ class ObsPackage(object):
     def _checkout_latest(self):
         """ checkout the 'latest' revision of package with link expanded
         """
-
+        print "checkout latest %s %s" % (self._prj, self._pkg)
         with Workdir(self._bdir):
             try:
                 self._bs.checkout(self._prj, self._pkg)
@@ -89,7 +90,13 @@ class ObsPackage(object):
     def is_new_pkg(self):
         """Check whether this is new package in obs
         """
-        return self._bs.isNewPackage(self._prj, self._pkg)
+        print "%s package list:" % self._prj, self._bs.getPackageList(self._prj)
+        if self._pkg in self._bs.getPackageList(self._prj):
+            print "%s is NOT new package in %s" % (self._pkg, self._prj)
+            return False
+        else:
+            print "%s is new package in %s" % (self._pkg, self._prj)
+            return True 
 
     def get_workdir(self):
         return self._pkgpath
similarity index 100%
rename from runner.py
rename to common/runner.py
similarity index 95%
rename from utils.py
rename to common/utils.py
index 93bf55d..f53c6db 100644 (file)
--- a/utils.py
@@ -34,9 +34,13 @@ import Filter
 import errors
 import msger
 import runner
-from envparas import *
+from envparas import export
 
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+envparas = ['GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME'] 
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
 
 class Workdir(object):
     def __init__(self, path):
@@ -192,9 +196,9 @@ def rpmlint(spec_file):
     return msg
 
 def get_gerrit_info(prj, cmitid):
-    ret, outs = runner.runtool('%s query --current-patch-set project: %s commit: %s' % (gerritcmd, prj, cmitid))
+    ret, outs = runner.runtool('%s query --current-patch-set project: %s commit: %s' % (GERRIT_CMD, prj, cmitid))
     print '\n-----------------------\nquery gerrit change info for commit %s' % cmitid
-    print '%s query --current-patch-set project: %s commit: %s' % (gerritcmd, prj, cmitid) 
+    print '%s query --current-patch-set project: %s commit: %s' % (GERRIT_CMD, prj, cmitid) 
     gerritinfo = {}
     for line in outs.splitlines():
         if line.startswith('  number: '):
index ea3b305..99a68e3 100755 (executable)
@@ -10,15 +10,27 @@ import tempfile
 import glob
 import shutil
 
-import runner
-import utils
-import git
-import obspkg
-from envparas import *
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common import obspkg
+from common.envparas import *
 import gbp.rpm
 
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+envparas = ['JENKINS_HOME',
+            'GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME',
+            'GERRIT_PROJECT',
+            'GERRIT_BRANCH',
+            'GERRIT_REFSPEC',
+            'GERRIT_PATCHSET_NUMBER',
+            'GERRIT_CHANGE_NUMBER',
+            'WORKSPACE']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
 
 def end(rc = 0):
     shutil.rmtree(tmpdir)
@@ -46,22 +58,22 @@ if __name__ == '__main__':
     prjpath, prj = os.path.split(GERRIT_PROJECT)
 
     # check whether exist git-obs-mapping.xml in local
-    if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
-        print('Update %s/git-obs-mapping.xml to local.' % mappingprj)
-        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+    if not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+        print('Update %s/git-obs-mapping.xml to local.' % MAPPING_PRJ)
+        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
             end(1)
 
     # update local git tree from remote
     try:
         if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
             print '\nuse local repo as reference to clone'
-            if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+            if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
                 print 'use local repo as reference to clone: Failed.'
                 shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
     except Exception, ex:
         print '\nExcept occur when use reference repo to clone code'
         print ex
-    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
         end(1)
 
     mygit = git.Git(prjdir)
@@ -86,7 +98,7 @@ if __name__ == '__main__':
     print('submitted to obs: %s' % needsr)
     '''
 
-    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
     print 'git-obs-mapping:', mapping
 
     obstarget = []
@@ -153,8 +165,8 @@ if __name__ == '__main__':
 
     print('\n-------------------------------\ncheck obs target result:\n%s' % checkobsmsg)
     if checkobsmsg:
-        runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkobsmsg))
+        runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkobsmsg))
     print('\n-------------------------------\ncheck specfile result:\n%s' % checkspecmsg)
     if checkspecmsg:
-        runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkspecmsg))
+        runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checkspecmsg))
     end()
diff --git a/rpmlint_wapper.py b/rpmlint_wapper.py
deleted file mode 100755 (executable)
index d09c847..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env python
-
-import sys, os
-import tempfile, locale
-
-sys.path.insert(1, '/usr/share/rpmlint')
-
-from Filter import setRawOut, printed_messages, badnessThreshold, _badness_score
-import SpecCheck
-import Config
-import Pkg
-import Filter
-
-def __print(s):
-    pass
-
-def _print(msgtype, pkg, reason, details):
-    global _badness_score
-
-    threshold = badnessThreshold()
-
-    badness = 0
-    if threshold >= 0:
-        badness = Config.badness(reason)
-        # anything with badness is an error
-        if badness:
-            msgtype = 'E'
-        # errors without badness become warnings
-        elif msgtype == 'E':
-            msgtype = 'W'
-
-    ln = ""
-    if pkg.current_linenum is not None:
-        ln = "%s:" % pkg.current_linenum
-    arch = ""
-    if pkg.arch is not None:
-        arch = ".%s" % pkg.arch
-    s = "%s%s:%s %s: %s" % (pkg.name, arch, ln, msgtype, reason)
-    if badness:
-        s = s + " (Badness: %d)" % badness
-    for d in details:
-        s = s + " %s" % d
-    else:
-        if not Config.isFiltered(s):
-            outputs.append(s)
-            printed_messages[msgtype] += 1
-            _badness_score += badness
-            if threshold >= 0:
-                _diagnostic.append(s + "\n")
-            else:
-                __print(s)
-                if Config.info:
-                    printDescriptions(reason)
-            return True
-
-    return False
-
-
-Filter._print=_print
-spec_file=sys.argv[1]
-
-# the tempfile is designed for python policycheck.py, bash script doesn't use it
-
-try:
-    execfile(os.path.expanduser('~/.config/rpmlint'))
-except IOError:
-    pass
-
-
-outputs = []
-
-pkg = Pkg.FakePkg(spec_file)
-check = SpecCheck.SpecCheck()
-check.check_spec(pkg, spec_file)
-pkg.cleanup()
-
-print "rpmlint checked %s: %d errors, %s warnings." % (spec_file, printed_messages["E"], printed_messages["W"])
-for line in outputs:
-    line = line.strip().lstrip(spec_file+':').strip()
-    if not line.startswith('W:') and not line.startswith('E:'):
-        line = 'line '+line
-    print '- '+line
index b563266..7ef7eb1 100755 (executable)
@@ -9,30 +9,54 @@ import tempfile
 import glob
 import shutil
 import re
-
-import runner
-import utils
-import git
-import obspkg
-from envparas import *
-import errors
-import mysql
-from send_mail import sendmail
+from time import sleep
+
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common import obspkg
+from common.envparas import *
+from common import errors
+from common import mysql
+from common.send_mail import sendmail
 
 import gbp.rpm
 
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+envparas = ['GERRIT_EVENT_TYPE',
+            'GERRIT_PROJECT',
+            'GERRIT_BRANCH',
+            'GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME',
+            'GERRIT_CHANGE_NUMBER',
+            'GERRIT_PATCHSET_NUMBER',
+            'GERRIT_PATCHSET_REVISION',
+            'GERRIT_OLDREV',
+            'GERRIT_NEWREV',
+            'GERRIT_REFNAME',
+            'WORKSPACE',
+            'JENKINS_HOME',
+            'OBS_API_URL',
+            'OBS_OSCRC_PATH',
+            'MYSQL_HOSTNAME',
+            'MYSQL_USERNAME',
+            'MYSQL_PASSWORD',
+            'MYSQL_DB_NAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+
 ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
         'dbstate': {'success' : 'TRIGGER_SUCCESS',
-                  'failure' : 'TRIGGER_FAILURE',
-                  'retry' : 'TRIGGER_RETRY'},
-        'dbtable': {'CHANGE_MERGED' : 'ChangeMerged_Event',
-                  'REF_UPDATED' : 'RefUpdated_Event'},
-        'dbkey': {'CHANGE_MERGED': {'changeNum' : GERRIT_CHANGE_NUMBER,
-                                  'patchsetNum' : GERRIT_PATCHSET_NUMBER},
-                'REF_UPDATED':{'oldRev' : GERRIT_OLDREV,
-                               'newRev' : GERRIT_NEWREV}},
+                    'failure' : 'TRIGGER_FAILURE',
+                    'retry' : 'TRIGGER_RETRY'},
+        'dbtable' : {'CHANGE_MERGED' : 'ChangeMerged_Event',
+                     'REF_UPDATED' : 'RefUpdated_Event'},
+        'dbkey' : {'CHANGE_MERGED' : {'changeNum' : GERRIT_CHANGE_NUMBER,
+                                      'patchsetNum' : GERRIT_PATCHSET_NUMBER},
+                  'REF_UPDATED' : {'oldRev' : GERRIT_OLDREV,
+                                   'newRev' : GERRIT_NEWREV}},
       }
 
 def end(result = 'success'):
@@ -58,31 +82,31 @@ if __name__ == '__main__':
             end('success')
 
     # check whether exist git-obs-mapping.xml in local
-    if GERRIT_PROJECT == mappingprj or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
-        print('Update %s/git-obs-mapping.xml to local.' % mappingprj)
-        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+    if GERRIT_PROJECT == MAPPING_PRJ or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+        print('Update %s/git-obs-mapping.xml to local.' % MAPPING_PRJ)
+        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
             end('retry')
-        if GERRIT_PROJECT == mappingprj:
+        if GERRIT_PROJECT == MAPPING_PRJ:
             print '\nPulled scm/git-obs-mapping change to local, exit now'
             end('success')
 
     # update local git tree from remote
     try:
-        if utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), GERRIT_PROJECT, giturl)):
+        if utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), GERRIT_PROJECT, GIT_URL)):
             if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
                 print '\nuse local repo as reference to clone'
-                if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+                if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
                     print 'use local repo as reference to clone: Failed.'
                     shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
     except Exception, ex:
         print '\nExcept occur when use reference repo to clone code'
         print ex
-    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
         end('retry')
 
     # if scm/rpmlint-config changed, update HOME/.config/rpmlint
-    print '\n', GERRIT_PROJECT, rpmlintprj
-    if GERRIT_PROJECT == rpmlintprj:
+    print '\n', GERRIT_PROJECT, RPMLINT_PRJ
+    if GERRIT_PROJECT == RPMLINT_PRJ:
         if not os.path.exists('%s/.config' % JENKINS_HOME):
             os.makedirs('%s/.config' % JENKINS_HOME)
         shutil.copy2('%s/rpmlint' % prjdir, '%s/.config/rpmlint' % JENKINS_HOME)
@@ -103,19 +127,19 @@ if __name__ == '__main__':
                 # the tagged commit has been merged on gerrit
                 if branch not in branchs:
                     title = '[Submit Request Failed]: improper tag: %s' % tag
-                    checktagmsg = 'The tag %s pushed, but it only can be used to submit commit on %s branch to OBS. Please "gbs submit" to trigger the submission.' % (tag, branch)
+                    checktagmsg = 'The tag %s pushed, but the related commit does NOT exist in %s branch. please follow the below format submit/{version}/{date.time}. Suggest to use gbs submit to trigger submission.' % (tag, branch)
                 else:
                     GERRIT_BRANCH = branch
                     print 'submit tag : %s, on branch %s'  % (tag, branch)
             else:
                 # The tagged commmit still open, abort submit this time
                 print '\nThis change is still open in gerrit, exit now'
-                title = '[Submit Request Failed]: tag: %s' % tag
+                title = '[Submit Request Pending]: tag: %s' % tag
                 checktagmsg = 'The commit tag %s attached is still under review in gerrit. After reviewer accpet this commit, it will be submitted to OBS corresponding project.' % tag
         else:
             print 'tag %s don\'t match the name format, exit now' % tag
             title = '[Submit Request Failed]: unknown tag: %s' % tag
-            checktagmsg = 'The tag %s pushed, but unknown tag format, please use "gbs submit" to trigger the submission.' % tag
+            checktagmsg = 'The tag %s pushed, but unknown tag format, please follow the below format submit/{version}/{date.time}. Suggest to use gbs submit to trigger submission.' % tag
     else:
         # Only when there is tag submit/*, it's for submit
         if GERRIT_BRANCH == 'master':
@@ -129,14 +153,7 @@ if __name__ == '__main__':
             print '\nThis change don\'t contain submit/*/* tag, exit now'
             end('success')
 
-    commitinfo = mygit.get_commit_info(tag)
     tagger = mygit.get_tagger(tag)
-    if GERRIT_EVENT_TYPE == "REF_UPDATED": 
-        gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
-        print 'gerritinfo', gerritinfo
-        if gerritinfo:
-            GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
-            GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
     if not tagger:
         print '\ntag %s is not annotated tag, exit now' % tag
         end('failure')
@@ -149,11 +166,20 @@ if __name__ == '__main__':
     packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
     print('packaging dir is %s/%s' % (prjdir, packagingdir))
 
+    if not GERRIT_PATCHSET_REVISION:
+        GERRIT_PATCHSET_REVISION = mygit.rev_parse(tag)
+    commitinfo = mygit.get_commit_info(GERRIT_PATCHSET_REVISION)
+    if GERRIT_EVENT_TYPE == "REF_UPDATED": 
+        gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
+        print 'gerritinfo', gerritinfo
+        if gerritinfo:
+            GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
+            GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
     msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag:%s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
 
     mygit.checkout(tag)
 
-    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
     print 'git-obs-mapping:', mapping
 
     for target in mapping:
@@ -175,18 +201,17 @@ if __name__ == '__main__':
 
         if not os.path.isfile(specfile):
             continue
-        # use gbp to parse specfile
         try:
+            # use gbp to parse specfile
             spec = gbp.rpm.parse_spec(specfile)
-        except GbpError, exc:
+            # use gbs export to generate tarball
+            outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
+            with utils.Workdir(prjdir):
+                runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
+        except Exception, exc:
             print('gbp parse spec failed. %s' % exc)
             end('failure')
 
-        # use gbs export to generate tarball
-        outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
-        with utils.Workdir(prjdir):
-            runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
-            print '\ngbs export --spec=%s -o %s' % (specfile, outdir)
         tarballdir = os.path.join(outdir, os.listdir(outdir)[0])
 
         if obs_stg_prj != obs_dst_prj:
@@ -218,8 +243,9 @@ if __name__ == '__main__':
                     newreq = localpkg.submit_req(obs_dst_prj, msg=msg)
                     print 'New request %s is created' % newreq
                 break
-            except errors.ObsError, exc:
+            except Exception, exc:
                 print('obs operation failed, retrying...')
+                print exc
                 sleep(1)
                 retry_count -= 1
 
@@ -231,8 +257,8 @@ if __name__ == '__main__':
         comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
 
         if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
-            print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
-            runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
+            print '%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
+            runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
         else:
             print 'GERRIT_CHANGE_NUMBER %s and GERRIT_CHANGE_NUMBER %s is empty.' % (GERRIT_CHANGE_NUMBER, GERRIT_CHANGE_NUMBER)
 
index a3596c7..272e677 100755 (executable)
@@ -9,30 +9,53 @@ import tempfile
 import glob
 import shutil
 import re
-
-import runner
-import utils
-import git
-import obspkg
-from envparas import *
-import errors
-import mysql
-from send_mail import sendmail
+from time import sleep
+
+# internal module
+from common import runner
+from common import utils
+from common import git
+from common import obspkg
+from common.envparas import *
+from common import errors
+from common import mysql
+from common.send_mail import sendmail
 
 import gbp.rpm
 
-giturl = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
-gerritcmd = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+envparas = ['GERRIT_EVENT_TYPE',
+            'GERRIT_PROJECT',
+            'GERRIT_BRANCH',
+            'GERRIT_SSHPORT',
+            'GERRIT_USERNAME',
+            'GERRIT_HOSTNAME',
+            'GERRIT_CHANGE_NUMBER',
+            'GERRIT_PATCHSET_NUMBER',
+            'GERRIT_PATCHSET_REVISION',
+            'GERRIT_OLDREV',
+            'GERRIT_NEWREV',
+            'GERRIT_REFNAME',
+            'WORKSPACE',
+            'JENKINS_HOME',
+            'OBS_API_URL',
+            'OBS_OSCRC_PATH',
+            'MYSQL_HOSTNAME',
+            'MYSQL_USERNAME',
+            'MYSQL_PASSWORD',
+            'MYSQL_DB_NAME']
+export(envparas, locals())
+GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
 ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
-        'dbstate': {'success' : 'TRIGGER_SUCCESS',
-                  'failure' : 'TRIGGER_FAILURE',
-                  'retry' : 'TRIGGER_RETRY'},
-        'dbtable': {'CHANGE_MERGED' : 'ChangeMerged_Event',
-                  'REF_UPDATED' : 'RefUpdated_Event'},
-        'dbkey': {'CHANGE_MERGED': {'changeNum' : GERRIT_CHANGE_NUMBER,
-                                  'patchsetNum' : GERRIT_PATCHSET_NUMBER},
-                'REF_UPDATED':{'oldRev' : GERRIT_OLDREV,
-                               'newRev' : GERRIT_NEWREV}},
+        'dbstate' : {'success' : 'TRIGGER_SUCCESS',
+                     'failure' : 'TRIGGER_FAILURE',
+                     'retry' : 'TRIGGER_RETRY'},
+        'dbtable' : {'CHANGE_MERGED' : 'ChangeMerged_Event',
+                     'REF_UPDATED' : 'RefUpdated_Event'},
+        'dbkey' : {'CHANGE_MERGED' : {'changeNum' : GERRIT_CHANGE_NUMBER,
+                                      'patchsetNum' : GERRIT_PATCHSET_NUMBER},
+                   'REF_UPDATED' : {'oldRev' : GERRIT_OLDREV,
+                                    'newRev' : GERRIT_NEWREV}},
       }
 
 def end(result = 'success'):
@@ -55,11 +78,11 @@ if __name__ == '__main__':
             end('success')
 
     # check whether exist git-obs-mapping.xml in local
-    if GERRIT_PROJECT == mappingprj or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj)):
-        print('Update %s/git-obs-mapping.xml to local.' % mappingprj)
-        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), mappingprj, giturl)):
+    if GERRIT_PROJECT == MAPPING_PRJ or not os.path.isfile('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ)):
+        print('Update %s/git-obs-mapping.xml to local.' % MAPPING_PRJ)
+        if not utils.retry(git.update_git_project, (os.path.join(JENKINS_HOME, 'git'), MAPPING_PRJ, GIT_URL)):
             end('retry')
-        if GERRIT_PROJECT == mappingprj:
+        if GERRIT_PROJECT == MAPPING_PRJ:
             print '\nPulled scm/git-obs-mapping change to local, exit now'
             end('success')
 
@@ -67,13 +90,13 @@ if __name__ == '__main__':
     try:
         if os.path.exists(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT)):
             print '\nuse local repo as reference to clone'
-            if runner.show('git clone %s/%s --reference %s %s' % (giturl, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+            if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
                 print 'use local repo as reference to clone: Failed.'
                 shutil.rmtree(os.path.join(JENKINS_HOME, 'git', GERRIT_PROJECT))
     except Exception, ex:
         print '\nExcept occur when use reference repo to clone code'
         print ex
-    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, giturl)):
+    if not utils.retry(git.update_git_project, (tmpdir, GERRIT_PROJECT, GIT_URL)):
         end('retry')
 
     packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
@@ -83,8 +106,8 @@ if __name__ == '__main__':
     checktagmsg = ''
     if GERRIT_EVENT_TYPE == "REF_UPDATED":
         tag = GERRIT_REFNAME[len('refs/tags/'):]
-        title = '[Submit Request Failed]: improper tag: %s' % tag
-        checktagmsg = 'The submission tag %s pushed, which will not work several weeks later. Because submission process changed, please upgrade gbs and use \'gbs submit\' to trigger the submission.' % tag
+        title = '[Submit Request Succeed]: improper tag %s in %s' % (tag, GERRIT_PROJECT)
+        checktagmsg = 'Warning: The submission tag %s pushed in %s project, please use new tag format: annotated tag submit/{version}/{date.time}. Example: submit/trunk/20120803.174859. Suggest to use gbs submit to trigger submission.' % (tag, GERRIT_PROJECT)
     else:
         needsr = False
         tag = mygit.describe('--exact-match --tags --match "build/*"', GERRIT_PATCHSET_REVISION)
@@ -101,29 +124,35 @@ if __name__ == '__main__':
         if not needsr:
             end('success')
 
-    commitinfo = mygit.get_commit_info(tag)
     tagger = mygit.get_tagger(tag)
+    if not GERRIT_PATCHSET_REVISION:
+        GERRIT_PATCHSET_REVISION = mygit.rev_parse(tag)
+    commitinfo = mygit.get_commit_info(GERRIT_PATCHSET_REVISION)
     if GERRIT_EVENT_TYPE == "REF_UPDATED":
         gerritinfo = utils.get_gerrit_info(GERRIT_PROJECT, commitinfo['id'])
         print 'gerritinfo', gerritinfo
         if gerritinfo:
             GERRIT_CHANGE_NUMBER = gerritinfo['changenum']
             GERRIT_PATCHSET_NUMBER = gerritinfo['patchsetnum']
+    
     if checktagmsg and title:
         if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
-            print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg)
-            runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg))
+            print '%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg)
+            runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, checktagmsg))
         if tagger:
             print checktagmsg
             checktagmsg = 'Hi, %s,\n\n' % tagger['author'] + checktagmsg + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!'
             sendmail(title, checktagmsg, FROM_EMAIL, tagger['email'])
         end('success')
 
-    msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag:%s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
+    if tagger:
+        msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag:%s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
+    else:
+        msg = 'Git project: %s\nTag:%s\nCommit: %s %s' % (GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'])
 
     mygit.checkout(tag)
 
-    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, mappingprj), GERRIT_PROJECT, GERRIT_BRANCH)
+    mapping = utils.parse_mapping('%s/git/%s/git-obs-mapping.xml' % (JENKINS_HOME, MAPPING_PRJ), GERRIT_PROJECT, GERRIT_BRANCH)
     print 'git-obs-mapping:', mapping
 
     for target in mapping:
@@ -145,27 +174,29 @@ if __name__ == '__main__':
 
         if not os.path.isfile(specfile):
             continue
-        # use gbp to parse specfile
         try:
+            # use gbp to parse specfile
             spec = gbp.rpm.parse_spec(specfile)
-        except GbpError, exc:
+            # use gbs export to generate tarball
+            outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
+            with utils.Workdir(prjdir):
+                runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
+        except Exception, exc:
             print('gbp parse spec failed. %s' % exc)
             end('failure')
 
-        # use gbs export to generate tarball
-        outdir = tempfile.mkdtemp(prefix=tmpdir+'/')
-        with utils.Workdir(prjdir):
-            runner.show('gbs export --spec=%s -o %s' % (specfile, outdir))
             print '\ngbs export --spec=%s -o %s' % (specfile, outdir)
         tarballdir = os.path.join(outdir, os.listdir(outdir)[0])
 
         if obs_stg_prj != obs_dst_prj:
+            print "check whether tmp package exist in build project"
             tmppkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, 'tmp',
                                        apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
             if tmppkg.is_new_pkg():
                 tmppkg.commit("Leave an empty package in this project to prevent OBS delete it automatically when all request from here are accepted.")
 
         print '\nCheckout %s/%s to local' % (obs_stg_prj, spec.name)
+        print tmpdir, obs_stg_prj, spec.name, OBS_API_URL, OBS_OSCRC_PATH
         localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name,
                                      apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
         oscworkdir = localpkg.get_workdir()
@@ -188,8 +219,9 @@ if __name__ == '__main__':
                     newreq = localpkg.submit_req(obs_dst_prj, msg=msg)
                     print 'New request %s is created' % newreq
                 break
-            except errors.ObsError, exc:
+            except Exception, exc:
                 print('obs operation failed, retrying...')
+                print exc
                 sleep(1)
                 retry_count -= 1
 
@@ -198,15 +230,19 @@ if __name__ == '__main__':
 
         # post sr info back to gerrit
         requrl = ' %s/request/show/%s' % (OBS_URL, newreq)
-        comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
+        if tagger:
+            comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, tagger['author'], tagger['email'], tagger['message'], GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
+        else:
+            comment = 'A SR (Submit Request) has been trigger to submit the commit to OBS %s project.\n- Git project: %s\n- Tag:%s\n- Commit: %s %s\n- Request URL:%s' % (obs_dst_prj, GERRIT_PROJECT, tag, commitinfo['id'], commitinfo['subject'], requrl)
 
         if GERRIT_CHANGE_NUMBER and GERRIT_CHANGE_NUMBER:
-            print '%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
-            runner.show('%s %s %s,%s --message \'"%s"\'' % (gerritcmd, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
+            print '%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment)
+            runner.show('%s %s %s,%s --message \'"%s"\'' % (GERRIT_CMD, 'review', GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER, comment))
         else:
             print 'GERRIT_CHANGE_NUMBER %s and GERRIT_CHANGE_NUMBER %s is empty.' % (GERRIT_CHANGE_NUMBER, GERRIT_CHANGE_NUMBER)
 
-        comment = 'Hi, %s,\n\n' % tagger['author'] + comment + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!' 
-        sendmail('[Submit Request]: changes to %s/%s' % (obs_dst_prj, spec.name), comment, FROM_EMAIL, tagger['email'])
+        if tagger:
+            comment = 'Hi, %s,\n\n' % tagger['author'] + comment + '\n\n----------------------------------------------------------------\nAutomatically generated by backend service.\nPlease DO NOT Reply!' 
+            sendmail('[Submit Request]: changes to %s/%s' % (obs_dst_prj, spec.name), comment, FROM_EMAIL, tagger['email'])
 
     end('success')