### 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
ifoutputfmt:
inputext=os.path.splitext(inputfn)[1]
inputfmt=fmts.byextension(inputext)
ifinputfmt:
forfmtinoutputfmt:
ifinputfmt[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
ifnotoutputfmt:
ifdoctype:
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)
returnoutputfmt
defconvert(self,inputfn):
globalexitcode
doc=None
outputfmt=self.getformat(inputfn)
ifop.verbose>0:
print>>sys.stderr,'Input file:',inputfn
ifnotos.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)
defmain():
globalconvertor,exitcode
try:
ifop.listener:
listener=Listener()
else:
convertor=Convertor()
forinputfninop.filenames:
convertor.convert(inputfn)
exceptNoConnectException,e:
error(0,"unoconv: could not find an existing connection to Open Office at %s:%s."%(op.server,op.port))
ifop.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.")
exceptOSError:
error(0,"Warning: failed to launch OpenOffice. Aborting.")