[fix] Many fixes to the clitools runner lib
This commit is contained in:
parent
1e43a5fc43
commit
2f54d37856
@ -10,6 +10,16 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import redis
|
import redis
|
||||||
|
|
||||||
|
|
||||||
|
environ = {
|
||||||
|
# "REDIS_IP" : "127.0.0.1",
|
||||||
|
"REDIS_IP" : "192.168.2.44",
|
||||||
|
"REDIS_PORT" : "6379",
|
||||||
|
"REDIS_KEY" : "/pl/0/0",
|
||||||
|
"REDIS_SCENE" : "0",
|
||||||
|
"REDIS_LASER" : "0"
|
||||||
|
}
|
||||||
|
|
||||||
class bcolors:
|
class bcolors:
|
||||||
HL = '\033[31m'
|
HL = '\033[31m'
|
||||||
OKBLUE = '\033[94m'
|
OKBLUE = '\033[94m'
|
||||||
@ -37,12 +47,12 @@ def intkey():
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print("Error.")
|
print("Error.")
|
||||||
|
|
||||||
current_id=0
|
current_id = 0
|
||||||
current_cmd=""
|
current_cmd = ""
|
||||||
process = None
|
process = None
|
||||||
current_filename = ""
|
current_filename = ""
|
||||||
currentPlayList = []
|
currentPlayList = []
|
||||||
playlistsDir = Path("./playlists")
|
playlistsDir = Path("./playlists")
|
||||||
if not playlistsDir.is_dir() : playlistsDir.mkdir()
|
if not playlistsDir.is_dir() : playlistsDir.mkdir()
|
||||||
|
|
||||||
def ask(q):
|
def ask(q):
|
||||||
@ -105,10 +115,12 @@ def action_changeCommand( inc ):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def action_match( k ):
|
def action_match( k ):
|
||||||
|
global current_id, currentPlayList
|
||||||
if int(k) > (len(currentPlayList) - 1):
|
if int(k) > (len(currentPlayList) - 1):
|
||||||
print( bcolors.HL + "This key does not exist" + bcolors.ENDC )
|
print( bcolors.HL + "This key does not exist" + bcolors.ENDC )
|
||||||
return False
|
return False
|
||||||
else :
|
else :
|
||||||
|
_ok("Changed action id to {}.".format(k))
|
||||||
current_id = int(k)
|
current_id = int(k)
|
||||||
|
|
||||||
def action_runCommand():
|
def action_runCommand():
|
||||||
@ -155,7 +167,7 @@ def action_deleteCommand():
|
|||||||
action_listAll()
|
action_listAll()
|
||||||
key = int(input())
|
key = int(input())
|
||||||
# Exit early
|
# Exit early
|
||||||
if "x" == k:
|
if "x" == key:
|
||||||
return(False)
|
return(False)
|
||||||
del currentPlayList[key]
|
del currentPlayList[key]
|
||||||
return True
|
return True
|
||||||
@ -163,7 +175,7 @@ def action_deleteCommand():
|
|||||||
|
|
||||||
|
|
||||||
def action_listAll():
|
def action_listAll():
|
||||||
global currentPlayList, current_cmd
|
global currentPlayList, current_cmd, current_id
|
||||||
print("\n--------------------------------------")
|
print("\n--------------------------------------")
|
||||||
for i,seq in enumerate(currentPlayList):
|
for i,seq in enumerate(currentPlayList):
|
||||||
pre=""
|
pre=""
|
||||||
@ -232,7 +244,7 @@ def action_loadPlaylist():
|
|||||||
print( bcolors.HL + "This key '{}' is not valid".format(k) + bcolors.ENDC )
|
print( bcolors.HL + "This key '{}' is not valid".format(k) + bcolors.ENDC )
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Load file
|
# @todo replace with _loadPlaylist
|
||||||
playlistFile = Path("./playlists/"+file_list[k].name)
|
playlistFile = Path("./playlists/"+file_list[k].name)
|
||||||
currentPlayList = json.loads(playlistFile.read_text())
|
currentPlayList = json.loads(playlistFile.read_text())
|
||||||
current_playlist_name = file_list[k].name
|
current_playlist_name = file_list[k].name
|
||||||
@ -242,7 +254,18 @@ def action_loadPlaylist():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def _loadPlaylist( filename ):
|
||||||
|
|
||||||
|
global currentPlayList, current_playlist_name, current_id
|
||||||
|
try:
|
||||||
|
playlistFile = Path(filename)
|
||||||
|
currentPlayList = json.loads(playlistFile.read_text())
|
||||||
|
current_playlist_name = filename
|
||||||
|
current_id = 0
|
||||||
|
_ok("Playlist loaded: {}\n".format(current_playlist_name))
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
_err("_loadPlaylist error when loading '{}':{}".format(filename,e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -353,13 +376,4 @@ def action_quit():
|
|||||||
quit = inkey()
|
quit = inkey()
|
||||||
if quit != "n":
|
if quit != "n":
|
||||||
_kill(process)
|
_kill(process)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
environ = {
|
|
||||||
# "REDIS_IP" : "127.0.0.1",
|
|
||||||
"REDIS_IP" : "192.168.2.44",
|
|
||||||
"REDIS_PORT" : "6379",
|
|
||||||
"REDIS_KEY" : "/pl/0/0",
|
|
||||||
"REDIS_SCENE" : "0",
|
|
||||||
"REDIS_LASER" : "0"
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user