Gentoo Archives: gentoo-commits

From: "Maurice van der Pot (griffon26)" <griffon26@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-proxy/http-replicator/files: http-replicator-3.0-repcacheman-0.44-r1 http-replicator-3.0-repcacheman-0.21
Date: Tue, 26 Aug 2008 18:33:48
Message-Id: E1KY3MP-0007u0-JV@stork.gentoo.org
1 griffon26 08/08/26 18:33:45
2
3 Added: http-replicator-3.0-repcacheman-0.44-r1
4 Removed: http-replicator-3.0-repcacheman-0.21
5 Log:
6 Fixed deprecation warnings in repcacheman (part of http-replicator).
7 (Portage version: 2.2_rc8/cvs/Linux 2.6.26.2 x86_64)
8
9 Revision Changes Path
10 1.1 net-proxy/http-replicator/files/http-replicator-3.0-repcacheman-0.44-r1
11
12 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/net-proxy/http-replicator/files/http-replicator-3.0-repcacheman-0.44-r1?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/net-proxy/http-replicator/files/http-replicator-3.0-repcacheman-0.44-r1?rev=1.1&content-type=text/plain
14
15 Index: http-replicator-3.0-repcacheman-0.44-r1
16 ===================================================================
17 #! /usr/bin/python
18 #
19 # repcacheman ver 0.44
20 #
21 # Cache Manager for Http-Replicator
22 # deletes duplicate files in PORTDIR.
23 # imports authenticated (checksum + listed in portage)
24 # files from PORTDIR to replicator's cache directory.
25 #
26 # Uses portage to perform checksum and database functions.
27 # All else, Copyright(C)2004-2007 Tom Poplawski (poplawtm@×××××××××.net)
28 # Distributed under the terms of the GNU General Public License v2
29 #
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
34
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38
39
40 import portage.manifest
41 import portage.checksum
42 import portage.exception
43 import portage
44 import string
45 import os
46 import pwd,sys,optparse
47
48 if os.getuid():
49 print"Must be root"
50 sys.exit(1)
51
52 # Parse Options
53
54 parser = optparse.OptionParser()
55 parser.add_option('-d', '--dir', type='string', default="/var/cache/http-replicator", help='http-replicators cache DIR')
56 parser.add_option('-u','--user', type='string', default="portage", help='http-replicator USER')
57 options, args = parser.parse_args() # parse command line
58
59 if options.user:
60 try:
61 uid=pwd.getpwnam(options.user)[2]
62 gid=pwd.getpwnam(options.user)[3]
63 except:
64 print "User \'" + options.user + "\' Doesn't exist on system - edit config or add user to system."
65 sys.exit(1)
66 else:
67 print "Error\n\tunable to get USER from /etc/http-replicator.conf"
68 sys.exit(1)
69
70 # dir is replicator's cache directory
71 dir=options.dir+"/"
72
73 if os.path.isdir(dir) :
74 newdir=0
75 else :
76 print"\n\nBegin Http-Replicator Setup...."
77 try:
78 os.makedirs(dir)
79 print "\tcreated " + dir
80 newdir=1
81 except:
82 print "\tcreate " + dir + " failed"
83 print '\terror:', sys.exc_info()[1]
84 sys.exit(1)
85 try:
86 os.chown(dir,uid,gid)
87 print "\tchanged owner of " + dir + " to " + options.user
88 except:
89 print "\tchange owner " + dir + " to " + options.user + " failed:"
90 print '\terror:', sys.exc_info()[1]
91
92 print "\n\nReplicator's cache directory: " + dir
93
94 # Import Portage settings
95
96 distdir=portage.settings["DISTDIR"]+"/"
97 if distdir:
98 print "Portage's DISTDIR: " + distdir
99 else:
100 print"Unable to get Portage's DISTDIR"
101 sys.exit(1)
102
103 # Start Work
104
105 print "\nComparing directories...."
106
107 # Create filecmp object
108 import filecmp
109 dc=filecmp.dircmp (distdir,dir,['cvs-src','git-src','hg-src','.locks'])
110 print "Done!"
111
112 dupes=dc.common
113 deleted=0
114
115 if dupes:
116 print "\nDeleting duplicate file(s) in " + distdir
117
118 for s in dupes:
119 print s
120 try:
121 os.remove(distdir + s )
122 deleted +=1
123 except:
124 print "\tdelete " + distdir + s + " failed:"
125 print '\terror:', sys.exc_info()[1]
126
127 print "Done!"
128
129
130 newfiles=dc.left_only
131 nf=len(dc.left_only)
132
133 if nf:
134 print "\nNew files in DISTDIR:"
135 for s in newfiles:
136 print s
137 print"\nChecking authenticity and integrity of new files..."
138 added=0
139 errors=0
140 badsum=0
141
142 # search all packages
143
144 for mycp in portage.db["/"]["porttree"].dbapi.cp_all():
145 manifest = portage.manifest.Manifest("/usr/portage/" + mycp , distdir)
146 if manifest == None:
147 portage.writemsg("Missing manifest: %s\n" % mycpv)
148
149 remove=[]
150 for file in newfiles:
151 if manifest.hasFile("DIST",file):
152 try:
153 myok, myreason = manifest.checkFileHashes("DIST",file)
154
155 try:
156 os.rename(distdir+file,dir+file)
157 added += 1
158 except:
159 try:
160 import shutil
161 shutil.copyfile(distdir+file,dir+file)
162 added += 1
163 os.remove(distdir+file)
164 except:
165 print "\tmove/copy " + file + " failed:"
166 print '\terror:', sys.exc_info()[1]
167 errors+=1
168
169 try:
170 os.chown(dir+file,uid,gid)
171 except:
172 print "\tchown " + file + " failed:"
173 print '\terror:', sys.exc_info()[1]
174 errors +=1
175
176 remove.append( file )
177
178 except portage.exception.DigestException, e:
179 print("\n!!! Digest verification failed:")
180 print("!!! %s" % e.value[0])
181 print("!!! Reason: %s" % e.value[1])
182 print("!!! Got: %s" % e.value[2])
183 print("!!! Expected: %s" % e.value[3])
184 badsum+=1
185 if remove:
186 for rf in remove:
187 newfiles.remove ( rf )
188
189
190 print "\nSUMMARY:"
191 print "Found " + str(len(dupes)) + " duplicate file(s)"
192 if deleted:
193 print "\tDeleted " + str(deleted) + " dupe(s)"
194
195 if nf:
196 print "Found " + str(nf) + " new file(s)"
197 print "\tAdded " + str(added) + " of those file(s) to the cache"
198
199 print "Rejected " +str(len(newfiles)) + " File(s) - ",
200 print str(badsum) + " failed checksum(s)"
201 for s in newfiles:
202 print "\t%s" %s
203 if errors:
204 print "Encountered " +str(errors) + " errors"
205 # if badsum:
206 # print str(badsum) + " partial/corrupted file(s)"
207
208 if newdir:
209 print"\n\nexecute:\n/etc/init.d/http-replicator start"
210 print"to run http-replicator.\n\nexecute:\nrc-update add http-replicator default"
211 print"to make http-replicator start at boot"
212 print"\n\nexecute:\n/usr/bin/repcacheman\nafter emerge's on the server to delete"
213 print"dup files and add new files to the cache"
214
215 print "\n\nHTTP-Replicator requires you delete any partial downloads in " + distdir
216 print "run rm -rf " + distdir +'*'