]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blobdiff - modules/ftptree.py
fix archive handling when moving packages around
[projects/pld-ftp-admin.git] / modules / ftptree.py
index 59d4ec1e9a21b2d872a127fecb902bae289770e9..e22833117410dd7631003cdef6a28d407c6712f0 100644 (file)
@@ -46,7 +46,7 @@ def mv(src, dst, test = False):
     fsrc = src
     fdst = dst + '/' + src.split('/')[-1]
     if test:
-        if not os.path.exists(src):
+        if not os.path.exists(fsrc):
             pinfo("TEST os.rename(%s, %s): source doesn't exists" % (fsrc, fdst))
         if not os.path.exists(dst):
             pinfo("TEST destination doesn't exist: %s" % dst)
@@ -90,6 +90,25 @@ class Pkg(BasePkg):
         pkg = nvr.split('-')[:-2]
         return pkg[-1] == 'debuginfo'
 
+    def is_sourcefile(self, file):
+        """
+        returns true if file is source package
+        """
+        return file[-8:] == '.src.rpm'
+
+    # returns true if package build is integer
+    def is_release(self):
+        """
+        To account Release tags with subver macros, we consider integer release
+        if it contains odd number of dots:
+
+        1 -> True
+        0.1 -> False
+        0.%{subver}.%{rel}, %{rel} = 1 -> 0.20010.1 -> True
+        0.%{subver}.%{rel}, %{rel} = 0.1 -> 0.20010.0.1 -> False
+        """
+        return self.release.count('.') % 2 == 0
+
     def mark4moving(self):
         if not self.marked4moving:
             # Only one pkg in this pool can be marked for moving
@@ -132,7 +151,7 @@ class Pkg(BasePkg):
         for arch in self.files.keys():
             for rpm in self.files[arch]:
                 f.write("file:%s:%s\n" % (arch, rpm))
-        
+
     def remove(self, test = False):
         """
         Remove package from ftp
@@ -150,7 +169,7 @@ class Pkg(BasePkg):
                         rm(noarchcachedir + rpm + '.reqlist', test)
         rm(self.tree.basedir + '/SRPMS/.metadata/' + self.nvr + '.src.rpm.info', test)
 
-    def rpmfiles(self):
+    def rpmfiles(self, debugfiles = True, sourcefiles  = True):
         """
         Return rpm files related to this package
         """
@@ -158,9 +177,14 @@ class Pkg(BasePkg):
         for arch, rpms in self.files.items():
             for nvr in rpms:
                 if self.is_debuginfo(nvr):
-                    files.append(self.tree.basedir + '/' + arch + '/debuginfo/' + nvr)
+                    if debugfiles:
+                        files.append(self.tree.basedir + '/' + arch + '/debuginfo/' + nvr)
                 else:
-                    files.append(self.tree.basedir + '/' + arch + '/RPMS/' + nvr)
+                    if self.is_sourcefile(nvr):
+                        if sourcefiles:
+                            files.append(self.tree.basedir + '/' + arch + '/RPMS/' + nvr)
+                    else:
+                        files.append(self.tree.basedir + '/' + arch + '/RPMS/' + nvr)
         return files
 
     def obsoletes(self):
@@ -172,7 +196,7 @@ class Pkg(BasePkg):
         """
         def rpmhdr(pkg):
             ts = rpm.ts()
-            ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
+            ts.setVSFlags(rpm.RPMVSF_NODSAHEADER)
             fdno = os.open(pkg, os.O_RDONLY)
             hdr = ts.hdrFromFdno(fdno)
             os.close(fdno)
@@ -180,6 +204,8 @@ class Pkg(BasePkg):
 
         obsoletes = {}
         for rpmfile in self.rpmfiles():
+            if not os.path.exists(rpmfile):
+                continue
             hdr = rpmhdr(rpmfile)
             if not hdr[rpm.RPMTAG_OBSOLETES]:
                 continue
@@ -275,12 +301,17 @@ class FtpTree(BaseFtpTree):
     def testmove(self, dsttree, archivetree = None):
         self.__checkbuild(self.marked4moving)
         self.__checkarchs(dsttree, self.marked4moving)
+        if not dsttree.treename.count("archive"):
+            self.__checkduplicates(self.marked4moving)
 
         self.__checksigns(dsttree, self.marked4moving, test = True)
         self.__checkforobsoletes(dsttree, self.marked4moving, test = True)
