def __init__(self, sourceURI, targetDirectory, password): self.gid = getgid() self.uid = getuid() # Initialize target and metadata self.target = MountLoadTarget(targetDirectory) self.metadata = MountLoadMetaData(self.target.getDBPath()) # Store and check source URI knownSourceURI = self.metadata.getConfigString('sourceURI') if sourceURI is None: if knownSourceURI is None: raise RuntimeError('No source URI supplied') sourceURI = knownSourceURI elif knownSourceURI is not None and knownSourceURI != sourceURI: raise RuntimeError( 'Given source URI differs from known source URI') # Initialize SFTP source self.source = MountLoadSource(sourceURI, password) # Bootstrap the remote root self.metadata.begin() if self._getPath('/') is None: rootEntry = self.source.getEntry('/') if rootEntry is None: raise RuntimeError( 'Failed to retrieve the remote root directory %s' % (self.source.getRemoteDirectory() + '/')) self._registerPath('/', rootEntry) self.metadata.commit() # Store the source URI in metadata if knownSourceURI is None: self.metadata.setConfig('sourceURI', sourceURI)