Пример #1
0
 def getById(self, id):
     src = Source()
     src.Id = id
     ext = 'py' if id % 2 else 'js'
     if id < 10:
         src.Component = str(id)
         src.Path = 'component_%d/src.%s' % (id, ext)
     else:
         src.Plugin = str(id)
         src.Path = 'plugin_%d/src.%s' % (id, ext)
     return src
Пример #2
0
 def getById(self, id):
     src = Source()
     src.Id = id
     ext = 'py' if id % 2 else 'js'
     if id < 10:
         src.Component = str(id)
         src.Path = 'component_%d/src.%s' % (id, ext)
     else:
         src.Plugin = str(id)
         src.Path = 'plugin_%d/src.%s' % (id, ext)
     return src
Пример #3
0
 def getAll(self, offset=None, limit=None, q=None):
     src = Source()
     src.LastModified = datetime(2012, 4, 1, 12, 15, 10)
     return [src]
Пример #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)
Пример #5
0
 def getAll(self, offset=None, limit=None, q=None):
     src = Source()
     src.LastModified = datetime(2012, 4, 1, 12, 15, 10)
     return [src]
Пример #6
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)