Exemplo n.º 1
0
def do_rewrite():
    """
    Starts the importer.
    """
    parser = optparse.OptionParser(usage="Usage: %prog [options] <mapping file>")
    parser.add_option("-d", "--debug", action="store_true", default=False, dest="debug",
                      help="activate verbose debug messages")
    options, args = parser.parse_args()   
    if len(args) < 1:
        print "Usage: import.py <mapping file>"  
        return

    # import the mapping from the given filename
    mapping_module = mod_import(args[0])
    try:
        mapping = eval("mapping_module.mapping")
    except AttributeError:
        print "ERROR: The mapping file must contain a variable called 'mapping'!"
        return

    # check for old output files and warn if they were found
    found_files = []
    for map_dict in mapping:
        outfile = map_dict.get("outfile", None)
        try:
            f = open(outfile, 'r')
            found_files.append(outfile)
            f.close()
        except IOError:
            pass
    if found_files:
        print "  Warning: output files already exists:"
        print "  " + ", ".join(found_files)
        print "  You should remove these before continuing (or they will be appended to)!"
        inp = raw_input("Continue Y/[N]? > ")
        if not inp.lower() == 'y':
            sys.exit()
    
    # run the full import        
    import rewrite
    rewrite.parse_mapping(mapping, debug=options.debug)
Exemplo n.º 2
0
def do_rewrite():
    """
    Starts the importer.
    """
    parser = optparse.OptionParser(usage="Usage: %prog [options] <mapping file>")
    parser.add_option("-d", "--debug", action="store_true", default=False, dest="debug",
                      help="activate verbose debug messages")
    options, args = parser.parse_args()   
    if len(args) < 1:
        print "Usage: import.py <mapping file>"  
        return

    # import the mapping from the given filename
    mapping_module = mod_import(args[0])
    try:
        mapping = eval("mapping_module.mapping")
    except AttributeError:
        print "ERROR: The mapping file must contain a variable called 'mapping'!"
        return

    # run the full import        
    import rewrite
    rewrite.parse_mapping(mapping, debug=options.debug)