3 #======================================================================
10 # $Id: Store.py,v 1.4 2002-07-08 17:56:11 acampi Exp $
13 # (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org>
14 # (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of either:
19 # The LGPL as published by the Free Software Foundation, version
20 # 2.1, available at: http://www.fsf.org/copyleft/lesser.html
24 # The Mozilla Public License Version 1.0. You may obtain a copy of
25 # the License at http://www.mozilla.org/MPL/
26 #======================================================================
28 from LibicalWrap import *
29 from Error import LibicalError
30 from Component import Component, CloneComponent
31 from Gauge import Gauge
35 Base class for several component storage methods
38 class AddFailedError(LibicalError):
39 "Failed to add a property to the file store"
41 class ConstructorFailedError(LibicalError):
42 "Failed to create a Store "
56 def add_component(self, comp):
59 def remove_component(self, comp):
62 def count_components(self, kind):
65 def select(self, gauge):
68 def clearSelect(self):
74 def fetchMatch(self, comp):
77 def modify(self, oldc, newc):
80 def current_component(self):
83 def first_component(self):
86 def next_component(self):
90 class FileStore(Store):
92 def __init__(self, file):
93 e1=icalerror_supress("FILE")
94 self._ref = icalfileset_new(file)
95 icalerror_restore("FILE",e1)
97 if self._ref == None or self._ref == 'NULL':
98 raise Store.ConstructorFailedError(file)
101 icalfileset_free(self._ref)
104 return icalfileset_path(self._ref)
107 icalfileset_mark(self._ref)
110 icalfileset_commit(self._ref)
112 def add_component(self, comp):
113 if not isinstance(comp,Component):
114 raise Store.AddFailedError("Argument is not a component")
116 error = icalfileset_add_component(self._ref,comp.ref())
118 def remove_component(self, comp):
119 if not isinstance(comp,Component):
120 raise Store.AddFailedError("Argument is not a component")
122 error = icalfileset_remove_component(self._ref,comp.ref())
124 def count_components(self, kind):
125 _kind = icalcomponent_string_to_kind(kind)
127 return icalfileset_count_components(self._ref, _kind)
129 def select(self, gauge):
130 error = icalfileset_select(self._ref, gauge.ref())
132 def clearSelect(self):
133 icalfileset_clear(self._ref)
135 def fetch(self, uid):
136 comp_ref = icalfileset_fetch(self._ref, uid)
141 return CloneComponent(comp_ref)
143 def fetchMatch(self, comp):
144 if not isinstance(comp,Component):
145 raise Store.AddFailedError("Argument is not a component")
147 comp_ref = icalfileset_fetch_match(self._ref,comp.ref())
152 return CloneComponent(comp_ref)
154 def modify(self, oldc, newc):
157 def current_component(self):
158 comp_ref = icalfileset_get_current_component(self._ref)
163 return CloneComponent(comp_ref)
165 def first_component(self):
166 comp_ref = icalfileset_get_first_component(self._ref)
171 return CloneComponent(comp_ref)
173 def next_component(self):
175 comp_ref = icalfileset_get_next_component(self._ref)
180 return CloneComponent(comp_ref)