-        
-        self.__rmolderfromsrc(test = True)
-        self.__rmotherfromdst(dsttree, test = True, archivetree = archivetree)
+        self.__checkforrelease(dsttree, self.marked4moving, test = True)
+
+        if not self.treename.count("archive"):
+            self.__rmolderfromsrc(test = True)
+        if not dsttree.treename.count("archive"):
+            self.__rmotherfromdst(dsttree, test = True, archivetree = archivetree)
 
         for pkg in self.marked4moving:
             pkg.move(dsttree, test = True)
@@ -296,19 +327,21 @@ class FtpTree(BaseFtpTree):
         self.__checksigns(dsttree, self.marked4moving)
         bailoutonerror()
 
-        self.__rmolderfromsrc()
-        self.__rmotherfromdst(dsttree, archivetree = archivetree)
+        if not self.treename.count("archive"):
+            self.__rmolderfromsrc()
+        if not dsttree.treename.count("archive"):
+            self.__rmotherfromdst(dsttree, archivetree = archivetree)
 
         for pkg in self.marked4moving:
             pkg.move(dsttree)
 
-    def rpmfiles(self):
+    def rpmfiles(self, debugfiles = True, sourcefiles = True):
         if self.do_checkbuild:
             self.__checkbuild(self.marked4moving)
 
         files = []
         for pkg in self.marked4moving:
-            files += pkg.rpmfiles()
+            files += pkg.rpmfiles(debugfiles = debugfiles, sourcefiles = sourcefiles)
         return files
 
     def removepkgs(self):
@@ -323,9 +356,14 @@ class FtpTree(BaseFtpTree):
 
     def mark4moving(self, wannabepkgs):
         self.__mark4something(wannabepkgs, Pkg.mark4moving)
-        
 
     # Internal functions below
+    def __arch_stringify(self, list):
+        ret = []
+        dist = config.ftp_dist;
+        for arch in list:
+            ret.append(dist + '-' + arch)
+        return ' '.join(ret)
 
     def __loadpkgnames(self):
         def checkfiletype(name):
@@ -397,17 +435,35 @@ class FtpTree(BaseFtpTree):
                     if arch not in pkg.files.keys():
                         missingarchs.append(arch)
                 if missingarchs:
-                    pkg.error('moving would remove archs: %s' % missingarchs)
+                    pkg.error('moving would remove archs: %s' % self.__arch_stringify(missingarchs))
             else:
                 # warn if a package isn't built for all archs
-                if (config.separate_noarch and 'noarch' in pkg.files.keys() and len(pkg.files.keys()) == 2):
-                    continue
-                elif len(pkg.files.keys()) != len(config.ftp_archs) + 1:
+                # ftp_archs + SRPMS
+                ftp_archs_num = len(config.ftp_archs) + 1
+                if (config.separate_noarch and 'noarch' in pkg.files.keys()):
+                    # ftp_archs + SRPMS + noarch subpackages
+                    ftp_archs_num += 1
+                    # plain simple noarch package
+                    if (len(pkg.files.keys()) == 2):
+                        continue
+
+                if len(pkg.files.keys()) != ftp_archs_num:
                     missingarchs = []
                     for arch in config.ftp_archs:
                         if arch not in pkg.files.keys():
                             missingarchs.append(arch)
-                    pkg.warning('not built for archs: %s' % missingarchs)
+                    pkg.warning('not built for archs: %s' % self.__arch_stringify(missingarchs))
+
+    def __checkduplicates(self, marked):
+        """
+        Checks if marked packages contain duplicate packages (with different versions)
+        """
+        for pkg in marked:
+            olderpkgnames = self.__find_older_pkgs(pkg)
+            for i in olderpkgnames:
+                markednames = [str(x) for x in marked]
+                if i in markednames:
+                    pkg.error('duplicate package: %s' % i)
 
     def __rmolderfromsrc(self, test = False):
         for pkg in self.marked4moving:
@@ -492,4 +548,16 @@ class FtpTree(BaseFtpTree):
                 for item in setlist:
                     p = findbyname(item)
                     if p:
-                        pkg.warning('obsoletes %s in dest tree, perhaps you want rmpkg' % (p,))
+                        pkg.warning('obsoletes %s (via %s) in dest tree, perhaps you want rmpkg' % (p,pn))
+
+    def __checkforrelease(self, tree, pkgs, test = False):
+        """
+        Checks queue file if package release is non integer.
+
+        """
+        if test != True:
+            return
+
+        for pkg in pkgs:
+            if not pkg.is_release():
+                pkg.warning('non-integer release: %s' % pkg.release)
This page took 0.035167 seconds and 4 git commands to generate.