コード例 #1
0
def main():
    parser = optparse.OptionParser()

    parser.add_option("-w",
                      "--write",
                      action="store_true",
                      dest="write",
                      default=False,
                      help="Writes file to incoming fileName + EXTENSION.")
    parser.add_option("-e",
                      "--extension",
                      dest="extension",
                      metavar="EXTENSION",
                      help="The EXTENSION to use",
                      default=".compiled")
    parser.add_option("--optimize-variables",
                      action="store_true",
                      dest="optimizeVariables",
                      default=False,
                      help="Optimize variables. Reducing size.")
    parser.add_option("--encoding",
                      dest="encoding",
                      default="utf-8",
                      metavar="ENCODING",
                      help="Defines the encoding expected for input files.")

    (options, args) = parser.parse_args()

    if len(args) == 0:
        print "Needs one or more arguments (files) to compile!"
        sys.exit(1)

    for fileName in args:
        if options.write:
            print "Generating tree of %s => %s%s" % (fileName, fileName,
                                                     options.extension)
        else:
            print "Generating tree of %s => stdout" % fileName

        restree = createSyntaxTree(
            tokenizer.parseFile(fileName, "", options.encoding))

        if options.optimizeVariables:
            variableoptimizer.search(restree, [], 0, "$")

        compiledString = tree.nodeToXmlString(restree)
        if options.write:
            filetool.save(fileName + options.extension, compiledString)

        else:
            try:
                print compiledString

            except UnicodeEncodeError:
                print "  * Could not encode result to ascii. Use '-w' instead."
                sys.exit(1)
コード例 #2
0
def main():
    global options

    parser = optparse.OptionParser()

    parser.add_option("--encoding", dest="encoding", default="utf-8", metavar="ENCODING", help="Defines the encoding expected for input files.")

    (options, args) = parser.parse_args()

    if len(args) == 0:
        print "Needs one or more arguments (files) to compile!"
        sys.exit(1)

    for fileName in args:
        print "Processing %s" % (fileName)

        restree = treegenerator.createSyntaxTree(tokenizer.parseFile(fileName, fileName, options.encoding))    
        
        track(restree)
コード例 #3
0
ファイル: compiler.py プロジェクト: technosaurus/samba4-GPL2
def main():
  parser = optparse.OptionParser()

  parser.add_option("-w", "--write", action="store_true", dest="write", default=False, help="Writes file to incoming fileName + EXTENSION.")
  parser.add_option("-e", "--extension", dest="extension", metavar="EXTENSION", help="The EXTENSION to use", default="")
  parser.add_option("-c", "--compress", action="store_true", dest="compress", help="Enable compression", default=False)
  parser.add_option("--optimize-variables", action="store_true", dest="optimizeVariables", default=False, help="Optimize variables. Reducing size.")
  parser.add_option("--encoding", dest="encoding", default="utf-8", metavar="ENCODING", help="Defines the encoding expected for input files.")

  (options, args) = parser.parse_args()

  if len(args) == 0:
    print "Needs one or more arguments (files) to compile!"
    sys.exit(1)

  for fileName in args:
    if options.write:
      print "Compiling %s => %s%s" % (fileName, fileName, options.extension)
    else:
      print "Compiling %s => stdout" % fileName

    restree = treegenerator.createSyntaxTree(tokenizer.parseFile(fileName, "", options.encoding))

    if options.optimizeVariables:
      variableoptimizer.search(restree, [], 0, "$")

    compiledString = compile(restree, not options.compress)
    if options.write:
      if compiledString != "" and not compiledString.endswith("\n"):
        compiledString += "\n"
        
      filetool.save(fileName + options.extension, compiledString)

    else:
      try:
        print compiledString

      except UnicodeEncodeError:
        print "  * Could not encode result to ascii. Use '-w' instead."
        sys.exit(1)
コード例 #4
0
def main():
    global options

    parser = optparse.OptionParser()

    parser.add_option("--encoding",
                      dest="encoding",
                      default="utf-8",
                      metavar="ENCODING",
                      help="Defines the encoding expected for input files.")

    (options, args) = parser.parse_args()

    if len(args) == 0:
        print "Needs one or more arguments (files) to compile!"
        sys.exit(1)

    for fileName in args:
        print "Processing %s" % (fileName)

        restree = treegenerator.createSyntaxTree(
            tokenizer.parseFile(fileName, fileName, options.encoding))

        track(restree)
