Beispiel #1
0
    def _lastModified(self, locale, component=None, plugin=None):
        '''
        Provides the last modification time stamp for the provided locale. You can specify the component id in order to
        get the last modification for the component domain, or plugin or either to get the global domain modification.

        @param locale: Locale
            The locale to get the last modification for.
        @param component: string|None
            The component id to get the last modification for.
        @param plugin: string|None
            The plugin id to get the last modification for.
        @return: datetime|None
            The last modification time stamp, None if there is no such time stamp available.
        '''
        assert isinstance(locale, Locale), 'Invalid locale %s' % locale
        assert not (
            component and plugin
        ), 'Cannot process a component id %s and a plugin id %s' % (component,
                                                                    plugin)

        q = QSource()
        q.lastModified.orderDesc()
        if component: q.component = component
        elif plugin: q.plugin = plugin
        sources = self.sourceService.getAll(0, 1, q=q)
        try:
            lastModified = next(iter(sources)).LastModified
        except StopIteration:
            lastModified = None

        path = self._filePath(locale, component, plugin)
        if isfile(path):
            lastModified = max(lastModified,
                               datetime.fromtimestamp(os.stat(path).st_mtime))
        return lastModified
Beispiel #2
0
    def _lastModified(self, locale, component=None, plugin=None):
        '''
        Provides the last modification time stamp for the provided locale. You can specify the component id in order to
        get the last modification for the component domain, or plugin or either to get the global domain modification.

        @param locale: Locale
            The locale to get the last modification for.
        @param component: string|None
            The component id to get the last modification for.
        @param plugin: string|None
            The plugin id to get the last modification for.
        @return: datetime|None
            The last modification time stamp, None if there is no such time stamp available.
        '''
        assert isinstance(locale, Locale), 'Invalid locale %s' % locale
        assert not(component and plugin), 'Cannot process a component id %s and a plugin id %s' % (component, plugin)

        q = QSource()
        q.lastModified.orderDesc()
        if component: q.component = component
        elif plugin: q.plugin = plugin
        sources = self.sourceService.getAll(0, 1, q=q)
        try: lastModified = next(iter(sources)).LastModified
        except StopIteration: lastModified = None

        path = self._filePath(locale, component, plugin)
        if isfile(path):
            lastModified = max(lastModified, datetime.fromtimestamp(os.stat(path).st_mtime))
        return lastModified
Beispiel #3
0
    def getGlobalAsDict(self, locale):
        '''
        @see: IPOFileManager.getGlobalAsDict
        '''
        try:
            locale = Locale.parse(locale)
        except UnknownLocaleError:
            raise InvalidLocaleError(locale)

        messages = self.messageService.getMessages(qs=QSource(
            type=TYPE_JAVA_SCRIPT))
        catalog = self._build(locale, messages, self._filePath(locale))
        return self._toDict('', catalog)
Beispiel #4
0
    def scanComponents(self):
        '''
        Scan the current application components for the localized text messages.
        '''
        for component in self.componentService.getComponents():
            assert isinstance(component, Component)
            files = {
                file.Path: file
                for file in self.fileService.getAll(q=QFile(
                    component=component.Id))
            }
            if component.InEgg:
                lastModified = modificationTimeFor(component.Path)
                file = files.get(component.Path)
                if file and lastModified <= file.LastModified:
                    log.info(
                        'No modifications for component zip file "%s" in %s',
                        component.Path, component.Name)
                    continue
                if not file:
                    file = File()
                    file.Component = component.Id
                    file.Path = component.Path
                    file.LastModified = lastModified
                    files[component.Path] = file
                    self.fileService.insert(file)
                else:
                    file.LastModified = lastModified
                    self.fileService.update(file)
                scanner = scanZip(component.Path)
            else:
                lastModified, scanner = None, scanFolder(component.Path)

            files.update({
                source.Path: source
                for source in self.sourceService.getAll(q=QSource(
                    component=component.Id))
            })
            self._persist(files, scanner, component.Path, lastModified,
                          component.Id, None)
Beispiel #5
0
    def scanPlugins(self):
        '''
        Scan the current application plugins for the localized text messages.
        '''
        for plugin in self.pluginService.getPlugins():
            assert isinstance(plugin, Plugin)
            files = {
                file.Path: file
                for file in self.fileService.getAll(q=QFile(plugin=plugin.Id))
            }
            if plugin.InEgg:
                lastModified = modificationTimeFor(plugin.Path)
                file = files.get(plugin.Path)
                if file and lastModified <= file.LastModified:
                    log.info('No modifications for plugin zip file "%s" in %s',
                             plugin.Path, plugin.Name)
                    continue
                if not file:
                    file = File()
                    file.Plugin = plugin.Id
                    file.Path = plugin.Path
                    file.LastModified = lastModified
                    files[plugin.Path] = file
                    self.fileService.insert(file)
                else:
                    file.LastModified = lastModified
                    self.fileService.update(file)
                scanner = scanZip(plugin.Path)
            else:
                lastModified, scanner = None, scanFolder(plugin.Path)

            files.update({
                source.Path: source
                for source in self.sourceService.getAll(q=QSource(
                    plugin=plugin.Id))
            })
            self._persist(files, scanner, plugin.Path, lastModified, None,
                          plugin.Id)