]> git.decadent.org.uk Git - dak.git/commitdiff
override_disparity.py: display YAML output
authorLuca Falavigna <dktrkranz@debian.org>
Sun, 12 Dec 2010 11:18:37 +0000 (11:18 +0000)
committerLuca Falavigna <dktrkranz@debian.org>
Mon, 10 Jan 2011 20:14:29 +0000 (20:14 +0000)
Signed-off-by: Luca Falavigna <dktrkranz@debian.org>
dak/override_disparity.py

index 94e1e9e8b0222863fe0db36d6f6436eff2931b75..383766ef4ae61ad2fc12904da710b359138f41d6 100755 (executable)
@@ -37,6 +37,7 @@ Generate a list of override disparities
 import os
 import sys
 import apt_pkg
+import yaml
 
 from daklib.config import Config
 from daklib.dbconn import *
@@ -48,11 +49,12 @@ def usage (exit_code=0):
     print """Generate a list of override disparities
 
        Usage:
-       dak override-disparity [ -p <package> ] [ -s <suite> ]
+       dak override-disparity [-f <file>] [ -p <package> ] [ -s <suite> ]
 
 Options:
 
   -h, --help                show this help and exit
+  -f, --file                store output into given file
   -p, --package             limit check on given package only
   -s, --suite               choose suite to look for (default: unstable)"""
 
@@ -61,6 +63,7 @@ Options:
 def main():
     cnf = Config()
     Arguments = [('h','help','Override-Disparity::Options::Help'),
+                 ('f','file','Override-Disparity::Options::File','HasArg'),
                  ('s','suite','Override-Disparity::Options::Suite','HasArg'),
                  ('p','package','Override-Disparity::Options::Package','HasArg')]
 
@@ -114,6 +117,11 @@ def main():
     packages = session.execute(query)
     session.commit()
 
+    out = {}
+    if Options.has_key('file'):
+        outfile = file(os.path.expanduser(Options['file']), 'w')
+    else:
+        outfile = sys.stdout
     for p in packages:
         priorities[p[0]] = [p[1], p[2], p[3], True]
     for d in sorted(depends.keys()):
@@ -121,13 +129,18 @@ def main():
             if priorities.has_key(d) and priorities.has_key(p):
                 if priorities[d][0] < priorities[p][0]:
                      if priorities[d][3]:
-                         print 'Package: ' + d
-                         print ' Priority: ' + priorities[d][1]
-                         print ' Maintainer: ' + priorities[d][2]
+                         if not out.has_key(d):
+                             out[d] = {}
+                         out[d]['priority'] = priorities[d][1]
+                         out[d]['maintainer'] = priorities[d][2]
+                         out[d]['priority'] = priorities[d][1]
                          priorities[d][3] = False
-                     print ' Dependency: ' + p
-                     print '  Priority: ' + priorities[p][1]
-                     print '  Maintainer: ' + priorities[p][2]
+                     if not out[d].has_key('dependency'):
+                         out[d]['dependency'] = {}
+                     out[d]['dependency'][p] = priorities[p][1]
+    yaml.dump(out, outfile, default_flow_style=False)
+    if Options.has_key('file'):
+        outfile.close()
 
 if __name__ == '__main__':
     main()