From 1084f5e25e9a86b0de566f58093d0cc25753f174 Mon Sep 17 00:00:00 2001
From: Evgeniy Gleba <60469435+geugenm@users.noreply.github.com>
Date: Sat, 2 Dec 2023 20:05:21 +0300
Subject: [PATCH 1/4] Fixed encoding
---
src/Lab_5/_biasedPN.html | 2 +-
src/Lab_5/_biasedPN2.html | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Lab_5/_biasedPN.html b/src/Lab_5/_biasedPN.html
index ba7e9e8..8e4cbdd 100644
--- a/src/Lab_5/_biasedPN.html
+++ b/src/Lab_5/_biasedPN.html
@@ -1,6 +1,6 @@
-
+
Токи через PN-переход
diff --git a/src/Lab_5/_biasedPN2.html b/src/Lab_5/_biasedPN2.html
index 1a76019..55c9516 100644
--- a/src/Lab_5/_biasedPN2.html
+++ b/src/Lab_5/_biasedPN2.html
@@ -1,6 +1,6 @@
-
+
Исследование ОПЗ
From c9e9462a4fd17bb69174a7a4ecc107aaa6b15513 Mon Sep 17 00:00:00 2001
From: Evgeniy Gleba <60469435+geugenm@users.noreply.github.com>
Date: Sat, 2 Dec 2023 20:31:26 +0300
Subject: [PATCH 2/4] Added compile_to_exe script
---
scripts/compile_to_exe.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 scripts/compile_to_exe.py
diff --git a/scripts/compile_to_exe.py b/scripts/compile_to_exe.py
new file mode 100644
index 0000000..5de52e3
--- /dev/null
+++ b/scripts/compile_to_exe.py
@@ -0,0 +1,37 @@
+import argparse
+import os
+import shutil
+import subprocess
+import sys
+
+def compile_exe(script_file, config):
+ output_directory = os.path.join(".build", config)
+ os.makedirs(output_directory, exist_ok=True)
+
+ # PyInstaller flags
+ pyinstaller_flags = ["--onefile", "--noconsole"]
+
+ if config == "debug":
+ pyinstaller_flags.remove("--noconsole")
+ # Add debug flags specific to your project if needed
+ # Example: pyinstaller_flags.extend(["--debug"])
+
+ try:
+ subprocess.run(["pyinstaller", *pyinstaller_flags, script_file])
+ except FileNotFoundError:
+ print("PyInstaller not found. Please install PyInstaller to proceed.")
+ sys.exit(1)
+
+ # Move the compiled executable to the output directory
+ script_name = os.path.splitext(os.path.basename(script_file))[0]
+ exe_name = f"{script_name}.exe"
+ shutil.move(os.path.join("dist", exe_name), os.path.join(output_directory, exe_name))
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Compile and move executable based on configuration")
+ parser.add_argument("script_file", help="Python script file to compile")
+ parser.add_argument("--config", choices=["release", "debug"], default="debug",
+ help="Configuration type (release or debug, default is debug)")
+ args = parser.parse_args()
+
+ compile_exe(args.script_file, args.config)
From 40c2f3ee54cb8478aa3086190d8d878b9fad7367 Mon Sep 17 00:00:00 2001
From: Evgeniy Gleba <60469435+geugenm@users.noreply.github.com>
Date: Sat, 2 Dec 2023 20:34:20 +0300
Subject: [PATCH 3/4] Refactored python code. Added port availability check
---
scripts/compile_to_exe.py | 2 ++
scripts/convert_win1251_to_utf8.py | 6 +++---
scripts/replace_html_win1252_with_utf8.py | 4 ++--
scripts/start_server_cli.py | 4 ++--
scripts/start_server_ui.py | 11 ++++++++++-
5 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/scripts/compile_to_exe.py b/scripts/compile_to_exe.py
index 5de52e3..15d5e74 100644
--- a/scripts/compile_to_exe.py
+++ b/scripts/compile_to_exe.py
@@ -4,6 +4,7 @@
import subprocess
import sys
+
def compile_exe(script_file, config):
output_directory = os.path.join(".build", config)
os.makedirs(output_directory, exist_ok=True)
@@ -27,6 +28,7 @@ def compile_exe(script_file, config):
exe_name = f"{script_name}.exe"
shutil.move(os.path.join("dist", exe_name), os.path.join(output_directory, exe_name))
+
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Compile and move executable based on configuration")
parser.add_argument("script_file", help="Python script file to compile")
diff --git a/scripts/convert_win1251_to_utf8.py b/scripts/convert_win1251_to_utf8.py
index e94dc16..d400021 100644
--- a/scripts/convert_win1251_to_utf8.py
+++ b/scripts/convert_win1251_to_utf8.py
@@ -1,9 +1,9 @@
# Import the necessary modules
-import os
-import codecs
+import argparse
import chardet
+import codecs
import logging
-import argparse
+import os
# Define the source and target encoding
source_encoding = "windows-1251"
diff --git a/scripts/replace_html_win1252_with_utf8.py b/scripts/replace_html_win1252_with_utf8.py
index ecc5550..cc0ca7a 100644
--- a/scripts/replace_html_win1252_with_utf8.py
+++ b/scripts/replace_html_win1252_with_utf8.py
@@ -1,7 +1,7 @@
-import os
-import fileinput
import argparse
+import fileinput
import logging
+import os
def replace_charset_in_file(file_path):
diff --git a/scripts/start_server_cli.py b/scripts/start_server_cli.py
index 4b0090e..23d8aab 100644
--- a/scripts/start_server_cli.py
+++ b/scripts/start_server_cli.py
@@ -18,10 +18,10 @@
python3 script.py
"""
-import webbrowser
+import logging
import socket
import subprocess
-import logging
+import webbrowser
# Define the custom log level
VERBOSE = 15
diff --git a/scripts/start_server_ui.py b/scripts/start_server_ui.py
index 6967252..5f11d1e 100644
--- a/scripts/start_server_ui.py
+++ b/scripts/start_server_ui.py
@@ -63,6 +63,11 @@ def setup_logging(self):
self.logger.info(f"Server started at {timestamp}")
+ @staticmethod
+ def is_port_in_use(port):
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+ return s.connect_ex(('localhost', port)) == 0
+
def start_server(self):
self.start_button.config(state=tk.DISABLED)
self.directory_entry.config(state=tk.DISABLED)
@@ -79,6 +84,10 @@ def start_server(self):
port = int(self.port.get())
+ if self.is_port_in_use(port):
+ messagebox.showinfo("Port in Use", f"Port {port} is already in use. Please choose another port.")
+ return
+
self.server = socketserver.TCPServer(("localhost", port), http.server.SimpleHTTPRequestHandler)
self.server_thread = threading.Thread(target=self.server.serve_forever)
self.server_thread.daemon = True
@@ -121,7 +130,7 @@ def run_server(directory, port, log_file):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Java WebAssembly Translation Server with UI")
- parser.add_argument("-dir", "--directory", type=str, default="", help="Directory to open")
+ parser.add_argument("-dir", "--directory", type=str, default="./", help="Directory to open")
parser.add_argument("-p", "--port", type=int, default=8080, help="Port to run the server on")
parser.add_argument("-log", "--logfile", type=str, default="log.txt", help="Log file name")
args = parser.parse_args()
From 7fb1a97f69efa67753482e09c8cf6927015f325e Mon Sep 17 00:00:00 2001
From: Evgeniy Gleba <60469435+geugenm@users.noreply.github.com>
Date: Sat, 2 Dec 2023 20:43:48 +0300
Subject: [PATCH 4/4] Removed socket check due to its slowness
---
scripts/start_server_ui.py | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/scripts/start_server_ui.py b/scripts/start_server_ui.py
index 5f11d1e..221a687 100644
--- a/scripts/start_server_ui.py
+++ b/scripts/start_server_ui.py
@@ -63,11 +63,6 @@ def setup_logging(self):
self.logger.info(f"Server started at {timestamp}")
- @staticmethod
- def is_port_in_use(port):
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
- return s.connect_ex(('localhost', port)) == 0
-
def start_server(self):
self.start_button.config(state=tk.DISABLED)
self.directory_entry.config(state=tk.DISABLED)
@@ -84,10 +79,6 @@ def start_server(self):
port = int(self.port.get())
- if self.is_port_in_use(port):
- messagebox.showinfo("Port in Use", f"Port {port} is already in use. Please choose another port.")
- return
-
self.server = socketserver.TCPServer(("localhost", port), http.server.SimpleHTTPRequestHandler)
self.server_thread = threading.Thread(target=self.server.serve_forever)
self.server_thread.daemon = True