rhel_to_json
Pierre-Yves Chibon
pingou at pingoured.fr
Mon Jan 19 16:55:38 UTC 2015
On Mon, Jan 19, 2015 at 05:41:41PM +0100, Pierre-Yves Chibon wrote:
> I would like to hear if people are fine with me breaking this already. It has
> been running for a week now and afaik we have nothing (in prod or testing)
> depending on it yet so it seems like the best time to make the schema evolve.
>
> Basically I would like to go from:
> {
> "pkg1": {
> "version": 0.2,
> "arch": ["i686", "x86_64"],
> ...
> },
> "pkg2": {
> "version": ...
> },
> ...
> }
>
> To:
> {
> "packages": [
> "pkg1": {
> "version": 0.2,
> "arch": ["i686", "x86_64"],
> ...
> },
> "pkg2": {
> "version": ...
> },
> ...
> ],
> "arches": ["i686", "x86_64", "ppc64"...],
> <eventually something if we need to>
> }
For the record, here is the change:
===
@@ -187,7 +187,7 @@ def main():
for el in PATHS:
- output = {}
+ output = {'packages': {}, 'arches': []}
dbfiles = find_primary_sqlite(PATHS[el])
@@ -208,14 +208,18 @@ def main():
cnt = 0
new = 0
for pkg in session.query(Package).all():
- if pkg.basename in output:
- if pkg.arch not in output[pkg.basename]['arch']:
- output[pkg.basename]['arch'].append(pkg.arch)
+ if pkg.basename in output['packages']:
+ if pkg.arch not in output['packages'][
+ pkg.basename]['arch']:
+ output['packages'][pkg.basename]['arch'].append(
+ pkg.arch)
+ if pkg.arch not in output['arches']:
+ output['arches'].append(pkg.arch)
# TODO: checks if the evr is more recent or not
# (and update if it is)
else:
new += 1
- output[pkg.basename] = {
+ output['packages'][pkg.basename] = {
'arch': [pkg.arch],
'epoch': pkg.epoch,
'version': pkg.version,
@@ -225,7 +229,8 @@ def main():
print '%s packages in %s' % (cnt, cur_fold)
print '%s packages were new packages' % (new)
- print '\n%s packages retrieved in %s' % (len(output), el)
+ print '\n%s packages retrieved in %s' % (len(output['packages']), el)
+ print '%s arches for in %s' % (len(output['arches']), el)
outputfile = 'pkg_%s.json' % el
with open(outputfile, 'w') as stream:
stream.write(json.dumps(output))
===
Pierre
More information about the rel-eng
mailing list