Пример #1
0
    def __init__(self, fileStorer):
        """ 
        Constructor. 
        
        @param fileStorer: Allowing access to the script data.
        @type fileStorer: L{FileStorer<datafinder.persistence.factory.FileStorer>}
        """

        self._fileStorer = fileStorer
        self.uri = self._fileStorer.uri
        self.name = self._fileStorer.name
        self._tmpdir = tempfile.mkdtemp()
        sys.path.append(self._tmpdir)

        self.title = self._fileStorer.name[:-4]
        sys.path.append(self._tmpdir)

        self._baseDirFileStorer = createFileStorer("file:///" + self._tmpdir +
                                                   "/" + self.title)
        atexit.register(self._cleanup)

        self.scripts = list()
        self.hasPreferences = False
        self.location = None

        self._extract()
        self._parse()
Пример #2
0
 def __init__(self, repositoryUri, user, password, dryRun, deleteOld, removeLinkPrefix=None):
     self._conversionMap = {
                       "DataFinderType": u"____datatype____",
                       "DataFinderDataStore": u"____datastorename____",
                       "DataFinderModificationDate": u"____contentmodificationdatetime____",
                       "DataFinderCreationDate": u"____contentcreationdatetime____",
                       "DataFinderLength": u"____content.size____",
                       "DataFinderArchiveIdentifier": u"____contentidentifier____",
                       "DataFinderArchiveRetentionExeededDate": u"____archiveretentionexceededdatetime____",
                       "DataFinderArchiveRootCollection": u"____archiverootcollection____",
                       }
     self._datetypes = ["DataFinderModificationDate", "DataFinderCreationDate", "DataFinderArchiveRetentionExeededDate"]
     self._oldPropertyIds = self._conversionMap.keys()[:] + [LINK_PROPERTY_OLD]
     
     self._dataFormatRegistry = registry.DataFormatRegistry()
     self._dataFormatRegistry.load()
     self._dryRun = dryRun
     self._deleteOld = deleteOld
     self._removeLinkPrefix = removeLinkPrefix
 
     # Little trick to correctly set the link target WebDAV property
     identifier_mapping._logicalToPersistenceIdMapping["linkTarget"] = ("http://dlr.de/system/", 
                                                                        "linkTarget")
             
     fs = factory.createFileStorer(repositoryUri, 
                                   BaseConfiguration(repositoryUri, username=user, password=password))
     self._walk([fs])
Пример #3
0
 def load(self):
     """ Initializes everything with the installed icons. """
     
     try:
         directoryFileStorer = createFileStorer("file:///" + LOCAL_INSTALLED_ICONS_DIRECTORY_PATH)
     except PersistenceError, error:
         raise ConfigurationError("Cannot parse local icon directory.\nReason:'%s'", error.message)
Пример #4
0
    def _cleanup(self):
        """ Cleanup the temporary directory. """

        if self._tmpdir in sys.path:
            sys.path.remove(self._tmpdir)
        try:
            fileStorer = createFileStorer("file:///" + self._tmpdir)
            if fileStorer.exists():
                fileStorer.delete()
        except PersistenceError, error:
            self._logger.debug(error.message)
Пример #5
0
 def importDataStores(self, localFilePath):
     """
     Imports the data store configuration from a local file.
     
     @param localFilePath: Path to file on the local file system.
     @type localFilePath: C{unicode}
     """
     
     try:
         localFileStorer = createFileStorer("file:///" + localFilePath)
         binaryStream = localFileStorer.readData()
     except PersistenceError, error:
         raise ConfigurationError("Cannot import data store configuration.\nReason: '%s'" % error.message)
Пример #6
0
    def importDataStores(self, localFilePath):
        """
        Imports the data store configuration from a local file.
        
        @param localFilePath: Path to file on the local file system.
        @type localFilePath: C{unicode}
        """

        try:
            localFileStorer = createFileStorer("file:///" + localFilePath)
            binaryStream = localFileStorer.readData()
        except PersistenceError, error:
            raise ConfigurationError(
                "Cannot import data store configuration.\nReason: '%s'" %
                error.message)
Пример #7
0
 def exportDataStores(self, localFilePath):
     """
     Exports the data store configuration to the local file path.
     
     @param localFilePath: Path to file on the local file system.
     @type localFilePath: C{unicode}
     """
     
     persistedDataStores = self._createPersistedDatastores()
     stream = self._streamWriterClass(StringIO())
     persistedDataStores.export(stream, 0)
     stream.seek(0)
     try:
         localFileStorer = createFileStorer("file:///" + localFilePath)
         localFileStorer.writeData(stream)
     except PersistenceError, error:
         raise ConfigurationError("Cannot export data model. Reason: '%s'" % error.message)
Пример #8
0
    def exportDataStores(self, localFilePath):
        """
        Exports the data store configuration to the local file path.
        
        @param localFilePath: Path to file on the local file system.
        @type localFilePath: C{unicode}
        """

        persistedDataStores = self._createPersistedDatastores()
        stream = self._streamWriterClass(StringIO())
        persistedDataStores.export(stream, 0)
        stream.seek(0)
        try:
            localFileStorer = createFileStorer("file:///" + localFilePath)
            localFileStorer.writeData(stream)
        except PersistenceError, error:
            raise ConfigurationError("Cannot export data model. Reason: '%s'" %
                                     error.message)
Пример #9
0
 def importDatamodel(self, localFilePath):
     """ 
     Imports a data model. 
     
     @param localFilePath: Path to file on the local file system.
     @type localFilePath: C{unicode}
     
     @raise ConfigurationError: Indicating problems on data model storing.
     """
     
     try:
         localFileStorer = createFileStorer("file:///" + localFilePath)
         binaryStream = localFileStorer.readData()
         try:
             persistedDatamodel = datamodel.parseString(binaryStream.read())
         finally:
             binaryStream.close()
     except PersistenceError, error:
         raise ConfigurationError("Cannot import data model. Reason: '%s'" % error.message)
