Ejemplo n.º 1
0
def _compileTree(tree, prettyFlag):
    result = [u'']

    if prettyFlag:
        # Set options
        def optns(): pass
        optns = formatter.defaultOptions(optns)
        optns.prettypCommentsBlockAdd = False
        result = formatter.formatNode(tree, optns, result)
    else:
        result =  Packer().serializeNode(tree, None, result, True)

    return u''.join(result)
Ejemplo n.º 2
0
def run_pretty(fileName, fileContent, options, args):
    #elif options.pretty:  # for testing formatter_2
    #    options = formatter.FormatterOptions()
    #    options = formatter.defaultOptions(options)
    #    print formatter.formatStream(tokens, options)
    tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName)
    tree = treegenerator_3.createFileTree(tokens)  # use special tree
    optns = formatter.defaultOptions()
    optns.prettypCommentsBlockAdd = False
    result = [u'']
    result = formatter.formatNode(tree, optns, result)
    result = u''.join(result)
    print(result)
    return
Ejemplo n.º 3
0
def run_pretty(fileName, fileContent, options, args):
    #elif options.pretty:  # for testing formatter_2
    #    options = formatter.FormatterOptions()
    #    options = formatter.defaultOptions(options)
    #    print formatter.formatStream(tokens, options)
    tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName)
    tree = treegenerator_3.createFileTree(tokens) # use special tree
    optns = formatter.defaultOptions()
    optns.prettypCommentsBlockAdd = False
    result = [u'']
    result = formatter.formatNode(tree, optns, result)
    result = u''.join(result)
    print(result)
    return
Ejemplo n.º 4
0
def _compileTree(tree, prettyFlag):
    result = [u'']

    if prettyFlag:
        # Set options
        def optns():
            pass

        optns = formatter.defaultOptions(optns)
        optns.prettypCommentsBlockAdd = False
        result = formatter.formatNode(tree, optns, result)
    else:
        result = Packer().serializeNode(tree, None, result, True)

    return u''.join(result)
