annotate python/example/ymldiff.py @ 808:48ea50d346de

comment re dependency
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Oct 2016 17:10:27 -0700
parents 26786fae0703
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
220
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
808
48ea50d346de comment re dependency
Jeff Hammel <k0scist@gmail.com>
parents: 807
diff changeset
3 # XXX/TODO:
48ea50d346de comment re dependency
Jeff Hammel <k0scist@gmail.com>
parents: 807
diff changeset
4 # I have no idea where this dependency comes from; on one hand, it sounds
48ea50d346de comment re dependency
Jeff Hammel <k0scist@gmail.com>
parents: 807
diff changeset
5 # awesome! On another hand, it should, at the very least, be documented
220
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 import datadiff
808
48ea50d346de comment re dependency
Jeff Hammel <k0scist@gmail.com>
parents: 807
diff changeset
7
221
d213d21e371b fix silly mistakes
Jeff Hammel <jhammel@mozilla.com>
parents: 220
diff changeset
8 import optparse
220
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 import yaml
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 def main(args=sys.argv[1:]):
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 usage = '%prog [options] from.yml to.yml'
221
d213d21e371b fix silly mistakes
Jeff Hammel <jhammel@mozilla.com>
parents: 220
diff changeset
14 parser = optparse.OptionParser(usage=usage)
220
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 options, args = parser.parse_args()
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 if len(args) != 2:
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 parser.error("Please supply two .yml files")
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 # compare the output
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 output0 = yaml.load(file(args[0]))
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 output1 = yaml.load(file(args[1]))
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 diff = datadiff.diff(output0, output1, context=1, fromfile=args[0], tofile=args[1])
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 print diff
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 if __name__ == '__main__':
192015ae3e4c add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 main()