Mercurial > hg > config
annotate python/diffex.py @ 623:69babe3ef8a7
STUB: .bashrc
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 05 Feb 2014 13:38:00 -0800 |
parents | be91c9fb3147 |
children | 4adc11d68e3d |
rev | line source |
---|---|
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 """ |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 diff before v after of executables (requires http://k0s.org/hg/config/file/f71f6ffa731a/python/lsex.py) |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 """ |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 import difflib |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 import lsex |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 import optparse |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 import os |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 import subprocess |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 import sys |
453 | 14 import tempfile |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 def add_options(parser): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 """add options to the OptionParser instance""" |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 def main(args=sys.argv[1:]): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 # parse command line options |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 usage = '%prog [options] ...' |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 """description formatter for console script entry point""" |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 def format_description(self, description): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 if description: |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 return description.strip() + '\n' |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 else: |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 return '' |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 options, args = parser.parse_args(args) |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
32 |
453 | 33 # get difference |
34 before = lsex.executable_names() # get executables before | |
35 raw_input("Press [Enter] to continue") | |
36 after = lsex.executable_names() # get executables after | |
37 | |
38 # display | |
39 added = [i for i in after if i not in before] | |
40 removed = [i for i in before if i not in after] | |
41 added.sort() | |
42 removed.sort() | |
43 | |
44 display = [('Added', added), | |
45 ('Removed', removed), | |
46 ] | |
47 | |
48 for display_name, var in display: | |
49 if var: | |
50 print '%s:' % display_name | |
51 print '\n'.join(var) | |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
52 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
53 if __name__ == '__main__': |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
54 main() |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
55 |