Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -31,12 +31,12 @@ def compile_and_zip():
|
|
31 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
32 |
cs_filename = f"script_{timestamp}.cs"
|
33 |
exe_filename = f"script_{timestamp}.exe"
|
34 |
-
|
35 |
|
36 |
# Full paths
|
37 |
cs_path = os.path.join(COMPILE_FOLDER, cs_filename)
|
38 |
exe_path = os.path.join(COMPILE_FOLDER, exe_filename)
|
39 |
-
|
40 |
|
41 |
# Write C# source
|
42 |
with open(cs_path, 'w') as f:
|
@@ -67,13 +67,13 @@ class Program
|
|
67 |
print(f"Compile error: {compile_result.stderr}")
|
68 |
return None
|
69 |
|
70 |
-
# Create
|
71 |
-
|
72 |
-
print(f"Running command: {' '.join(
|
73 |
|
74 |
-
|
75 |
-
if
|
76 |
-
print(f"
|
77 |
return None
|
78 |
|
79 |
# Cleanup temporary files
|
@@ -83,15 +83,15 @@ class Program
|
|
83 |
except Exception as e:
|
84 |
print(f"Cleanup error: {e}")
|
85 |
|
86 |
-
# Remove old
|
87 |
-
for old_file in Path(UPLOAD_FOLDER).glob('*.
|
88 |
-
if old_file != Path(
|
89 |
try:
|
90 |
os.remove(old_file)
|
91 |
except:
|
92 |
pass
|
93 |
|
94 |
-
return
|
95 |
|
96 |
except Exception as e:
|
97 |
print(f"Error: {str(e)}")
|
|
|
31 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
32 |
cs_filename = f"script_{timestamp}.cs"
|
33 |
exe_filename = f"script_{timestamp}.exe"
|
34 |
+
archive_filename = f"output_{timestamp}.7z" # Use .7z instead of .rar
|
35 |
|
36 |
# Full paths
|
37 |
cs_path = os.path.join(COMPILE_FOLDER, cs_filename)
|
38 |
exe_path = os.path.join(COMPILE_FOLDER, exe_filename)
|
39 |
+
archive_path = os.path.join(UPLOAD_FOLDER, archive_filename)
|
40 |
|
41 |
# Write C# source
|
42 |
with open(cs_path, 'w') as f:
|
|
|
67 |
print(f"Compile error: {compile_result.stderr}")
|
68 |
return None
|
69 |
|
70 |
+
# Create 7z archive using 7zip
|
71 |
+
seven_zip_cmd = ["/usr/bin/7z", "a", archive_path, exe_path]
|
72 |
+
print(f"Running command: {' '.join(seven_zip_cmd)}") # Debugging output
|
73 |
|
74 |
+
seven_zip_result = subprocess.run(seven_zip_cmd, capture_output=True, text=True)
|
75 |
+
if seven_zip_result.returncode != 0:
|
76 |
+
print(f"7z error: {seven_zip_result.stderr}")
|
77 |
return None
|
78 |
|
79 |
# Cleanup temporary files
|
|
|
83 |
except Exception as e:
|
84 |
print(f"Cleanup error: {e}")
|
85 |
|
86 |
+
# Remove old archive files
|
87 |
+
for old_file in Path(UPLOAD_FOLDER).glob('*.7z'):
|
88 |
+
if old_file != Path(archive_path):
|
89 |
try:
|
90 |
os.remove(old_file)
|
91 |
except:
|
92 |
pass
|
93 |
|
94 |
+
return archive_path
|
95 |
|
96 |
except Exception as e:
|
97 |
print(f"Error: {str(e)}")
|