Updated code to:
. http://www.gramps-project.org/bugs/view.php?id=3430 . . added a $G[vtdelcspnom] to display . . . researcher information . . . gramps version and database name . be more vim compliant and a little more PEP compliant svn: r22661
This commit is contained in:
parent
afc8a28d6e
commit
bcc17b3700
@ -45,6 +45,7 @@ from gramps.gen.lib import EventType
|
||||
from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback
|
||||
from gramps.gen.constfunc import STRTYPE, cuni
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Local constants
|
||||
@ -121,7 +122,7 @@ class GenericFormat(object):
|
||||
tmp = tmp.upper()
|
||||
if tmp == "" or tmp is None:
|
||||
main.add_remove()
|
||||
elif isinstance(tmp, VarString): #events cause this
|
||||
elif isinstance(tmp, VarString): # events cause this
|
||||
main.extend(tmp)
|
||||
else:
|
||||
main.add_variable(tmp)
|
||||
@ -135,6 +136,7 @@ class GenericFormat(object):
|
||||
|
||||
return main
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Name Format strings
|
||||
#------------------------------------------------------------------------
|
||||
@ -166,18 +168,19 @@ class NameFormat(GenericFormat):
|
||||
|
||||
code = "tfcnxslg"
|
||||
upper = code.upper()
|
||||
function = [name.get_title, #t
|
||||
name.get_first_name, #f
|
||||
name.get_call_name, #c
|
||||
name.get_nick_name, #n
|
||||
common, #x
|
||||
name.get_suffix, #s
|
||||
name.get_surname, #l
|
||||
name.get_family_nick_name #g
|
||||
function = [name.get_title, # t
|
||||
name.get_first_name, # f
|
||||
name.get_call_name, # c
|
||||
name.get_nick_name, # n
|
||||
common, # x
|
||||
name.get_suffix, # s
|
||||
name.get_surname, # l
|
||||
name.get_family_nick_name # g
|
||||
]
|
||||
|
||||
return self.generic_format(name, code, upper, function)
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Date Format strings
|
||||
#------------------------------------------------------------------------
|
||||
@ -198,7 +201,7 @@ class DateFormat(GenericFormat):
|
||||
|
||||
def __count_chars(self, char, max_amount):
|
||||
""" count the year/month/day codes """
|
||||
count = 1 #already have seen/passed one
|
||||
count = 1 # already have seen/passed one
|
||||
while count < max_amount and self.string_in.this == char:
|
||||
self.string_in.step()
|
||||
count = count +1
|
||||
@ -217,23 +220,23 @@ class DateFormat(GenericFormat):
|
||||
if year == "0":
|
||||
return
|
||||
|
||||
if count == 1: #found 'y'
|
||||
if count == 1: # found 'y'
|
||||
if len(year) == 1:
|
||||
return year
|
||||
elif year[-2] == "0":
|
||||
return year[-1]
|
||||
else:
|
||||
return year[-2:]
|
||||
elif count == 2: #found 'yy'
|
||||
elif count == 2: # found 'yy'
|
||||
tmp = "0" + year
|
||||
return tmp[-2:]
|
||||
elif count == 3: #found 'yyy'
|
||||
elif count == 3: # found 'yyy'
|
||||
if len(year) > 2:
|
||||
return year
|
||||
else:
|
||||
tmp = "00" + year
|
||||
return tmp[-3:]
|
||||
else: #count == 4 #found 'yyyy'
|
||||
else: #count == 4 # found 'yyyy'
|
||||
tmp = "000" + year
|
||||
return tmp[-4:]
|
||||
|
||||
@ -247,12 +250,12 @@ class DateFormat(GenericFormat):
|
||||
|
||||
if count == 1:
|
||||
return month
|
||||
elif count == 2: #found 'mm'
|
||||
elif count == 2: # found 'mm'
|
||||
tmp = "0" + month
|
||||
return tmp[-2:]
|
||||
elif count == 3: #found 'mmm'
|
||||
elif count == 3: # found 'mmm'
|
||||
return displayer.short_months[int(month)]
|
||||
else: #found 'mmmm'
|
||||
else: # found 'mmmm'
|
||||
return displayer.long_months[int(month)]
|
||||
|
||||
def month_up():
|
||||
@ -263,12 +266,12 @@ class DateFormat(GenericFormat):
|
||||
""" The day part only """
|
||||
day = cuni(date.get_day())
|
||||
count = self.__count_chars("d", 2)
|
||||
if day == "0": #0 means not defined!
|
||||
if day == "0": # 0 means not defined!
|
||||
return
|
||||
|
||||
if count == 1: #found 'd'
|
||||
if count == 1: # found 'd'
|
||||
return day
|
||||
else: #found 'dd'
|
||||
else: # found 'dd'
|
||||
tmp = "0" + day
|
||||
return tmp[-2:]
|
||||
|
||||
@ -286,6 +289,7 @@ class DateFormat(GenericFormat):
|
||||
|
||||
return self.generic_format(date, code, upper, function)
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Place Format strings
|
||||
#------------------------------------------------------------------------
|
||||
@ -312,7 +316,7 @@ class PlaceFormat(GenericFormat):
|
||||
if self.is_blank(place):
|
||||
return
|
||||
|
||||
code = "elcuspnitxy"
|
||||
code = "elcuspn" + "oitxy"
|
||||
upper = code.upper()
|
||||
function = [place.get_main_location().get_street,
|
||||
place.get_main_location().get_locality,
|
||||
@ -321,6 +325,8 @@ class PlaceFormat(GenericFormat):
|
||||
place.get_main_location().get_state,
|
||||
place.get_main_location().get_postal_code,
|
||||
place.get_main_location().get_country,
|
||||
|
||||
place.get_main_location().get_phone,
|
||||
place.get_main_location().get_parish,
|
||||
place.get_title,
|
||||
place.get_longitude,
|
||||
@ -329,6 +335,7 @@ class PlaceFormat(GenericFormat):
|
||||
|
||||
return self.generic_format(place, code, upper, function)
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Event Format strings
|
||||
#------------------------------------------------------------------------
|
||||
@ -409,6 +416,50 @@ class EventFormat(GenericFormat):
|
||||
|
||||
return self.generic_format(None, code, "", function)
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# gramps info Format strings
|
||||
#------------------------------------------------------------------------
|
||||
class GrampsFormat():
|
||||
""" The Gramps Info Format class.
|
||||
This only polls information from system information.
|
||||
"""
|
||||
|
||||
def __init__(self, _in, _db):
|
||||
self.string_in = _in
|
||||
self.db = _db
|
||||
|
||||
def parse_format(self):
|
||||
""" Parse the Gramps format string.
|
||||
let the date or place classes handle any sub-format strings """
|
||||
from gramps.version import VERSION
|
||||
|
||||
from gramps.gen.utils.config import get_researcher
|
||||
owner = get_researcher()
|
||||
|
||||
code = "vtd" + "elcspn" + "om"
|
||||
info = [VERSION,
|
||||
owner.get_name(),
|
||||
self.db.get_dbname(),
|
||||
|
||||
owner.get_address(),
|
||||
owner.get_locality(),
|
||||
owner.get_city(),
|
||||
owner.get_state(),
|
||||
owner.get_postal_code(),
|
||||
owner.get_country(),
|
||||
|
||||
owner.get_phone(),
|
||||
owner.get_email()
|
||||
]
|
||||
|
||||
where = code.find(self.string_in.this)
|
||||
if where != -1:
|
||||
self.string_in.step()
|
||||
return info[where]
|
||||
return "$G"
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Gallery Format strings
|
||||
#------------------------------------------------------------------------
|
||||
@ -480,6 +531,7 @@ class GalleryFormat(GenericFormat):
|
||||
|
||||
return self.generic_format(None, code, "", function)
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# ConsumableString - The Input string class
|
||||
@ -571,8 +623,8 @@ class VarString(object):
|
||||
it is used for groups and format strings.
|
||||
"""
|
||||
def __init__(self, start_state = TXT.remove):
|
||||
self.state = start_state #overall state of the string.
|
||||
self._text = [] #list of tuples (TXT.?, string)
|
||||
self.state = start_state # overall state of the string.
|
||||
self._text = [] # list of tuples (TXT.?, string)
|
||||
|
||||
def __update_state(self, new_status):
|
||||
if new_status > self.state:
|
||||
@ -604,12 +656,12 @@ class VarString(object):
|
||||
if self._text[index][0] == TXT.text:
|
||||
curr_string += self._text[index][1]
|
||||
index = index + 1
|
||||
continue #while self._text:
|
||||
continue # while self._text:
|
||||
if index +1 == len(self._text):
|
||||
if self._text[index][0] == TXT.separator and curr_string != '':
|
||||
curr_string += self._text[index][1]
|
||||
index = index + 1
|
||||
break #while self._text:
|
||||
break # while self._text:
|
||||
|
||||
type_0_1 = (self._text[index][0], self._text[index+1][0])
|
||||
|
||||
@ -642,7 +694,7 @@ class VarString(object):
|
||||
|
||||
if acquisition.state != TXT.display:
|
||||
#The sub {} was TXT.remove. We don't want to simply ignore it.
|
||||
self.add_remove() #add a remove que here to note it.
|
||||
self.add_remove() # add a remove que here to note it.
|
||||
return
|
||||
|
||||
self._text.extend(acquisition._text)
|
||||
@ -719,7 +771,7 @@ class VariableParse(object):
|
||||
def is_a(self):
|
||||
""" check """
|
||||
return self._in.this == "$" and self._in.next is not None and \
|
||||
"nsijbBdDmMvVauetTpP".find(self._in.next) != -1
|
||||
"nsijbBdDmMvVauetTpPG".find(self._in.next) != -1
|
||||
|
||||
def get_event_by_type(self, marriage, e_type):
|
||||
""" get an event from a type """
|
||||
@ -942,6 +994,10 @@ class VariableParse(object):
|
||||
#photo for the marriage
|
||||
return self.__parse_photo(self.friend.family)
|
||||
|
||||
elif next_char == "G":
|
||||
gramps_format = GrampsFormat(self._in, self.database)
|
||||
return gramps_format.parse_format()
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -969,7 +1025,7 @@ class SubstKeywords(object):
|
||||
self.person = database.get_person_from_handle(person_handle)
|
||||
self.family = None
|
||||
self.spouse = None
|
||||
self.line = None #Consumable_string - set below
|
||||
self.line = None # Consumable_string - set below
|
||||
|
||||
if self.person is None:
|
||||
return
|
||||
@ -1184,6 +1240,7 @@ if __name__ == '__main__':
|
||||
from gramps.gen.lib.date import Date
|
||||
y_or_n = ()
|
||||
date_to_test = Date()
|
||||
|
||||
def date_set():
|
||||
date_to_test.set_yr_mon_day(
|
||||
1970 if 0 in y_or_n else 0,
|
||||
@ -1259,6 +1316,7 @@ if __name__ == '__main__':
|
||||
from gramps.gen.lib.name import Name
|
||||
y_or_n = ()
|
||||
name_to_test = Name()
|
||||
|
||||
def name_set():
|
||||
#code = "tfcnxslg"
|
||||
name_to_test.set_call_name("Bob" if 0 in y_or_n else "")
|
||||
@ -1318,7 +1376,7 @@ if __name__ == '__main__':
|
||||
consume_str = ConsumableString(line_in)
|
||||
answer = main_level_test(consume_str, NameFormat, name_to_test)
|
||||
print(answer)
|
||||
print("Good" if answer == "BobDr.2Billy3Buck4BobIV6The Clubs" \
|
||||
print("Good" if answer == "BobDr.2Billy3Buck4BobIV6The Clubs"
|
||||
else "!! bad !!")
|
||||
|
||||
|
||||
@ -1330,6 +1388,7 @@ if __name__ == '__main__':
|
||||
from gramps.gen.lib.place import Place
|
||||
y_or_n = ()
|
||||
place_to_test = Place()
|
||||
|
||||
def place_set():
|
||||
#code = "elcuspnitxy"
|
||||
main_loc = place_to_test.get_main_location()
|
||||
@ -1412,4 +1471,3 @@ if __name__ == '__main__':
|
||||
34, 35, 38, 39, 38, 33, 32, 33, 36, 37, 36, 40, 41, 40, 44, 33, 32, 33,
|
||||
36, 37, 36, 40, 41, 40, 44, 38, 39, 38, 42, 46] else "!! bad !!")
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user