Esempio n. 1
0
    def getCompiled(self, fileId, variants, optimize, format=False):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        variantsId = idlist.toString(variants)
        optimizeId = self.generateOptimizeId(optimize)

        cacheId = "compiled-%s-%s-%s-%s" % (fileId, variantsId, optimizeId, format)

        compiled = self._cache.read(cacheId, filePath)
        if compiled != None:
            return compiled

        tree = self._treeLoader.getTree(fileId, variants)

        if len(optimize) > 0:
            # Protect original before optimizing
            tree = copy.deepcopy(tree)

            self._console.debug("Optimizing tree: %s..." % fileId)
            self._console.indent()
            self._optimizeHelper(tree, fileId, variants, optimize)
            self._console.outdent()

        self._console.debug("Compiling tree: %s..." % fileId)
        compiled = self.compileTree(tree, format)
        self._console.indent()
        self._console.debug("Size: %d" % len(compiled))
        self._console.outdent()

        self._cache.write(cacheId, compiled)
        return compiled
Esempio n. 2
0
    def getCompiled(self, fileId, variants, optimize, format=False):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        variantsId = idlist.toString(variants)
        optimizeId = self.generateOptimizeId(optimize)

        cacheId = "compiled-%s-%s-%s-%s" % (fileId, variantsId, optimizeId,
                                            format)

        compiled = self._cache.read(cacheId, filePath)
        if compiled != None:
            return compiled

        tree = self._treeLoader.getTree(fileId, variants)

        if len(optimize) > 0:
            # Protect original before optimizing
            tree = copy.deepcopy(tree)

            self._console.debug("Optimizing tree: %s..." % fileId)
            self._console.indent()
            self._optimizeHelper(tree, fileId, variants, optimize)
            self._console.outdent()

        self._console.debug("Compiling tree: %s..." % fileId)
        compiled = self.compileTree(tree, format)

        self._cache.write(cacheId, compiled)
        return compiled
Esempio n. 3
0
    def getCompiledSize(self, fileId, variants):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        variantsId = idlist.toString(variants)
        cacheId = "compiledsize-%s-%s" % (fileId, variantsId)

        size = self._cache.readmulti(cacheId, filePath)
        if size != None:
            return size

        tree = self._treeLoader.getTree(fileId, variants)

        self._console.debug("Computing compiled size: %s..." % fileId)
        compiled = self.compileTree(tree)
        size = len(compiled)

        self._cache.writemulti(cacheId, size)
        return size
Esempio n. 4
0
    def getCompiledSize(self, fileId, variants):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        variantsId = idlist.toString(variants)
        cacheId = "compiledsize-%s-%s" % (fileId, variantsId)

        size = self._cache.readmulti(cacheId, filePath)
        if size != None:
            return size

        tree = self._treeLoader.getTree(fileId, variants)

        self._console.debug("Computing compiled size: %s..." % fileId)
        compiled = self.compileTree(tree)
        size = len(compiled)

        self._cache.writemulti(cacheId, size)
        return size
Esempio n. 5
0
    def getTree(self, fileId, variants=None):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        if variants:
            cacheId = "tree-%s-%s" % (fileId, idlist.toString(variants))
        else:
            cacheId = "tree-%s" % fileId

        tree = self._cache.read(cacheId, filePath)
        if tree != None:
            return tree

        # Lookup for unoptimized tree
        if variants != None:
            tree = self._cache.read("tree-%s" % fileId, filePath)

        # Tree still undefined?, create it!
        if tree == None:
            self._console.debug("Parsing file: %s..." % fileId)
            self._console.indent()

            fileEntry = self._classes[fileId]
            fileContent = filetool.read(fileEntry["path"], fileEntry["encoding"])
            tokens = tokenizer.parseStream(fileContent, fileId)
            
            self._console.outdent()
            self._console.debug("Generating tree: %s..." % fileId)
            self._console.indent()

            try:
                tree = treegenerator.createSyntaxTree(tokens)
            except treegenerator.SyntaxException, detail:
                self._console.error("%s" % detail)
                sys.exit(1)

            self._console.outdent()
            self._console.debug("Selecting variants: %s..." % fileId)
            self._console.indent()
