/usr/share/lokalize/scripts/odf/xliff2odf-standalone.py is in lokalize 4:15.12.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | # -*- coding: utf-8 -*-
import sys,os,re
if os.name=='nt': import socket # only needed on win32-OOo3.0.0
try: import uno
except:
#opensuse needs this, while debian rocks w/o this
sys.path.append('/usr/lib/ooo3/basis-link/program/')
import uno
import time
def show_in_ooo(odfpathname,entryid):
if len(odfpathname)==0: return
def establish_connection():
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )
return resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
try: ctx = establish_connection()
except:
os.system('soffice "-accept=socket,host=localhost,port=2002;urp;"')
for c in range(30):
time.sleep(1) #sleeps rule )))
try:ctx = establish_connection()
except: continue
break
print "file://"+odfpathname
desktop = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model = desktop.loadComponentFromURL( "file://"+odfpathname,"_default", 0, () )
dispatcher = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.frame.DispatchHelper",ctx)
dispatcher.executeDispatch(model.getCurrentController().getFrame(),".uno:Reload","",0,())
model = desktop.loadComponentFromURL( "file://"+odfpathname,"_default", 0, () )
#model = desktop.getCurrentComponent()
cursor = model.Text.createTextCursor()
cursor.gotoStart(False)
try:
print entryid
#office:document-content[0]/office:body[0]/office:text[0]/text:h[0]
standardstart='office:document-content[0]/office:body[0]/office:text[0]/'
if entryid.startswith(standardstart): entryid=entryid[len(standardstart):]
else: print 'non-standard start: %s' % entryid
numre=re.compile('\\[([0-9]*)\\]')
elemre=re.compile(':([^\\[]*)\\[')
tableprops={}
for pathcomponent in entryid.split('/'):
paranum=int(numre.search(pathcomponent).group(1))
elem=elemre.search(pathcomponent).group(1)
if pathcomponent.startswith('text'):
if elem=='p':
#office:document-content[0]/office:body[0]/office:text[0]/text:p[0]
for i in range(paranum): cursor.gotoNextParagraph(False)
elif pathcomponent.startswith('table'):
#office:document-content[0]/office:body[0]/office:text[0]/table:table[0]/table:table-row[0]/table:table-cell[0]/text:p[0]
tableprops[elem]=paranum
if len(tableprops.keys())==3:
cell=model.getTextTables().getByIndex(tableprops['table']).getCellByPosition(tableprops['table-cell'],tableprops['table-row'])
tableprops={}
cursor=cell.Text.createTextCursor()
cursor.gotoStart(False)
c=model.getCurrentController().getViewCursor()
c.gotoRange(cursor,False)
except:
print 'error determining pos'
#return ctx
ctx.ServiceManager
def main(argv=None):
odfpathname=argv[1]
entryid=argv[2]
show_in_ooo(odfpathname,entryid)
if __name__ == '__main__':
main(sys.argv)
|