Editorial changes & Fixes from QuLogic

This commit is contained in:
Sam Manzi 2016-04-19 09:15:05 +10:00
parent 5dc5615bfd
commit 3f86dd3e25
No known key found for this signature in database
GPG Key ID: F4A16068AE36B402
3 changed files with 76 additions and 93 deletions

View File

@ -219,7 +219,6 @@ class DbState(Callback):
fname = os.path.join(dirpath, "lock") fname = os.path.join(dirpath, "lock")
with open(fname, 'r', encoding='utf8') as ifile: with open(fname, 'r', encoding='utf8') as ifile:
locked_by = ifile.read().strip() locked_by = ifile.read().strip()
ifile.close()
except (OSError, IOError): except (OSError, IOError):
pass pass
return (dirpath, locked, locked_by, backend) return (dirpath, locked, locked_by, backend)

View File

@ -436,7 +436,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
def __log_error(self): def __log_error(self):
mypath = os.path.join(self.get_save_path(),DBRECOVFN) mypath = os.path.join(self.get_save_path(),DBRECOVFN)
with open(mypath, "w") as ofile: ofile = open(mypath, "w")
ofile.close()
try: try:
clear_lock_file(self.get_save_path()) clear_lock_file(self.get_save_path())
except: except:

View File

@ -37,11 +37,11 @@ Examples:
python update_po.py -p python update_po.py -p
Generates a new template/catalog (gramps.pot). Generates a new template/catalog (gramps.pot).
python update_po.py -m de.po python update_po.py -m de.po
Merges 'de.po' file with 'gramps.pot'. Merges 'de.po' file with 'gramps.pot'.
python update_po.py -k de.po python update_po.py -k de.po
Checks 'de.po' file, tests to compile and generates a textual resume. Checks 'de.po' file, tests to compile and generates a textual resume.
@ -55,7 +55,7 @@ from argparse import ArgumentParser
# Windows OS # Windows OS
if sys.platform == 'win32': if sys.platform == 'win32':
# GetText Win 32 obtained from http://gnuwin32.sourceforge.net/packages/gettext.htm # GetText Win 32 obtained from http://gnuwin32.sourceforge.net/packages/gettext.htm
# ....\gettext\bin\msgmerge.exe needs to be on the path # ....\gettext\bin\msgmerge.exe needs to be on the path
msgmergeCmd = os.path.join('C:', 'Program Files(x86)', 'gettext', 'bin', 'msgmerge.exe') msgmergeCmd = os.path.join('C:', 'Program Files(x86)', 'gettext', 'bin', 'msgmerge.exe')
@ -96,67 +96,64 @@ def tests():
print ("\n====='msgmerge'=(merge our translation)================\n") print ("\n====='msgmerge'=(merge our translation)================\n")
os.system('''%(program)s -V''' % {'program': msgmergeCmd}) os.system('''%(program)s -V''' % {'program': msgmergeCmd})
except: except:
print ('Please, install %(program)s for updating your translation' print ('Please, install %(program)s for updating your translation'
% {'program': msgmergeCmd}) % {'program': msgmergeCmd})
try: try:
print ("\n==='msgfmt'=(format our translation for installation)==\n") print ("\n==='msgfmt'=(format our translation for installation)==\n")
os.system('''%(program)s -V''' % {'program': msgfmtCmd}) os.system('''%(program)s -V''' % {'program': msgfmtCmd})
except: except:
print ('Please, install %(program)s for checking your translation' print ('Please, install %(program)s for checking your translation'
% {'program': msgfmtCmd}) % {'program': msgfmtCmd})
try: try:
print ("\n===='msgattrib'==(list groups of messages)=============\n") print ("\n===='msgattrib'==(list groups of messages)=============\n")
os.system('''%(program)s -V''' % {'program': msgattribCmd}) os.system('''%(program)s -V''' % {'program': msgattribCmd})
except: except:
print ('Please, install %(program)s for listing groups of messages' print ('Please, install %(program)s for listing groups of messages'
% {'program': msgattribCmd}) % {'program': msgattribCmd})
try: try:
print("\n===='xgettext' =(generate a new template)==============\n") print("\n===='xgettext' =(generate a new template)==============\n")
os.system('''%(program)s -V''' % {'program': xgettextCmd}) os.system('''%(program)s -V''' % {'program': xgettextCmd})
except: except:
print ('Please, install %(program)s for generating a new template' print ('Please, install %(program)s for generating a new template'
% {'program': xgettextCmd}) % {'program': xgettextCmd})
try: try:
print("\n=================='python'=============================\n") print("\n=================='python'=============================\n")
os.system('''%(program)s -V''' % {'program': pythonCmd}) os.system('''%(program)s -V''' % {'program': pythonCmd})
except: except:
print ('Please, install python') print ('Please, install python')
def TipsParse(filename, mark): def TipsParse(filename, mark):
""" """
Experimental alternative to 'intltool-extract' for 'tips.xml'. Experimental alternative to 'intltool-extract' for 'tips.xml'.
""" """
from xml.etree import ElementTree from xml.etree import ElementTree
tree = ElementTree.parse(filename) tree = ElementTree.parse(filename)
root = tree.getroot() root = tree.getroot()
''' '''
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<tips> <tips>
<_tip number="1"> <_tip number="1">
<b>Working with Dates</b> <b>Working with Dates</b>
<br/> <br/>
A range of dates can be given by using the format &quot;between A range of dates can be given by using the format &quot;between
January 4, 2000 and March 20, 2003&quot;. You can also indicate January 4, 2000 and March 20, 2003&quot;. You can also indicate
the level of confidence in a date and even choose between seven the level of confidence in a date and even choose between seven
different calendars. Try the button next to the date field in the different calendars. Try the button next to the date field in the
Events Editor. Events Editor.
</_tip> </_tip>
char *s = N_("<b>Working with Dates</b><br/>A range of dates can be char *s = N_("<b>Working with Dates</b><br/>A range of dates can be
given by using the format &quot;between January 4, 2000 and March 20, given by using the format &quot;between January 4, 2000 and March 20,
2003&quot;. You can also indicate the level of confidence in a date 2003&quot;. You can also indicate the level of confidence in a date
and even choose between seven different calendars. Try the button and even choose between seven different calendars. Try the button
next to the date field in the Events Editor."); next to the date field in the Events Editor.");
gramps.pot: gramps.pot:
msgid "" msgid ""
"<b>Working with Dates</b><br/>A range of dates can be given by using the " "<b>Working with Dates</b><br/>A range of dates can be given by using the "
@ -165,7 +162,7 @@ def TipsParse(filename, mark):
"different calendars. Try the button next to the date field in the Events " "different calendars. Try the button next to the date field in the Events "
"Editor." "Editor."
''' '''
with open('../data/tips.xml.in.h', 'w') as tips: with open('../data/tips.xml.in.h', 'w') as tips:
marklist = root.iter(mark) marklist = root.iter(mark)
for key in marklist: for key in marklist:
@ -184,14 +181,13 @@ def TipsParse(filename, mark):
tips.write('char *s = N_("%s");\n' % tip) tips.write('char *s = N_("%s");\n' % tip)
print ('Wrote ../data/tips.xml.in.h') print ('Wrote ../data/tips.xml.in.h')
root.clear() root.clear()
def HolidaysParse(filename, mark): def HolidaysParse(filename, mark):
""" """
Experimental alternative to 'intltool-extract' for 'holidays.xml'. Experimental alternative to 'intltool-extract' for 'holidays.xml'.
""" """
from xml.etree import ElementTree from xml.etree import ElementTree
tree = ElementTree.parse(filename) tree = ElementTree.parse(filename)
root = tree.getroot() root = tree.getroot()
ellist = root.iter() ellist = root.iter()
@ -203,17 +199,16 @@ def HolidaysParse(filename, mark):
.. ..
<country _name="Jewish Holidays"> <country _name="Jewish Holidays">
<date _name="Yom Kippur" value="> passover(y)" offset="172"/> <date _name="Yom Kippur" value="> passover(y)" offset="172"/>
char *s = N_("Bulgaria"); char *s = N_("Bulgaria");
char *s = N_("Jewish Holidays"); char *s = N_("Jewish Holidays");
char *s = N_("Yom Kippur"); char *s = N_("Yom Kippur");
gramps.pot: gramps.pot:
msgid "Bulgaria" msgid "Bulgaria"
msgid "Jewish Holidays" msgid "Jewish Holidays"
msgid "Yom Kippur" msgid "Yom Kippur"
''' '''
with open('../data/holidays.xml.in.h', 'w') as holidays: with open('../data/holidays.xml.in.h', 'w') as holidays:
for key in ellist: for key in ellist:
if key.attrib.get(mark): if key.attrib.get(mark):
@ -230,12 +225,11 @@ def XmlParse(filename, mark):
""" """
Experimental alternative to 'intltool-extract' for 'file.xml.in'. Experimental alternative to 'intltool-extract' for 'file.xml.in'.
""" """
from xml.etree import ElementTree from xml.etree import ElementTree
tree = ElementTree.parse(filename) tree = ElementTree.parse(filename)
root = tree.getroot() root = tree.getroot()
''' '''
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
@ -250,18 +244,17 @@ def XmlParse(filename, mark):
<glob pattern="*.gedcom"/> <glob pattern="*.gedcom"/>
<glob pattern="*.GED"/> <glob pattern="*.GED"/>
<glob pattern="*.GEDCOM"/> <glob pattern="*.GEDCOM"/>
msgid "Gramps database" msgid "Gramps database"
msgid "GEDCOM" msgid "GEDCOM"
<_p> Gramps is a free software project and community. <_p> Gramps is a free software project and community.
We strive to produce a genealogy program that is both intuitive for hobbyists We strive to produce a genealogy program that is both intuitive for hobbyists
and feature-complete for professional genealogists. and feature-complete for professional genealogists.
</p> </p>
''' '''
with open(filename + '.h', 'w') as head:
with open(filename + '.h', 'w') as head:
for key in root.iter(): for key in root.iter():
if key.tag == '{http://www.freedesktop.org/standards/shared-mime-info}%s' % mark: if key.tag == '{http://www.freedesktop.org/standards/shared-mime-info}%s' % mark:
comment = 'char *s = N_("%s");\n' % key.text comment = 'char *s = N_("%s");\n' % key.text
@ -276,20 +269,19 @@ def XmlParse(filename, mark):
print ('Wrote %s' % filename) print ('Wrote %s' % filename)
root.clear() root.clear()
def DesktopParse(filename): def DesktopParse(filename):
""" """
Experimental alternative to 'intltool-extract' for 'gramps.desktop'. Experimental alternative to 'intltool-extract' for 'gramps.desktop'.
""" """
''' '''
[Desktop Entry] [Desktop Entry]
_Name=Gramps _Name=Gramps
_GenericName=Genealogy System _GenericName=Genealogy System
_X-GNOME-FullName=Gramps Genealogy System _X-GNOME-FullName=Gramps Genealogy System
_Comment=Manage genealogical information, _Comment=Manage genealogical information,
perform genealogical research and analysis perform genealogical research and analysis
msgid "Gramps" msgid "Gramps"
msgid "Genealogy System" msgid "Genealogy System"
msgid "Gramps Genealogy System" msgid "Gramps Genealogy System"
@ -297,7 +289,6 @@ def DesktopParse(filename):
"Manage genealogical information, "Manage genealogical information,
perform genealogical research and analysis" perform genealogical research and analysis"
''' '''
with open('../data/gramps.desktop.in.h', 'w') as desktop: with open('../data/gramps.desktop.in.h', 'w') as desktop:
with open(filename) as f: with open(filename) as f:
@ -316,7 +307,7 @@ def KeyParse(filename, mark):
""" """
Experimental alternative to 'intltool-extract' for 'gramps.keys'. Experimental alternative to 'intltool-extract' for 'gramps.keys'.
""" """
''' '''
application/x-gramps-xml: application/x-gramps-xml:
_description=Gramps XML database _description=Gramps XML database
@ -332,11 +323,10 @@ def KeyParse(filename, mark):
application/x-gedcom: application/x-gedcom:
_description=GEDCOM _description=GEDCOM
default_action_type=application default_action_type=application
msgid "Gramps XML database" msgid "Gramps XML database"
msgid "GEDCOM" msgid "GEDCOM"
''' '''
with open('../data/gramps.keys.in.h', 'w') as key: with open('../data/gramps.keys.in.h', 'w') as key:
with open(filename) as f: with open(filename) as f:
@ -362,15 +352,15 @@ def main():
The utility for handling translation stuff. The utility for handling translation stuff.
What is need by Gramps, nothing more. What is need by Gramps, nothing more.
""" """
parser = ArgumentParser( parser = ArgumentParser(
description='This program generates a new template and ' description='This program generates a new template and '
'also provides some common features.', 'also provides some common features.',
) )
parser.add_argument("-t", "--test", parser.add_argument("-t", "--test",
action="store_true", dest="test", default=True, action="store_true", dest="test", default=True,
help="test if 'python' and 'gettext' are properly installed") help="test if 'python' and 'gettext' are properly installed")
parser.add_argument("-x", "--xml", parser.add_argument("-x", "--xml",
action="store_true", dest="xml", default=False, action="store_true", dest="xml", default=False,
help="extract messages from xml based file formats") help="extract messages from xml based file formats")
@ -383,76 +373,75 @@ def main():
parser.add_argument("-p", "--pot", parser.add_argument("-p", "--pot",
action="store_true", dest="catalog", default=False, action="store_true", dest="catalog", default=False,
help="create a new catalog") help="create a new catalog")
update = parser.add_argument_group('Update', 'Maintenance around translations') update = parser.add_argument_group('Update', 'Maintenance around translations')
# need at least one argument (sv.po, de.po, etc ...) # need at least one argument (sv.po, de.po, etc ...)
# lang.po files maintenance # lang.po files maintenance
update.add_argument("-m", dest="merge", update.add_argument("-m", dest="merge",
choices=LANG, choices=LANG,
help="merge lang.po files with last catalog") help="merge lang.po files with last catalog")
update.add_argument("-k", dest="check", update.add_argument("-k", dest="check",
choices=LANG, choices=LANG,
help="check lang.po files") help="check lang.po files")
# testing stage # testing stage
trans = parser.add_argument_group('Translation', 'Display content of translations file') trans = parser.add_argument_group('Translation', 'Display content of translations file')
# need one argument (eg, de.po) # need one argument (eg, de.po)
trans.add_argument("-u", dest="untranslated", trans.add_argument("-u", dest="untranslated",
choices=[file for file in os.listdir('.') if file.endswith('.po')], choices=[file for file in os.listdir('.') if file.endswith('.po')],
help="list untranslated messages") help="list untranslated messages")
trans.add_argument("-f", dest="fuzzy", trans.add_argument("-f", dest="fuzzy",
choices=[file for file in os.listdir('.') if file.endswith('.po')], choices=[file for file in os.listdir('.') if file.endswith('.po')],
help="list fuzzy messages") help="list fuzzy messages")
args = parser.parse_args() args = parser.parse_args()
namespace, extra = parser.parse_known_args() namespace, extra = parser.parse_known_args()
if args.test: if args.test:
tests() tests()
if args.xml: if args.xml:
extract_xml() extract_xml()
if args.glade: if args.glade:
create_filesfile() create_filesfile()
extract_glade() extract_glade()
if os.path.isfile('tmpfiles'): if os.path.isfile('tmpfiles'):
os.unlink('tmpfiles') os.unlink('tmpfiles')
if args.catalog: if args.catalog:
retrieve() retrieve()
if args.clean: if args.clean:
clean() clean()
if args.merge: if args.merge:
#retrieve() windows os? #retrieve() windows os?
if sys.argv[2:] == ['all']: if sys.argv[2:] == ['all']:
sys.argv[2:] = LANG sys.argv[2:] = LANG
merge(sys.argv[2:]) merge(sys.argv[2:])
if args.check: if args.check:
#retrieve() windows os? #retrieve() windows os?
if sys.argv[2:] == ['all']: if sys.argv[2:] == ['all']:
sys.argv[2:] = LANG sys.argv[2:] = LANG
check(sys.argv[2:]) check(sys.argv[2:])
if args.untranslated: if args.untranslated:
untranslated(sys.argv[2:]) untranslated(sys.argv[2:])
if args.fuzzy: if args.fuzzy:
fuzzy(sys.argv[2:]) fuzzy(sys.argv[2:])
def create_filesfile(): def create_filesfile():
""" """
Create a file with all files that we should translate. Create a file with all files that we should translate.
These are all python files not in POTFILES.skip added with those in These are all python files not in POTFILES.skip added with those in
POTFILES.in POTFILES.in
""" """
dir = os.getcwd() dir = os.getcwd()
@ -480,7 +469,7 @@ def create_filesfile():
# if the directory does not exist or is a link, do nothing # if the directory does not exist or is a link, do nothing
if not os.path.isdir(dirpath) or os.path.islink(dirpath): if not os.path.isdir(dirpath) or os.path.islink(dirpath):
continue continue
for filename in os.listdir(dirpath): for filename in os.listdir(dirpath):
name = os.path.split(filename)[1] name = os.path.split(filename)[1]
if name.endswith('.py') or name.endswith('.glade'): if name.endswith('.py') or name.endswith('.glade'):
@ -505,7 +494,6 @@ def listing(name, extensionlist):
files = [file.strip() for file in f if file and not file[0]=='#'] files = [file.strip() for file in f if file and not file[0]=='#']
with open(name, 'w') as temp: with open(name, 'w') as temp:
for entry in files: for entry in files:
for ext in extensionlist: for ext in extensionlist:
if entry.endswith(ext): if entry.endswith(ext):
@ -516,7 +504,7 @@ def listing(name, extensionlist):
def headers(): def headers():
""" """
Look at existing C file format headers. Look at existing C file format headers.
Generated by 'intltool-extract' but want to get rid of this Generated by 'intltool-extract' but want to get rid of this
dependency (perl, just a set of tools). dependency (perl, just a set of tools).
""" """
headers = [] headers = []
@ -536,7 +524,7 @@ def headers():
headers.append('''../data/gramps.appdata.xml.in.h''') headers.append('''../data/gramps.appdata.xml.in.h''')
if os.path.isfile('''gtklist.h'''): if os.path.isfile('''gtklist.h'''):
headers.append('''gtklist.h''') headers.append('''gtklist.h''')
return headers return headers
def extract_xml(): def extract_xml():
@ -544,7 +532,6 @@ def extract_xml():
Extract translation strings from XML based, keys, mime and desktop Extract translation strings from XML based, keys, mime and desktop
files. Own XML files parsing and custom translation marks. files. Own XML files parsing and custom translation marks.
""" """
HolidaysParse('../data/holidays.xml.in', '_name') HolidaysParse('../data/holidays.xml.in', '_name')
TipsParse('../data/tips.xml.in', '_tip') TipsParse('../data/tips.xml.in', '_tip')
XmlParse('../data/gramps.xml.in', '_comment') XmlParse('../data/gramps.xml.in', '_comment')
@ -557,6 +544,7 @@ def create_template():
Create a new file for template, if it does not exist. Create a new file for template, if it does not exist.
""" """
with open('gramps.pot', 'w') as template: with open('gramps.pot', 'w') as template:
pass
def extract_glade(): def extract_glade():
""" """
@ -577,9 +565,9 @@ def extract_gtkbuilder():
https://savannah.gnu.org/bugs/index.php?29216 https://savannah.gnu.org/bugs/index.php?29216
See bug reports #6595, #5621 See bug reports #6595, #5621
""" """
from xml.etree import ElementTree from xml.etree import ElementTree
''' '''
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
@ -602,7 +590,7 @@ def extract_gtkbuilder():
</row> </row>
</data> </data>
</object> </object>
msgid "All rules must apply" msgid "All rules must apply"
msgid "At least one rule must apply" msgid "At least one rule must apply"
msgid "Exactly one rule must apply" msgid "Exactly one rule must apply"
@ -610,7 +598,6 @@ def extract_gtkbuilder():
files = ['../gramps/plugins/importer/importgedcom.glade', '../gramps/gui/glade/rule.glade'] files = ['../gramps/plugins/importer/importgedcom.glade', '../gramps/gui/glade/rule.glade']
with open('gtklist.h', 'w') as temp: with open('gtklist.h', 'w') as temp:
for filename in files: for filename in files:
tree = ElementTree.parse(filename) tree = ElementTree.parse(filename)
root = tree.getroot() root = tree.getroot()
@ -628,14 +615,14 @@ def retrieve():
Extract messages from all files used by Gramps (python, glade, xml) Extract messages from all files used by Gramps (python, glade, xml)
""" """
extract_xml() extract_xml()
extract_gtkbuilder() extract_gtkbuilder()
create_template() create_template()
create_filesfile() create_filesfile()
listing('python.txt', ['.py', '.py.in']) listing('python.txt', ['.py', '.py.in'])
# additional keywords must always be kept in sync with those in genpot.sh # additional keywords must always be kept in sync with those in genpot.sh
os.system('''%(xgettext)s -F -c -j --directory=./ -d gramps ''' os.system('''%(xgettext)s -F -c -j --directory=./ -d gramps '''
'''-L Python -o gramps.pot --files-from=python.txt ''' '''-L Python -o gramps.pot --files-from=python.txt '''
@ -643,14 +630,14 @@ def retrieve():
'''--keyword=_T_ --keyword=trans_text ''' '''--keyword=_T_ --keyword=trans_text '''
'''--keyword=sgettext --from-code=UTF-8''' % {'xgettext': xgettextCmd} '''--keyword=sgettext --from-code=UTF-8''' % {'xgettext': xgettextCmd}
) )
extract_glade() extract_glade()
# C format header (.h extension) # C format header (.h extension)
for h in headers(): for h in headers():
print ('xgettext for %s' % h) print ('xgettext for %s' % h)
os.system('''%(xgettext)s -F --add-comments -j -o gramps.pot ''' os.system('''%(xgettext)s -F --add-comments -j -o gramps.pot '''
'''--keyword=N_ --from-code=UTF-8 %(head)s''' '''--keyword=N_ --from-code=UTF-8 %(head)s'''
% {'xgettext': xgettextCmd, 'head': h} % {'xgettext': xgettextCmd, 'head': h}
) )
clean() clean()
@ -680,10 +667,9 @@ def merge(args):
""" """
Merge messages with 'gramps.pot' Merge messages with 'gramps.pot'
""" """
for arg in args: for arg in args:
if arg == 'all': if arg == 'all':
continue continue
print ('Merge %(lang)s with current template' % {'lang': arg}) print ('Merge %(lang)s with current template' % {'lang': arg})
os.system('''%(msgmerge)s %(lang)s gramps.pot -o updated_%(lang)s''' \ os.system('''%(msgmerge)s %(lang)s gramps.pot -o updated_%(lang)s''' \
% {'msgmerge': msgmergeCmd, 'lang': arg}) % {'msgmerge': msgmergeCmd, 'lang': arg})
@ -693,7 +679,6 @@ def check(args):
""" """
Check the translation file Check the translation file
""" """
for arg in args: for arg in args:
if arg == 'all': if arg == 'all':
continue continue
@ -708,14 +693,12 @@ def untranslated(arg):
""" """
List untranslated messages List untranslated messages
""" """
os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]}) os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]})
def fuzzy(arg): def fuzzy(arg):
""" """
List fuzzy messages List fuzzy messages
""" """
os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]}) os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]})
if __name__ == "__main__": if __name__ == "__main__":