Skip to content

Commit 8d3f1b8

Browse files
committed
1.2.0 - Added a basic API, minor refactoring
API frontend is available on PlugM
1 parent 34dd916 commit 8d3f1b8

12 files changed

Lines changed: 122 additions & 46 deletions

File tree

make

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ build () {
8080
../../src/pyziniter/__init__.py
8181
../../src/pyziniter/pyzinit.py
8282
../../src/pyziniter/verJSONcreate.py
83+
../../src/api/__init__.py
84+
../../src/api/connection.py
85+
../../src/api/pyzprompt.py
86+
../../src/api/pyzshell.py
8387
)
8488

8589
pyinstaller --onefile "${pythonfiles[@]}"
@@ -215,6 +219,7 @@ installdeps () {
215219
sudo apt install python3-pip pandoc || sudo pacman -S python-pip pandoc || sudo dnf install python3-pip pandoc
216220
pip install termcolor
217221
pip install pyinstaller
222+
pip install pynput
218223

219224
elif [[ "$1" == "dev" ]]; then
220225
sudo apt install python3-pip pandoc || sudo pacman -S python-pip pandoc || sudo dnf install python3-pip pandoc
@@ -223,6 +228,7 @@ installdeps () {
223228
elif [[ "$1" == "runtime" ]]; then
224229
sudo apt install python3-pip || sudo pacman -S python-pip || sudo dnf install python3-pip
225230
pip install termcolor
231+
pip install pynput
226232
fi
227233
}
228234

make.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function build () {
4444
mkdir -p bin\Windows
4545
Set-Location bin\Windows
4646

47-
pyinstaller --onefile ..\..\src\main.py ..\..\src\shell\shell.py ..\..\src\shell\rccreator.py ..\..\src\pluginmgr\manager.py ..\..\src\shell\pluginimport.py ..\..\src\pluginmgr\installer.py ..\..\src\pluginmgr\mgrinit.py ..\..\src\pluginmgr\remover.py ..\..\src\pluginmgr\searcher.py ..\..\src\pluginmgr\updater.py ..\..\src\pyziniter\__init__.py ..\..\src\pyziniter\pyzinit.py ..\..\src\pyziniter\verJSONcreate.py
47+
pyinstaller --onefile ..\..\src\main.py ..\..\src\shell\shell.py ..\..\src\shell\rccreator.py ..\..\src\pluginmgr\manager.py ..\..\src\shell\pluginimport.py ..\..\src\pluginmgr\installer.py ..\..\src\pluginmgr\mgrinit.py ..\..\src\pluginmgr\remover.py ..\..\src\pluginmgr\searcher.py ..\..\src\pluginmgr\updater.py ..\..\src\pyziniter\__init__.py ..\..\src\pyziniter\pyzinit.py ..\..\src\pyziniter\verJSONcreate.py ..\..\src\api\__init__.py ..\..\src\api\pyzprompt.py ..\..\src\api\pyzshell.py
4848
Set-Location -Path dist
4949
Rename-Item -Path main.exe pyz.exe
5050
Move-Item -Path .\pyz.exe -Destination ..\pyz.exe
@@ -94,6 +94,7 @@ function installdeps () {
9494
} elseif ($args[0] -eq "runtime") {
9595
installPython
9696
pip install termcolor
97+
pip install pynput
9798
}
9899
}
99100

pyz-workspace.code-workspace

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
{
22
"folders": [
3+
/*
4+
You might want to edit these paths, depending on what you have and what you don't
5+
For some dumb-ass reason, VS Code workspaces only support paths relative to the workspace file. (Either that, or I can't set it up properly)
6+
*/
37
{
48
"path": ".",
5-
"name": "PyZ Shell"
9+
"name": "PyZ Shell" // The actuall program
610
},
711
{
812
"path": "../pyz-plugm-repo",
9-
"name": "Main repo"
13+
"name": "Main repo" // The plugin repository
1014
},
1115
{
1216
"path": "../pyz-repo-template",
13-
"name": "Repo Template"
17+
"name": "Repo Template" // Repo template
18+
},
19+
{
20+
"path": "../pyz-extensions",
21+
"name": "Plugins (dev)" // Not available anywhere, it's just a folder where I have plugins that are W.I.P
1422
},
1523
{
16-
/*
17-
You might want to edit paths for Plugins (*nix) and Plugins (Windows), depending on where you placed the workspace file.
18-
For some dumb-ass reason, VS Code workspaces only support paths relative to the workspace file. (Either that, or I can't set it up properly)
19-
*/
2024
"path": "../../../.local/share/pyz/plugins",
2125
"name": "Plugins (*nix)"
2226
},

rmpycache.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if [[ "$(pwd)" == *"pyz-shell"* ]]; then
77
src/shell/__pycache__
88
src/updatemgr/__pycache__
99
src/pyziniter/__pycache__
10+
src/api/__pycache__
1011
)
1112
rm -r ${pycachedirs[*]}
1213
else

src/api/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import api.connection as connection
2+
import api.pyzprompt as pyzprompt
3+
import api.pyzshell as pyzshell

src/api/connection.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import socket
2+
import threading
3+
import api
4+
import shell.shell as shell
5+
6+
HEADER = 64
7+
PORT = 23465
8+
SERVER = socket.gethostbyname(socket.gethostname())
9+
ADDR = (SERVER, PORT)
10+
FORMAT = 'utf-8'
11+
DISCONNECT_MSG = "!DISCONNECT"
12+
13+
14+
connected = None
15+
16+
def handle_client(conn, addr):
17+
18+
connected = True
19+
while connected:
20+
msg_length = conn.recv(HEADER).decode(FORMAT)
21+
if msg_length:
22+
msg_length = int(msg_length)
23+
24+
msg = conn.recv(msg_length).decode(FORMAT)
25+
if msg == DISCONNECT_MSG:
26+
connected = False # could also be "break", both are possible
27+
28+
if msg.__contains__("pyzchprompt"):
29+
msgarr = msg.split()
30+
msgarr.pop(0)
31+
api.pyzprompt.chPrompt(" ".join(msgarr))
32+
33+
if msg.__contains__("gtprompt"):
34+
api.pyzprompt.getPrompt()
35+
36+
if msg.__contains__("setalias"):
37+
api.pyzshell.setAlias(msg.split(" ")[1], msg.split(" ")[2])
38+
39+
40+
41+
def stop():
42+
connected = False
43+
44+
def start():
45+
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
46+
server.bind(ADDR)
47+
server.listen()
48+
while True:
49+
conn, addr = server.accept()
50+
handlethread = threading.Thread(target=handle_client, args=(conn, addr))
51+
handlethread.start()

src/api/pyzprompt.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import shell.shell as shell
2+
3+
def chPrompt(newprompt):
4+
shell.prompt = newprompt
5+
return None
6+
7+
def getPrompt():
8+
return shell.prompt

src/api/pyzshell.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def setAlias(alias, cmd):
2+
try:
3+
if alias == None or cmd == None or alias == None and cmd == None:
4+
raise ValueError
5+
else:
6+
alias = cmd
7+
except ValueError:
8+
print("Setting alias failed! No alias/cmd found")

src/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
# Importing modules
44
import os
55
import sys
6-
import platform
7-
from pyziniter import pyzinit # Basically only for returning the host's arch
6+
import platform # Basically only for returning the host's arch
7+
import threading
88

99
# Importing other files
1010
import shell
1111
import pluginmgr
1212
import updatemgr
1313
import pyziniter
14+
import api
1415

1516
homedir = os.path.expanduser('~')
1617
pyver = sys.version.split(" ")
1718

19+
apithread = threading.Thread(target=api.connection.start, daemon=True)
20+
1821
# Putting "everything" together and running.
1922
def main():
2023
sys.argv.extend(" ")
@@ -51,6 +54,7 @@ def main():
5154
sys.exit(0)
5255

5356
elif sys.argv[1] == " ":
57+
apithread.start()
5458
if os.path.isdir(pyziniter.PYZFOLDER):
5559
updatemgr.checker.checkForUpdates()
5660
else:
@@ -72,4 +76,5 @@ def main():
7276

7377
return 0
7478

75-
main()
79+
pyzthread = threading.Thread(target=main)
80+
pyzthread.start()

src/pluginmgr/installer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def getRepo():
1919
def install(package):
2020
try:
2121
if package != " ":
22-
validrepobrokey = getRepo() # Contains a 0A byte (\n) at the end, that's doo doo
23-
validrepo = validrepobrokey[:-1] # and we need to remove it
22+
validrepo = getRepo()
2423

2524
with open(manager.PLUGINFOLDER+"/MANIFEST/mainrepo.json") as manifestfile:
2625
parsedmanifest = json.load(manifestfile)
@@ -50,7 +49,7 @@ def install(package):
5049

5150
os.remove(os.path.join(manager.PLUGINFOLDER, validzip))
5251
else:
53-
print("Error! Repository returned code "+ str(zipurl.status_code) +".") # Else, throw a hissy fit about the repository not returning 200
52+
print(f"Error! Repository returned code {str(zipurl.status_code)}.") # Else, throw a hissy fit about the repository not returning 200
5453
sys.exit(0)
5554

5655
else:

0 commit comments

Comments
 (0)