コード例 #5
0
def main():
    global options

    parser = optparse.OptionParser(option_class=optparseext.ExtendAction)

    parser.add_option("-w", "--write", action="store_true", dest="write", default=False, help="Writes file to incoming fileName + EXTENSION.")
    parser.add_option("-e", "--extension", dest="extension", metavar="EXTENSION", help="The EXTENSION to use", default="")
    parser.add_option("-c", "--compress", action="store_true", dest="compress", help="Enable compression", default=False)
    parser.add_option("--optimize-variables", action="store_true", dest="optimizeVariables", default=False, help="Optimize variables. Reducing size.")
    parser.add_option("--optimize-privates", action="store_true", dest="optimizePrivates", default=False, help="Optimize privates. Protected them and reducing size.")
    parser.add_option("--obfuscate-accessors", action="store_true", dest="obfuscateAccessors", default=False, help="Enable accessor obfuscation")
    parser.add_option("--encoding", dest="encoding", default="utf-8", metavar="ENCODING", help="Defines the encoding expected for input files.")
    parser.add_option("--use-variant", action="extend", dest="useVariant", type="string", metavar="NAMESPACE.KEY:VALUE", default=[], help="Optimize for the given variant.")
    
    # Options for pretty printing
    addCommandLineOptions(parser)

    (options, args) = parser.parse_args()

    if len(args) == 0:
        print "Needs one or more arguments (files) to compile!"
        sys.exit(1)

    for fileName in args:
        if options.write:
            print "Compiling %s => %s%s" % (fileName, fileName, options.extension)

        restree = treegenerator.createSyntaxTree(tokenizer.parseFile(fileName, fileName, options.encoding))

        if len(options.useVariant) > 0:
            variantMap = {}
            for variant in options.useVariant:
                keyValue = variant.split(":")
                if len(keyValue) != 2:
                    print "  * Error: Variants must be specified as key value pair separated by ':'!"
                    sys.exit(1)
    
                variantMap[keyValue[0]] = keyValue[1]     
                
            variantoptimizer.search(restree, variantMap, fileName)  
            
        if options.obfuscateAccessors:
            accessorobfuscator.process(restree)
            
        if options.optimizePrivates:
            privateoptimizer.patch("A", restree, {})

        if options.optimizeVariables:
            variableoptimizer.search(restree, [], 0, 0, "$")

        if options.compress:
            options.prettyPrint = False  # make sure it's set
        else:
            options.prettyPrint = True
            
        compiledString = compile(restree, options)
        if options.write:
            if compiledString != "" and not compiledString.endswith("\n"):
                compiledString += "\n"

            filetool.save(fileName + options.extension, compiledString)

        else:
            try:
                print compiledString

            except UnicodeEncodeError:
                print "  * Could not encode result to ascii. Use '-w' instead."
                sys.exit(1)
コード例 #6
0
ファイル: compiler.py プロジェクト: emtee40/testingazuan
def main():
    global options

    parser = optparse.OptionParser(option_class=optparseext.ExtendAction)

    parser.add_option("-w",
                      "--write",
                      action="store_true",
                      dest="write",
                      default=False,
                      help="Writes file to incoming fileName + EXTENSION.")
    parser.add_option("-e",
                      "--extension",
                      dest="extension",
                      metavar="EXTENSION",
                      help="The EXTENSION to use",
                      default="")
    parser.add_option("-c",
                      "--compress",
                      action="store_true",
                      dest="compress",
                      help="Enable compression",
                      default=False)
    parser.add_option("--optimize-variables",
                      action="store_true",
                      dest="optimizeVariables",
                      default=False,
                      help="Optimize variables. Reducing size.")
    parser.add_option(
        "--optimize-privates",
        action="store_true",
        dest="optimizePrivates",
        default=False,
        help="Optimize privates. Protected them and reducing size.")
    parser.add_option("--obfuscate-accessors",
                      action="store_true",
                      dest="obfuscateAccessors",
                      default=False,
                      help="Enable accessor obfuscation")
    parser.add_option("--encoding",
                      dest="encoding",
                      default="utf-8",
                      metavar="ENCODING",
                      help="Defines the encoding expected for input files.")
    parser.add_option("--use-variant",
                      action="extend",
                      dest="useVariant",
                      type="string",
                      metavar="NAMESPACE.KEY:VALUE",
                      default=[],
                      help="Optimize for the given variant.")

    # Options for pretty printing
    addCommandLineOptions(parser)

    (options, args) = parser.parse_args()

    if len(args) == 0:
        print "Needs one or more arguments (files) to compile!"
        sys.exit(1)

    for fileName in args:
        if options.write:
            print "Compiling %s => %s%s" % (fileName, fileName,
                                            options.extension)

        restree = treegenerator.createSyntaxTree(
            tokenizer.parseFile(fileName, fileName, options.encoding))

        if len(options.useVariant) > 0:
            variantMap = {}
            for variant in options.useVariant:
                keyValue = variant.split(":")
                if len(keyValue) != 2:
                    print "  * Error: Variants must be specified as key value pair separated by ':'!"
                    sys.exit(1)

                variantMap[keyValue[0]] = keyValue[1]

            variantoptimizer.search(restree, variantMap, fileName)

        if options.obfuscateAccessors:
            accessorobfuscator.process(restree)

        if options.optimizePrivates:
            privateoptimizer.patch("A", restree, {})

        if options.optimizeVariables:
            variableoptimizer.search(restree, [], 0, 0, "$")

        if options.compress:
            options.prettyPrint = False  # make sure it's set
        else:
            options.prettyPrint = True

        compiledString = compile(restree, options)
        if options.write:
            if compiledString != "" and not compiledString.endswith("\n"):
                compiledString += "\n"

            filetool.save(fileName + options.extension, compiledString)

        else:
            try:
                print compiledString

            except UnicodeEncodeError:
                print "  * Could not encode result to ascii. Use '-w' instead."
                sys.exit(1)