[yum-cvs] yum-utils reposync.py,1.3,1.4

Seth Vidal skvidal at linux.duke.edu
Tue Apr 11 09:06:38 UTC 2006


Update of /home/groups/yum/cvs/yum-utils
In directory login1.linux.duke.edu:/tmp/cvs-serv6865

Modified Files:
	reposync.py 
Log Message:

- make reposync create subdirs per repo in destination dir
- remove confusing --newest 'toggle' for  a simpler --all-versions option
that produces the same result


Index: reposync.py
===================================================================
RCS file: /home/groups/yum/cvs/yum-utils/reposync.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- reposync.py	7 Mar 2006 07:14:44 -0000	1.3
+++ reposync.py	11 Apr 2006 09:06:36 -0000	1.4
@@ -1,3 +1,5 @@
+#!/usr/bin/python -tt
+
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
@@ -62,7 +64,7 @@
 
 
 def parseArgs():
-    usage = "usage: %s [options] package1 [package2] [package..]" % sys.argv[0]
+    usage = "usage: %s [options]" % sys.argv[0]
     parser = OptionParser(usage=usage)
     parser.add_option("-c", "--config", default='/etc/yum.conf',
         help='config file to use (defaults to /etc/yum.conf)')
@@ -76,8 +78,8 @@
         default=os.getcwd(), help="Path to download packages to")
     parser.add_option("-u", "--urls", default=False, action="store_true", 
         help="Just list urls of what would be downloaded, don't download")
-    parser.add_option("-n", "--newest", default=True, action="store_false", 
-        help="Toggle downloading only the newest packages(defaults to newest-only)")
+    parser.add_option("--all-versions", dest='allversions', default=False, action="store_true", 
+        help="Download all versions of all packages, not just newest per-repo")
     parser.add_option("-q", "--quiet", default=False, action="store_true", 
         help="Output as little as possible")
         
@@ -130,38 +132,52 @@
         for repo in myrepos:
             repo.enable()
 
-    my.doRepoSetup()    
+    my.doRepoSetup()
     my.doSackSetup()
     
     download_list = []
     
-    if opts.newest:
-        download_list = my.pkgSack.returnNewestByNameArch()
-    else:
-        download_list = list(my.pkgSack)
-        
-    download_list.sort(sortPkgObj)
-    for pkg in download_list:
-        repo = my.repos.getRepo(pkg.repoid)
-        remote = pkg.returnSimple('relativepath')
-        local = os.path.basename(remote)
-        local = os.path.join(opts.destdir, local)
-        if (os.path.exists(local) and 
-            str(os.path.getsize(local)) == pkg.returnSimple('packagesize')):
+
+    for repo in my.repos.listEnabled():
+        local_repo_path = opts.destdir + '/' + repo.id
+            
+        reposack = ListPackageSack(my.pkgSack.returnPackages(repoid=repo.id))
+            
+        if opts.allversions:
+            download_list = list(reposack)
+        else:
+            download_list = reposack.returnNewestByNameArch()
+        
+        download_list.sort(sortPkgObj)
+        for pkg in download_list:
+            repo = my.repos.getRepo(pkg.repoid)
+            remote = pkg.returnSimple('relativepath')
+            local = os.path.basename(remote)
+            local = os.path.join(local_repo_path, local)
+            if (os.path.exists(local) and 
+                str(os.path.getsize(local)) == pkg.returnSimple('packagesize')):
+                
+                if not opts.quiet:
+                    my.errorlog(0,"%s already exists and appears to be complete" % local)
+                continue
+    
+            if opts.urls:
+                url = urljoin(repo.urls[0],remote)
+                print '%s' % url
+                continue
+    
+            # make sure the repo subdir is here before we go on.
+            if not os.path.exists(local_repo_path):
+                try:
+                    os.makedirs(local_repo_path)
+                except IOError, e:
+                    my.errorlog(0, "Could not make repo subdir: %s" % e)
+                    sys.exit(1)
             
-            if not opts.quiet:
-                my.errorlog(0,"%s already exists and appears to be complete" % local)
-            continue
-
-        if opts.urls:
-            url = urljoin(repo.urls[0],remote)
-            print '%s' % url
-            continue
-
-        # Disable cache otherwise things won't download
-        repo.cache = 0
-        my.log(2, 'Downloading %s' % os.path.basename(remote))
-        repo.get(relative=remote, local=local)
+            # Disable cache otherwise things won't download            
+            repo.cache = 0
+            my.log(2, 'Downloading %s' % os.path.basename(remote))
+            repo.get(relative=remote, local=local)
 
 
 if __name__ == "__main__":




More information about the Yum-cvs-commits mailing list