Module pisiinterfaces
[hide private]
[frames] | no frames]

Source Code for Module pisiinterfaces

  1  """ 
  2  Provides interfaces (abstract super classes) for generic functionality. 
  3   
  4  This file is part of Pisi. 
  5   
  6  Pisi 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 3 of the License, or 
  9  (at your option) any later version. 
 10   
 11  Pisi 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 Pisi.  If not, see <http://www.gnu.org/licenses/>. 
 18  """ 
 19  import os 
 20   
21 -class Syncable:
22 """ 23 Common interface (Super-class) for a syncable items (calendar event, contact entry) 24 """
25 - def __init__(self, id, attributes):
26 """ 27 Constructor 28 """ 29 self.id = id 30 self.attributes = attributes
31
32 - def compare(self, contactEntry):
33 """ 34 Compares this entry with another one and checks, whether all attributes from this one have the same values in the other one and vice verse 35 36 @return: 0 if there is at least a single difference in attributes; 1 if all attributes are the same 37 """ 38 raise ValueError("!!!Implementation missing!!!") # this has to be implemented individually for each syncable type
39
40 - def getID(self):
41 """ 42 GETTER 43 """ 44 return self.id
45
46 - def prettyPrint (self ):
47 """ 48 Beautyful output for one Syncable entry 49 50 Prints a headline containing the ID of the entry and iterates through all attributes available for the entry and displays each in a single line. 51 """ 52 print "\t_PrettyPrint of id:",self.id 53 for key,value in self.attributes.iteritems(): 54 print ("\t\t- %s = %s" %(key,value)) #.encode("utf8", "replace")
55 56 57
58 -class AbstractSynchronizationModule:
59 """ 60 Super class for all synchronization modules, which aim to synchronize any kind of information. 61 62 Each Synchronization class should inherit from this class. 63 64 @ivar _allEntries: Dictionary for storing all information entries 65 """
66 - def __init__(self, verbose, soft, modulesString, config, configsection, name = "unkown source"):
67 """ 68 Constructor 69 70 Instance variables are initialized. 71 """ 72 self.verbose = verbose 73 self.soft = soft 74 self.modulesString = modulesString 75 self._name = name 76 self._description = config.get(configsection,'description') 77 78 try: 79 self._preProcess = config.get(configsection,'preprocess') 80 except: 81 self._preProcess = None 82 try: 83 self._postProcess = config.get(configsection,'postprocess') 84 except: 85 self._postProcess = None 86 self._allEntries = {}
87
88 - def getName(self):
89 """ 90 GETTER 91 """ 92 return self._name
93
94 - def getDescription(self):
95 """ 96 GETTER 97 """ 98 return self._description
99
100 - def prettyPrint (self ):
101 """ 102 Beautyful output for the entries in the repository 103 104 Prints a small headline and calls the function L{Syncable.prettyPrint} for each contact Entry in turn. 105 """ 106 print "Pretty print of %s content:" %(self._name) 107 for entry in self.allEntires().values(): 108 entry.prettyPrint()
109
110 - def allEntries( self ):
111 """ 112 Getter. 113 114 @return: The link to the instance variable L{_allEntries}. 115 """ 116 return self._allEntries
117
118 - def getEntry(self, id):
119 """ 120 GETTER 121 122 @return: The link with the given ID. 123 """ 124 return self._allEntries[id]
125
126 - def flush(self):
127 """ 128 Remove all entries in repository 129 130 The dictionary for all entries (L{_allEntries}) is flushed. 131 """ 132 self._allEntries = {}
133
134 - def addEntry( self, entry):
135 """ 136 Saves an entry for later writing 137 138 The new instance is stored in the dictionary (L{_allEntries}). 139 """ 140 self._allEntries[entry.getID()] = entry
141
142 - def replaceEntry( self, id, updatedEntry):
143 """ 144 Replaces an existing entry with a new one. 145 146 The old instance is replaced by the new one in the dictionary (L{_allEntries}). 147 """ 148 self._allEntries[id] = updatedEntry
149
150 - def removeEntry( self, id ):
151 """ 152 Removes an entry 153 154 The instance is removed from the dictionary (L{_allEntries}). 155 """ 156 del self._allEntries[id]
157
158 - def preProcess(self):
159 """ 160 Executes the shell command that has been configured for this source under 'preprocess' 161 """ 162 if self._preProcess: 163 ret = os.system(self._preProcess)
164
165 - def postProcess(self):
166 """ 167 Executes the shell command that has been configured for this source under 'postprocess' 168 """ 169 if self._postProcess: 170 ret = os.system(self._postProcess)
171