← Back to team overview

keryx team mailing list archive

[Merge] lp:~jacseen/keryx/tr-repoopts into lp:keryx

 

Jack N has proposed merging lp:~jacseen/keryx/tr-repoopts into lp:keryx.

    Requested reviews:
    Keryx Admins (keryx-admins)


optparse support for LocalRepo-Add.py
for now.:)
-- 
https://code.launchpad.net/~jacseen/keryx/tr-repoopts/+merge/14061
Your team Keryx Development Team is subscribed to branch lp:keryx.
=== modified file 'doc/LocalRepo-Add.py' (properties changed: +x to -x)
--- doc/LocalRepo-Add.py	2009-08-05 20:27:15 +0000
+++ doc/LocalRepo-Add.py	2009-10-28 02:25:18 +0000
@@ -1,17 +1,35 @@
-import os, os.path, shutil
+# This script is based off of mac9416's QuickRepo.py script
+# with some behavioral changes made by jaseen
+#
+# Designed for use with Keryx 0.92.x
+#
+
+import sys, os, os.path, shutil
 from gzip import GzipFile
-
-REPO_NAME = 'quick_repo'
-repodir = os.path.join(os.getcwd(), REPO_NAME)
-
-listdir   = os.path.join(os.getcwd(), 'lists')
-packdir   = os.path.join(os.getcwd(), 'packages')
-if not os.path.exists(listdir):
-    print "There is somethin' wrong with you, son! You don't even have a ./lists directory. Make sure that you are running this script from within an APT-type Keryx project.'"
-if not os.path.exists(packdir):
-    print "What's this?! I can't find a ./packages directory. Make sure that you are running this script from within an APT-type Keryx project."
-listfiles = os.listdir(listdir)
-packfiles = os.listdir(packdir)
+from optparse import OptionParser
+
+parser = OptionParser(description='%prog uses a set of package lists to assemble a debian repository structure from a pile of packages. Designed for use with Keryx inside \'projects/<projectname>\'.')
+
+parser.add_option('-l', '--lists', dest='listdir', default='./lists', metavar='DIR', help='Dir from which the lists are to be loaded. [default: %default]')
+parser.add_option('-p', '--pkgs', dest='packdir', default='./packages', metavar='DIR', help='Dir of packages to process. [default: %default]')
+parser.add_option('-r', '--repo', dest='repodir', default='./quick_repo', metavar='DIR', help='Dir for the repo. Will be added to if it exists, created if not. [default: %default]')
+parser.add_option('-m', action='store_true', dest='move', default=False, help='Move the packages to the repo. Always deletes source deb, even if not \'-o\'. Default is to copy packages.')
+parser.add_option('-o', action='store_true', dest='overwrite', default=False, help='If packages already exist in repo, they will overwritten. Default is to leave packages untouched.')
+
+(options, args) = parser.parse_args()
+options.listdir = os.path.abspath(options.listdir)
+options.packdir = os.path.abspath(options.packdir)
+options.repodir = os.path.abspath(options.repodir)
+
+if not os.path.isdir(options.listdir): parser.error('There is somethin\' wrong with you, son! You don\'t even have a %s directory. Make sure that you are running this script from within an APT-type Keryx project.' % options.listdir)
+if not os.path.isdir(options.packdir): parser.error('What\'s this?! I can\'t find the %s directory. Try running this script from within an APT-type Keryx project.' % options.packdir)
+
+listfiles = os.listdir(options.listdir)
+packfiles = os.listdir(options.packdir)
+
+for i in listfiles[:]:
+    if (not i.endswith('Packages')) or (i.startswith('_')): listfiles.remove(i)
+
 
 def stripDotCom(text):
     append = False
@@ -39,11 +57,20 @@
             packs.update({filename:block})
     return packs
 
+def sendFile(src, dest, move):
+    if not move:                                                            # If user wanted the package copied...
+        print "Copying: " + os.path.split(pack[0])[-1] + "..."              # Then copy the deb into the repo.
+        shutil.copy(src, dest)
+    else:                                                                   # If user wanted package moved...
+        print "Moving: " + os.path.split(pack[0])[-1] + "..."               # then move deb and delete src
+        shutil.move(src, dest)
+    return
+
 count = 0
 lists = {}
 for filename in listfiles:
     try:
-        listfile = open(os.path.join(listdir, filename), 'rb')
+        listfile = open(os.path.join(options.listdir, filename), 'rb')
     except:
         print "Well, that list just wouldn't load: " + filename
         continue
@@ -59,21 +86,30 @@
 
 for packlist in lists.iteritems():
     packlisttext = ""
-    dirlist = os.path.abspath(os.path.join(repodir, packlist[0]))
+    dirlist = os.path.abspath(os.path.join(options.repodir, packlist[0]))
     for pack in packlist[1].iteritems():
-        dirpack = os.path.abspath(os.path.join(repodir, pack[0]))
-        if os.path.split(pack[0])[-1] in packfiles and not os.path.exists(dirpack): # If the file from the index file is in the packages directory but not yet in repo...
-            packlisttext += (pack[1] + '\n\n')                                      # Add this to the new index file,
-            if not os.path.exists(os.path.dirname(dirpack)):                        # Then copy the deb into the repo.
-                try:
-                    os.makedirs(os.path.dirname(dirpack))                           # If the destination dir doesn't exist, create it.
-                    print "Creating dir: " + os.path.dirname(pack[0])
-                except:
-                    print "Failed creating dir: " + os.path.dirname(pack[0])
-                    pass
-            print "Copying: " + os.path.split(pack[0])[-1] + "..."
-            shutil.copy(os.path.join(packdir, os.path.split(pack[0])[-1]), dirpack)
-    if packlisttext != '':               # Only bother with the Packages.gz file if there is a reason
+        dirpack = os.path.abspath(os.path.join(options.repodir, pack[0]))
+        packname = os.path.split(pack[0])[-1]
+        if packname in packfiles:                                               # If the file from the index file is in the packages directory...
+            if not os.path.exists(dirpack):                                     # If the package does not already exist in repo,
+                packlisttext += (pack[1] + '\n\n')                              # add the files' info to the new index file,
+                if not os.path.exists(os.path.dirname(dirpack)):                # and check if directory needs to be created.
+                    try:
+                        os.makedirs(os.path.dirname(dirpack))                   # If the destination dir doesn't exist, create it.
+                        print "Creating dir: " + os.path.dirname(pack[0])
+                    except:
+                        print "Failed creating dir: " + os.path.dirname(pack[0])
+                        pass
+                sendFile(os.path.join(options.packdir, packname), dirpack, options.move)
+            else:                                                               # Package already exists in repo
+                if options.overwrite:
+                    sendFile(os.path.join(options.packdir, packname), dirpack, options.move)
+                else:
+                    if options.move:
+                        print 'File exists ' + packname + ', deleting...'
+                        os.remove(os.path.join(options.packdir, packname))
+            packfiles.remove(packname)
+    if packlisttext != '':                                            # Only bother with the Packages.gz file if there is a reason
         if not os.path.exists(os.path.dirname(dirlist)): 
             try:
                 os.makedirs(os.path.dirname(dirlist))
@@ -87,3 +123,4 @@
         gzfile.write(packlisttext)
         gzfile.close()
         packlistfile.close()
+


Follow ups