Ejemplo n.º 5
0
def main():

    parser = optparse.OptionParser(
        "usage: %prog [options]",
        option_class=ExtendAction
    )

    migrator_options = optparse.OptionGroup(parser, "Migrator Options")
    migrator_options.add_option(
          "-m", "--from-makefile",
          dest="makefile", metavar="MAKEFILE",
          help="Makefile of the skeleton project to migrate (optional)"
    )
    migrator_options.add_option(
          "-c", "--migrate-config",
          dest="config", metavar="CONFIG_JSON",
          help="Configuration file of the skeleton project to migrate (optional)"
    )
    migrator_options.add_option(
          "--from-version", dest="from_version",
          metavar="VERSION", default=str(default_old_version),
          help="qooxdoo version used for the project e.g. '1.2.2'"
    )
    migrator_options.add_option(
          "--migrate-html",
          action="store_true", dest="migrateHtml", default=False,
          help="Migrates recursively all HTML files. Starting from the current directory."
    )

    migrator_options.add_option(
          "-i", "--input",
          dest="file", metavar="FILE.js",
          help="Migrate just one JavaScript file. Writes the generated file to STDOUT."
    )

    migrator_options.add_option(
          "--class-path",
          action="extend", dest="classPath",
          metavar="DIRECTORY", type="string", default=[],
          help="Define a class path."
    )
    parser.add_option_group(migrator_options)

    # options from generator.py
    parser.add_option(
          "-v", "--verbose",
          action="store_true", dest="verbose", default=False,
          help="Verbose output mode."
    )
    parser.add_option(
          "--class-encoding",
          action="extend", dest="classEncoding",
          metavar="ENCODING", type="string", default=[],
          help="Encoding of the files to migrate."
    )

    # Options for pretty printing
    pp_options = optparse.OptionGroup(parser,"Pretty printer options")
    #compiler.addCommandLineOptions(pp_options)
    parser.add_option_group(pp_options)

    (options, args) = parser.parse_args()
    #pretty.defaultOptions(options)
    formatter_.defaultOptions(options)

    from_version = ""
    while from_version == "":
        choice = raw_input("""
NOTE:    To apply only the necessary changes to your project, we
         need to know the qooxdoo version it currently works with.

Please enter your current qooxdoo version [%s] : """ % options.from_version)

        if choice == "":
            from_version = options.from_version
        elif re.match(r'\d\.\d(\.\d)?', choice):
            from_version = options.from_version = choice

    if not isValidVersion(options.from_version):
        print "\nERROR: The version '%s' is not a valid version string!\n" % options.from_version
        sys.exit(1)


    if MIGRATION_ORDER[-1] == getNormalizedVersion(options.from_version):
        print "\n Nothing to do. Your application is up to date!\n"
        sys.exit()

    # to migrate a single file extract the class path
    if options.classPath == [] and options.file:
        options.classPath = [os.path.dirname(os.path.abspath(options.file))]

    if options.classPath == []:
        print """
ERROR: The class path is empty. Please specify the class pass using the
       --class-path option
"""
        sys.exit(0)


    neededUpdates = getNeededUpdates(options.from_version)

    # check whether tree bases modifications will be used
    hasPatchModule = False
    for version in neededUpdates:
        if getPatchModulePath(version) is not None:
            hasPatchModule = True
            break

    # set options for the loader and migrator
    options.classUri = []
    options.resourceInput = []
    options.resourceOutput = []
    options.cacheDirectory = None
    options.disableInternalCheck = False
    options.prettyPrint = True

    # migrate a single file
    if options.file:
        migrateSingleFile(options.file, options, neededUpdates)
        sys.exit(0)

    # build file database
    fileDb = {}
    listIndex = 0
    for path in options.classPath:
        indexClassPath(path, listIndex, options, fileDb)
        listIndex += 1


    print"""
MIGRATION SUMMARY:

Current qooxdoo version:   %s
Upgrade path:              %s

Affected Classes:
    %s""" % (options.from_version, " -> ".join(neededUpdates), "\n    ".join(fileDb.keys()))

    if hasPatchModule:
        print """
WARNING: The JavaScript files will be pretty printed. You can customize the
         pretty printer using the PRETTY_PRINT_OPTIONS variable in your
         Makefile. You can find a complete list of pretty printing options
         at http://qooxdoo.org/documentation/articles/code_style."""

    choice = raw_input("""
NOTE:    It is advised to do a 'generate.py distclean' before migrating any files.
         If you choose 'yes', a subprocess will be invoked to run distclean,
         and after completion you will be prompted if you want to
         continue with the migration. If you choose 'no', the distclean
         step will be skipped (which might result in potentially unnecessary
         files being migrated).

Do you want to run 'distclean' now? [yes] : """)

    if choice.lower() in ["j", "ja", "y", "yes", ""]:
        os.system("%s ./generate.py distclean" % sys.executable)

    choice = raw_input("""

WARNING: The migration process will update the files in place. Please make
         sure, you have a backup of your project. The complete output of the
         migration process will be logged to '%s'.

Do you want to start the migration now? [no] : """ % LOGFILE)

    if not choice.lower() in ["j", "y", "yes"]:
        sys.exit()

    # start migration
    setupLogging(options.verbose)
    fileLogger = logging.FileHandler(LOGFILE, "w")
    formatter = logging.Formatter('%(message)s')
    fileLogger.setFormatter(formatter)
    fileLogger.setLevel(logging.NOTSET)
    logging.getLogger().addHandler(fileLogger)

    if options.migrateHtml:
        htmlFiles = "."
    else:
        htmlFiles = None

    for version in neededUpdates:
        logging.info("")
        logging.info("UPGRADE TO %s" % (version))
        logging.info("----------------------------------------------------------------------------")

        handle(fileDb, options, getNormalizedVersion(version), htmlFiles, verbose=options.verbose)


    # patch makefile
    if not options.makefile is None:
      patchMakefile(options.makefile, MIGRATION_ORDER[-1], options.from_version)

    # patch config
    if options.config is not None:
        patchConfig(options.config, neededUpdates)

    print """

The complete output of the migration process has been logged to the file '%s'.

""" % LOGFILE
Ejemplo n.º 6
0
def main():

    parser = optparse.OptionParser(
        "usage: %prog [options]",
        option_class=ExtendAction
    )

    migrator_options = optparse.OptionGroup(parser, "Migrator Options")
    migrator_options.add_option(
          "-m", "--from-makefile",
          dest="makefile", metavar="MAKEFILE",
          help="Makefile of the skeleton project to migrate (optional)"
    )
    migrator_options.add_option(
          "-c", "--migrate-config",
          dest="config", metavar="CONFIG_JSON",
          help="Configuration file of the skeleton project to migrate (optional)"
    )
    migrator_options.add_option(
          "--from-version", dest="from_version",
          metavar="VERSION", default=str(default_old_version),
          help="qooxdoo version used for the project e.g. '1.2.2'"
    )
    migrator_options.add_option(
          "--migrate-html",
          action="store_true", dest="migrateHtml", default=False,
          help="Migrates recursively all HTML files. Starting from the current directory."
    )

    migrator_options.add_option(
          "-i", "--input",
          dest="file", metavar="FILE.js",
          help="Migrate just one JavaScript file. Writes the generated file to STDOUT."
    )

    migrator_options.add_option(
          "--class-path",
          action="extend", dest="classPath",
          metavar="DIRECTORY", type="string", default=[],
          help="Define a class path."
    )
    parser.add_option_group(migrator_options)

    # options from generator.py
    parser.add_option(
          "-v", "--verbose",
          action="store_true", dest="verbose", default=False,
          help="Verbose output mode."
    )
    parser.add_option(
          "--class-encoding",
          action="extend", dest="classEncoding",
          metavar="ENCODING", type="string", default=[],
          help="Encoding of the files to migrate."
    )

    # Options for pretty printing
    pp_options = optparse.OptionGroup(parser,"Pretty printer options")
    #compiler.addCommandLineOptions(pp_options)
    parser.add_option_group(pp_options)

    (options, args) = parser.parse_args()
    #pretty.defaultOptions(options)
    formatter_.defaultOptions(options)

    from_version = ""
    while from_version == "":
        choice = raw_input("""
NOTE:    To apply only the necessary changes to your project, we
         need to know the qooxdoo version it currently works with.

Please enter your current qooxdoo version [%s] : """ % options.from_version)

        if choice == "":
            from_version = options.from_version
        elif re.match(r'\d\.\d(\.\d)?', choice):
            from_version = options.from_version = choice

    if not isValidVersion(options.from_version):
        print "\nERROR: The version '%s' is not a valid version string!\n" % options.from_version
        sys.exit(1)


    if MIGRATION_ORDER[-1] == getNormalizedVersion(options.from_version):
        print "\n Nothing to do. Your application is up to date!\n"
        sys.exit()

    # to migrate a single file extract the class path
    if options.classPath == [] and options.file:
        options.classPath = [os.path.dirname(os.path.abspath(options.file))]

    if options.classPath == []:
        print """
ERROR: The class path is empty. Please specify the class pass using the
       --class-path option
"""
        sys.exit(0)


    neededUpdates = getNeededUpdates(options.from_version)

    # check whether tree bases modifications will be used
    hasPatchModule = False
    for version in neededUpdates:
        if getPatchModulePath(version) is not None:
            hasPatchModule = True
            break

    # set options for the loader and migrator
    options.classUri = []
    options.resourceInput = []
    options.resourceOutput = []
    options.cacheDirectory = None
    options.disableInternalCheck = False
    options.prettyPrint = True

    # migrate a single file
    if options.file:
        migrateSingleFile(options.file, options, neededUpdates)
        sys.exit(0)

    # build file database
    fileDb = {}
    listIndex = 0
    for path in options.classPath:
        indexClassPath(path, listIndex, options, fileDb)
        listIndex += 1


    print"""
MIGRATION SUMMARY:

Current qooxdoo version:   %s
Upgrade path:              %s

Affected Classes:
    %s""" % (options.from_version, " -> ".join(neededUpdates), "\n    ".join(fileDb.keys()))

    if hasPatchModule:
        print """
WARNING: The JavaScript files will be pretty printed. You can customize the
         pretty printer using the PRETTY_PRINT_OPTIONS variable in your
         Makefile. You can find a complete list of pretty printing options
         at http://qooxdoo.org/documentation/articles/code_style."""

    choice = raw_input("""
NOTE:    It is advised to do a 'generate.py distclean' before migrating any files.
         If you choose 'yes', a subprocess will be invoked to run distclean,
         and after completion you will be prompted if you want to
         continue with the migration. If you choose 'no', the distclean
         step will be skipped (which might result in potentially unnecessary
         files being migrated).

Do you want to run 'distclean' now? [yes] : """)

    if choice.lower() in ["j", "ja", "y", "yes", ""]:
        os.system("%s ./generate.py distclean" % sys.executable)

    choice = raw_input("""

WARNING: The migration process will update the files in place. Please make
         sure, you have a backup of your project. The complete output of the
         migration process will be logged to '%s'.

Do you want to start the migration now? [no] : """ % LOGFILE)

    if not choice.lower() in ["j", "y", "yes"]:
        sys.exit()

    # start migration
    setupLogging(options.verbose)
    fileLogger = logging.FileHandler(LOGFILE, "w")
    formatter = logging.Formatter('%(message)s')
    fileLogger.setFormatter(formatter)
    fileLogger.setLevel(logging.NOTSET)
    logging.getLogger().addHandler(fileLogger)

    if options.migrateHtml:
        htmlFiles = "."
    else:
        htmlFiles = None

    for version in neededUpdates:
        logging.info("")
        logging.info("UPGRADE TO %s" % (version))
        logging.info("----------------------------------------------------------------------------")

        handle(fileDb, options, getNormalizedVersion(version), htmlFiles, verbose=options.verbose)


    # patch makefile
    if not options.makefile is None:
      patchMakefile(options.makefile, MIGRATION_ORDER[-1], options.from_version)

    # patch config
    if options.config is not None:
        patchConfig(options.config, neededUpdates)

    print """

The complete output of the migration process has been logged to the file '%s'.

""" % LOGFILE
Ejemplo n.º 7
0
    ("qx.lang.Object.getKeys", 1, "Object.keys(%(1)s)"),
    ("qx.lang.Array.toArray", 1, "qx.lang.Array.cast(%(1)s, Array)"),
    ("qx.lang.Array.toArray", 2, "qx.lang.Array.cast(%(1)s, Array, %(2)s)"),
    ("qx.lang.Array.fromCollection", 1,
     "Array.prototype.slice.call(%(1)s, 0)"),
    ("qx.lang.Object.hasMinLength", 2, "(%(1)s.length >= %(2)s)"),
    ("qx.Bootstrap.getKeysAsString", 1,
     '''('"' + qx.Bootstrap.keys(%(1)s).join('\", "') + '"')'''),
    ("qx.lang.Object.getKeysAsString", 1,
     '''('"' + qx.Bootstrap.keys(%(1)s).join('\", "') + '"')'''),
    ("qx.lang.Object.select", 2, "%(2)s[%(1)s]"),
    ("qx.lang.Object.carefullyMergeWith", 2,
     "qx.lang.Object.mergeWith(%(1)s, %(2)s, false)"),
]

