示例#1
0
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
示例#2
0
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
示例#3
0
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"))
示例#4
0
 def copy_to(self, target_path: Path):
     with self.filesystem.open() as fs:
         fs.copy(self.path.s, target_path.s, True)
     return File(target_path, self.filesystem)
示例#5
0
  def deploy(self, force, backup, reinstall=True):
    self.callbacks.run_pre_script()

    #Delete files
    for file, sys_file, orig_args in reversed(self.deleted_files()):
      if exists(file):
        if backup:
          os.rename(file, '%s.gitman' % file)
        elif orig_args['isdir']:
          try:
            os.rmdir(file)
          except:
            ansi.writeout('${BRIGHT_RED}ERROR: Failed to remove directory: %s${RESET}' % file)
        else:
          os.unlink(file)

    #Add files
    for file, sys_file, new_args in self.added_files():
      dir = os.path.dirname(file)
      if not os.path.isdir(dir):
        os.makedirs(dir)
        if new_args['dirattr']:
          new_args['dirattr'].applyto(dir)
      if new_args['isdir']:
        if not os.path.exists(file):
          os.mkdir(file)
      else:
        fs.copy(sys_file, file, backup)
      if not os.path.islink(file):
        new_args['acl'].applyto(file)

    #Update files
    for file, sys_file, orig_args, new_args in self.common_files():
      dir = os.path.dirname(file)
      if not os.path.isdir(dir):
        os.makedirs(dir)
        if new_args['dirattr']:
          new_args['dirattr'].applyto(dir)
      if new_args['isdir']:
        if not os.path.exists(file):
          os.mkdir(file)
      else:
        fs.copy(sys_file, file, backup)
      if not os.path.islink(file):
        new_args['acl'].applyto(file)

    for crontab in self.deleted_crontabs():
      cmd = 'crontab -r -u %s' % crontab['user']
      if 0 != os.system(cmd):
        raise RuntimeError('Failed to run cmd: %s' % cmd)

    crontabs = self.added_crontabs()
    crontabs.extend(self.modified_crontabs())

    for crontab in crontabs:
      cmd = 'crontab -u %s %s' % (crontab['user'], crontab['crontab'].name)
      if 0 != os.system(cmd):
        raise RuntimeError('Failed to run cmd: %s' % cmd)

    self.rpmdb.run(test=False, reinstall=reinstall)

    self.callbacks.run_deployment_callbacks()
    self.callbacks.run_post_script()

    with open(os.path.join(self.path, self.deploy_file), 'w') as f:
      f.write(self.latest_version())