Convert to Python 3

This commit is contained in:
Bradley M. Kuhn 2015-12-21 23:57:18 -08:00
parent ff1d7beba2
commit 8852595327
2 changed files with 19 additions and 19 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# ods2xls.py # ods2xls.py
# adapted from ssconv.py # adapted from ssconv.py
# see also # see also
@ -6,7 +6,7 @@
# http://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options # http://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
# http://linuxsleuthing.blogspot.com/2012/01/unoconv-is-number-one.html # http://linuxsleuthing.blogspot.com/2012/01/unoconv-is-number-one.html
# #
# Copyright © 2013, Tom Marble. # Copyright (C) 2013, Tom Marble.
# #
# This software's license gives you freedom; you can copy, convey, # This software's license gives you freedom; you can copy, convey,
# propogate, redistribute and/or modify this program under the terms of # propogate, redistribute and/or modify this program under the terms of
@ -86,13 +86,13 @@ if __name__ == "__main__":
ooutils.oo_shutdown_if_running() ooutils.oo_shutdown_if_running()
else: else:
if len(argv) < 2: if len(argv) < 2:
print "USAGE:" print("USAGE:")
print " python %s INPUT-FILE [INPUT-FILE ...]" % argv[0] print(" python %s INPUT-FILE [INPUT-FILE ...]" % argv[0])
print "OR" print("OR")
print " python %s --shutdown" % argv[0] print(" python %s --shutdown" % argv[0])
exit(255) exit(255)
if not isfile(argv[1]): if not isfile(argv[1]):
print "File not found: %s" % argv[1] print("File not found: %s" % argv[1])
exit(1) exit(1)
try: try:
@ -101,10 +101,10 @@ if __name__ == "__main__":
while i < len(argv): while i < len(argv):
odsname = argv[i] odsname = argv[i]
xlsname = odsname.replace('.ods', '.xls') xlsname = odsname.replace('.ods', '.xls')
print '%s => %s' % (odsname, xlsname) print('%s => %s' % (odsname, xlsname))
converter.convert(odsname, xlsname) converter.convert(odsname, xlsname)
i += 1 i += 1
except ErrorCodeIOException, exception: except ErrorCodeIOException as exception:
print "ERROR! ErrorCodeIOException %d" % exception.ErrCode print("ERROR! ErrorCodeIOException %d" % exception.ErrCode)
exit(1) exit(1)

View file

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# ooutils.py # ooutils.py
# from http://www.linuxjournal.com/node/1007788 # from http://www.linuxjournal.com/node/1007788
@ -83,12 +83,12 @@ class OORunner:
n += 1 n += 1
if not context: if not context:
raise Exception, "Failed to connect to OpenOffice on port %d" % self.port raise Exception("Failed to connect to OpenOffice on port %d" % self.port)
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context) desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
if not desktop: if not desktop:
raise Exception, "Failed to create OpenOffice desktop on port %d" % self.port raise Exception("Failed to create OpenOffice desktop on port %d" % self.port)
if did_start: if did_start:
_started_desktops[self.port] = desktop _started_desktops[self.port] = desktop
@ -113,11 +113,11 @@ class OORunner:
try: try:
pid = os.spawnve(os.P_NOWAIT, args[0], args, env) pid = os.spawnve(os.P_NOWAIT, args[0], args, env)
except Exception, e: except Exception as e:
raise Exception, "Failed to start OpenOffice on port %d: %s" % (self.port, e.message) raise Exception("Failed to start OpenOffice on port %d: %s" % (self.port, e.message))
if pid <= 0: if pid <= 0:
raise Exception, "Failed to start OpenOffice on port %d" % self.port raise Exception("Failed to start OpenOffice on port %d" % self.port)
def shutdown(self): def shutdown(self):
@ -128,7 +128,7 @@ class OORunner:
if _started_desktops.get(self.port): if _started_desktops.get(self.port):
_started_desktops[self.port].terminate() _started_desktops[self.port].terminate()
del _started_desktops[self.port] del _started_desktops[self.port]
except Exception, e: except Exception as e:
pass pass
@ -142,7 +142,7 @@ def _shutdown_desktops():
try: try:
if desktop: if desktop:
desktop.terminate() desktop.terminate()
except Exception, e: except Exception as e:
pass pass
@ -155,7 +155,7 @@ def oo_shutdown_if_running(port=OPENOFFICE_PORT):
try: try:
desktop = oorunner.connect(no_startup=True) desktop = oorunner.connect(no_startup=True)
desktop.terminate() desktop.terminate()
except Exception, e: except Exception as e:
pass pass