Esempio n. 6
0
    def getTranslation(self, fileId, variants):
        fileEntry = self._classes[fileId]
        filePath = fileEntry["path"]

        variantsId = idlist.toString(variants)

        cacheId = "translation-%s-%s" % (fileId, variantsId)

        translation = self._cache.readmulti(cacheId, filePath)
        if translation != None:
            return translation

        self._console.debug("Looking for translation strings: %s..." % fileId)
        self._console.indent()

        tree = self._treeLoader.getTree(fileId, variants)

        try:
            translation = self._findTranslationBlocks(tree, [])
        except NameError, detail:
            self._console.error("Could not extract translation from %s!" % fileId)
            self._console.error("%s" % detail)
            sys.exit(1)
Esempio n. 7
0
    def getDeps(self, fileId, variants):
        if not self._classes.has_key(fileId):
            raise NameError("Could not find class to fulfil dependency: %s" % fileId)

        filePath = self._classes[fileId]["path"]
        cacheId = "deps-%s-%s" % (fileId, idlist.toString(variants))

        # print "Read from cache: %s" % fileId
        
        deps = self._cache.readmulti(cacheId, filePath)
        if deps != None:
            return deps

        # Notes:
        # load time = before class = require
        # runtime = after class = use

        load = []
        run = []

        self._console.debug("Gathering dependencies: %s" % fileId)
        self._console.indent()

        # Read meta data
        meta = self.getMeta(fileId)
        metaLoad = self._readDictKey(meta, "loadtimeDeps", [])
        metaRun = self._readDictKey(meta, "runtimeDeps", [])
        metaOptional = self._readDictKey(meta, "optionalDeps", [])
        metaIgnore = self._readDictKey(meta, "ignoreDeps", [])

        # Process meta data
        load.extend(metaLoad)
        run.extend(metaRun)

        # Read content data
        (autoLoad, autoRun, autoWarn) = self._analyzeClassDeps(fileId, variants)
        
        # Process content data
        if not "auto-require" in metaIgnore:
            for item in autoLoad:
                if item in metaOptional:
                    pass
                elif item in load:
                    self._console.warn("%s: #require(%s) is auto-detected" % (fileId, item))
                else:
                    load.append(item)

        if not "auto-use" in metaIgnore:
            for item in autoRun:
                if item in metaOptional:
                    pass
                elif item in load:
                    pass
                elif item in run:
                    self._console.warn("%s: #use(%s) is auto-detected" % (fileId, item))
                else:
                    run.append(item)

        self._console.outdent()

        # Build data structure
        deps = {
            "load" : load,
            "run"  : run,
            'undef' : autoWarn
        }
        
        self._cache.writemulti(cacheId, deps)
        return deps
Esempio n. 8
0
    def getDeps(self, fileId, variants):
        if not self._classes.has_key(fileId):
            raise NameError("Could not find class to fulfil dependency: %s" %
                            fileId)

        filePath = self._classes[fileId]["path"]
        cacheId = "deps-%s-%s" % (fileId, idlist.toString(variants))

        # print "Read from cache: %s" % fileId

        deps = self._cache.readmulti(cacheId, filePath)
        if deps != None:
            return deps

        # Notes:
        # load time = before class = require
        # runtime = after class = use

        load = []
        run = []

        self._console.debug("Gathering dependencies: %s" % fileId)
        self._console.indent()

        # Read meta data
        meta = self.getMeta(fileId)
        metaLoad = self._readDictKey(meta, "loadtimeDeps", [])
        metaRun = self._readDictKey(meta, "runtimeDeps", [])
        metaOptional = self._readDictKey(meta, "optionalDeps", [])
        metaIgnore = self._readDictKey(meta, "ignoreDeps", [])

        # Process meta data
        load.extend(metaLoad)
        run.extend(metaRun)

        # Read content data
        (autoLoad, autoRun) = self._analyzeClassDeps(fileId, variants)

        # Process content data
        if not "auto-require" in metaIgnore:
            for item in autoLoad:
                if item in metaOptional:
                    pass
                elif item in load:
                    self._console.warn("%s: #require(%s) is auto-detected" %
                                       (fileId, item))
                else:
                    load.append(item)

        if not "auto-use" in metaIgnore:
            for item in autoRun:
                if item in metaOptional:
                    pass
                elif item in load:
                    pass
                elif item in run:
                    self._console.warn("%s: #use(%s) is auto-detected" %
                                       (fileId, item))
                else:
                    run.append(item)

        self._console.outdent()

        # Build data structure
        deps = {"load": load, "run": run}

        self._cache.writemulti(cacheId, deps)
        return deps