From e978a43d3a36fdbd24dbea8b18ff6036dc9e8f71 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 24 Jun 2007 04:32:54 +0000 Subject: [PATCH] * src/LdsUtils.py: switch to parsing an external XML file instead of hard coded values * src/data/lds.xml: new file * src/data/Makefile.am: handle new lds.xml * src/Editors/_EditLdsOrd.py: handle new LDS temple scheme * src/GrampsDbUtils/_GedcomParse.py: handle new LDS temple scheme * DisplayTabs/_LdsModel.py: handle new LDS temple scheme 2007-06-23 Don Allingham svn: r8648 --- ChangeLog | 9 + TODO | 2 +- src/DisplayTabs/_LdsModel.py | 6 +- src/Editors/_EditLdsOrd.py | 12 +- src/GrampsDbUtils/_GedcomParse.py | 6 +- src/LdsUtils.py | 253 ++++++--------- src/data/Makefile.am | 1 + src/data/lds.xml | 490 ++++++++++++++++++++++++++++++ 8 files changed, 607 insertions(+), 172 deletions(-) create mode 100644 src/data/lds.xml diff --git a/ChangeLog b/ChangeLog index 7cbe83e1b..9f041380b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-06-23 Don Allingham + * src/LdsUtils.py: switch to parsing an external XML file instead of + hard coded values + * src/data/lds.xml: new file + * src/data/Makefile.am: handle new lds.xml + * src/Editors/_EditLdsOrd.py: handle new LDS temple scheme + * src/GrampsDbUtils/_GedcomParse.py: handle new LDS temple scheme + * DisplayTabs/_LdsModel.py: handle new LDS temple scheme + 2007-06-23 Don Allingham * src/Editors/_EditUrl.py: add jump button * src/DisplayTabs/_WebEmbedList.py: add jump button diff --git a/TODO b/TODO index a7dcd6106..5c5de4fda 100644 --- a/TODO +++ b/TODO @@ -49,7 +49,7 @@ http://sourceforge.net/mailarchive/forum.php?thread_id=3134931&forum_id=1993 for the details. -* Move LDS temple info out of const.py and into an XML file +* Move LDS temple info out of const.py and into an XML file: DONE * Make the descendant graph adapt to the page size, not stuck with the current 3 entries per page. diff --git a/src/DisplayTabs/_LdsModel.py b/src/DisplayTabs/_LdsModel.py index 5d2bde992..2281dd518 100644 --- a/src/DisplayTabs/_LdsModel.py +++ b/src/DisplayTabs/_LdsModel.py @@ -40,6 +40,7 @@ import gtk # #------------------------------------------------------------------------- import DateHandler +import LdsUtils #------------------------------------------------------------------------- # @@ -53,16 +54,13 @@ class LdsModel(gtk.ListStore): def __init__(self, lds_list, db): gtk.ListStore.__init__(self, str, str, str, str, str, object) - import LdsUtils - self.db = db for lds_ord in lds_list: self.append(row=[ lds_ord.type2str(), DateHandler.get_date(lds_ord), lds_ord.status2str(), - LdsUtils.temple_to_abrev.get(lds_ord.get_temple(), - _("unknown")), + LdsUtils.Temples.name(lds_ord.get_temple()), self.column_place(lds_ord), lds_ord, ]) diff --git a/src/Editors/_EditLdsOrd.py b/src/Editors/_EditLdsOrd.py index d1d7cb920..72f71f646 100644 --- a/src/Editors/_EditLdsOrd.py +++ b/src/Editors/_EditLdsOrd.py @@ -202,15 +202,11 @@ class EditLdsOrd(EditSecondary): self.db.readonly, changed=self.ord_type_changed) - temple_list = [] - for val in LdsUtils.temples: - temple_list.append((val[1],val[0])) - self.temple_menu = MonitoredStrMenu( self.top.get_widget('temple'), self.obj.set_temple, self.obj.get_temple, - temple_list, + LdsUtils.Temples.name_code_data(), self.db.readonly) self.status_menu = MonitoredMenu( @@ -387,15 +383,11 @@ class EditFamilyLdsOrd(EditSecondary): if item[0] in self._get_types()], self.db.readonly) - temple_list = [] - for val in LdsUtils.temples: - temple_list.append((val[1],val[0])) - self.temple_menu = MonitoredStrMenu( self.top.get_widget('temple'), self.obj.set_temple, self.obj.get_temple, - temple_list, + Ldsutils.Temples.name_code_data(), self.db.readonly) self.status_menu = MonitoredMenu( diff --git a/src/GrampsDbUtils/_GedcomParse.py b/src/GrampsDbUtils/_GedcomParse.py index d5ec1199a..44e195bd3 100644 --- a/src/GrampsDbUtils/_GedcomParse.py +++ b/src/GrampsDbUtils/_GedcomParse.py @@ -4456,10 +4456,10 @@ class GedcomParser(UpdateCallback): def extract_temple(self, line): def get_code(code): - if LdsUtils.temple_to_abrev.has_key(code): + if LdsUtils.Temples.is_valid_code(code): return code - elif LdsUtils.temple_codes.has_key(code): - return LdsUtils.temple_codes[code] + elif LdsUtils.Temples.is_valid_name(code): + return LdsUtils.Temples.code(code) code = get_code(line.data) if code: diff --git a/src/LdsUtils.py b/src/LdsUtils.py index 2f7788c84..cfbd177d1 100644 --- a/src/LdsUtils.py +++ b/src/LdsUtils.py @@ -20,160 +20,105 @@ # $Id$ -temples = ( - # Temple Name , Code , [Old Codes...] - ("Aba, Nigeria" , "ABA", ), - ("Accra, Ghana" , "ACCRA", ), - ("Adelaide, Australia" , "ADELA", ), - ("Albuquerque, New Mexico" , "ALBUQ", ), - ("Anchorage, Alaska" , "ANCHO", ), - ("Apia, Samoa" , "APIA", "SAMOA", "AP"), - ("Asuncion, Paraguay" , "ASUNC", ), - ("Atlanta, Georgia" , "ATLAN", "AT"), - ("Baton Rouge, Louisiana" , "BROUG", ), - ("Bern, Switzerland" , "SWISS", "SW"), - ("Billings, Montana" , "BILLI", ), - ("Birmingham, Alabama" , "BIRMI", ), - ("Bismarck, North Dakota" , "BISMA", ), - ("Bogota, Columbia" , "BOGOT", "BG"), - ("Boise, Idaho" , "BOISE", "BO"), - ("Boston, Massachusetts" , "BOSTO", ), - ("Bountiful, Utah" , "BOUNT", ), - ("Brisbane, Australia" , "BRISB", ), - ("Buenos Aires, Argentina" , "BAIRE", "BA"), - ("Campinas, Brazil" , "CAMPI", ), - ("Caracas, Venezuela" , "CARAC", ), - ("Cardston, Alberta" , "ALBER", "AL", "ALBR"), - ("Cebu, Philippines" , "CEBU", ), - ("Chicago, Illinois" , "CHICA", "CH"), - ("Ciudad Juarez, Mexico" , "CIUJU", ), - ("Cochabamba, Boliva" , "COCHA", ), - ("Colonia Juarez, Chihuahua, Mexico" , "COLJU", ), - ("Columbia, South Carolina" , "COLSC", ), - ("Columbia River, Washington" , "CRIVE", ), - ("Columbus, Ohio" , "COLUM", ), - ("Copenhagen, Denmark" , "COPEN", ), - ("Curitiba, Brazil" , "CURIT", ), - ("Dallas, Texas" , "DALLA", "DA"), - ("Denver, Colorado" , "DENVE", "DV"), - ("Detroit, Michigan" , "DETRO", ), - ("Draper, Utah" , "DRAPE", ), - ("Edmonton, Alberta" , "EDMON", ), - ("Frankfurt, Germany" , "FRANK", "FR"), - ("Freiberg, Germany" , "FREIB", "FD"), - ("Fresno, California" , "FRESN", ), - ("Fukuoka, Japan" , "FUKUO", ), - ("Guadalajara, Mexico" , "GUADA", ), - ("Guatemala City, Guatemala" , "GUATE", "GA", "GU"), - ("Guayaquil, Ecuador" , "GUAYA", "GY"), - ("Halifax, Nova Scotia" , "HALIF", ), - ("Hamilton, New Zealand" , "NZEAL", "NZ"), - ("Harrison, New York" , "HARRI", "NYORK"), - ("Hartford, Connecticut" , "HARTF", ), - ("Helsinki, Finland" , "HELSI", ), - ("Hermosillo, Sonora, Mexico" , "HERMO", ), - ("Hong Kong, China" , "HKONG", ), - ("Houston, Texas" , "HOUST", ), - ("Idaho Falls, Idaho" , "IFALL", "IF"), - ("Johannesburg, South Africa" , "JOHAN", "JO"), - ("Jordan River, Utah" , "JRIVE", "JR"), - ("Kona, Hawaii" , "KONA", ), - ("Kiev, Ukraine" , "KIEV", ), - ("Kirtland, Ohio" , "KIRTL", ), - ("Laie, Hawaii" , "HAWAI", "HA"), - ("Las Vegas, Nevada" , "LVEGA", "LV"), - ("Lima, Peru" , "LIMA" , "LI"), - ("Logan, Utah" , "LOGAN", "LG"), - ("London, England" , "LONDO", "LD"), - ("Los Angeles, California" , "LANGE", "LA"), - ("Louisville, Kentucky" , "LOUIS", ), - ("Lubbock, Texas" , "LUBBO", ), - ("Madrid, Spain" , "MADRI", ), - ("Manhattan, New York" , "MANHA", ), - ("Manila, Philippines" , "MANIL", "MA"), - ("Manti, Utah" , "MANTI", "MT"), - ("Medford, Oregon" , "MEDFO", ), - ("Melbourne, Australia" , "MELBO", ), - ("Memphis, Tennessee" , "MEMPH", ), - ("Merida, Mexico" , "MERID", ), - ("Mesa, Arizona" , "ARIZO", "AZ"), - ("Mexico City, Mexico" , "MEXIC", "MX"), - ("Monterrey, Mexico" , "MONTE", ), - ("Montevideo, Uruguay" , "MNTVD", ), - ("Monticello, Utah" , "MONTI", ), - ("Montreal, Quebec" , "MONTR", ), - ("Mt. Timpanogos, Utah" , "MTIMP", ), - ("Nashville, Tennessee" , "NASHV", ), - ("Nauvoo, Illinois" , "NAUVO", "NV"), - ("Nauvoo, Illinois (New)" , "NAUV2", ), - ("Newport Beach, California" , "NBEAC", ), - ("Nuku'alofa, Tonga" , "NUKUA", "TG"), - ("Oakland, California" , "OAKLA", "OK"), - ("Oaxaca, Mexico" , "OAXAC", ), - ("Ogden, Utah" , "OGDEN", "OG"), - ("Oklahoma City, Oklahoma" , "OKLAH", ), - ("Oquirrh Mountain, Utah" , "OMOUN", ), - ("Orlando, Florida" , "ORLAN", ), - ("Palmyra, New York" , "PALMY", ), - ("Panama City, Panama" , "PANAM", ), - ("Papeete, Tahiti" , "PAPEE", "TA"), - ("Perth, Australia" , "PERTH", ), - ("Portland, Oregon" , "PORTL", "PT"), - ("Porto Alegre, Brazil" , "PALEG", ), - ("Preston, England" , "PREST", ), - ("Provo, Utah" , "PROVO", "PV"), - ("Quetzaltenango, Guatemala" , "QUETZ", ), - ("Raleigh, North Carolina" , "RALEI", ), - ("Recife, Brazil" , "RECIF", ), - ("Redlands, California" , "REDLA", ), - ("Regina, Saskatchewan" , "REGIN", ), - ("Reno, Nevada" , "RENO", ), - ("Rexburg, Idaho" , "REXBU", ), - ("Sacramento, California" , "SACRA", ), - ("St. George, Utah" , "SGEOR", "SG"), - ("St. Louis, Missouri" , "SLOUI", ), - ("St. Paul, Minnesota" , "SPMIN", ), - ("Salt Lake City, Utah" , "SLAKE", "SL"), - ("San Antonio, Texas" , "SANTO", ), - ("San Diego, California" , "SDIEG", "SA"), - ("San Jose, Costa Rica" , "SJOSE", ), - ("Santiago, Chile" , "SANTI", "SN"), - ("Santo Domingo, Dominican Republic" , "SDOMI", ), - ("Sao Paulo, Brazil" , "SPAUL", "SP"), - ("Seattle, Washington" , "SEATT", "SE"), - ("Seoul, South Korea" , "SEOUL", "SO"), - ("Snowflake, Arizona" , "SNOWF", ), - ("Spokane, Washington" , "SPOKA", ), - ("Stockholm, Sweden" , "STOCK", "ST"), - ("Suva, Fiji" , "SUVA", ), - ("Sydney, Australia" , "SYDNE", "SD"), - ("Taipei, Taiwan" , "TAIPE", "TP"), - ("Tampico, Mexico" , "TAMPI", ), - ("Tegucigalpa, Honduras" , "TEGUC", ), - ("The Hague, Netherlands" , "HAGUE", ), - ("Tokyo, Japan" , "TOKYO", "TK"), - ("Toronto, Ontario" , "TORON", "TORNO", "TR"), - ("Tuxtla Gutierrez, Mexico" , "TGUTI", ), - ("Twin Falls, Idaho" , "TFALL", "TWINF"), - ("Vancouver, British Columbia" , "VANCO", ), - ("Veracruz, Mexico" , "VERAC", ), - ("Vernal, Utah" , "VERNA", ), - ("Villahermosa, Mexico" , "VILLA", ), - ("Washington, D.C." , "WASHI", "WA"), - ("Winter Quarters, Nebraska" , "WINTE", "WQUAR"), +""" +Parses the lds.xml file to build the temple/code maps +""" -# Other places. Not temples. - ("Endowment House" , "EHOUS", "EH"), - ("President's Office" , "POFFI", "PO"), - ("Historian's Office" , "HOFFI", "HO"), - ("Other" , "OTHER", ), -) +import const +import os +import logging -temple_codes = {} -for x in temples: - temple_codes[x[0]] = x[1] +from xml.parsers.expat import ParserCreate +from gettext import gettext as _ + +LOG = logging.getLogger(".") + +class LdsTemples: + """ + Parsing class for the LDS temples file + """ + + def __init__(self): + """ + Parses the lds.xml file to load the LDS temple code to name + maps + """ + self.__temple_codes = {} + self.__temple_to_abrev = {} + self.__current_temple = "" + self.__tlist = [] + + lds_filename = os.path.join(const.data_dir, "lds.xml") + + try: + xml_file = open(os.path.expanduser(lds_filename)) + parser = ParserCreate() + parser.StartElementHandler = self.__start_element + parser.EndElementHandler = self.__end_element + parser.CharacterDataHandler = self.__characters + parser.ParseFile(xml_file) + xml_file.close() + except Exception, msg: + LOG.error(str(msg)) + + def is_valid_code(self, code): + """ + returns True if the code is a valid LDS temple code according + to the lds.xml file + """ + return self.__temple_to_abrev.get(code) != None + + def is_valid_name(self, name): + """ + returns True if the name matches a temple name (not code) in + the lds.xml file + """ + return self.__temple_codes.get(name) != None + + def code(self, name): + """ + returns the LDS Temple code that corresponds to the name + """ + return self.__temple_codes.get(name, _("Unknown")) + + def name(self, code): + """ + returns the name associated with the LDS Temple code + """ + return self.__temple_to_abrev.get(code, _("Unknown")) + + def name_code_data(self): + """ + returns a list of temple codes, temple name tuples + """ + return [ (self.__temple_codes[name], name) \ + for name in self.__temple_codes.keys() ] + + def __start_element(self, tag, attrs): + """ + XML parsing function that is called when an XML element is first found + """ + self.__tlist = [] + if tag == "temple": + self.__current_temple = attrs.get('name') + + def __end_element(self, tag): + """ + XML parsing function that is called when an XML element is closed + """ + + text = ''.join(self.__tlist) + + if tag == "code": + if self.__temple_codes.get(self.__current_temple) == None: + self.__temple_codes[self.__current_temple] = text + self.__temple_to_abrev[text] = self.__current_temple + + def __characters(self, data): + """ + XML parsing function that collects text data + """ + self.__tlist.append(data) + +Temples = LdsTemples() -temple_to_abrev = {} -for x in temples: - for y in x[1:]: - temple_to_abrev[y] = x[0] diff --git a/src/data/Makefile.am b/src/data/Makefile.am index b7b1c48d1..31d606e6b 100644 --- a/src/data/Makefile.am +++ b/src/data/Makefile.am @@ -8,6 +8,7 @@ dist_pkgdata_DATA = \ papersize.xml \ system_filters.xml \ tips.xml\ + lds.xml\ main1.css\ main2.css\ main3.css\ diff --git a/src/data/lds.xml b/src/data/lds.xml new file mode 100644 index 000000000..593b05eae --- /dev/null +++ b/src/data/lds.xml @@ -0,0 +1,490 @@ + + + + ABA + + + ACCRA + + + ADELA + + + ALBUQ + + + ANCHO + + + APIA + SAMOA + AP + + + ASUNC + + + ATLAN + AT + + + BROUG + + + SWISS + SW + + + BILLI + + + BIRMI + + + BISMA + + + BOGOT + BG + + + BOISE + BO + + + BOSTO + + + BOUNT + + + BRISB + + + BAIRE + BA + + + CAMPI + + + CARAC + + + ALBER + AL + ALBR + + + CEBU + + + CHICA + CH + + + CIUJU + + + COCHA + + + COLJU + + + COLSC + + + CRIVE + + + COLUM + + + COPEN + + + CURIT + + + DALLA + DA + + + DENVE + DV + + + DETRO + + + DRAPE + + + EDMON + + + FRANK + FR + + + FREIB + FD + + + FRESN + + + FUKUO + + + GUADA + + + GUATE + GA + GU + + + GUAYA + GY + + + HALIF + + + NZEAL + NZ + + + HARRI + NYORK + + + HARTF + + + HELSI + + + HERMO + + + HKONG + + + HOUST + + + IFALL + IF + + + JOHAN + JO + + + JRIVE + JR + + + KONA + + + KIEV + + + KIRTL + + + HAWAI + HA + + + LVEGA + LV + + + LIMA + LI + + + LOGAN + LG + + + LONDO + LD + + + LANGE + LA + + + LOUIS + + + LUBBO + + + MADRI + + + MANHA + + + MANIL + MA + + + MANTI + MT + + + MEDFO + + + MELBO + + + MEMPH + + + MERID + + + ARIZO + AZ + + + MEXIC + MX + + + MONTE + + + MNTVD + + + MONTI + + + MONTR + + + MTIMP + + + NASHV + + + NAUVO + NV + + + NAUV2 + + + NBEAC + + + NUKUA + TG + + + OAKLA + OK + + + OAXAC + + + OGDEN + OG + + + OKLAH + + + OMOUN + + + ORLAN + + + PALMY + + + PANAM + + + PAPEE + TA + + + PERTH + + + PORTL + PT + + + PALEG + + + PREST + + + PROVO + PV + + + QUETZ + + + RALEI + + + RECIF + + + REDLA + + + REGIN + + + RENO + + + REXBU + + + SACRA + + + SGEOR + SG + + + SLOUI + + + SPMIN + + + SLAKE + SL + + + SANTO + + + SDIEG + SA + + + SJOSE + + + SANTI + SN + + + SDOMI + + + SPAUL + SP + + + SEATT + SE + + + SEOUL + SO + + + SNOWF + + + SPOKA + + + STOCK + ST + + + SUVA + + + SYDNE + SD + + + TAIPE + TP + + + TAMPI + + + TEGUC + + + HAGUE + + + TOKYO + TK + + + TORON + TORNO + TR + + + TGUTI + + + TFALL + TWINF + + + VANCO + + + VERAC + + + VERNA + + + VILLA + + + WASHI + WA + + + WINTE + WQUAR + + + EHOUS + EH + + + POFFI + PO + + + HOFFI + HO + + + OTHER + +