comparison python/diffex.py @ 805:4adc11d68e3d

mostly formatting
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Oct 2016 17:05:35 -0700
parents be91c9fb3147
children
comparison
equal deleted inserted replaced
804:624a7fc0d7ca 805:4adc11d68e3d
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 """ 4 """
5 diff before v after of executables (requires http://k0s.org/hg/config/file/f71f6ffa731a/python/lsex.py) 5 diff before v after of executables
6 (requires http://k0s.org/hg/config/file/f71f6ffa731a/python/lsex.py)
6 """ 7 """
7 8
9 # improts
8 import difflib 10 import difflib
9 import lsex 11 import lsex
10 import optparse 12 import optparse
11 import os 13 import os
12 import subprocess 14 import subprocess
13 import sys 15 import sys
14 import tempfile 16 import tempfile
15 17
18
16 def add_options(parser): 19 def add_options(parser):
17 """add options to the OptionParser instance""" 20 """add options to the OptionParser instance"""
18 21
22
19 def main(args=sys.argv[1:]): 23 def main(args=sys.argv[1:]):
20 24
21 # parse command line options 25 # parse command line
22 usage = '%prog [options] ...' 26 usage = '%prog [options] ...'
23 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): 27 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
24 """description formatter for console script entry point""" 28 """description formatter for console script entry point"""
25 def format_description(self, description): 29 def format_description(self, description):
26 if description: 30 if description:
27 return description.strip() + '\n' 31 return description.strip() + '\n'
28 else: 32 else:
29 return '' 33 return ''
30 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) 34 parser = optparse.OptionParser(usage=usage,
35 description=__doc__,
36 formatter=PlainDescriptionFormatter())
31 options, args = parser.parse_args(args) 37 options, args = parser.parse_args(args)
32 38
33 # get difference 39 # get difference in executables
34 before = lsex.executable_names() # get executables before 40 before = lsex.executable_names() # get executables before
35 raw_input("Press [Enter] to continue") 41 raw_input("Press [Enter] to continue")
36 after = lsex.executable_names() # get executables after 42 after = lsex.executable_names() # get executables after
37 43
38 # display 44 # display
46 ] 52 ]
47 53
48 for display_name, var in display: 54 for display_name, var in display:
49 if var: 55 if var:
50 print '%s:' % display_name 56 print '%s:' % display_name
51 print '\n'.join(var) 57 print ('\n'.join(var))
58
52 59
53 if __name__ == '__main__': 60 if __name__ == '__main__':
54 main() 61 main()
55 62