Supoort create new package in OBS linked project 0.8
authorLin Yang <lin.a.yang@intel.com>
Fri, 24 Aug 2012 07:16:24 +0000 (15:16 +0800)
committerLin Yang <lin.a.yang@intel.com>
Tue, 28 Aug 2012 03:23:08 +0000 (11:23 +0800)
When OBS project is linked to another one, before commit code to this
OBS project, should branch corresponding package to this linked project.

common/buildservice.py
common/obspkg.py
submitobs.py
submitobs_orig.py

index bf934b9..c65c241 100644 (file)
@@ -1079,6 +1079,22 @@ class BuildService(object):
 
         return data
 
+    def getPackageRealProjectName(self, project, package):
+        """
+        getPackageRealProjectName(project, package) -> string
+
+        Get real project name in metadata of this package
+        """
+        try:
+            root = ElementTree.fromstring(self.getPackageMeta(project, package))
+            if root.attrib.has_key('project'):
+                realprj = root.attrib['project']
+        except Exception, exc:
+            print exc
+            realprj = ''
+
+        return realprj
+
     def getPackagePersons(self, project, package, role):
         """
         getPackagePersons(project, package, role) -> list
index 030a75b..2d845e5 100644 (file)
@@ -29,7 +29,7 @@ class ObsPackage(object):
     """ Wrapper class of local package dir of OBS
     """
 
-    def __init__(self, basedir, prj, pkg, dest_prj=None, dest_pkg=None, apiurl=None, oscrc=None):
+    def __init__(self, basedir, prj, pkg, apiurl=None, oscrc=None):
         """Arguments:
           basedir: the base local dir to store obs packages
           prj: obs project
@@ -56,11 +56,6 @@ class ObsPackage(object):
         self._bdir = os.path.abspath(os.path.expanduser(basedir))
         self._prj = prj
         self._pkg = pkg
-        self._dest_prj = dest_prj
-        if not dest_pkg:
-            self._dest_pkg = pkg
-        else:
-            self._dest_pkg = dest_pkg
         self._pkgpath = os.path.join(self._bdir, prj, pkg)
 
         if not os.path.exists(self._bdir):
@@ -69,16 +64,20 @@ class ObsPackage(object):
         with Workdir(self._bdir):
             shutil.rmtree(prj, ignore_errors = True)
 
-        if self.is_new_pkg():
-            if self._dest_prj and self._is_in_dest_prj():
-                # branch from target project
-                self._branch_checkout()
+        realprj = self._bs.getPackageRealProjectName(self._prj, self._pkg)
+        print 'realprj', realprj
+        if realprj:
+            if realprj == self._prj:
+                # to checkout server stuff
+                self._checkout_latest()
             else:
-                # to init new package in local dir
-                self._mkpac()
+                # branch from target project
+                print "branch package %s from %s" % (self._pkg, realprj)
+                self._bs.branchPkg(realprj, self._pkg, target_project=self._prj)
+                self._checkout_latest()
         else:
-            # to checkout server stuff
-            self._checkout_latest()
+            # to init new package in local dir
+            self._mkpac()
 
     def _mkpac(self):
         print "mkpac %s %s" % (self._prj, self._pkg)
@@ -107,22 +106,6 @@ class ObsPackage(object):
             print "%s is new package in %s" % (self._pkg, self._prj)
             return True 
 
-    def _is_in_dest_prj(self):
-        """Check whether this is new package in obs target project
-        """
-        print "%s package list:" % self._dest_prj, self._bs.getPackageList(self._dest_prj)
-        if self._pkg in self._bs.getPackageList(self._dest_prj):
-            print "%s is NOT new package in %s" % (self._pkg, self._dest_prj)
-            return True
-        else:
-            print "%s is new package in %s" % (self._pkg, self._dest_prj)
-            return False
-
-    def _branch_checkout(self):
-        print "branch package %s from %s" % (self._pkg, self._dest_prj)
-        self._bs.branchPkg(self._dest_prj, self._dest_pkg, target_project=self._prj)
-        self._checkout_latest()
-
     def get_workdir(self):
         return self._pkgpath
 
index 63d0e78..96310e6 100755 (executable)
@@ -234,13 +234,13 @@ if __name__ == '__main__':
         tarballdir = os.path.join(outdir, os.listdir(outdir)[0])
 
         if obs_stg_prj != obs_dst_prj:
-            tmppkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, 'tmp', dest_prj = obs_dst_prj,
+            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)
-        localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name, dest_prj = obs_dst_prj,
+        localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name,
                                      apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
         oscworkdir = localpkg.get_workdir()
         localpkg.remove_all()
index 00d8978..5e8d7cf 100755 (executable)
@@ -207,14 +207,14 @@ if __name__ == '__main__':
 
         if obs_stg_prj != obs_dst_prj:
             print "check whether tmp package exist in build project"
-            tmppkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, 'tmp', dest_prj = obs_dst_prj,
+            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, dest_prj = obs_dst_prj,
+        localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name,
                                      apiurl = OBS_API_URL, oscrc = OBS_OSCRC_PATH)
         oscworkdir = localpkg.get_workdir()
         localpkg.remove_all()