Exemplo n.º 1
0
    def migrateFile(self, filePath, compiledPatches, compiledInfos,
                    hasPatchModule=False, options=None, encoding="UTF-8"):

        logging.info("  - File: %s" % filePath)

        # Read in original content
        fileContent = filetool.read(filePath, encoding)

        fileId = loader.extractFileContentId(fileContent);

        # Apply patches
        patchedContent = fileContent

        if hasPatchModule and fileId is not None:

            import patch
            tree = treegenerator.createSyntaxTree(tokenizer.parseStream(fileContent))

            # If there were any changes, compile the result
            if patch.patch(fileId, tree):
                options.prettyPrint = True  # make sure it's set
                patchedContent = compiler.compile(tree, options)

        # apply RE patches
        patchedContent = self.regtool(patchedContent, compiledPatches, True, filePath)
        patchedContent = self.regtool(patchedContent, compiledInfos, False, filePath)

        # Write file
        if patchedContent != fileContent:
            logging.info("    - %s has been modified. Storing modifications ..." % filePath)
            filetool.save(filePath, patchedContent, encoding)
Exemplo n.º 2
0
    def migrateFile(self, filePath, compiledPatches, compiledInfos,
                    hasPatchModule=False, options=None, encoding="UTF-8"):

        logging.info("  - File: %s" % filePath)

        # Read in original content
        fileContent = filetool.read(filePath, encoding)

        fileId = loader.extractFileContentId(fileContent);

        # Apply patches
        patchedContent = fileContent

        if hasPatchModule and fileId is not None:

            import patch
            tree = treegenerator.createSyntaxTree(tokenizer.parseStream(fileContent))

            # If there were any changes, compile the result
            if patch.patch(fileId, tree):
                options.prettyPrint = True  # make sure it's set
                patchedContent = compiler.compile(tree, options)

        # apply RE patches
        patchedContent = self.regtool(patchedContent, compiledPatches, True, filePath)
        patchedContent = self.regtool(patchedContent, compiledInfos, False, filePath)

        # Write file
        if patchedContent != fileContent:
            logging.info("    - %s has been modified. Storing modifications ..." % filePath)
            filetool.save(filePath, patchedContent, encoding)
Exemplo n.º 3
0
    def compileTree(self, restree, format=False):
        # Emulate options
        parser = optparse.OptionParser()
        parser.add_option("--p1", action="store_true", dest="prettyPrint", default=False)
        parser.add_option("--p2", action="store_true", dest="prettypIndentString", default="  ")
        parser.add_option("--p3", action="store_true", dest="prettypCommentsInlinePadding", default="  ")
        parser.add_option("--p4", action="store_true", dest="prettypCommentsTrailingCommentCols", default="")

        (options, args) = parser.parse_args([])

        return compiler.compile(restree, options, format)
Exemplo n.º 4
0
    def compileTree(self, restree, format=False):
        # Emulate options
        parser = optparse.OptionParser()
        parser.add_option("--p1", action="store_true", dest="prettyPrint", default=False)
        parser.add_option("--p2", action="store_true", dest="prettypIndentString", default="  ")
        parser.add_option("--p3", action="store_true", dest="prettypCommentsInlinePadding", default="  ")
        parser.add_option("--p4", action="store_true", dest="prettypCommentsTrailingCommentCols", default="")

        (options, args) = parser.parse_args([])

        return compiler.compile(restree, options, format)
Exemplo n.º 5
0
    def runPrettyPrinting(self, classes, classesObj):
        "Gather all relevant config settings and pass them to the compiler"

        if not isinstance(self._job.get("pretty-print", False),
                          types.DictType):
            return

        self._console.info("Pretty-printing code...")
        self._console.indent()
        ppsettings = ExtMap(self._job.get(
            "pretty-print"))  # get the pretty-print config settings

        # init options
        parser = optparse.OptionParser()
        compiler.addCommandLineOptions(parser)
        (options, args) = parser.parse_args([])

        # modify according to config
        setattr(options, 'prettyPrint', True)  # turn on pretty-printing
        if ppsettings.get('general/indent-string', False):
            setattr(options, 'prettypIndentString',
                    ppsettings.get('general/indent-string'))
        if ppsettings.get('comments/trailing/keep-column', False):
            setattr(options, 'prettypCommentsTrailingKeepColumn',
                    ppsettings.get('comments/trailing/keep-column'))
        if ppsettings.get('comments/trailing/comment-cols', False):
            setattr(options, 'prettypCommentsTrailingCommentCols',
                    ppsettings.get('comments/trailing/comment-cols'))
        if ppsettings.get('comments/trailing/padding', False):
            setattr(options, 'prettypCommentsInlinePadding',
                    ppsettings.get('comments/trailing/padding'))
        if ppsettings.get('blocks/align-with-curlies', False):
            setattr(options, 'prettypAlignBlockWithCurlies',
                    ppsettings.get('blocks/align-with-curlies'))
        if ppsettings.get('blocks/open-curly/newline-before', False):
            setattr(options, 'prettypOpenCurlyNewlineBefore',
                    ppsettings.get('blocks/open-curly/newline-before'))
        if ppsettings.get('blocks/open-curly/indent-before', False):
            setattr(options, 'prettypOpenCurlyIndentBefore',
                    ppsettings.get('blocks/open-curly/indent-before'))

        self._console.info("Pretty-printing files: ", False)
        numClasses = len(classes)
        for pos, classId in enumerate(classes):
            self._console.progress(pos + 1, numClasses)
            #tree = treeLoader.getTree(classId)
            tree = classesObj[classId].tree()
            compiled = compiler.compile(tree, options)
            filetool.save(self._classes[classId]['path'], compiled)

        self._console.outdent()

        return
