def main(): info = settings.ini(fs.home() + "/.lir/main.ini") PORT = int(info.get("server", "port")) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) print("Created Socket") try: s.bind((HOST, PORT)) except socket.error as e: print("Bind Failed.", e) return False print("Bind Complete.") s.listen(10) print("Socket Listening on port " + str(PORT)) listen = True while listen: con, addr = s.accept() print("Connected with " + addr[0] + ":" + str(addr[1])) start_new_thread(resp, (con,))
def installFolder(path): path = fs.expand_path(path) info = settings.ini(path+"/info.ini") print(lang.get("install","start"),info.get("info","name")) #move files to "install" plugin fs.copy(path+"/info.ini","~/.lir/plugins/"+info.get("info","name").replace(" ","_").lower()+".ini") for s in ["tts","sst","services","bin"]: #if info.has_section(s): if os.path.exists(path+"/"+s): if not fs.copy(path+"/"+s,"~/.lir/"+s): print(lang.get("error","transfer"),fs.expand_path(path+"/"+s),fs.expand_path("~/.lir/"+s)) return False if os.path.isdir(path+"/actions"): for dic in os.listdir(path+"/actions"): if os.path.isfile(path+"/actions/"+dic) and not dic.endswith("~"): add_dictionary(path+"/actions/"+dic,info.get("info","name")) print(lang.get("install","done"),info.get("info","name")) return True
def installCompressed(path): #resolve path and open tar path = fs.expand_path(path) tar = tarfile.open(path,'r:gz') fs.create_directory("/tmp/lir") #extract into /tmp print(lang.get("install","extract"),path,"/tmp/lir") tar.extractall("/tmp/lir/") #load info info = settings.ini("/tmp/lir/info.ini") print(lang.get("install","start"),info.get("info","name")) #move files to "install" plugin fs.copy("/tmp/lir/info.ini","~/.lir/plugins/"+info.get("info","name").replace(" ","_").lower()+".ini") for s in ["tts","sst","services","bin"]: if info.has_section(s): if not fs.copy("/tmp/lir/"+s,"~/.lir/"+s): print(lang.get("error","transfer"),fs.expand_path("/tmp/lir/"+s),fs.expand_path("~/.lir/"+s)) return False for dic in os.listdir("/tmp/lir/actions"): if os.path.isfile("/tmp/lir/actions/"+dic): add_dictionary("/tmp/lir/actions/"+dic,info.get("info","name")) fs.delete("/tmp/lir") print(lang.get("install","done"),info.get("info","name")) return True
#!/usr/bin/env python3.4 import settings,os #this will be replaced by language detection if os.path.exists(os.getcwd()+"/langs/en.ini"): l = settings.ini("langs/en") else: l = settings.ini("~/.lispeak/langs/en") def get(section,key): return l.get(section,key)
def main(): print(lang.get("setup","welcome")) print(lang.get("setup","info")) print() print(lang.get("setup","notice")) print() #Create directories fs.delete("~/.lir") fs.create_directory("~/.lir") for d in ["plugins","tts","stt","actions","services","bin","langs"]: fs.create_directory("~/.lir/"+d) fs.create("~/.lir/actions/default.dic") fs.copy("langs","~/.lir/langs") #Create ini ini = settings.ini("~/.lir/main.ini") ini.create_section("general") try: import pwd,os name = pwd.getpwuid(os.getuid())[4].replace(",","") print() if input("Is "+name+" your name? [Y/N]").lower() == "y": ini.set("general","name",name) else: ini.set("general","name",input(lang.get("setup","name"))) except: ini.set("general","name",input(lang.get("setup","name"))) #make dictionary program debug(lang.get("setup","build"),"Dictionary") os.chdir("dictionary") fs.delete("dictionary") if DEBUG: os.system("make") else: fs.system("make") os.chdir("../") fs.copy("dictionary/dictionary","~/.lir/dictionary") #Install required packages #Install default plugins dev_plugins = os.listdir("dev_plugins") for plugin in dev_plugins: if not pm.installFolder("dev_plugins/" + plugin): print(lang.get("error","install"), plugin) #FIXME install twice if not pm.installFolder("dev_plugins/espeak"): print(lang.get("error","install"),"espeak") else: ini.create_section("tts") #right now espeak is the default tts engine ini.set("tts","engine","espeak") print() #ask if tts should be used ini.set("tts","read-responses",str(input("Do you want Lir to read out responses? [Y/N]").lower() == "y")) print() #copy needed python scripts for f in ["settings.py","lang.py","fs.py","lir.py"]: fs.copy(f,"~/.lir/bin") fs.copy(f,"~/.lir/services") fs.copy(f,"~/.lir/tts") #Create server info in config ini.create_section("server") ini.set("server","host","127.0.0.1") ini.set("server","port","8090") debug("Saving ini") ini.save() print() print(lang.get("setup","done"))
import argparse import socket import settings import fs parser = argparse.ArgumentParser(description='Send commands to the Lir backend') parser.add_argument('--host', type=str, help='Address of host computer (default to main.ini value)') parser.add_argument('--port', type=str, help='Port of host computer (default to main.ini value)') parser.add_argument('--speak', dest="text", type=str, help='Title of notification') parser.add_argument('--notify-title', dest="title", type=str, help='Title of notification', required=False) parser.add_argument('--notify-body', dest="body", type=str, help='Body of notification', required=False) parser.add_argument('--notify-icon', dest="icon", type=str, help='Path to icon for noticiation',required=False) args = parser.parse_args() info = settings.ini("~/.lir/main.ini") if args.host != None: HOST = args.host else: HOST = info.get("server","host") if args.port != None: PORT = int(args.port) else: PORT = int(info.get("server","port")) def display_notification(title,body=None,icon=None,speech=None): cmd = "notify \""+title+"\"" if body != None: cmd += " -b \""+body+"\"" if icon != None: