]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blobdiff - modules/ftptree.py
- do not break when pkg name has '+' or '.' signs in it
[projects/pld-ftp-admin.git] / modules / ftptree.py
index d453b6ec906b0e29bf351ae173f978008a477ecc..6fdc1b40040639926c475fd8fe905ecbc269cd05 100644 (file)
@@ -1,14 +1,16 @@
 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
 
-import sys, os, config, string, urllib, re
+import os, config, string, urllib, re
 from common import fileexists, noarchcachedir
 from baseftptree import BasePkg, BaseFtpTree
 errnum=0
 
+SomeError="Oh no"
+
 def bailoutonerror():
     if not errnum == 0:
         print "%d error(s) encountered... aborting" % errnum
-        sys.exit(1)
+        raise SomeError
 
 def pinfo(msg):
     print msg
@@ -16,7 +18,10 @@ def pinfo(msg):
 def perror(msg):
     global errnum
     errnum=errnum+1
-    print msg
+    print 'ERR: ' + msg
+
+def pwarning(msg):
+    print 'WARN: ' + msg
 
 def rm(file):
     os.remove(file)
@@ -104,6 +109,8 @@ class FtpTree(BaseFtpTree):
         if loadall:
             for pkgname in self.pkgnames:
                 self.loadedpkgs[pkgname]=Pkg(pkgname, self)
+        # Tests:
+        self.do_checkbuild=True
 
     def __getitem__(self, key):
         if self.loadedpkgs.has_key(key):
@@ -114,11 +121,13 @@ class FtpTree(BaseFtpTree):
             return pkg
         else:
             raise KeyError, key
+
     def has_key(self, key):
         if key in self.pkgnames:
             return True
         else:
             return False
+
     def keys(self):
         return self.pkgnames
 
@@ -127,7 +136,8 @@ class FtpTree(BaseFtpTree):
         self.__checkarchs(dsttree)
 
     def movepkgs(self, dsttree):
-        self.__checkbuild()
+        if self.do_checkbuild:
+            self.__checkbuild()
         bailoutonerror()
         self.__checkarchs(dsttree)
         bailoutonerror()
@@ -173,7 +183,7 @@ class FtpTree(BaseFtpTree):
                     self.loadedpkgs[pkgname]=Pkg(pkgname, self)
                 markfunction(self.loadedpkgs[pkgname])
             else:
-                perror(pkgname+" was not found in source tree")
+                perror('%s not found in source tree' % pkgname)
         bailoutonerror()
 
     def __checkbuild(self):
@@ -192,20 +202,36 @@ class FtpTree(BaseFtpTree):
         for pkg in self.marked4moving:
             for bid in pkg.build.keys():
                 if requests.has_key(bid) and not requests[bid].find('?') == -1:
-                    perror("Building of package %s (buildid %s) not finished" % (pkg,bid))
+                    perror("%s (buildid %s) building not finished" % (pkg,bid))
 
     def __checkarchs(self, dsttree):
         for pkg in self.marked4moving:
+            if len(pkg.files.keys()) <= 1:
+                perror('%s has only src.rpm built' % pkg)
+                continue
             otherpkgnames=self.__find_other_pkgs(pkg, dsttree)
-            curarchs=[]
-            missingarchs=[]
-            for somepkg in otherpkgnames:
-                curarchs.extend(Pkg(somepkg, dsttree).files.keys())
-            for arch in curarchs:
-                if arch not in pkg.files.keys():
-                    missingarchs.append(arch)
-            if missingarchs:
-                perror('Moving %s would remove archs: %s' % (pkg, missingarchs))
+            if otherpkgnames: # check if we're not removing some archs
+                curarchs=[]
+                missingarchs=[]
+                for somepkg in otherpkgnames:
+                    curarchs.extend(Pkg(somepkg, dsttree).files.keys())
+                for arch in curarchs:
+                    if arch not in pkg.files.keys():
+                        missingarchs.append(arch)
+                if missingarchs:
+                    perror('%s moving would remove archs: %s' %
+                                                            (pkg, 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:
+                    missingarchs=[]
+                    for arch in config.ftp_archs:
+                        if arch not in pkg.files.keys():
+                            missingarchs.append(arch)
+                    pwarning('%s not built for archs: %s' %
+                                                            (pkg, missingarchs))
 
     def __rmolderfromsrc(self):
         for pkg in self.marked4moving:
@@ -222,7 +248,9 @@ class FtpTree(BaseFtpTree):
     # Used more than once filter functions
 
     def __find_other_pkgs(self, pkg, tree):
-        ziewre=re.compile(string.join(pkg.name.split('-')[:-2], '-')+'-[^-]*-[^-]*$')
+        pkgname=string.join(pkg.name.split('-')[:-2], '-')
+        escapedpkgname=pkgname.replace('.', '\.').replace('+', '\+')
+        ziewre=re.compile(escapedpkgname+'-[^-]*-[^-]*$')
         def filter_other_pkgs(x):
             if ziewre.match(x) and not x == pkg.name:
                 return True
This page took 0.032922 seconds and 4 git commands to generate.