Commit f41fe3655d2a9b46affbcdaff10a5b2f2a13e940

Authored by decalage2
1 parent 10e0f16c

olemeta: added main function for entry points in setup.py - issue #69

Showing 2 changed files with 56 additions and 49 deletions
oletools/olemeta.py
@@ -15,7 +15,7 @@ http://www.decalage.info/python/oletools @@ -15,7 +15,7 @@ http://www.decalage.info/python/oletools
15 15
16 #=== LICENSE ================================================================= 16 #=== LICENSE =================================================================
17 17
18 -# olemeta is copyright (c) 2013-2015, Philippe Lagadec (http://www.decalage.info) 18 +# olemeta is copyright (c) 2013-2016, Philippe Lagadec (http://www.decalage.info)
19 # All rights reserved. 19 # All rights reserved.
20 # 20 #
21 # Redistribution and use in source and binary forms, with or without modification, 21 # Redistribution and use in source and binary forms, with or without modification,
@@ -44,8 +44,9 @@ http://www.decalage.info/python/oletools @@ -44,8 +44,9 @@ http://www.decalage.info/python/oletools
44 # 2014-11-29 v0.02 PL: - use olefile instead of OleFileIO_PL 44 # 2014-11-29 v0.02 PL: - use olefile instead of OleFileIO_PL
45 # - improved usage display 45 # - improved usage display
46 # 2015-12-29 v0.03 PL: - only display properties present in the file 46 # 2015-12-29 v0.03 PL: - only display properties present in the file
  47 +# 2016-09-06 v0.50 PL: - added main entry point for setup.py
47 48
48 -__version__ = '0.03' 49 +__version__ = '0.50'
49 50
50 #------------------------------------------------------------------------------ 51 #------------------------------------------------------------------------------
51 # TODO: 52 # TODO:
@@ -63,50 +64,54 @@ from thirdparty.tablestream import tablestream @@ -63,50 +64,54 @@ from thirdparty.tablestream import tablestream
63 64
64 #=== MAIN ================================================================= 65 #=== MAIN =================================================================
65 66
66 -try:  
67 - ole = olefile.OleFileIO(sys.argv[1])  
68 -except IndexError:  
69 - sys.exit(__doc__)  
70 -  
71 -# parse and display metadata:  
72 -meta = ole.get_metadata()  
73 -  
74 -# console output with UTF8 encoding:  
75 -console_utf8 = codecs.getwriter('utf8')(sys.stdout)  
76 -  
77 -# TODO: move similar code to a function  
78 -  
79 -print('Properties from the SummaryInformation stream:')  
80 -t = tablestream.TableStream([21, 30], header_row=['Property', 'Value'], outfile=console_utf8)  
81 -for prop in meta.SUMMARY_ATTRIBS:  
82 - value = getattr(meta, prop)  
83 - if value is not None:  
84 - # TODO: pretty printing for strings, dates, numbers  
85 - # TODO: better unicode handling  
86 - # print('- %s: %s' % (prop, value))  
87 - if isinstance(value, unicode):  
88 - # encode to UTF8, avoiding errors  
89 - value = value.encode('utf-8', errors='replace')  
90 - else:  
91 - value = str(value)  
92 - t.write_row([prop, value], colors=[None, 'yellow'])  
93 -t.close()  
94 -print ''  
95 -  
96 -print('Properties from the DocumentSummaryInformation stream:')  
97 -t = tablestream.TableStream([21, 30], header_row=['Property', 'Value'], outfile=console_utf8)  
98 -for prop in meta.DOCSUM_ATTRIBS:  
99 - value = getattr(meta, prop)  
100 - if value is not None:  
101 - # TODO: pretty printing for strings, dates, numbers  
102 - # TODO: better unicode handling  
103 - # print('- %s: %s' % (prop, value))  
104 - if isinstance(value, unicode):  
105 - # encode to UTF8, avoiding errors  
106 - value = value.encode('utf-8', errors='replace')  
107 - else:  
108 - value = str(value)  
109 - t.write_row([prop, value], colors=[None, 'yellow'])  
110 -t.close()  
111 -  
112 -ole.close() 67 +def main():
  68 + try:
  69 + ole = olefile.OleFileIO(sys.argv[1])
  70 + except IndexError:
  71 + sys.exit(__doc__)
  72 +
  73 + # parse and display metadata:
  74 + meta = ole.get_metadata()
  75 +
  76 + # console output with UTF8 encoding:
  77 + console_utf8 = codecs.getwriter('utf8')(sys.stdout)
  78 +
  79 + # TODO: move similar code to a function
  80 +
  81 + print('Properties from the SummaryInformation stream:')
  82 + t = tablestream.TableStream([21, 30], header_row=['Property', 'Value'], outfile=console_utf8)
  83 + for prop in meta.SUMMARY_ATTRIBS:
  84 + value = getattr(meta, prop)
  85 + if value is not None:
  86 + # TODO: pretty printing for strings, dates, numbers
  87 + # TODO: better unicode handling
  88 + # print('- %s: %s' % (prop, value))
  89 + if isinstance(value, unicode):
  90 + # encode to UTF8, avoiding errors
  91 + value = value.encode('utf-8', errors='replace')
  92 + else:
  93 + value = str(value)
  94 + t.write_row([prop, value], colors=[None, 'yellow'])
  95 + t.close()
  96 + print ''
  97 +
  98 + print('Properties from the DocumentSummaryInformation stream:')
  99 + t = tablestream.TableStream([21, 30], header_row=['Property', 'Value'], outfile=console_utf8)
  100 + for prop in meta.DOCSUM_ATTRIBS:
  101 + value = getattr(meta, prop)
  102 + if value is not None:
  103 + # TODO: pretty printing for strings, dates, numbers
  104 + # TODO: better unicode handling
  105 + # print('- %s: %s' % (prop, value))
  106 + if isinstance(value, unicode):
  107 + # encode to UTF8, avoiding errors
  108 + value = value.encode('utf-8', errors='replace')
  109 + else:
  110 + value = str(value)
  111 + t.write_row([prop, value], colors=[None, 'yellow'])
  112 + t.close()
  113 +
  114 + ole.close()
  115 +
  116 +if __name__ == '__main__':
  117 + main()
113 \ No newline at end of file 118 \ No newline at end of file
setup.py
@@ -271,8 +271,10 @@ entry_points = { @@ -271,8 +271,10 @@ entry_points = {
271 'oleid=oletools.oleid:main', 271 'oleid=oletools.oleid:main',
272 'oledir=oletools.oledir:main', 272 'oledir=oletools.oledir:main',
273 'olemap=oletools.olemap:main', 273 'olemap=oletools.olemap:main',
  274 + 'olemeta=oletools.olemeta:main',
274 'oletimes=oletools.oletimes:main', 275 'oletimes=oletools.oletimes:main',
275 'pyxswf=oletools.pyxswf:main', 276 'pyxswf=oletools.pyxswf:main',
  277 + 'ezhexviewer=oletools.ezhexviewer:main',
276 'rtfobj=oletools.rtfobj:main' 278 'rtfobj=oletools.rtfobj:main'
277 ], 279 ],
278 } 280 }