Lines 196-214
class fakedom:
Link Here
|
196 |
class PortageMangle(object): |
196 |
class PortageMangle(object): |
197 |
_xml = None |
197 |
_xml = None |
198 |
_xml_category = None |
198 |
_xml_category = None |
199 |
_xml_package = None |
199 |
_xml_package = None |
200 |
_xml_files = None |
200 |
_xml_files = None |
201 |
_xml_uses = None |
201 |
_xml_uses = None |
202 |
|
202 |
|
203 |
_settings = None |
203 |
_settings = None |
204 |
_portdbapi = None |
204 |
_portdbapi = None |
205 |
_vardbapi = None |
205 |
_vardbapi = None |
206 |
|
206 |
|
207 |
def __init__(self): |
207 |
def __init__(self): |
208 |
# main portage config object, lots of interresting stuff in there |
208 |
# main portage config object, lots of interresting stuff in there |
209 |
self._settings = config() |
209 |
self._settings = config() |
210 |
self._settings['PORTDIR_OVERLAY'] = '' # does not matter for me |
210 |
self._settings['PORTDIR_OVERLAY'] = '' # does not matter for me |
211 |
|
211 |
|
212 |
self._xml = fakedom(DEBUG) |
212 |
self._xml = fakedom(DEBUG) |
213 |
self._xml.newelem('pfl') |
213 |
self._xml.newelem('pfl') |
214 |
self._xml.newattr('xmlns', "http://www.portagefilelist.de/xsd/collect") |
214 |
self._xml.newattr('xmlns', "http://www.portagefilelist.de/xsd/collect") |
Lines 227-233
class PortageMangle(object):
Link Here
|
227 |
c, p, v, r = catpkgsplit(cpv) |
227 |
c, p, v, r = catpkgsplit(cpv) |
228 |
if r <> 'r0': |
228 |
if r <> 'r0': |
229 |
v = '%s-%s' % (v, r) |
229 |
v = '%s-%s' % (v, r) |
230 |
|
230 |
|
231 |
repo, = self._vardbapi.aux_get(cpv, ['repository']) |
231 |
repo, = self._vardbapi.aux_get(cpv, ['repository']) |
232 |
|
232 |
|
233 |
# timestamp of merge |
233 |
# timestamp of merge |
Lines 236-242
class PortageMangle(object):
Link Here
|
236 |
if repo == 'gentoo' and mergedstamp >= since: |
236 |
if repo == 'gentoo' and mergedstamp >= since: |
237 |
wellknown.setdefault(c, {}).setdefault(p, []).append(v) |
237 |
wellknown.setdefault(c, {}).setdefault(p, []).append(v) |
238 |
wellknown_count = wellknown_count + 1 |
238 |
wellknown_count = wellknown_count + 1 |
239 |
|
239 |
|
240 |
return [wellknown_count, wellknown] |
240 |
return [wellknown_count, wellknown] |
241 |
|
241 |
|
242 |
def get_contents(self, c, p, v): |
242 |
def get_contents(self, c, p, v): |
Lines 245-261
class PortageMangle(object):
Link Here
|
245 |
|
245 |
|
246 |
def collect_into_xml(self, since, uuid): |
246 |
def collect_into_xml(self, since, uuid): |
247 |
count, cpvs = self.get_wellknown_cpvs(since); |
247 |
count, cpvs = self.get_wellknown_cpvs(since); |
248 |
|
248 |
|
249 |
# nothing to do |
249 |
# nothing to do |
250 |
if count == 0: |
250 |
if count == 0: |
251 |
return None |
251 |
return None |
252 |
|
252 |
|
253 |
workingon = 0 |
253 |
workingon = 0 |
254 |
self._xml.indent() |
254 |
self._xml.indent() |
255 |
for c in cpvs: |
255 |
for c in cpvs: |
256 |
if DEBUG and c <> 'sys-kernel': |
256 |
if DEBUG and c <> 'sys-kernel': |
257 |
continue |
257 |
continue |
258 |
|
258 |
|
259 |
self._xml.newelem("category") |
259 |
self._xml.newelem("category") |
260 |
self._xml.newattr("name", c) |
260 |
self._xml.newattr("name", c) |
261 |
self._xml.indent() |
261 |
self._xml.indent() |
Lines 268-283
class PortageMangle(object):
Link Here
|
268 |
print 'working on (%d of %d) %s/%s-%s' % (workingon, count, c, p, v) |
268 |
print 'working on (%d of %d) %s/%s-%s' % (workingon, count, c, p, v) |
269 |
|
269 |
|
270 |
self._xml.newelem('package') |
270 |
self._xml.newelem('package') |
271 |
|
271 |
|
272 |
contents = self.get_contents(c, p, v) |
272 |
contents = self.get_contents(c, p, v) |
273 |
|
273 |
|
274 |
# no files -> this package does not matter |
274 |
# no files -> this package does not matter |
275 |
if len(contents) == 0: |
275 |
if len(contents) == 0: |
276 |
continue |
276 |
continue |
277 |
|
277 |
|
278 |
|
278 |
|
279 |
mergedstamp = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['_mtime_'])[0] |
279 |
mergedstamp = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['_mtime_'])[0] |
280 |
|
280 |
|
281 |
use = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['USE'])[0].split() |
281 |
use = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['USE'])[0].split() |
282 |
iuse = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['IUSE'])[0].split() |
282 |
iuse = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['IUSE'])[0].split() |
283 |
keywords = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['KEYWORDS'])[0].split() |
283 |
keywords = self._vardbapi.aux_get('%s/%s-%s' % (c, p, v), ['KEYWORDS'])[0].split() |
Lines 322-328
class PortageMangle(object):
Link Here
|
322 |
xmlfile = './%s.pfl.xml' % uuid |
322 |
xmlfile = './%s.pfl.xml' % uuid |
323 |
else: |
323 |
else: |
324 |
xmlfile = '/tmp/%s.pfl.xml.bz2' % uuid |
324 |
xmlfile = '/tmp/%s.pfl.xml.bz2' % uuid |
325 |
|
325 |
|
326 |
print 'writing xml file %s ...' % xmlfile |
326 |
print 'writing xml file %s ...' % xmlfile |
327 |
xmlf = open(xmlfile, 'w') |
327 |
xmlf = open(xmlfile, 'w') |
328 |
if DEBUG: |
328 |
if DEBUG: |
Lines 330-338
class PortageMangle(object):
Link Here
|
330 |
else: |
330 |
else: |
331 |
xmlf.write(bz2.compress(self._xml.bytes)) |
331 |
xmlf.write(bz2.compress(self._xml.bytes)) |
332 |
xmlf.close() |
332 |
xmlf.close() |
333 |
|
333 |
|
334 |
return xmlfile |
334 |
return xmlfile |
335 |
|
335 |
|
336 |
class PFLConfigParser(ConfigParser.RawConfigParser): |
336 |
class PFLConfigParser(ConfigParser.RawConfigParser): |
337 |
def get(self, section, option, default = None): |
337 |
def get(self, section, option, default = None): |
338 |
if not self.has_option(section, option): |
338 |
if not self.has_option(section, option): |
Lines 342-352
class PFLConfigParser(ConfigParser.RawCo
Link Here
|
342 |
raise ConfigParser.NoOptionError(option, section) |
342 |
raise ConfigParser.NoOptionError(option, section) |
343 |
else: |
343 |
else: |
344 |
return ConfigParser.RawConfigParser.get(self, section, option) |
344 |
return ConfigParser.RawConfigParser.get(self, section, option) |
345 |
|
345 |
|
346 |
def set (self, section, option, value): |
346 |
def set (self, section, option, value): |
347 |
if (not self.has_section(section)): |
347 |
if (not self.has_section(section)): |
348 |
self.add_section(section) |
348 |
self.add_section(section) |
349 |
|
349 |
|
350 |
ConfigParser.RawConfigParser.set(self, section, option, value) |
350 |
ConfigParser.RawConfigParser.set(self, section, option, value) |
351 |
|
351 |
|
352 |
""" |
352 |
""" |
Lines 389-401
class HTTP(object):
Link Here
|
389 |
h.putrequest('POST', selector) |
389 |
h.putrequest('POST', selector) |
390 |
except: |
390 |
except: |
391 |
raise Exception("Could not set up the put request to the server! Reason unknown.") |
391 |
raise Exception("Could not set up the put request to the server! Reason unknown.") |
392 |
|
392 |
|
393 |
h.putheader('Host', host) |
393 |
h.putheader('Host', host) |
394 |
h.putheader('Content-Type', content_type) |
394 |
h.putheader('Content-Type', content_type) |
395 |
h.putheader('Content-Length', str(len(body))) |
395 |
h.putheader('Content-Length', str(len(body))) |
396 |
h.putheader('Keep-Alive', '300') |
396 |
h.putheader('Keep-Alive', '300') |
397 |
h.putheader('Connection', 'close') |
397 |
h.putheader('Connection', 'close') |
398 |
|
398 |
|
399 |
try: |
399 |
try: |
400 |
h.endheaders() |
400 |
h.endheaders() |
401 |
except: |
401 |
except: |
Lines 409-415
class HTTP(object):
Link Here
|
409 |
return h.file.read() |
409 |
return h.file.read() |
410 |
else: |
410 |
else: |
411 |
return errmsg |
411 |
return errmsg |
412 |
|
412 |
|
413 |
def encode_multipart_formdata(self, fields, files): |
413 |
def encode_multipart_formdata(self, fields, files): |
414 |
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' |
414 |
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' |
415 |
CRLF = '\r\n' |
415 |
CRLF = '\r\n' |
Lines 430-439
class HTTP(object):
Link Here
|
430 |
body = CRLF.join(L) |
430 |
body = CRLF.join(L) |
431 |
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY |
431 |
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY |
432 |
return content_type, body |
432 |
return content_type, body |
433 |
|
433 |
|
434 |
def get_content_type(self, filename): |
434 |
def get_content_type(self, filename): |
435 |
return mimetypes.guess_type(filename)[0] or 'application/octet-stream' |
435 |
return mimetypes.guess_type(filename)[0] or 'application/octet-stream' |
436 |
|
436 |
|
437 |
def _read_file(self, file): |
437 |
def _read_file(self, file): |
438 |
f = open(file, 'r') |
438 |
f = open(file, 'r') |
439 |
content = f.read() |
439 |
content = f.read() |
Lines 443-449
class HTTP(object):
Link Here
|
443 |
class PFL(object): |
443 |
class PFL(object): |
444 |
_lastrun = 0 |
444 |
_lastrun = 0 |
445 |
_config = None |
445 |
_config = None |
446 |
|
446 |
|
447 |
def __init__(self): |
447 |
def __init__(self): |
448 |
self._read_config() |
448 |
self._read_config() |
449 |
|
449 |
|
Lines 454-473
class PFL(object):
Link Here
|
454 |
else: |
454 |
else: |
455 |
self._config.set('PFL', 'lastrun', long(time())) |
455 |
self._config.set('PFL', 'lastrun', long(time())) |
456 |
self._config.set('PFL', 'version', VERSION) |
456 |
self._config.set('PFL', 'version', VERSION) |
457 |
|
457 |
|
458 |
hconfig = open(INFOFILE, 'w') |
458 |
hconfig = open(INFOFILE, 'w') |
459 |
self._config.write(hconfig) |
459 |
self._config.write(hconfig) |
460 |
hconfig.close() |
460 |
hconfig.close() |
461 |
|
461 |
|
462 |
if xmlfile and os.path.isfile(xmlfile) and not DEBUG: |
462 |
if xmlfile and os.path.isfile(xmlfile) and not DEBUG: |
463 |
print 'deleting xml file %s ...' % xmlfile |
463 |
print 'deleting xml file %s ...' % xmlfile |
464 |
os.unlink(xmlfile) |
464 |
os.unlink(xmlfile) |
465 |
|
465 |
|
466 |
def _read_config(self): |
466 |
def _read_config(self): |
467 |
self._config = PFLConfigParser() |
467 |
self._config = PFLConfigParser() |
468 |
if os.path.isfile(INFOFILE): |
468 |
if os.path.isfile(INFOFILE): |
469 |
self._config.read(INFOFILE) |
469 |
self._config.read(INFOFILE) |
470 |
|
470 |
|
471 |
def _last_run(self): |
471 |
def _last_run(self): |
472 |
if self._config.get('PFL', 'version', 'noversion') == 'noversion': |
472 |
if self._config.get('PFL', 'version', 'noversion') == 'noversion': |
473 |
return 0 |
473 |
return 0 |
Lines 480-496
class PFL(object):
Link Here
|
480 |
|
480 |
|
481 |
def do_job(self): |
481 |
def do_job(self): |
482 |
pm = PortageMangle() |
482 |
pm = PortageMangle() |
483 |
|
483 |
|
484 |
# use uuid |
484 |
# use uuid |
485 |
if os.path.exists(UUIDFILE): |
485 |
uuid = self._config.get('PFL', 'uuid', 'nouuid') |
486 |
uuid = self._config.get('PFL', 'uuid', 'nouuid') |
486 |
if uuid == 'nouuid': |
487 |
if uuid == 'nouuid': |
487 |
f = open(UUIDFILE, 'r') |
488 |
f = open(UUIDFILE, 'r') |
488 |
uuid = f.readline().strip() |
489 |
uuid = f.readline().strip() |
489 |
f.close() |
490 |
f.close() |
490 |
self._config.set('PFL', 'uuid', uuid) |
491 |
self._config.set('PFL', 'uuid', uuid) |
|
|
492 |
else: |
493 |
uuid = "PFLnone" |
494 |
xmlfile = pm.collect_into_xml(self._last_run(), uuid) |
491 |
xmlfile = pm.collect_into_xml(self._last_run(), uuid) |
495 |
|
492 |
|
496 |
if xmlfile == None: |
493 |
if xmlfile == None: |