Пример #10
0
    def load(self):
        """ 
        Loads local script extensions. 
        
        @raise ConfigurationError: Indicating problems on initialization.
        """

        scripts = list()
        for scriptUri in self._preferences.scriptUris:
            try:
                fileStorer = createFileStorer(scriptUri)
            except PersistenceError, error:
                self._logger.debug("Cannot access script '%s'. Reason '%s'" % (scriptUri, error.message))
            else:
                try:
                    script = createScript(fileStorer)
                except ConfigurationError, error:
                    self._logger.debug(error.message)
                else:
Пример #11
0
    def __init__(self,
                 repositoryUri,
                 user,
                 password,
                 dryRun,
                 deleteOld,
                 removeLinkPrefix=None):
        self._conversionMap = {
            "DataFinderType": u"____datatype____",
            "DataFinderDataStore": u"____datastorename____",
            "DataFinderModificationDate":
            u"____contentmodificationdatetime____",
            "DataFinderCreationDate": u"____contentcreationdatetime____",
            "DataFinderLength": u"____content.size____",
            "DataFinderArchiveIdentifier": u"____contentidentifier____",
            "DataFinderArchiveRetentionExeededDate":
            u"____archiveretentionexceededdatetime____",
            "DataFinderArchiveRootCollection":
            u"____archiverootcollection____",
        }
        self._datetypes = [
            "DataFinderModificationDate", "DataFinderCreationDate",
            "DataFinderArchiveRetentionExeededDate"
        ]
        self._oldPropertyIds = self._conversionMap.keys()[:] + [
            LINK_PROPERTY_OLD
        ]

        self._dataFormatRegistry = registry.DataFormatRegistry()
        self._dataFormatRegistry.load()
        self._dryRun = dryRun
        self._deleteOld = deleteOld
        self._removeLinkPrefix = removeLinkPrefix

        # Little trick to correctly set the link target WebDAV property
        identifier_mapping._logicalToPersistenceIdMapping["linkTarget"] = (
            "http://dlr.de/system/", "linkTarget")

        fs = factory.createFileStorer(
            repositoryUri,
            BaseConfiguration(repositoryUri, username=user, password=password))
        self._walk([fs])
Пример #12
0
    def addIcon(self, iconBaseName, localBaseDirectoryPath):
        """
        Adds a new icon.

        @param iconBaseName: Base name of the new icon.
        @type iconBaseName: C{unicode}
        @param localBaseDirectoryPath: Path to the base directory for small and large icon representation.
        @type localBaseDirectoryPath: C{unicode} 
        
        @raise ConfigurationError: Indicating problems on icon importing.
        """

        try:
            str(iconBaseName)
        except UnicodeEncodeError:
            raise ConfigurationError("Currently only icon file names in ASCII encoding are supported.")
        else:
            try:
                baseDirectoryFileStorer = createFileStorer("file:///" + localBaseDirectoryPath)
                smallIconFileName = iconBaseName + SMALL_ICONFILENAME_SUFFIX
                largeIconFileName = iconBaseName + LARGE_ICONFILENAME_SUFFIX
                smallIconFileStorer = baseDirectoryFileStorer.getChild(smallIconFileName)
                largeIconFileStorer = baseDirectoryFileStorer.getChild(largeIconFileName)
    
                if not smallIconFileStorer.exists():
                    raise ConfigurationError("The small icon file '%s' cannot be found." % smallIconFileName)
                if not largeIconFileStorer.exists():
                    raise ConfigurationError("The large icon file '%s' cannot be found." % largeIconFileName)
                
                for smallIconDestination in [self._sourceFileStorer, self._targetFileStorer]:
                    smallIconDestinationFileStorer = smallIconDestination.getChild(smallIconFileName)
                    self._copy(smallIconFileStorer, smallIconDestinationFileStorer)
                for largeIconDestination in [self._sourceFileStorer, self._targetFileStorer]:
                    largeIconDestinationFileStorer = largeIconDestination.getChild(largeIconFileName)
                    self._copy(largeIconFileStorer, largeIconDestinationFileStorer)
                    
                self._iconRegistry.register(self._location, [Icon(iconBaseName, smallIconFileName, 
                                                                  largeIconFileName, localBaseDirectoryPath)])
            except PersistenceError, error:
                raise ConfigurationError("Cannot add icon '%s'. Reason: '%s'" % (iconBaseName, error.message))
Пример #13
0
    def addScript(self, scriptUri):
        """
        Adds a new script.

        @param scriptUri: URI identifying the new script extension.
        @type scriptUri: C{unicode}
        
        @raise ConfigurationError: Indicating problems on icon importing.
        """

        try:
            scriptFileStorer = createFileStorer(scriptUri)
            if not scriptFileStorer.exists():
                raise ConfigurationError("The script '%s' cannot be found." % scriptUri)
            script = createScript(scriptFileStorer)
            for scriptDestination in [self._sourceFileStorer, self._targetFileStorer]:
                scriptDestinationFileStorer = scriptDestination.getChild(scriptFileStorer.name)
                self._copy(scriptFileStorer, scriptDestinationFileStorer)
            script = createScript(self._targetFileStorer.getChild(scriptFileStorer.name), self._location)
            self._scriptRegistry.register(self._location, [script])
        except PersistenceError, error:
            raise ConfigurationError("Cannot add script '%s'. Reason: '%s'" % (scriptUri, error.message))