Mercurial > hg > config
annotate python/ymldiff.py @ 220:192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 08 May 2012 08:26:55 -0700 |
parents | |
children | d213d21e371b |
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 |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 import datadiff |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 imoprt optparse |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 import sys |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 import yaml |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 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
|
9 usage = '%prog [options] from.yml to.yml' |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 parser = OptionParser(usage=usage) |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 options, args = parser.parse_args() |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 if len(args) != 2: |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 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
|
14 |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 # compare the output |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 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
|
17 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
|
18 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
|
19 print diff |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 if __name__ == '__main__': |
192015ae3e4c
add ymldiff.py, requires datadiff and pyyaml to be installed
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 main() |