Fixed broken parsing of glade files
svn: r1298
This commit is contained in:
parent
8092878181
commit
ef14a02023
@ -90,6 +90,7 @@ filtersDir = "%s/filters" % rootDir
|
|||||||
dataDir = "%s/data" % rootDir
|
dataDir = "%s/data" % rootDir
|
||||||
gtkrcFile = "%s/gtkrc" % rootDir
|
gtkrcFile = "%s/gtkrc" % rootDir
|
||||||
template_dir = "%s/templates" % dataDir
|
template_dir = "%s/templates" % dataDir
|
||||||
|
fdl = "%s/fdl.txt" % dataDir
|
||||||
|
|
||||||
startup = 1
|
startup = 1
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ filtersDir = "%s/filters" % rootDir
|
|||||||
dataDir = "%s/data" % rootDir
|
dataDir = "%s/data" % rootDir
|
||||||
gtkrcFile = "%s/gtkrc" % rootDir
|
gtkrcFile = "%s/gtkrc" % rootDir
|
||||||
template_dir = "%s/templates" % dataDir
|
template_dir = "%s/templates" % dataDir
|
||||||
|
fdl = "%s/fdl.txt" % dataDir
|
||||||
|
|
||||||
startup = 1
|
startup = 1
|
||||||
|
|
||||||
|
119
src/get_strings
119
src/get_strings
@ -116,10 +116,11 @@ import getopt
|
|||||||
import tokenize
|
import tokenize
|
||||||
import operator
|
import operator
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
|
import os
|
||||||
|
|
||||||
from xml.sax import make_parser,handler,SAXParseException
|
from xml.sax import make_parser,handler,SAXParseException
|
||||||
|
|
||||||
|
|
||||||
intRe = re.compile("^\d+$")
|
intRe = re.compile("^\d+$")
|
||||||
|
|
||||||
_ignore = {
|
_ignore = {
|
||||||
@ -137,90 +138,76 @@ __version__ = '1.4'
|
|||||||
default_keywords = ['_']
|
default_keywords = ['_']
|
||||||
EMPTYSTRING = ''
|
EMPTYSTRING = ''
|
||||||
|
|
||||||
import sys
|
|
||||||
import string
|
|
||||||
import xmllib
|
|
||||||
|
|
||||||
class TranslatableStringParser(xmllib.XMLParser):
|
_int_re = re.compile("^\d+$")
|
||||||
|
_ignore = { ':' : 0, '*' : 0, }
|
||||||
|
|
||||||
|
class GladeExtractor:
|
||||||
|
|
||||||
def __init__(self,msgs):
|
def __init__(self,msgs):
|
||||||
xmllib.XMLParser.__init__(self)
|
|
||||||
self.filename = None
|
|
||||||
self.strings = msgs
|
self.strings = msgs
|
||||||
self.data = ""
|
|
||||||
|
|
||||||
def add_string(self, string):
|
def add_string(self, string, lineno):
|
||||||
if string == "":
|
if string == "":
|
||||||
return
|
return
|
||||||
if _ignore.has_key(string):
|
if _ignore.has_key(string):
|
||||||
return
|
return
|
||||||
entry = (self.filename, self.lineno)
|
entry = (self.file, lineno)
|
||||||
if self.strings.has_key(string):
|
if self.strings.has_key(string):
|
||||||
self.strings[string][entry] = 0
|
self.strings[string][entry] = 0
|
||||||
else:
|
else:
|
||||||
self.strings[string] = {entry: 0}
|
self.strings[string] = {entry: 0}
|
||||||
|
|
||||||
def read_file(self, filename):
|
def parse(self,file):
|
||||||
self.reset()
|
self.p = make_parser()
|
||||||
self.filename = filename
|
self.p.setContentHandler(GladeParser(self,file))
|
||||||
fp = open(filename, "r")
|
filename = "file://" + os.path.abspath(file)
|
||||||
data = fp.read(8192)
|
self.file = file
|
||||||
while data:
|
self.p.parse(filename)
|
||||||
self.feed(data)
|
|
||||||
data = fp.read(8192)
|
|
||||||
fp.close()
|
|
||||||
|
|
||||||
def syntax_error(self, message):
|
class GladeParser(handler.ContentHandler):
|
||||||
sys.stderr.write("%s:%d: %s\n" % (self.filename, self.lineno,
|
"""
|
||||||
message))
|
SAX parsing class for the StyleSheetList XML file.
|
||||||
sys.exit(1)
|
"""
|
||||||
|
|
||||||
|
def __init__(self,parent,filename):
|
||||||
|
"""
|
||||||
|
Creates a SheetParser class that populates the passed StyleSheetList
|
||||||
|
class.
|
||||||
|
|
||||||
def unknown_starttag(self, tag, attrs):
|
sheetlist - StyleSheetList instance to be loaded from the file.
|
||||||
self.data = ""
|
"""
|
||||||
|
|
||||||
def handle_data(self, data):
|
|
||||||
self.data = self.data + data
|
|
||||||
|
|
||||||
def translate_this_string(self):
|
|
||||||
if not intRe.match(self.data):
|
|
||||||
self.add_string(self.data)
|
|
||||||
|
|
||||||
# this list should include all tags for which translation should occur
|
|
||||||
end_label = translate_this_string
|
|
||||||
end_title = translate_this_string
|
|
||||||
end_text = translate_this_string
|
|
||||||
end_format = translate_this_string
|
|
||||||
end_copyright = translate_this_string
|
|
||||||
end_comments = translate_this_string
|
|
||||||
end_preview_text = translate_this_string
|
|
||||||
end_tooltip = translate_this_string
|
|
||||||
|
|
||||||
def end_items(self):
|
|
||||||
for item in string.split(self.data, '\n'):
|
|
||||||
self.add_string(item)
|
|
||||||
|
|
||||||
class XMLParser(handler.ContentHandler):
|
|
||||||
def __init__(self,name,msgs):
|
|
||||||
self.filename = name
|
|
||||||
self.strings = msgs
|
|
||||||
handler.ContentHandler.__init__(self)
|
handler.ContentHandler.__init__(self)
|
||||||
|
self.parent = parent
|
||||||
|
self.translate = 0
|
||||||
|
self.text = ""
|
||||||
|
self.filename = filename
|
||||||
|
self.lineno = 0
|
||||||
|
|
||||||
def startElement(self,tag,attrs):
|
def startElement(self,tag,attrs):
|
||||||
if tag == "filter":
|
"""
|
||||||
self.add_string(attrs['name'])
|
Overridden class that handles the start of a XML element
|
||||||
|
"""
|
||||||
|
if tag == "property":
|
||||||
|
if attrs.has_key('translatable'):
|
||||||
|
self.text = ""
|
||||||
|
if attrs['translatable'] == 'yes':
|
||||||
|
self.translate = 1
|
||||||
|
else:
|
||||||
|
self.translate = 0
|
||||||
|
|
||||||
|
def endElement(self,tag):
|
||||||
|
"Overridden class that handles the start of a XML element"
|
||||||
|
if self.translate:
|
||||||
|
if not _int_re.match(self.text):
|
||||||
|
self.parent.add_string(self.text, self.locator.getLineNumber())
|
||||||
|
self.translate = 0
|
||||||
|
|
||||||
def setDocumentLocator(self,locator):
|
def setDocumentLocator(self,locator):
|
||||||
self.locator = locator
|
self.locator = locator
|
||||||
|
|
||||||
def add_string(self, string):
|
def characters(self, data):
|
||||||
if string == "":
|
self.text = self.text + data
|
||||||
return
|
|
||||||
if _ignore.has_key(string):
|
|
||||||
return
|
|
||||||
entry = (self.filename, self.locator.getLineNumber())
|
|
||||||
if self.strings.has_key(string):
|
|
||||||
self.strings[string][entry] = 0
|
|
||||||
else:
|
|
||||||
self.strings[string] = {entry: 0}
|
|
||||||
|
|
||||||
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
|
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
|
||||||
# there.
|
# there.
|
||||||
@ -231,7 +218,7 @@ pot_header = _('''\
|
|||||||
#
|
#
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\\n"
|
"Project-Id-Version: GRAMPS VERSION\\n"
|
||||||
"POT-Creation-Date: %(time)s\\n"
|
"POT-Creation-Date: %(time)s\\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
|
||||||
@ -509,12 +496,12 @@ def main():
|
|||||||
|
|
||||||
# slurp through all the files
|
# slurp through all the files
|
||||||
eater = TokenEater(options)
|
eater = TokenEater(options)
|
||||||
p = TranslatableStringParser(eater.get_messages())
|
p = GladeExtractor(eater.get_messages())
|
||||||
|
|
||||||
for filename in args:
|
for filename in args:
|
||||||
if filename[-5:] == 'glade':
|
if filename[-5:] == 'glade':
|
||||||
print 'Working on %s' % filename
|
print 'Working on %s' % filename
|
||||||
p.read_file(filename)
|
p.parse(filename)
|
||||||
elif filename[-3:] == 'xml':
|
elif filename[-3:] == 'xml':
|
||||||
print 'Working on %s' % filename
|
print 'Working on %s' % filename
|
||||||
try:
|
try:
|
||||||
|
@ -356,10 +356,14 @@ class GedcomWriter:
|
|||||||
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport")
|
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport")
|
||||||
self.topDialog.signal_autoconnect({
|
self.topDialog.signal_autoconnect({
|
||||||
"destroy_passed_object" : Utils.destroy_passed_object,
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
||||||
|
"gnu_free" : self.gnu_free,
|
||||||
|
"standard_copyright" : self.standard_copyright,
|
||||||
|
"no_copyright" : self.no_copyright,
|
||||||
"on_ok_clicked" : self.on_ok_clicked
|
"on_ok_clicked" : self.on_ok_clicked
|
||||||
})
|
})
|
||||||
|
|
||||||
filter_obj = self.topDialog.get_widget("filter")
|
filter_obj = self.topDialog.get_widget("filter")
|
||||||
|
self.copy = 0
|
||||||
|
|
||||||
all = GenericFilter.GenericFilter()
|
all = GenericFilter.GenericFilter()
|
||||||
all.set_name(_("Entire Database"))
|
all.set_name(_("Entire Database"))
|
||||||
@ -402,6 +406,15 @@ class GedcomWriter:
|
|||||||
|
|
||||||
self.topDialog.get_widget("gedcomExport").show()
|
self.topDialog.get_widget("gedcomExport").show()
|
||||||
|
|
||||||
|
def gnu_free(self,obj):
|
||||||
|
self.copy = 1
|
||||||
|
|
||||||
|
def standard_copyright(self,obj):
|
||||||
|
self.copy = 0
|
||||||
|
|
||||||
|
def no_copyright(self,obj):
|
||||||
|
self.copy = 2
|
||||||
|
|
||||||
def on_ok_clicked(self,obj):
|
def on_ok_clicked(self,obj):
|
||||||
|
|
||||||
self.restrict = self.topDialog.get_widget("restrict").get_active()
|
self.restrict = self.topDialog.get_widget("restrict").get_active()
|
||||||
@ -489,14 +502,16 @@ class GedcomWriter:
|
|||||||
self.g.write("1 DEST %s\n" % self.dest)
|
self.g.write("1 DEST %s\n" % self.dest)
|
||||||
self.g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4]))
|
self.g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4]))
|
||||||
if self.cnvtxt == ansel_utf8.utf8_to_ansel:
|
if self.cnvtxt == ansel_utf8.utf8_to_ansel:
|
||||||
self.g.write("1 CHAR ANSEL\n");
|
self.g.write("1 CHAR ANSEL\n")
|
||||||
else:
|
else:
|
||||||
self.g.write("1 CHAR UTF-8\n");
|
self.g.write("1 CHAR UTF-8\n")
|
||||||
self.g.write("1 SUBM @SUBM@\n")
|
self.g.write("1 SUBM @SUBM@\n")
|
||||||
self.g.write("1 FILE %s\n" % filename)
|
self.g.write("1 FILE %s\n" % filename)
|
||||||
|
self.write_copy()
|
||||||
self.g.write("1 GEDC\n")
|
self.g.write("1 GEDC\n")
|
||||||
self.g.write("2 VERS 5.5\n")
|
self.g.write("2 VERS 5.5\n")
|
||||||
self.g.write('2 FORM LINEAGE-LINKED\n')
|
self.g.write('2 FORM LINEAGE-LINKED\n')
|
||||||
|
self.gnu_fdl()
|
||||||
self.g.write("0 @SUBM@ SUBM\n")
|
self.g.write("0 @SUBM@ SUBM\n")
|
||||||
owner = self.db.getResearcher()
|
owner = self.db.getResearcher()
|
||||||
if owner.getName():
|
if owner.getName():
|
||||||
@ -550,6 +565,38 @@ class GedcomWriter:
|
|||||||
self.g.write("0 TRLR\n")
|
self.g.write("0 TRLR\n")
|
||||||
self.g.close()
|
self.g.close()
|
||||||
|
|
||||||
|
def write_copy(self):
|
||||||
|
import time
|
||||||
|
|
||||||
|
t = time.localtime(time.time())
|
||||||
|
y = t[0]
|
||||||
|
|
||||||
|
if self.copy == 0:
|
||||||
|
o = self.db.getResearcher().getName()
|
||||||
|
self.g.write('1 COPR Copyright (c) %d %s.\n' % (y,o))
|
||||||
|
elif self.copy == 1:
|
||||||
|
o = self.db.getResearcher().getName()
|
||||||
|
self.g.write('1 COPR Copyright (c) %d %s. See additional copyright NOTE below.\n' % (y,o))
|
||||||
|
|
||||||
|
def gnu_fdl(self):
|
||||||
|
import time
|
||||||
|
|
||||||
|
if self.copy != 1:
|
||||||
|
return
|
||||||
|
|
||||||
|
t = time.localtime(time.time())
|
||||||
|
y = t[0]
|
||||||
|
o = self.db.getResearcher().getName()
|
||||||
|
|
||||||
|
self.g.write('1 NOTE Copyright (c) %d %s.\n' % (y,o))
|
||||||
|
try:
|
||||||
|
f = open(const.fdl,"r")
|
||||||
|
for line in f.readlines():
|
||||||
|
self.g.write('2 CONT %s' % line)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def write_families(self):
|
def write_families(self):
|
||||||
nump = float(len(self.flist))
|
nump = float(len(self.flist))
|
||||||
index = 0.0
|
index = 0.0
|
||||||
|
File diff suppressed because it is too large
Load Diff
2498
src/po/template.po
2498
src/po/template.po
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user