annotate python/diffex.py @ 901:d01703658029

gitconfig
author Jeff Hammel <k0scist@gmail.com>
date Thu, 09 Feb 2023 14:16:11 -0800
parents 4adc11d68e3d
children
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 """
805
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
5 diff before v after of executables
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
16 import tempfile
446
95afeaf9c42d -> http://k0s.org/portfolio/ideas/install_software_trifecta.txt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
805
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
34 parser = optparse.OptionParser(usage=usage,
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
35 description=__doc__,
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
39 # get difference in executables
453
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
40 before = lsex.executable_names() # get executables before
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
41 raw_input("Press [Enter] to continue")
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
42 after = lsex.executable_names() # get executables after
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
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
45 added = [i for i in after if i not in before]
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
46 removed = [i for i in before if i not in after]
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
47 added.sort()
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
48 removed.sort()
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
49
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
50 display = [('Added', added),
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
51 ('Removed', removed),
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
52 ]
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
53
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
54 for display_name, var in display:
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
55 if var:
be91c9fb3147 python/diffex.py
Jeff Hammel <jhammel@mozilla.com>
parents: 446
diff changeset
56 print '%s:' % display_name
805
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
57 print ('\n'.join(var))
4adc11d68e3d mostly formatting
Jeff Hammel <k0scist@gmail.com>
parents: 453
diff changeset
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