MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / _rewrite_codes

Method _rewrite_codes

applications/chatdev_lite/chatdev/codes.py:103–146  ·  view source on GitHub ↗

Rewrites code files to disk, with optional Git management. Args: git_management: Whether to enable Git management phase_info: Current phase information (for Git commit message)

(self, git_management, phase_info=None)

Source from the content-addressed store, hash-verified

101 self.codebooks[key] = new_codes.codebooks[key]
102
103 def _rewrite_codes(self, git_management, phase_info=None) -> None:
104 """
105 Rewrites code files to disk, with optional Git management.
106 Args:
107 git_management: Whether to enable Git management
108 phase_info: Current phase information (for Git commit message)
109 """
110 directory = self.directory
111 rewrite_codes_content = "**[Rewrite Codes]**\n\n"
112
113 if os.path.exists(directory) and len(os.listdir(directory)) > 0:
114 self.version += 1.0
115 if not os.path.exists(directory):
116 os.mkdir(self.directory)
117 rewrite_codes_content += "{} Created\n".format(directory)
118
119 for filename in self.codebooks.keys():
120 filepath = os.path.join(directory, filename)
121 with open(filepath, "w", encoding="utf-8") as writer:
122 writer.write(self.codebooks[filename])
123 rewrite_codes_content += os.path.join(directory, filename) + " Wrote\n"
124
125 if git_management:
126 if not phase_info:
127 phase_info = ""
128 log_git_info = "**[Git Information]**\n\n"
129 if self.version == 1.0:
130 os.system(f"cd {self.directory}; git init")
131 log_git_info += f"cd {self.directory}; git init\n"
132 os.system(f"cd {self.directory}; git add .")
133 log_git_info += f"cd {self.directory}; git add .\n"
134
135 completed_process = subprocess.run(f"cd {self.directory}; git status", shell=True, text=True, stdout=subprocess.PIPE)
136 if "nothing to commit" in completed_process.stdout:
137 self.version -= 1.0
138 return
139
140 os.system(f"cd {self.directory}; git commit -m 'v{self.version} {phase_info}'")
141 log_git_info += f"cd {self.directory}; git commit -m 'v{self.version} {phase_info}'\n"
142 if self.version == 1.0:
143 os.system(f"cd {os.path.dirname(os.path.dirname(self.directory))}; git submodule add ./{os.path.basename(self.directory)} WareHouse/{os.path.basename(self.directory)}")
144 log_git_info += f"cd {os.path.dirname(os.path.dirname(self.directory))}; git submodule add ./{os.path.basename(self.directory)} WareHouse/{os.path.basename(self.directory)}\n"
145 log_visualize(rewrite_codes_content)
146 log_visualize(log_git_info)
147
148 def _get_codes(self) -> list:
149 """

Callers 1

Calls 5

log_visualizeFunction · 0.90
keysMethod · 0.80
joinMethod · 0.80
runMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected