Example #1
0
def main():
    """
        Will contain main logic
    """
    script, script_path = get_input()
    bundle = (script, script_path)
    if (verify_input(bundle)):
        ast = tokenize(bundle)

        # Rewrite the script to get the dependency log
        dpt_log = run(bundle, ast)

        # Analyze logs
        analysis = DPTAnalyzer.analize(dpt_log)
        logger.debug("Analysis: {0}".format(analysis))

        # Refactor the script based on rules and DPT, AST and tokens
        rewrt = Rewriter(bundle[0], analysis)
        new_script = rewrt.rewrite()

        # Write file to disk
        target_dir = os.path.dirname(script_path)
        file_base = os.path.basename(script_path)
        target_script = os.path.join(
            target_dir,
            file_base + "_" + conf.Rewritter.output_file)
        fp = open(target_script, "wb")
        fp.write(new_script)
        fp.close()

        return
def get_new_script(script, script_path):
    my_preanalyzer = Preanalyzer(script)
    if my_preanalyzer.check() is False:
        return False

    my_tokenizer = Tokenizer(script)
    ast = my_tokenizer.tokenize()

    rn = Runner(script, script_path, ast)
    rn.run()

    dpt_log = rn.get_log()
    analysis = DPTAnalyzer.analize(dpt_log)

    rewrt = Rewriter(script, analysis)

    return rewrt.rewrite()