Merge lp://staging/~jacseen/keryx/tr-repoopts into lp://staging/keryx/stable

Proposed by Jack N
Status: Merged
Merge reported by: mac9416
Merged at revision: not available
Proposed branch: lp://staging/~jacseen/keryx/tr-repoopts
Merge into: lp://staging/keryx/stable
Diff against target: 124 lines
1 file modified
doc/LocalRepo-Add.py (+65/-28)
To merge this branch: bzr merge lp://staging/~jacseen/keryx/tr-repoopts
Reviewer Review Type Date Requested Status
mac9416 Approve
Review via email: mp+14061@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Jack N (jacseen) wrote :

optparse support for LocalRepo-Add.py
for now.:)

Revision history for this message
mac9416 (mac9416) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/LocalRepo-Add.py' (properties changed: +x to -x)
2--- doc/LocalRepo-Add.py 2009-08-05 20:27:15 +0000
3+++ doc/LocalRepo-Add.py 2009-10-28 02:25:18 +0000
4@@ -1,17 +1,35 @@
5-import os, os.path, shutil
6+# This script is based off of mac9416's QuickRepo.py script
7+# with some behavioral changes made by jaseen
8+#
9+# Designed for use with Keryx 0.92.x
10+#
11+
12+import sys, os, os.path, shutil
13 from gzip import GzipFile
14-
15-REPO_NAME = 'quick_repo'
16-repodir = os.path.join(os.getcwd(), REPO_NAME)
17-
18-listdir = os.path.join(os.getcwd(), 'lists')
19-packdir = os.path.join(os.getcwd(), 'packages')
20-if not os.path.exists(listdir):
21- 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.'"
22-if not os.path.exists(packdir):
23- 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."
24-listfiles = os.listdir(listdir)
25-packfiles = os.listdir(packdir)
26+from optparse import OptionParser
27+
28+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>\'.')
29+
30+parser.add_option('-l', '--lists', dest='listdir', default='./lists', metavar='DIR', help='Dir from which the lists are to be loaded. [default: %default]')
31+parser.add_option('-p', '--pkgs', dest='packdir', default='./packages', metavar='DIR', help='Dir of packages to process. [default: %default]')
32+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]')
33+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.')
34+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.')
35+
36+(options, args) = parser.parse_args()
37+options.listdir = os.path.abspath(options.listdir)
38+options.packdir = os.path.abspath(options.packdir)
39+options.repodir = os.path.abspath(options.repodir)
40+
41+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)
42+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)
43+
44+listfiles = os.listdir(options.listdir)
45+packfiles = os.listdir(options.packdir)
46+
47+for i in listfiles[:]:
48+ if (not i.endswith('Packages')) or (i.startswith('_')): listfiles.remove(i)
49+
50
51 def stripDotCom(text):
52 append = False
53@@ -39,11 +57,20 @@
54 packs.update({filename:block})
55 return packs
56
57+def sendFile(src, dest, move):
58+ if not move: # If user wanted the package copied...
59+ print "Copying: " + os.path.split(pack[0])[-1] + "..." # Then copy the deb into the repo.
60+ shutil.copy(src, dest)
61+ else: # If user wanted package moved...
62+ print "Moving: " + os.path.split(pack[0])[-1] + "..." # then move deb and delete src
63+ shutil.move(src, dest)
64+ return
65+
66 count = 0
67 lists = {}
68 for filename in listfiles:
69 try:
70- listfile = open(os.path.join(listdir, filename), 'rb')
71+ listfile = open(os.path.join(options.listdir, filename), 'rb')
72 except:
73 print "Well, that list just wouldn't load: " + filename
74 continue
75@@ -59,21 +86,30 @@
76
77 for packlist in lists.iteritems():
78 packlisttext = ""
79- dirlist = os.path.abspath(os.path.join(repodir, packlist[0]))
80+ dirlist = os.path.abspath(os.path.join(options.repodir, packlist[0]))
81 for pack in packlist[1].iteritems():
82- dirpack = os.path.abspath(os.path.join(repodir, pack[0]))
83- 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...
84- packlisttext += (pack[1] + '\n\n') # Add this to the new index file,
85- if not os.path.exists(os.path.dirname(dirpack)): # Then copy the deb into the repo.
86- try:
87- os.makedirs(os.path.dirname(dirpack)) # If the destination dir doesn't exist, create it.
88- print "Creating dir: " + os.path.dirname(pack[0])
89- except:
90- print "Failed creating dir: " + os.path.dirname(pack[0])
91- pass
92- print "Copying: " + os.path.split(pack[0])[-1] + "..."
93- shutil.copy(os.path.join(packdir, os.path.split(pack[0])[-1]), dirpack)
94- if packlisttext != '': # Only bother with the Packages.gz file if there is a reason
95+ dirpack = os.path.abspath(os.path.join(options.repodir, pack[0]))
96+ packname = os.path.split(pack[0])[-1]
97+ if packname in packfiles: # If the file from the index file is in the packages directory...
98+ if not os.path.exists(dirpack): # If the package does not already exist in repo,
99+ packlisttext += (pack[1] + '\n\n') # add the files' info to the new index file,
100+ if not os.path.exists(os.path.dirname(dirpack)): # and check if directory needs to be created.
101+ try:
102+ os.makedirs(os.path.dirname(dirpack)) # If the destination dir doesn't exist, create it.
103+ print "Creating dir: " + os.path.dirname(pack[0])
104+ except:
105+ print "Failed creating dir: " + os.path.dirname(pack[0])
106+ pass
107+ sendFile(os.path.join(options.packdir, packname), dirpack, options.move)
108+ else: # Package already exists in repo
109+ if options.overwrite:
110+ sendFile(os.path.join(options.packdir, packname), dirpack, options.move)
111+ else:
112+ if options.move:
113+ print 'File exists ' + packname + ', deleting...'
114+ os.remove(os.path.join(options.packdir, packname))
115+ packfiles.remove(packname)
116+ if packlisttext != '': # Only bother with the Packages.gz file if there is a reason
117 if not os.path.exists(os.path.dirname(dirlist)):
118 try:
119 os.makedirs(os.path.dirname(dirlist))
120@@ -87,3 +123,4 @@
121 gzfile.write(packlisttext)
122 gzfile.close()
123 packlistfile.close()
124+

Subscribers

People subscribed via source and target branches

to all changes: