47
48 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
49
50
51 pattern = re.compile("#include \"(.*)\"")
52
53
54 files = []
55 for i in range(len(source)):
56 src = source[i]
57 dst = target[i]
58 f = open(src)
59 cts = f.read()
60 f.close()
61 contents = cts.splitlines()
62 entry = FileEntry(target_name=dst, file_contents=contents)
63 files.append((os.path.basename(src), entry))
64
65
66 files_dict = dict(files)
67
68
69 final_files = []
70 for file in files:
71 done = False
72 tmp_file = file[1].file_contents
73 print(file[1].target_name)
74 while not done:
75 file_count = 0
76 updated_file = []
77 for line in tmp_file:
78 found = pattern.search(line)
79 if found:
80 include_file = found.group(1)
81 data = files_dict[include_file].file_contents
82 updated_file.extend(data)
83 else:
84 updated_file.append(line)
85 file_count += 1
86
87
88 if file_count == len(tmp_file):
89 done = True
90
91
92 tmp_file = updated_file
93
94
95 tmp_file.insert(0, "R\"(\n")
96 tmp_file.append("\n)\"")
97 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
98 final_files.append((file[0], entry))
99
100
101 for file in final_files:
102 with open(file[1].target_name, 'w+') as out_file:
103 out_file.write("\n".join(file[1].file_contents))
104
105
106