Package gen :: Package lib :: Module repo
[frames] | no frames]

Source Code for Module gen.lib.repo

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2000-2007  Donald N. Allingham 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 19  # 
 20   
 21  # $Id: repo.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Repository object for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # Python modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from types import InstanceType 
 33   
 34  #------------------------------------------------------------------------- 
 35  # 
 36  # GRAMPS modules 
 37  # 
 38  #------------------------------------------------------------------------- 
 39  from gen.lib.primaryobj import PrimaryObject 
 40  from gen.lib.notebase import NoteBase 
 41  from gen.lib.addressbase import AddressBase 
 42  from gen.lib.urlbase import UrlBase 
 43  from gen.lib.repotype import RepositoryType 
 44  from gen.lib.markertype import MarkerType 
 45   
 46  #------------------------------------------------------------------------- 
 47  # 
 48  # Repository class 
 49  # 
 50  #------------------------------------------------------------------------- 
51 -class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject):
52 """A location where collections of Sources are found.""" 53
54 - def __init__(self):
55 """ 56 Create a new Repository instance. 57 """ 58 PrimaryObject.__init__(self) 59 NoteBase.__init__(self) 60 AddressBase.__init__(self) 61 UrlBase.__init__(self) 62 self.type = RepositoryType() 63 self.name = ""
64
65 - def serialize(self):
66 """ 67 Convert the object to a serialized tuple of data. 68 """ 69 return (self.handle, self.gramps_id, self.type.serialize(), 70 unicode(self.name), 71 NoteBase.serialize(self), 72 AddressBase.serialize(self), 73 UrlBase.serialize(self), 74 self.change, self.marker.serialize(), self.private)
75
76 - def unserialize(self, data):
77 """ 78 Convert the data held in a tuple created by the serialize method 79 back into the data in a Repository structure. 80 """ 81 (self.handle, self.gramps_id, the_type, self.name, note_list, 82 address_list, urls, self.change, marker, self.private) = data 83 84 self.marker = InstanceType(MarkerType) 85 self.marker.unserialize(marker) 86 self.type = InstanceType(RepositoryType) 87 self.type.unserialize(the_type) 88 NoteBase.unserialize(self, note_list) 89 AddressBase.unserialize(self, address_list) 90 UrlBase.unserialize(self, urls)
91
92 - def get_text_data_list(self):
93 """ 94 Return the list of all textual attributes of the object. 95 96 @return: Returns the list of all textual attributes of the object. 97 @rtype: list 98 """ 99 return [self.name, str(self.type)]
100
101 - def get_text_data_child_list(self):
102 """ 103 Return the list of child objects that may carry textual data. 104 105 @return: Returns the list of child objects that may carry textual data. 106 @rtype: list 107 """ 108 return self.address_list + self.urls
109
110 - def get_sourcref_child_list(self):
111 """ 112 Return the list of child secondary objects that may refer sources. 113 114 @return: Returns the list of child secondary child objects that may 115 refer sources. 116 @rtype: list 117 """ 118 return self.address_list
119
120 - def get_note_child_list(self):
121 """ 122 Return the list of child secondary objects that may refer notes. 123 124 @return: Returns the list of child secondary child objects that may 125 refer notes. 126 @rtype: list 127 """ 128 return self.address_list
129
130 - def get_handle_referents(self):
131 """ 132 Return the list of child objects which may, directly or through 133 their children, reference primary objects. 134 135 @return: Returns the list of objects refereincing primary objects. 136 @rtype: list 137 """ 138 return self.address_list
139
140 - def get_referenced_handles(self):
141 """ 142 Return the list of (classname, handle) tuples for all directly 143 referenced primary objects. 144 145 @return: List of (classname, handle) tuples for referenced objects. 146 @rtype: list 147 """ 148 return self.get_referenced_note_handles()
149
150 - def has_source_reference(self, src_handle) :
151 """ 152 Return True if any of the child objects has reference to this source 153 handle. 154 155 @param src_handle: The source handle to be checked. 156 @type src_handle: str 157 @return: Returns whether any of it's child objects has reference to 158 this source handle. 159 @rtype: bool 160 """ 161 for item in self.get_sourcref_child_list(): 162 if item.has_source_reference(src_handle): 163 return True 164 165 return False
166
167 - def remove_source_references(self, src_handle_list):
168 """ 169 Remove references to all source handles in the list in all child 170 objects. 171 172 @param src_handle_list: The list of source handles to be removed. 173 @type src_handle_list: list 174 """ 175 for item in self.get_sourcref_child_list(): 176 item.remove_source_references(src_handle_list)
177
178 - def replace_source_references(self, old_handle, new_handle):
179 """ 180 Replace references to source handles in the list in this object and 181 all child objects. 182 183 @param old_handle: The source handle to be replaced. 184 @type old_handle: str 185 @param new_handle: The source handle to replace the old one with. 186 @type new_handle: str 187 """ 188 for item in self.get_sourcref_child_list(): 189 item.replace_source_references(old_handle, new_handle)
190
191 - def set_type(self, the_type):
192 """ 193 @param the_type: descriptive type of the Repository 194 @type the_type: str 195 """ 196 self.type.set(the_type)
197
198 - def get_type(self):
199 """ 200 @returns: the descriptive type of the Repository 201 @rtype: str 202 """ 203 return self.type
204
205 - def set_name(self, name):
206 """ 207 @param name: descriptive name of the Repository 208 @type name: str 209 """ 210 self.name = name
211
212 - def get_name(self):
213 """ 214 @returns: the descriptive name of the Repository 215 @rtype: str 216 """ 217 return self.name
218