Exemple #1
0
 def getPluginMessages(self, plugin, offset=None, limit=None, qm=None, qs=None):
     '''
     Provides the messages for the given plugin.
     '''
     messages = []
     for m in range(self._pluginMessages):
         if qs and m % 2: continue
         msg = Message()
         msg.Id = self._pluginStartId + int(plugin) * self._pluginMessages + m
         if m > 3:
             msg.Singular = 'plugin %s message %d' % (plugin, m)
             msg.Plural = None if m % 2 else ['plugin %s message %d plural' % (plugin, m)]
             msg.Context = 'plugin'
         else:
             msg.Singular = 'message %i' % m
             msg.Plural = None if m % 2 else ['message %d plural' % m]
             msg.Context = ''
         msg.Source = 10 + int(plugin)
         msg.LineNumber = 200 + m
         messages.append(msg)
     return messages
Exemple #2
0
 def getComponentMessages(self, component, offset=None, limit=None, qm=None, qs=None):
     '''
     Provides the messages for the given component.
     '''
     messages = []
     for m in range(self._componentMessages):
         if qs and m % 2: continue
         msg = Message()
         msg.Id = self._componentStartId + int(component) * self._componentMessages + m
         if m > 2:
             msg.Singular = 'component %s message %d' % (component, m)
             msg.Plural = None if m % 2 else ['component %s message %d plural' % (component, m)]
             msg.Context = 'component'
         else:
             msg.Singular = 'message %i' % m
             msg.Plural = None if m % 2 else ['message %d plural' % m]
             msg.Context = ''
         msg.Source = int(component)
         msg.LineNumber = 100 + m
         messages.append(msg)
     return messages
Exemple #3
0
 def getById(self, id):
     msg = Message()
     msg.Id = id
     return msg
Exemple #4
0
    def _persist(self, files, scanner, path, lastModified, componentId,
                 pluginId):
        '''
        Persist the sources and messages. 
        '''
        assert isinstance(files, dict), 'Invalid files %s' % files
        processModified = lastModified is None
        for filePath, method, extractor in scanner:
            assert method in TYPES, 'Invalid method %s' % method

            file = files.get(filePath)
            if processModified:
                lastModified = modificationTimeFor(filePath)
                if file:
                    assert isinstance(file, File)
                    if lastModified <= file.LastModified:
                        log.info('No modifications for file "%s"', filePath)
                        continue
                    file.LastModified = lastModified
                    self.fileService.update(file)

            if isinstance(file, Source): source = file
            else: source = None
            messages = None
            try:
                for text, context, lineno, comments in extractor:
                    if not source:
                        if file: self.fileService.delete(file.Id)
                        source = Source()
                        source.Component = componentId
                        source.Plugin = pluginId
                        source.Path = filePath
                        source.Type = method
                        source.LastModified = lastModified
                        files[filePath] = source
                        self.sourceService.insert(source)

                    if messages is None:
                        messages = {
                            msg.Singular: msg
                            for msg in self.messageService.getMessages(
                                source.Id)
                        }

                    if isinstance(text, str): singular, plurals = text, None
                    elif len(text) == 1: singular, plurals = text[0], None
                    else: singular, plurals = text[0], list(text[1:])

                    msg = messages.get(singular)
                    if not msg:
                        msg = Message()
                        msg.Source = source.Id
                        msg.Singular = singular
                        msg.Plural = plurals
                        msg.Context = context
                        msg.LineNumber = lineno
                        msg.Comments = '\n'.join(comments)

                        self.messageService.insert(msg)
                        messages[singular] = msg
                    else:
                        msg.Plural = plurals
                        msg.Context = context
                        msg.LineNumber = lineno
                        msg.Comments = '\n'.join(comments)
                        self.messageService.update(msg)
            except UnicodeDecodeError as e:
                log.error('%s: %s' % (filePath, str(e)))

            if processModified and filePath not in files:
                file = File()
                file.Component = componentId
                file.Plugin = pluginId
                file.Path = filePath
                file.LastModified = lastModified
                files[filePath] = file
                self.fileService.insert(file)
