Blender  V2.59
rna_cleaner_merge.py
Go to the documentation of this file.
00001 #! /usr/bin/env python3.1
00002 
00003 import sys
00004 
00005 '''
00006 Example usage:
00007  python3 rna_cleaner_merge.py out_work.py rna_booleans_work.py
00008 '''
00009 def main():
00010         
00011         def work_line_id(line):
00012                 return line[2].split("|")[-1], line[3] # class/from
00013         
00014         
00015         if not (sys.argv[-1].endswith(".py") and sys.argv[-2].endswith(".py")):
00016                 print("Only accepts 2 py files as arguments.")
00017         
00018         sys.path.insert(0, ".")
00019 
00020         mod_from = __import__(sys.argv[-1][:-3])
00021         mod_to = __import__(sys.argv[-2][:-3])
00022         
00023         mod_to_dict = dict([(work_line_id(line), line) for line in mod_to.rna_api])
00024         mod_from_dict = dict([(work_line_id(line), line) for line in mod_from.rna_api])
00025         
00026         rna_api_new = []
00027         
00028         for key, val_orig in mod_to_dict.items():
00029                 try:
00030                         val_new = mod_from_dict.pop(key)
00031                 except:
00032                         # print("not found", key)
00033                         val_new = val_orig
00034                         
00035                 # always take the class from the base
00036                 val = list(val_orig)
00037                 val[0] = val_new[0] # comment
00038                 val[4] = val_new[4] # -> to
00039                 val = tuple(val)
00040                 rna_api_new.append(val)
00041         
00042         def write_work_file(file_path, rna_api):
00043                 rna_api = list(rna_api)
00044                 rna_api.sort(key=work_line_id)
00045                 file_out = open(file_path, "w")
00046                 file_out.write("rna_api = [\n")
00047                 for line in rna_api:
00048                         file_out.write("    %s,\n" % (repr(line)))
00049                 file_out.write("]\n")
00050                 file_out.close()
00051 
00052         file_path = sys.argv[-2][:-3] + "_merged.py"
00053         write_work_file(file_path, rna_api_new)
00054         
00055         if mod_from_dict:
00056                 file_path = sys.argv[-2][:-3] + "_lost.py"
00057                 write_work_file(file_path, list(mod_from_dict.values()))
00058                 print("Warning '%s' contains lost %d items from module %s.py" % (file_path, len(mod_from_dict), mod_from.__name__))
00059 
00060 if __name__ == "__main__":
00061         main()