Imported Upstream version 0.48
[platform/upstream/libical.git] / src / python / Store.py
1 #!/usr/bin/env python 
2 # -*- Mode: python -*-
3 #======================================================================
4 # FILE: Store.py
5 # CREATOR: eric 
6 #
7 # DESCRIPTION:
8 #   
9 #
10 #  $Id: Store.py,v 1.4 2002-07-08 17:56:11 acampi Exp $
11 #  $Locker:  $
12 #
13 # (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org>
14 # (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com>  
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of either: 
18 #
19 #    The LGPL as published by the Free Software Foundation, version
20 #    2.1, available at: http://www.fsf.org/copyleft/lesser.html
21 #
22 #  Or:
23 #
24 #    The Mozilla Public License Version 1.0. You may obtain a copy of
25 #    the License at http://www.mozilla.org/MPL/
26 #======================================================================
27
28 from LibicalWrap import *
29 from Error import LibicalError
30 from Component import Component, CloneComponent
31 from Gauge import Gauge
32
33 class Store:
34     """ 
35     Base class for several component storage methods 
36     """
37
38     class AddFailedError(LibicalError):
39         "Failed to add a property to the file store"
40         
41     class ConstructorFailedError(LibicalError):
42         "Failed to create a Store "
43     
44     def __init__(self):
45         pass
46
47     def path(self):
48         pass
49     
50     def mark(self):
51         pass
52     
53     def commit(self): 
54         pass
55     
56     def add_component(self, comp):
57         pass
58     
59     def remove_component(self, comp):
60         pass
61     
62     def count_components(self, kind):
63         pass
64     
65     def select(self, gauge):
66         pass
67     
68     def clearSelect(self):
69         pass
70     
71     def fetch(self, uid):
72         pass
73     
74     def fetchMatch(self, comp):
75         pass
76     
77     def modify(self, oldc, newc):
78         pass
79     
80     def current_component(self):
81         pass
82     
83     def first_component(self):
84         pass
85     
86     def next_component(self):
87         pass
88
89
90 class FileStore(Store):
91
92     def __init__(self, file):
93         e1=icalerror_supress("FILE")
94         self._ref = icalfileset_new(file)
95         icalerror_restore("FILE",e1)
96
97         if self._ref == None or self._ref == 'NULL':
98             raise  Store.ConstructorFailedError(file)
99
100     def __del__(self):
101         icalfileset_free(self._ref)
102
103     def path(self):
104         return icalfileset_path(self._ref)
105
106     def mark(self):
107         icalfileset_mark(self._ref)
108
109     def commit(self): 
110         icalfileset_commit(self._ref)
111
112     def add_component(self, comp):
113         if not isinstance(comp,Component):
114             raise Store.AddFailedError("Argument is not a component")
115             
116         error = icalfileset_add_component(self._ref,comp.ref())
117
118     def remove_component(self, comp):
119         if not isinstance(comp,Component):
120             raise Store.AddFailedError("Argument is not a component")
121
122         error = icalfileset_remove_component(self._ref,comp.ref())
123
124     def count_components(self, kind):
125         _kind = icalcomponent_string_to_kind(kind)
126
127         return icalfileset_count_components(self._ref, _kind)
128
129     def select(self, gauge):
130         error = icalfileset_select(self._ref, gauge.ref())
131
132     def clearSelect(self):
133         icalfileset_clear(self._ref)
134
135     def fetch(self, uid):
136         comp_ref = icalfileset_fetch(self._ref, uid)
137
138         if comp_ref == None:
139             return None
140
141         return CloneComponent(comp_ref)
142
143     def fetchMatch(self, comp):
144         if not isinstance(comp,Component):
145             raise Store.AddFailedError("Argument is not a component")
146             
147         comp_ref = icalfileset_fetch_match(self._ref,comp.ref())
148
149         if comp_ref == None:
150             return None
151
152         return CloneComponent(comp_ref)
153
154     def modify(self, oldc, newc):
155         pass
156
157     def current_component(self):
158         comp_ref = icalfileset_get_current_component(self._ref)
159
160         if comp_ref == None:
161             return None
162
163         return CloneComponent(comp_ref)
164
165     def first_component(self):
166         comp_ref = icalfileset_get_first_component(self._ref)
167
168         if comp_ref == None:
169             return None
170
171         return CloneComponent(comp_ref)
172
173     def next_component(self):
174         
175         comp_ref = icalfileset_get_next_component(self._ref)
176
177         if comp_ref == None:
178             return None
179
180         return CloneComponent(comp_ref)
181