Exemple #5
0
 def getComponentMessages(self,
                          component,
                          offset=None,
                          limit=None,
                          qm=None,
                          qs=None):
     '''
     Provides the messages for the given component.
     '''
     messages = []
     for m in range(self._componentMessages):
         if qs and m % 2: continue
         msg = Message()
         msg.Id = self._componentStartId + int(
             component) * self._componentMessages + m
         if m > 2:
             msg.Singular = 'component %s message %d' % (component, m)
             msg.Plural = None if m % 2 else [
                 'component %s message %d plural' % (component, m)
             ]
             msg.Context = 'component'
         else:
             msg.Singular = 'message %i' % m
             msg.Plural = None if m % 2 else ['message %d plural' % m]
             msg.Context = ''
         msg.Source = int(component)
         msg.LineNumber = 100 + m
         messages.append(msg)
     return messages
Exemple #6
0
 def getById(self, id):
     msg = Message()
     msg.Id = id
     return msg
Exemple #7
0
 def getPluginMessages(self,
                       plugin,
                       offset=None,
                       limit=None,
                       qm=None,
                       qs=None):
     '''
     Provides the messages for the given plugin.
     '''
     messages = []
     for m in range(self._pluginMessages):
         if qs and m % 2: continue
         msg = Message()
         msg.Id = self._pluginStartId + int(
             plugin) * self._pluginMessages + m
         if m > 3:
             msg.Singular = 'plugin %s message %d' % (plugin, m)
             msg.Plural = None if m % 2 else [
                 'plugin %s message %d plural' % (plugin, m)
             ]
             msg.Context = 'plugin'
         else:
             msg.Singular = 'message %i' % m
             msg.Plural = None if m % 2 else ['message %d plural' % m]
             msg.Context = ''
         msg.Source = 10 + int(plugin)
         msg.LineNumber = 200 + m
         messages.append(msg)
     return messages
Exemple #8
0
    def _persist(self, files, scanner, path, lastModified, componentId, pluginId):
        """
        Persist the sources and messages. 
        """
        assert isinstance(files, dict), "Invalid files %s" % files
        processModified = lastModified is None
        for filePath, method, extractor in scanner:
            assert method in TYPES, "Invalid method %s" % method

            file = files.get(filePath)
            if processModified:
                lastModified = modificationTimeFor(filePath)
                if file:
                    assert isinstance(file, File)
                    if lastModified <= file.LastModified:
                        log.info('No modifications for file "%s"', filePath)
                        continue
                    file.LastModified = lastModified
                    self.fileService.update(file)

            if isinstance(file, Source):
                source = file
            else:
                source = None
            messages = None
            try:
                for text, context, lineno, comments in extractor:
                    if not source:
                        if file:
                            self.fileService.delete(file.Id)
                        source = Source()
                        source.Component = componentId
                        source.Plugin = pluginId
                        source.Path = filePath
                        source.Type = method
                        source.LastModified = lastModified
                        files[filePath] = source
                        self.sourceService.insert(source)

                    if messages is None:
                        messages = {msg.Singular: msg for msg in self.messageService.getMessages(source.Id)}

                    if isinstance(text, str):
                        singular, plurals = text, None
                    elif len(text) == 1:
                        singular, plurals = text[0], None
                    else:
                        singular, plurals = text[0], list(text[1:])

                    msg = messages.get(singular)
                    if not msg:
                        msg = Message()
                        msg.Source = source.Id
                        msg.Singular = singular
                        msg.Plural = plurals
                        msg.Context = context
                        msg.LineNumber = lineno
                        msg.Comments = "\n".join(comments)

                        self.messageService.insert(msg)
                        messages[singular] = msg
                    else:
                        msg.Plural = plurals
                        msg.Context = context
                        msg.LineNumber = lineno
                        msg.Comments = "\n".join(comments)
                        self.messageService.update(msg)
            except UnicodeDecodeError as e:
                log.error("%s: %s" % (filePath, str(e)))

            if processModified and filePath not in files:
                file = File()
                file.Component = componentId
                file.Plugin = pluginId
                file.Path = filePath
                file.LastModified = lastModified
                files[filePath] = file
                self.fileService.insert(file)