-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathp4wnsolo-terminal.py
74 lines (61 loc) · 2.08 KB
/
p4wnsolo-terminal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-2020 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK
"""
Simple println capabilities.
"""
import os
import time
import subprocess
from pathlib import Path
from demo_opts import get_device
from luma.core.virtual import terminal
from PIL import ImageFont
# Init variables
textfile = 'theoutput.txt'
brpath = '/home/pi/p4wnsolo/blueranger.sh'
inputfile = 'thecommand.txt'
# Get input
file1 = open(inputfile, 'r')
userinput = file1.readlines()
userinput = userinput[1]
userinput = userinput.strip('\n')
print('\nCommand: ' + str(userinput) + '\n')
def make_font(name, size):
font_path = str(Path(__file__).resolve().parent.joinpath('fonts', name))
return ImageFont.truetype(font_path, size)
print("Displaying output..\n")
# Define output file name variable
outputfilename = textfile
# Open the output file in WRITE mode (for logging)
outputfile = open(outputfilename, "w")
# Define script command to be run, insert the MAC, output to txt log file
prep_cmd = userinput
cmd = prep_cmd + " >> " + outputfilename
print(cmd)
######################## Run the script Subprocess ################################
pro = subprocess.Popen(cmd, stdout=subprocess.PIPE,shell=True, preexec_fn=os.setsid)
print('\n*****OUTPUT*****:\n')
def main():
while True:
for fontname, size in [(None, None), ("tiny.ttf", 6), ("ProggyTiny.ttf", 16), ("creep.bdf", 16), ("miscfs_.ttf", 12), ("FreePixel.ttf", 12), ('ChiKareGo.ttf', 16)]:
font = make_font(fontname, size) if fontname else None
term = terminal(device, font)
term.clear()
with open(textfile) as f:
for line in f:
# For Python3, use print(line)
print(line.strip('\n'))
term.println(line.strip('\n'))
if 'xyz' in line:
break
time.sleep(2)
exit()
if __name__ == "__main__":
try:
device = get_device()
main()
except KeyboardInterrupt:
pass