diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +venv diff --git a/Makefile b/Makefile index fd58fce..8b1bbc3 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ dev: - @bots/dev + @bots/dev.sh release: - @bots/builder + @bots/builder.sh run: - @bots/runner + @bots/runner.sh build-spec: - @bots/spec-builder \ No newline at end of file + @bots/spec-builder.sh \ No newline at end of file diff --git a/__main__.spec b/__main__.spec new file mode 100644 index 0000000..fb74e02 --- /dev/null +++ b/__main__.spec @@ -0,0 +1,43 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['__main__.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='__main__', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +coll = COLLECT( + exe, + a.binaries, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='__main__', +) diff --git a/app/main.py b/app/main.py index eb2e9e8..0f79d1c 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,7 @@ from _system import * from server import * +from utils import list_all_themes +from src.rpc import evalRPC app.on_startup.append(on_startup) app.router.add_static('/static', STATIC_PATH) @@ -44,6 +46,12 @@ def run(): help="Enter a theme to uxterm", default="default", type = str) + + parser.add_argument('-ct', + '--custom-theme', + help="Use a custom theme on uxterm", + default="", + type = str) parser.add_argument('--list-themes', help="List all themes and exit", action='store_true') @@ -53,7 +61,7 @@ def run(): sys.exit(list_all_themes()) - sys.exit(run_new_term(args.command, args.host, args.port, args.binargs, args.theme)) + sys.exit(run_new_term(args.command, args.host, args.port, args.binargs, args.theme, args.custom_theme)) diff --git a/app/server.py b/app/server.py index 6ee857e..4186b9d 100644 --- a/app/server.py +++ b/app/server.py @@ -1,5 +1,3 @@ -import pprint - import aiohttp_jinja2 import jinja2 import socketio @@ -7,10 +5,10 @@ import src.uterm as uterm from _system import * from aiohttp import web -import rich urequirements.main() + usocket = socketio.AsyncServer() app = web.Application() aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(TEMPLATES_PATH)) @@ -19,9 +17,10 @@ terminal_api = uterm.TerminalCoreApi(rows=50, cols=50) + class PtyInterface: - def input_(text:str, *args, **kwargs) -> None: + def input_(text: str, *args, **kwargs) -> None: terminal_api.write(text.encode()) @@ -34,7 +33,7 @@ def post_theme(request) -> web.Response: ... async def get_theme(request) -> web.Response: - theme_name = request.match_info['theme_name'] + theme_name:str = request.match_info['theme_name'] theme = uterm.XTERM_SETTINGS.themes.get( theme_name.lower(), @@ -73,83 +72,6 @@ async def on_startup(app): usocket_config["theme"] = "default" -async def eval_payload(prompt: str, aio: bool) -> str: - if aio: - try: - return await eval(prompt) - except: - return None - - try: - return eval(prompt) - except: - return None - - -async def exec_payload(prompt: str, aio: bool) -> None: - if aio: - try: - await exec(prompt) - except: - pass - - try: - exec(prompt) - except: - pass - - -async def evalRPC(request) -> web.Response: - payload = await request.json() - - if "eval" in payload.keys(): - try: - evaluated_res = await eval_payload( - prompt=payload["eval"][">>>"], - aio=payload["eval"]["async"] - ) - except Exception as e: - return web.json_response( - { - "status": False, - "log": "Not Evaluated", - "code": 1, - f"Exception {e}": { - "name": str(e), - "args": e.args, - } - } - ) - - if "exec" in payload.keys(): - try: - _ = await exec_payload( - prompt=payload["exec"][">>>"], - aio=payload["exec"]["async"] - ) - except Exception as e: - return web.json_response( - { - "status": False, - "log": "Not Excuted", - "code": 2, - f"Exception {e}": { - "name": str(e), - "args": e.args, - } - } - ) - - return web.json_response( - { - "status": True, - "log": "sucess", - "code": 0, - "evaluated": evaluated_res - } - ) - - @aiohttp_jinja2.template('index.html') async def index(request) -> dict: """Serve the client-side application.""" @@ -183,15 +105,12 @@ async def connect(sid, environ) -> None: await usocket.emit("pty-set-theme", {"name": usocket_config["theme"]}, namespace="/pty") -def run_new_term(command: str = "python3", host: str = "127.0.0.1", port: int = 9990, command_args: str = "", theme: str = "default") -> None: +def run_new_term(command: str = "python3", host: str = "127.0.0.1", port: int = 9990, command_args: str = "", theme: str = "default", custom_theme: str = None) -> None: usocket_config["cmd"] = uterm.TermUtils.get_split_command( command, command_args) usocket_config["theme"] = theme.lower() - web.run_app(app, port=port, host=host) - + + if custom_theme: + usocket_config["theme"] = uterm.XTERM_SETTINGS.add_theme(custom_theme) -def list_all_themes() -> None: - themes = uterm.XTERM_SETTINGS.themes.keys() - for theme in themes: - rich.print(f"[bold green]{theme}") - rich.print(f"[bold yellow]TOTAL[/]: {len(themes)}") \ No newline at end of file + web.run_app(app, port=port, host=host) \ No newline at end of file diff --git a/app/src/rpc.py b/app/src/rpc.py new file mode 100644 index 0000000..5612c6b --- /dev/null +++ b/app/src/rpc.py @@ -0,0 +1,77 @@ +from aiohttp import web + +async def eval_payload(prompt: str, aio: bool) -> str: + if aio: + try: + return await eval(prompt) + except: + return None + + try: + return eval(prompt) + except: + return None + + +async def exec_payload(prompt: str, aio: bool) -> None: + if aio: + try: + await exec(prompt) + except: + pass + + try: + exec(prompt) + except: + pass + + +async def evalRPC(request) -> web.Response: + payload = await request.json() + + if "eval" in payload.keys(): + try: + evaluated_res = await eval_payload( + prompt=payload["eval"][">>>"], + aio=payload["eval"]["async"] + ) + except Exception as e: + return web.json_response( + { + "status": False, + "log": "Not Evaluated", + "code": 1, + f"Exception {e}": { + "name": str(e), + "args": e.args, + } + } + ) + + if "exec" in payload.keys(): + try: + _ = await exec_payload( + prompt=payload["exec"][">>>"], + aio=payload["exec"]["async"] + ) + except Exception as e: + return web.json_response( + { + "status": False, + "log": "Not Excuted", + "code": 2, + f"Exception {e}": { + "name": str(e), + "args": e.args, + } + } + ) + + return web.json_response( + { + "status": True, + "log": "sucess", + "code": 0, + "evaluated": evaluated_res + } + ) diff --git a/app/src/uterm.py b/app/src/uterm.py index f7237b4..369a689 100644 --- a/app/src/uterm.py +++ b/app/src/uterm.py @@ -14,30 +14,33 @@ class Defaults: THEME = {"background": "#212121"} def __init__(self): - self.__themes = self.read_themes() + self.__themes = dict() + self.load_themes() @property def themes(self) -> dict: return self.__themes + def add_theme(self, theme_file:str) -> str: + name = pathlib.Path(theme_file).name + name = name.split(".")[0].lower() + with open(theme_file, "r") as fp: + self.__themes[name] = hjson.load(fp) + return name + def update_themes(self) -> None: self.__themes.clear() - self.__themes = self.read_themes() + self.__themes = self.load_themes() - def read_themes(self) -> dict: - themes = dict() + def load_themes(self) -> None: possible_themes = glob.glob( os.path.join("/",os.environ["UTERM_ROOT_PATH"],"settings","themes")+"/**.theme.json", recursive=True ) - for file in possible_themes: - name = pathlib.Path(file).name - name = name.split(".")[0].lower() - with open(file, "r") as fp: - themes[name] = hjson.load(fp) - - return themes + for theme_file in possible_themes: + self.add_theme(theme_file) + XTERM_SETTINGS = XTermSettings() diff --git a/app/utils.py b/app/utils.py new file mode 100644 index 0000000..db493a4 --- /dev/null +++ b/app/utils.py @@ -0,0 +1,9 @@ +import src.uterm as uterm +from _system import * +import rich + +def list_all_themes() -> None: + themes = uterm.XTERM_SETTINGS.themes.keys() + for theme in themes: + rich.print(f"[bold green]{theme}") + rich.print(f"[bold yellow]TOTAL[/]: {len(themes)}") diff --git a/bots/builder b/bots/builder deleted file mode 100755 index bc699e5..0000000 --- a/bots/builder +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -source ~/Ideas/Pyuxterm/pyenv/bin/activate -cd ~/Ideas/Pyuxterm -pyinstaller build.spec - -#rm -rfv ~/Ideas/Pyuxterm/dist && mkdir ~/Ideas/Pyuxterm/dist -#rm -rfv ~/Ideas/Pyuxterm/build && mkdir ~/Ideas/Pyuxterm/build - -#mv ~/Ideas/Pyuxterm/app/dist ~/Ideas/Pyuxterm/ -#mv ~/Ideas/Pyuxterm/app/build ~/Ideas/Pyuxterm/ \ No newline at end of file diff --git a/bots/builder.sh b/bots/builder.sh new file mode 100755 index 0000000..7d16082 --- /dev/null +++ b/bots/builder.sh @@ -0,0 +1 @@ +pyinstaller build.spec \ No newline at end of file diff --git a/bots/dev b/bots/dev deleted file mode 100755 index 21b7202..0000000 --- a/bots/dev +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -source ~/Ideas/Pyuxterm/pyenv/bin/activate -cd ~/Ideas/Pyuxterm/app -aiohttp-devtools runserver \ No newline at end of file diff --git a/bots/dev.sh b/bots/dev.sh new file mode 100755 index 0000000..43635d2 --- /dev/null +++ b/bots/dev.sh @@ -0,0 +1,2 @@ +cd app +aiohttp-devtools runserver \ No newline at end of file diff --git a/bots/runner b/bots/runner deleted file mode 100755 index 4c37257..0000000 --- a/bots/runner +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -source ~/Ideas/Pyuxterm/pyenv/bin/activate -cd ~/Ideas/Pyuxterm -./bots/builder #| tee build/build.app.log -./dist/pyuxterm \ No newline at end of file diff --git a/bots/runner.sh b/bots/runner.sh new file mode 100755 index 0000000..c7589ca --- /dev/null +++ b/bots/runner.sh @@ -0,0 +1,2 @@ +./bots/builder.sh #| tee build/build.app.log +./dist/pyuxterm \ No newline at end of file diff --git a/bots/spec-builder b/bots/spec-builder deleted file mode 100755 index 50b3e76..0000000 --- a/bots/spec-builder +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -source ~/Ideas/Pyuxterm/pyenv/bin/activate -cd ~/Ideas/Pyuxterm/app -pyi-makespec --onefile __main__.py -pyi-makespec __main__.py \ No newline at end of file diff --git a/bots/spec-builder.sh b/bots/spec-builder.sh new file mode 100755 index 0000000..770fcfa --- /dev/null +++ b/bots/spec-builder.sh @@ -0,0 +1,2 @@ +pyi-makespec --onefile __main__.py +pyi-makespec __main__.py \ No newline at end of file diff --git a/bots/tester b/bots/tester deleted file mode 100755 index 05a7907..0000000 --- a/bots/tester +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash - diff --git a/requirements.txt b/requirements.txt index 7e7112c..082a349 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,48 +1,46 @@ -aiohttp==3.8.1 -aiohttp-devtools==1.0.post0 -aiohttp-jinja2==1.5 -aiosignal==1.2.0 -altgraph==0.17.2 -anyio==3.6.2 -asttokens==2.2.1 -async-timeout==4.0.2 -attrs==21.4.0 -autopep8==2.0.0 -bidict==0.22.0 -certifi==2022.5.18.1 -charset-normalizer==2.0.12 -click==8.1.3 -commonmark==0.9.1 -cx-Freeze==6.10 -devtools==0.10.0 -exceptiongroup==1.0.4 -executing==1.2.0 -frozenlist==1.3.0 +aiohttp==3.9.1 +aiohttp-devtools==1.1.2 +aiohttp-jinja2==1.6 +aiosignal==1.3.1 +altgraph==0.17.4 +anyio==4.2.0 +asttokens==2.4.1 +async-timeout==4.0.3 +attrs==23.1.0 +autopep8==2.0.4 +bidict==0.22.1 +certifi==2023.11.17 +charset-normalizer==3.3.2 +click==8.1.7 +devtools==0.12.2 +exceptiongroup==1.2.0 +executing==2.0.1 +frozenlist==1.4.1 +h11==0.14.0 hjson==3.1.0 -idna==3.3 -importlib-metadata==4.11.4 -iniconfig==1.1.1 +idna==3.6 +importlib-metadata==7.0.0 Jinja2==3.1.2 -MarkupSafe==2.1.1 -multidict==6.0.2 -packaging==22.0 -patchelf==0.14.5.0 -pluggy==1.0.0 -pycodestyle==2.10.0 -Pygments==2.13.0 -pyinstaller==5.1 -pyinstaller-hooks-contrib==2022.6 -pytest==7.2.0 -pytest-aiohttp==1.0.4 -pytest-asyncio==0.20.3 -python-engineio==4.3.2 -python-socketio==5.6.0 -requests==2.27.1 -rich==12.6.0 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +mdurl==0.1.2 +multidict==6.0.4 +packaging==23.2 +pycodestyle==2.11.1 +Pygments==2.17.2 +pyinstaller==6.3.0 +pyinstaller-hooks-contrib==2023.11 +python-engineio==4.8.0 +python-socketio==5.10.0 +requests==2.31.0 +rich==13.7.0 +simple-websocket==1.0.0 six==1.16.0 sniffio==1.3.0 tomli==2.0.1 -urllib3==1.26.9 -watchgod==0.8.2 -yarl==1.7.2 -zipp==3.8.0 +typing_extensions==4.9.0 +urllib3==2.1.0 +watchfiles==0.21.0 +wsproto==1.2.0 +yarl==1.9.4 +zipp==3.17.0