forked from Nboxff/thss-2025-compiler-final
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.py
More file actions
36 lines (31 loc) · 1.11 KB
/
package.py
File metadata and controls
36 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import zipfile
def zip_directory(zipf, directory):
for root, _, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
zipf.write(file_path)
def main():
# Check if all required files are present
if not (os.path.isdir("src") and os.path.isfile("CMakeLists.txt")):
print("Error: Missing src directory or CMakeLists.txt file")
return
if not os.path.isdir("include"):
print("Error: Missing include directory")
return
if not os.path.isfile("SysYLexer.g4"):
print("Error: Missing SysYLexer.g4 file")
return
if not os.path.isfile("SysYParser.g4"):
print("Error: Missing SysYParser.g4 file")
return
# Create the zip archive
with zipfile.ZipFile("project.zip", "w", zipfile.ZIP_DEFLATED) as zipf:
zip_directory(zipf, "src")
zip_directory(zipf, "include")
zipf.write("CMakeLists.txt")
zipf.write("SysYLexer.g4")
zipf.write("SysYParser.g4")
print("Zip archive created: project.zip")
if __name__ == "__main__":
main()