Exemplo n.º 6
0
    def toJavascript(self):
        from ecmascript import compiler
        def options(): pass
        options.prettyPrint =  True
        options.prettypIndentString = "  "
        options.prettypCommentsInlinePadding = "  "
        options.prettypCommentsTrailingCommentCols = ""
        options.prettypOpenCurlyNewlineBefore = "m"
        options.prettypOpenCurlyIndentBefore = False
        options.prettypAlignBlockWithCurlies = False
        options.prettypCommentsTrailingKeepColumn = False

        return compiler.compile(self, options)
Exemplo n.º 7
0
def _compileTree(tree, pretty):
    # Emulate options
    parser = optparse.OptionParser()
    parser.add_option("-a", action="store_true", dest="prettyPrint", default=pretty)
    parser.add_option("-b", action="store_true", dest="prettypIndentString", default="  ")
    parser.add_option("-c", action="store_true", dest="prettypCommentsInlinePadding", default="  ")
    parser.add_option("-d", action="store_true", dest="prettypCommentsTrailingCommentCols", default="")
    parser.add_option("-e", action="store_true", dest="prettypOpenCurlyNewlineBefore", default="")
    parser.add_option("-f", action="store_true", dest="prettypOpenCurlyIndentBefore", default="")
    parser.add_option("-g", action="store_true", dest="prettypCommentsTrailingKeepColumn", default=False)
    parser.add_option("-i", action="store_true", dest="prettypAlignBlockWithCurlies", default=False)

    (options, args) = parser.parse_args([])

    return compiler.compile(tree, options, True)
Exemplo n.º 8
0
Arquivo: tree.py Projeto: vuuvv/vshop1
    def toJavascript(self):
        from ecmascript import compiler

        def options():
            pass

        options.prettyPrint = True
        options.prettypIndentString = "  "
        options.prettypCommentsInlinePadding = "  "
        options.prettypCommentsTrailingCommentCols = ""
        options.prettypOpenCurlyNewlineBefore = "m"
        options.prettypOpenCurlyIndentBefore = False
        options.prettypAlignBlockWithCurlies = False
        options.prettypCommentsTrailingKeepColumn = False

        return compiler.compile(self, options)
Exemplo n.º 9
0
    def runPrettyPrinting(self, classes, classesObj):
        "Gather all relevant config settings and pass them to the compiler"

        if not isinstance(self._job.get("pretty-print", False), types.DictType):
            return

        self._console.info("Pretty-printing code...")
        self._console.indent()
        ppsettings = ExtMap(self._job.get("pretty-print"))  # get the pretty-print config settings

        # init options
        parser  = optparse.OptionParser()
        compiler.addCommandLineOptions(parser)
        (options, args) = parser.parse_args([])

        # modify according to config
        setattr(options, 'prettyPrint', True)  # turn on pretty-printing
        if ppsettings.get('general/indent-string',False):
            setattr(options, 'prettypIndentString', ppsettings.get('general/indent-string'))
        if ppsettings.get('comments/trailing/keep-column',False):
            setattr(options, 'prettypCommentsTrailingKeepColumn', ppsettings.get('comments/trailing/keep-column'))
        if ppsettings.get('comments/trailing/comment-cols',False):
            setattr(options, 'prettypCommentsTrailingCommentCols', ppsettings.get('comments/trailing/comment-cols'))
        if ppsettings.get('comments/trailing/padding',False):
            setattr(options, 'prettypCommentsInlinePadding', ppsettings.get('comments/trailing/padding'))
        if ppsettings.get('blocks/align-with-curlies',False):
            setattr(options, 'prettypAlignBlockWithCurlies', ppsettings.get('blocks/align-with-curlies'))
        if ppsettings.get('blocks/open-curly/newline-before',False):
            setattr(options, 'prettypOpenCurlyNewlineBefore', ppsettings.get('blocks/open-curly/newline-before'))
        if ppsettings.get('blocks/open-curly/indent-before',False):
            setattr(options, 'prettypOpenCurlyIndentBefore', ppsettings.get('blocks/open-curly/indent-before'))

        self._console.info("Pretty-printing files: ", False)
        numClasses = len(classes)
        for pos, classId in enumerate(classes):
            self._console.progress(pos+1, numClasses)
            #tree = treeLoader.getTree(classId)
            tree = classesObj[classId].tree()
            compiled = compiler.compile(tree, options)
            filetool.save(self._classes[classId]['path'], compiled)

        self._console.outdent()

        return
Exemplo n.º 10
0
def _compileTree(tree, pretty):
    # Emulate options
    parser = optparse.OptionParser()
    parser.add_option("-a",
                      action="store_true",
                      dest="prettyPrint",
                      default=pretty)
    parser.add_option("-b",
                      action="store_true",
                      dest="prettypIndentString",
                      default="  ")
    parser.add_option("-c",
                      action="store_true",
                      dest="prettypCommentsInlinePadding",
                      default="  ")
    parser.add_option("-d",
                      action="store_true",
                      dest="prettypCommentsTrailingCommentCols",
                      default="")
    parser.add_option("-e",
                      action="store_true",
                      dest="prettypOpenCurlyNewlineBefore",
                      default="")
    parser.add_option("-f",
                      action="store_true",
                      dest="prettypOpenCurlyIndentBefore",
                      default="")
    parser.add_option("-g",
                      action="store_true",
                      dest="prettypCommentsTrailingKeepColumn",
                      default=False)
    parser.add_option("-i",
                      action="store_true",
                      dest="prettypAlignBlockWithCurlies",
                      default=False)

    (options, args) = parser.parse_args([])

    return compiler.compile(tree, options, True)