Skip to content

Commit 630ed19

Browse files
committed
feat: Prepare project for first release
- Updated app.py, main.py, and interactive_cli.py for executable building. - Adjusted dependencies and file structure for release readiness.
1 parent 894e44d commit 630ed19

File tree

5 files changed

+89
-42
lines changed

5 files changed

+89
-42
lines changed

interactive_cli.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import subprocess
2+
import sys
3+
import os
4+
from colorama import init, Fore, Style
5+
6+
# Initialize colorama
7+
init(autoreset=True)
8+
9+
def resource_path(relative_path):
10+
"""Get the absolute path to a resource, works for PyInstaller"""
11+
if getattr(sys, '_MEIPASS', False): # If running in a PyInstaller bundle
12+
return os.path.join(sys._MEIPASS, relative_path)
13+
return os.path.join(os.path.abspath("."), relative_path)
14+
15+
def print_ascii_banner():
16+
banner = """
17+
{}
18+
::
19+
%%
20+
%%
21+
#*:*##%#+. -*###%#= -*%###+:%% .=#####+: .+#%%%#+: =*%%%%#+. .=*%%%%#=. *#+=#%%%#=. :+#%%%#+:
22+
%%#. -%# #%- :#%. +%+ -%%% :%# *%- .%%%:.-**= .%%%#)%%%. -%%% %%%: #%%%*==*%%%: =%%# *%%=
23+
%% #% *%- .%# :%+ .%% %%=::::::%% #%%+-:. *%%: .%%%: .%%# #%%. :%%% :%%%=====#%%
24+
%# *% %%. #% =%- %% .%%========= -+*#%%%+ #%% .%%# *%% #%* #%%.-%%.
25+
%# *% =%+ -%+ .%# =%% *%- -. .-+: +%%- =%%+. =+-. #%%+. .=%%* #%%= .+%%* %%%: ==.
26+
%# *% :##=--=#%= :#%+--=#*%% =%*=--+%#: .*%%%##%%* =#%%%%%%%+ +%%%%%%%%= #%%#%%%%%%= .*%%%#%%%#:
27+
-- :- :-===: .===-. -- :===-. .-===-. :-===- :====: #%# :===- -===-.
28+
#%#
29+
#%#
30+
31+
Nodescope: an XML Editor and Visualizer
32+
{}""".format(Fore.CYAN, Style.RESET_ALL)
33+
print(banner)
34+
35+
def interactive_loop():
36+
print_ascii_banner()
37+
try:
38+
from src.cli.cli_handler import main as cli_main # Import the CLI handler's main function
39+
except ImportError as e:
40+
print(f"{Fore.RED}Error importing CLI handler: {e}{Style.RESET_ALL}")
41+
sys.exit(1)
42+
43+
while True:
44+
try:
45+
command = input(f"{Fore.GREEN}>> {Style.RESET_ALL}").strip()
46+
if command.lower() in ["exit", "quit"]:
47+
print(f"{Fore.LIGHTRED_EX}Exiting CLI mode. Goodbye!{Style.RESET_ALL}")
48+
sys.exit(0)
49+
elif not command:
50+
continue # Skip empty commands
51+
52+
# Split the command into arguments
53+
args = command.split()
54+
55+
# Backup original sys.argv
56+
original_argv = sys.argv.copy()
57+
58+
# Set sys.argv to mimic command-line arguments
59+
sys.argv = [sys.executable, *args]
60+
61+
try:
62+
cli_main() # Call the CLI handler's main function
63+
except SystemExit:
64+
# argparse may call sys.exit(), which raises SystemExit
65+
pass
66+
finally:
67+
# Restore original sys.argv
68+
sys.argv = original_argv
69+
except KeyboardInterrupt:
70+
print(f"\n{Fore.LIGHTRED_EX}Exiting CLI mode. Goodbye!{Style.RESET_ALL}")
71+
sys.exit(0)
72+
except Exception as e:
73+
print(f"{Fore.RED}An unexpected error occurred: {e}{Style.RESET_ALL}")
74+
75+
if __name__ == "__main__":
76+
interactive_loop()

main.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import argparse
22
import subprocess
3-
import sys
3+
import sys, os
44
from colorama import init, Fore, Style
5+
from interactive_cli import interactive_loop
56

67
# Initialize colorama
78
init(autoreset=True)
89

10+
def resource_path(relative_path):
11+
""" Get the absolute path to a resource, works for PyInstaller """
12+
if getattr(sys, '_MEIPASS', False): # If running in a PyInstaller bundle
13+
return os.path.join(sys._MEIPASS, relative_path)
14+
return os.path.join(os.path.abspath("."), relative_path)
15+
916
def launch_gui():
1017
from src.gui.gui_handler import App
1118
app = App()
@@ -32,21 +39,7 @@ def print_ascii_banner():
3239
print(banner)
3340

3441
def launch_cli():
35-
print_ascii_banner()
36-
while True:
37-
try:
38-
# Prompt the user for input with styled text
39-
command = input(f"{Fore.GREEN}>> {Style.RESET_ALL}")
40-
if command.lower() in ["exit", "quit"]:
41-
print("Exiting CLI mode.")
42-
break
43-
# Pass the command to the CLI handler
44-
subprocess.run(["python", "src/cli/cli_handler.py"] + command.split(), check=True)
45-
except subprocess.CalledProcessError as e:
46-
print(f"Error: {e}")
47-
except KeyboardInterrupt:
48-
print("\nExiting CLI mode.")
49-
break
42+
interactive_loop()
5043

5144
def main():
5245
parser = argparse.ArgumentParser(description="nodescope: an XML Editor and Visualizer")

src/gui/gui_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from PIL import Image
33
import os
44
import sys
5+
from main import resource_path
56

67
# Add the project root to sys.path dynamically
78
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -71,8 +72,8 @@ def center_window(self):
7172

7273
def load_images(self):
7374
# Placeholder for image loading - replace with actual paths
74-
self.light_logo_path = r"src/gui/gui_assets/nodescope_light.png"
75-
self.dark_logo_path = r"src/gui/gui_assets/nodescope_dark.png"
75+
self.light_logo_path = resource_path("src/gui/gui_assets/nodescope_light.png")
76+
self.dark_logo_path = resource_path("src/gui/gui_assets/nodescope_dark.png")
7677

7778
# Load placeholder images (replace with actual images)
7879
try:

src/modules/xml_to_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,4 @@ def convert(self, output_path):
282282

283283
# # Log detailed error information
284284
# with open('error_log.txt', 'w') as error_log:
285-
# error_log.write(f"Error Details:\n{traceback.format_exc()}\n")
285+
# error_log.write(f"Error Details:\n{traceback.format_exc()}\n")

src/postsearch/post_search.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,3 @@ def _extract_tag_value(self, content, tag):
109109
return None
110110
return content[start:end]
111111

112-
113-
114-
# Example Usage
115-
# Ensure the XML file path is correct
116-
xml_file_path = r"samples/test.xml" # Use raw string or forward slashes
117-
118-
searcher = PostSearch(xml_file_path)
119-
120-
"""
121-
# Search for posts containing a specific word (case-insensitive)
122-
word = "EXercitation "
123-
word_results = searcher.search_word(word)
124-
print(f"Posts containing the word '{word}':")
125-
for post_body in word_results:
126-
print(post_body)
127-
128-
# Search for posts with a specific topic (case-insensitive)
129-
topic = "tOPiC1"
130-
topic_results = searcher.search_topic(topic)
131-
print(f"\nPosts with topic '{topic}':")
132-
for post_body in topic_results:
133-
print(post_body)
134-
"""

0 commit comments

Comments
 (0)