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

Proposed by Jack N
Status: Merged
Merge reported by: mac9416
Merged at revision: not available
Proposed branch: lp:~jacseen/keryx/tr-repoopts
Merge into: lp:keryx/stable
Diff against target: 124 lines
1 file modified
doc/LocalRepo-Add.py (+65/-28)
To merge this branch: bzr merge lp:~jacseen/keryx/tr-repoopts
Reviewer Review Type Date Requested Status
mac9416 Approve
Review via email: mp+14061@code.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
=== 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 @@
1import os, os.path, shutil1# This script is based off of mac9416's QuickRepo.py script
2# with some behavioral changes made by jaseen
3#
4# Designed for use with Keryx 0.92.x
5#
6
7import sys, os, os.path, shutil
2from gzip import GzipFile8from gzip import GzipFile
39from optparse import OptionParser
4REPO_NAME = 'quick_repo'10
5repodir = os.path.join(os.getcwd(), REPO_NAME)11parser = 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>\'.')
612
7listdir = os.path.join(os.getcwd(), 'lists')13parser.add_option('-l', '--lists', dest='listdir', default='./lists', metavar='DIR', help='Dir from which the lists are to be loaded. [default: %default]')
8packdir = os.path.join(os.getcwd(), 'packages')14parser.add_option('-p', '--pkgs', dest='packdir', default='./packages', metavar='DIR', help='Dir of packages to process. [default: %default]')
9if not os.path.exists(listdir):15parser.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]')
10 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.'"16parser.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.')
11if not os.path.exists(packdir):17parser.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.')
12 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."18
13listfiles = os.listdir(listdir)19(options, args) = parser.parse_args()
14packfiles = os.listdir(packdir)20options.listdir = os.path.abspath(options.listdir)
21options.packdir = os.path.abspath(options.packdir)
22options.repodir = os.path.abspath(options.repodir)
23
24if 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)
25if 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)
26
27listfiles = os.listdir(options.listdir)
28packfiles = os.listdir(options.packdir)
29
30for i in listfiles[:]:
31 if (not i.endswith('Packages')) or (i.startswith('_')): listfiles.remove(i)
32
1533
16def stripDotCom(text):34def stripDotCom(text):
17 append = False35 append = False
@@ -39,11 +57,20 @@
39 packs.update({filename:block})57 packs.update({filename:block})
40 return packs58 return packs
4159
60def sendFile(src, dest, move):
61 if not move: # If user wanted the package copied...
62 print "Copying: " + os.path.split(pack[0])[-1] + "..." # Then copy the deb into the repo.
63 shutil.copy(src, dest)
64 else: # If user wanted package moved...
65 print "Moving: " + os.path.split(pack[0])[-1] + "..." # then move deb and delete src
66 shutil.move(src, dest)
67 return
68
42count = 069count = 0
43lists = {}70lists = {}
44for filename in listfiles:71for filename in listfiles:
45 try:72 try:
46 listfile = open(os.path.join(listdir, filename), 'rb')73 listfile = open(os.path.join(options.listdir, filename), 'rb')
47 except:74 except:
48 print "Well, that list just wouldn't load: " + filename75 print "Well, that list just wouldn't load: " + filename
49 continue76 continue
@@ -59,21 +86,30 @@
5986
60for packlist in lists.iteritems():87for packlist in lists.iteritems():
61 packlisttext = ""88 packlisttext = ""
62 dirlist = os.path.abspath(os.path.join(repodir, packlist[0]))89 dirlist = os.path.abspath(os.path.join(options.repodir, packlist[0]))
63 for pack in packlist[1].iteritems():90 for pack in packlist[1].iteritems():
64 dirpack = os.path.abspath(os.path.join(repodir, pack[0]))91 dirpack = os.path.abspath(os.path.join(options.repodir, pack[0]))
65 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...92 packname = os.path.split(pack[0])[-1]
66 packlisttext += (pack[1] + '\n\n') # Add this to the new index file,93 if packname in packfiles: # If the file from the index file is in the packages directory...
67 if not os.path.exists(os.path.dirname(dirpack)): # Then copy the deb into the repo.94 if not os.path.exists(dirpack): # If the package does not already exist in repo,
68 try:95 packlisttext += (pack[1] + '\n\n') # add the files' info to the new index file,
69 os.makedirs(os.path.dirname(dirpack)) # If the destination dir doesn't exist, create it.96 if not os.path.exists(os.path.dirname(dirpack)): # and check if directory needs to be created.
70 print "Creating dir: " + os.path.dirname(pack[0])97 try:
71 except:98 os.makedirs(os.path.dirname(dirpack)) # If the destination dir doesn't exist, create it.
72 print "Failed creating dir: " + os.path.dirname(pack[0])99 print "Creating dir: " + os.path.dirname(pack[0])
73 pass100 except:
74 print "Copying: " + os.path.split(pack[0])[-1] + "..."101 print "Failed creating dir: " + os.path.dirname(pack[0])
75 shutil.copy(os.path.join(packdir, os.path.split(pack[0])[-1]), dirpack)102 pass
76 if packlisttext != '': # Only bother with the Packages.gz file if there is a reason103 sendFile(os.path.join(options.packdir, packname), dirpack, options.move)
104 else: # Package already exists in repo
105 if options.overwrite:
106 sendFile(os.path.join(options.packdir, packname), dirpack, options.move)
107 else:
108 if options.move:
109 print 'File exists ' + packname + ', deleting...'
110 os.remove(os.path.join(options.packdir, packname))
111 packfiles.remove(packname)
112 if packlisttext != '': # Only bother with the Packages.gz file if there is a reason
77 if not os.path.exists(os.path.dirname(dirlist)): 113 if not os.path.exists(os.path.dirname(dirlist)):
78 try:114 try:
79 os.makedirs(os.path.dirname(dirlist))115 os.makedirs(os.path.dirname(dirlist))
@@ -87,3 +123,4 @@
87 gzfile.write(packlisttext)123 gzfile.write(packlisttext)
88 gzfile.close()124 gzfile.close()
89 packlistfile.close()125 packlistfile.close()
126

Subscribers

People subscribed via source and target branches

to all changes: