sigyllly commited on
Commit
667dc69
·
verified ·
1 Parent(s): f0c849a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -11
main.py CHANGED
@@ -110,7 +110,7 @@ def index():
110
 
111
  @app.route('/generate', methods=['POST'])
112
  def generate_script():
113
- # Step 7: Generate the randomized assembly information using meaningful words
114
  assembly_info = {
115
  'title': random.choice(titles),
116
  'description': random.choice(descriptions),
@@ -124,7 +124,7 @@ def generate_script():
124
  'informational_version': random_version()
125
  }
126
 
127
- # Step 8: Replace placeholders in the base template
128
  modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
129
  .replace('<<description>>', assembly_info['description']) \
130
  .replace('<<configuration>>', assembly_info['configuration']) \
@@ -144,19 +144,20 @@ def generate_script():
144
  with open(script_path, 'w') as file:
145
  file.write(modified_cs)
146
 
147
- # Step 10: Compile the C# script using dotnet
148
- compile_command = f'dotnet build {script_path} -o /app/out'
149
- print(f"Running compile command: {compile_command}") # Debugging line
150
- result = subprocess.run(compile_command, shell=True, check=False)
151
 
152
- if result.returncode != 0:
153
- print("Compilation failed!") # Debugging line
154
- return "Compilation failed!", 500
155
 
156
- print("Compilation succeeded!") # Debugging line
 
157
 
158
  # Provide a link to download the compiled executable
159
- return send_file('/app/out/polymorphic_program.dll', as_attachment=True)
 
160
 
161
  # Start the Flask app
162
  if __name__ == '__main__':
 
110
 
111
  @app.route('/generate', methods=['POST'])
112
  def generate_script():
113
+ # Generate the randomized assembly information using meaningful words
114
  assembly_info = {
115
  'title': random.choice(titles),
116
  'description': random.choice(descriptions),
 
124
  'informational_version': random_version()
125
  }
126
 
127
+ # Replace placeholders in the base template
128
  modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
129
  .replace('<<description>>', assembly_info['description']) \
130
  .replace('<<configuration>>', assembly_info['configuration']) \
 
144
  with open(script_path, 'w') as file:
145
  file.write(modified_cs)
146
 
147
+ # Compile the C# script using csc
148
+ compile_command = f'csc /target:exe /out:run.exe {script_path}' # Removed unnecessary options
149
+ process = subprocess.run(compile_command, shell=True, capture_output=True, text=True)
 
150
 
151
+ # Log the output and errors for debugging
152
+ print("Compilation Output:", process.stdout)
153
+ print("Compilation Error:", process.stderr)
154
 
155
+ if process.returncode != 0:
156
+ return f"Compilation failed: {process.stderr}", 500
157
 
158
  # Provide a link to download the compiled executable
159
+ return send_file('run.exe', as_attachment=True)
160
+
161
 
162
  # Start the Flask app
163
  if __name__ == '__main__':