| |
78 |
def parseArgs():
|
| |
79 |
import sys
|
| |
80 |
from optparse import OptionParser
|
| |
81 |
|
| |
82 |
usage = "usage: %prog [options] [tmxpath]"
|
| |
83 |
|
| |
84 |
op = OptionParser(usage=usage)
|
| |
85 |
op.add_option('-s', '--slang',default = 'en',
|
| |
86 |
action='store', type='string', dest='slang',
|
| |
87 |
help='TM source language')
|
| |
88 |
op.add_option('-r', '--recursive',
|
| |
89 |
action='store_true', dest='recursive',
|
| |
90 |
help='Process files recursive.')
|
| |
91 |
op.add_option('-f', '--fmask',
|
| |
92 |
action='store', type='string', dest='fmask',
|
| |
93 |
help='File mask to use when running recursive.')
|
| |
94 |
op.add_option('-p', '--port',default=port,
|
| |
95 |
action='store', type='int', dest='port',
|
| |
96 |
help='Port to use.')
|
| |
97 |
|
| |
98 |
|
| |
99 |
options, args = op.parse_args(sys.argv[1:])
|
| |
100 |
try:
|
| |
101 |
pname = path(args[0])
|
| |
102 |
except IndexError,e:
|
| |
103 |
op.error("Invalid number if arguments, use -h for help")
|
| |
104 |
options.fnames = []
|
| |
105 |
else:
|
| |
106 |
if options.recursive:
|
| |
107 |
if not options.fmask:
|
| |
108 |
op.error("must give filemask option to when recurse")
|
| |
109 |
else:
|
| |
110 |
fnames = pname.walkfiles(options.fmask)
|
| |
111 |
else:
|
| |
112 |
if options.fmask:
|
| |
113 |
if not pname.isdir():
|
| |
114 |
op.error("must give a directory path when option fmask is given")
|
| |
115 |
else:
|
| |
116 |
fnames = pname.listdir(options.fmask)
|
| |
117 |
else:
|
| |
118 |
fnames = [path(f) for f in args]
|
| |
119 |
|
| |
120 |
options.fnames = fnames
|
| |
121 |
return options
|
| |
122 |
|
| |
123 |
from transolution.tmx import getTMXFromFile
|
| |
124 |
def importTMX(tmx,tmidx):
|
| |
125 |
## import codecs
|
| |
126 |
|
| |
127 |
tm = getTMXFromFile(tmx)
|
| |
128 |
totents = 0
|
| |
129 |
ents = 0
|
| |
130 |
for tu in tm.body.tus:
|
| |
131 |
try:
|
| |
132 |
key = tu.getKey(slang)
|
| |
133 |
except IndexError,e:
|
| |
134 |
continue
|
| |
135 |
val = ( getSeg(tu,slang), getSeg(tu,tlang) )
|
| |
136 |
tmidx.addItem(index.IndexItem(key,val))
|
| |
137 |
ents += 1
|
| |
138 |
if ents % 100 == 0:
|
| |
139 |
print ents
|
| |
140 |
print "Total TU's added:%d"%(ents,)
|
| |
141 |
del tm
|
| |
142 |
return tmidx
|
| |
143 |
|
| |
144 |
def getSeg(tu,lang):
|
| |
145 |
for tuv in tu.tuvs:
|
| |
146 |
if tuv.lang == lang:
|
| |
147 |
return tuv.seg.node.cloneNode(True)
|