Package modules :: Module contacts_remotevcf
[hide private]
[frames] | no frames]

Source Code for Module modules.contacts_remotevcf

 1  """ 
 2  Syncronize with a remote VCF file 
 3   
 4  This file is part of Pisi. 
 5   
 6  This module is based on contacts_vcf and generic_remote and is only pulling functionality from these two modules together. 
 7   
 8  Pisi is free software: you can redistribute it and/or modify 
 9  it under the terms of the GNU General Public License as published by 
10  the Free Software Foundation, either version 3 of the License, or 
11  (at your option) any later version. 
12   
13  Pisi is distributed in the hope that it will be useful, 
14  but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  GNU General Public License for more details. 
17   
18  You should have received a copy of the GNU General Public License 
19  along with Pisi.  If not, see <http://www.gnu.org/licenses/> 
20  """ 
21   
22  import sys,  os 
23  # Allows us to import other modules 
24  sys.path.insert(0,os.path.abspath(__file__+"/../..")) 
25  from modules import generic_remote,  contacts_vcf 
26  from pisiconstants import * 
27  import pisiprogress 
28  import urllib2 
29   
30 -class SynchronizationModule(contacts_vcf.SynchronizationModule, generic_remote.RemoteRessourceHandler):
31 """ 32 The implementation of the interface L{events.AbstractCalendarSynchronizationModule} for the VCF remote backend 33 """ 34
35 - def __init__( self, modulesString, config, configsection, folder, verbose=False, soft=False):
36 """ 37 Constructor 38 39 Local variables are initialized. 40 The settings from the configuration file are loaded. 41 Super class constructors are called. 42 """ 43 self._url = config.get(configsection,'url') 44 self._file = config.get(configsection,'file') 45 self._username = config.get(configsection,'username') 46 self._password = config.get(configsection,'password') 47 config.set(configsection, 'vcfpath', FILEDOWNLOAD_TMPFILE) # for constructor of superclass 48 pisiprogress.getCallback().verbose('remote vcf-module using server %s' % (self._url)) 49 contacts_vcf.SynchronizationModule.__init__(self, modulesString, config, configsection, folder, verbose, soft) 50 generic_remote.RemoteRessourceHandler.__init__(self, self._url, self._file, FILEDOWNLOAD_TMPFILE, self._username, self._password)
51
52 - def load(self):
53 """ 54 The file is downloaded from the webserver and then passed on to the (local) vcf module for parsing 55 """ 56 try: 57 self.download() 58 except urllib2.HTTPError, e: 59 raise IOError("Problems when downloading remote VCF file.\nFor ressource <%s> error code %d was returned." %(e.url, e.code)) 60 contacts_vcf.SynchronizationModule.load(self) 61 self.cleanup()
62
63 - def saveModifications(self):
64 """ 65 Modifications are applied by local VCF module - the new file is uploaded to the original location. 66 """ 67 pisiprogress.getCallback().verbose("Remote VCF module: I apply %d changes now" %(len(self._history))) 68 if len(self._history) == 0: 69 return # don't touch anything if there haven't been any changes 70 71 contacts_vcf.SynchronizationModule.saveModifications(self) 72 self.upload() 73 self.cleanup()
74