sigyllly commited on
Commit
6eed034
·
verified ·
1 Parent(s): 745a661

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -12
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
- rar_filename = f"output_{timestamp}.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
- rar_path = os.path.join(UPLOAD_FOLDER, rar_filename)
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 RAR using 7zip
71
- rar_cmd = ["/usr/bin/7z", "a", rar_path, exe_path]
72
- print(f"Running command: {' '.join(rar_cmd)}") # Debugging output
73
 
74
- rar_result = subprocess.run(rar_cmd, capture_output=True, text=True)
75
- if rar_result.returncode != 0:
76
- print(f"RAR error: {rar_result.stderr}")
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 RAR files
87
- for old_file in Path(UPLOAD_FOLDER).glob('*.rar'):
88
- if old_file != Path(rar_path):
89
  try:
90
  os.remove(old_file)
91
  except:
92
  pass
93
 
94
- return rar_path
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)}")