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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
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
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
33 # get difference
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
34 before = lsex.executable_names() # get executables before
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
35 raw_input("Press [Enter] to continue")
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
36 after = lsex.executable_names() # get executables after
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
37
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
38 # display
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
39 added = [i for i in after if i not in before]
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
40 removed = [i for i in before if i not in after]
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
41 added.sort()
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
42 removed.sort()
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
43
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
44 display = [('Added', added),
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
45 ('Removed', removed),
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
46 ]
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
47
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
48 for display_name, var in display:
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
49 if var:
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
50 print '%s:' % display_name
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
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