defaultOptions = formatter.defaultOptions()


def assembleVar(node):
    assert node.isVar()
    var_root = treeutil.findVarRoot(node)
    return var_root.toJS(defaultOptions)


##
# Search through <node> and yield call nodes where <key> is the operand.
def findCallNodes(node, key):
    for call_node in treeutil.nodeIterator(node, ["call"]):
        oper_node = call_node.getChild("operand").getChild(0)
        if not oper_node.isVar():
            continue
Ejemplo n.º 8
0
    ("qx.lang.Array.fromCollection",
        1, "Array.prototype.slice.call(%(1)s, 0)" ),

    ("qx.lang.Object.hasMinLength",
        2, "(%(1)s.length >= %(2)s)" ),
    ("qx.Bootstrap.getKeysAsString",
        1, '''('"' + qx.Bootstrap.keys(%(1)s).join('\", "') + '"')''' ),
    ("qx.lang.Object.getKeysAsString",
        1, '''('"' + qx.Bootstrap.keys(%(1)s).join('\", "') + '"')''' ),
    ("qx.lang.Object.select",
        2, "%(2)s[%(1)s]" ),
    ("qx.lang.Object.carefullyMergeWith",
        2, "qx.lang.Object.mergeWith(%(1)s, %(2)s, false)" ),
]

