### If no doctype given, check list of acceptable formats for input file ext doctype
### FIXME: This should go into the for-loop to match each individual input filename
if outputfmt:
inputext = os.path.splitext(inputfn)[1]
inputfmt = fmts.byextension(inputext)
if inputfmt:
for fmt in outputfmt:
if inputfmt[0].doctype == fmt.doctype:
doctype = inputfmt[0].doctype
outputfmt = fmt
break
else:
outputfmt = outputfmt[0]
# print >>sys.stderr, 'unoconv: format `%s\' is part of multiple doctypes %s, selecting `%s\'.' % (format, [fmt.doctype for fmt in outputfmt], outputfmt[0].doctype)
else:
outputfmt = outputfmt[0]
### No format found, throw error
if not outputfmt:
if doctype:
print >>sys.stderr, 'unoconv: format [%s/%s] is not known to unoconv.' % (op.doctype, op.format)
else:
print >>sys.stderr, 'unoconv: format [%s] is not known to unoconv.' % op.format
die(1)
return outputfmt
def convert(self, inputfn):
global exitcode
doc = None
outputfmt = self.getformat(inputfn)
if op.verbose > 0:
print >>sys.stderr, 'Input file:', inputfn
if not os.path.exists(inputfn):
print >>sys.stderr, 'unoconv: file `%s\' does not exist.' % inputfn
# error(2, 'Taking down OpenOffice with pid %s.' % oopid)
# os.setpgid(oopid, 0)
# os.killpg(os.getpgid(oopid), 15)
# try:
# os.kill(oopid, 15)
# error(2, 'Waiting for OpenOffice with pid %s to disappear.' % oopid)
# os.waitpid(oopid, os.WUNTRACED)
# except:
# error(2, 'No OpenOffice with pid %s to take down' % oopid)
sys.exit(ret)
def main():
global convertor, exitcode
try:
if op.listener:
listener = Listener()
else:
convertor = Convertor()
for inputfn in op.filenames:
convertor.convert(inputfn)
except NoConnectException, e:
error(0, "unoconv: could not find an existing connection to Open Office at %s:%s." % (op.server, op.port))
if op.connection:
error(0, "Please start an OpenOffice instance on server '%s' by doing:\n\n unoconv --listener --server %s --port %s\n\nor alternatively:\n\n ooffice -nologo -nodefault -accept=\"%s\"" % (op.server, op.server, op.port, op.connection))
else:
error(0, "Please start an OpenOffice instance on server '%s' by doing:\n\n unoconv --listener --server %s --port %s\n\nor alternatively:\n\n ooffice -nologo -nodefault -accept=\"socket,host=%s,port=%s;urp;\"" % (op.server, op.server, op.port, op.server, op.port))
error(0, "Please start an ooffice instance on server '%s' by doing:\n\n ooffice -nologo -nodefault -accept=\"socket,host=localhost,port=%s;urp;\"" % (op.server, op.port))
exitcode = 1
# except UnboundLocalError:
# die(252, "Failed to connect to remote listener.")
except OSError:
error(0, "Warning: failed to launch OpenOffice. Aborting.")