Mercurial > hg > config
annotate python/diffex.py @ 879:79b52aec477e
function for java_home
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 24 May 2019 15:34:11 -0700 |
parents | 4adc11d68e3d |
children |
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 """ |
805 | 5 diff before v after of executables |
6 (requires http://k0s.org/hg/config/file/f71f6ffa731a/python/lsex.py) | |
446
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 |
805 | 9 # improts |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 import difflib |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 import lsex |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 import optparse |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 import os |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 import subprocess |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 import sys |
453 | 16 import tempfile |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 |
805 | 18 |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 def add_options(parser): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 """add options to the OptionParser instance""" |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 |
805 | 22 |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 def main(args=sys.argv[1:]): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 |
805 | 25 # parse command line |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 usage = '%prog [options] ...' |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 """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
|
29 def format_description(self, description): |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 if description: |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 return description.strip() + '\n' |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
32 else: |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
33 return '' |
805 | 34 parser = optparse.OptionParser(usage=usage, |
35 description=__doc__, | |
36 formatter=PlainDescriptionFormatter()) | |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
37 options, args = parser.parse_args(args) |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
38 |
805 | 39 # get difference in executables |
453 | 40 before = lsex.executable_names() # get executables before |
41 raw_input("Press [Enter] to continue") | |
42 after = lsex.executable_names() # get executables after | |
43 | |
44 # display | |
45 added = [i for i in after if i not in before] | |
46 removed = [i for i in before if i not in after] | |
47 added.sort() | |
48 removed.sort() | |
49 | |
50 display = [('Added', added), | |
51 ('Removed', removed), | |
52 ] | |
53 | |
54 for display_name, var in display: | |
55 if var: | |
56 print '%s:' % display_name | |
805 | 57 print ('\n'.join(var)) |
58 | |
446
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
59 |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
60 if __name__ == '__main__': |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
61 main() |
95afeaf9c42d
-> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
62 |