defaultOptions = formatter.defaultOptions(formatter.FormatterOptions())

def assembleVar(node):
    assert node.isVar()
    var_root = treeutil.findVarRoot(node)
    return var_root.toJS(defaultOptions)

##
# Search through <node> and yield call nodes where <key> is the operand.
def findCallNodes(node, key):
    for call_node in treeutil.nodeIterator(node, ["call"]):
        oper_node = call_node.getChild("operand").getChild(0)
        if not oper_node.isVar():
            continue
        oper_str = assembleVar(oper_node)
        if oper_str == key:
Ejemplo n.º 9
0
    ("qx.lang.Array.fromCollection",
        1, "Array.prototype.slice.call(%(1)s, 0)" ),

    ("qx.lang.Object.hasMinLength",
        2, "(%(1)s.length >= %(2)s)" ),
    ("qx.Bootstrap.getKeysAsString",
        1, '''('"' + qx.Bootstrap.keys(%(1)s).join('\", "') + '"')''' ),
    ("qx.lang.Object.getKeysAsString",
        1, '''('"' + qx.Bootstrap.keys(%(1)s).join('\", "') + '"')''' ),
    ("qx.lang.Object.select",
        2, "%(2)s[%(1)s]" ),
    ("qx.lang.Object.carefullyMergeWith",
        2, "qx.lang.Object.mergeWith(%(1)s, %(2)s, false)" ),
]

defaultOptions = formatter.defaultOptions()

def assembleVar(node):
    assert node.isVar()
    var_root = treeutil.findVarRoot(node)
    return var_root.toJS(defaultOptions)

##
# Search through <node> and yield call nodes where <key> is the operand.
def findCallNodes(node, key):
    for call_node in treeutil.nodeIterator(node, ["call"]):
        oper_node = call_node.getChild("operand").getChild(0)
        if not oper_node.isVar():
            continue
        oper_str = assembleVar(oper_node)
        if oper_str == key: