def set(self, layout=None, model=None, variant=None): """ Sets the desired layout and model. """ for line in fileinput.input(self.KEYBFILE,inplace=1): # WARNING: Ugly-ness excess in this for if line[0] != "#": splitted = line.split("=") if splitted[0] == "XKBLAYOUT": if layout != None and layout != []: if type(layout) == list: layout = ",".join(layout) sys.stdout.write(line.replace("XKBLAYOUT=%s" % (splitted[1]),"XKBLAYOUT=\"%s\"" % (layout)) + "\n") else: sys.stdout.write(line) elif splitted[0] == "XKBMODEL": if model != None: sys.stdout.write(line.replace("XKBMODEL=%s" % (splitted[1]),"XKBMODEL=\"%s\"" % (model)) + "\n") else: sys.stdout.write(line) elif splitted[0] == "XKBVARIANT": if variant != None: sys.stdout.write(line.replace("XKBVARIANT=%s" % (splitted[1]),"XKBVARIANT=\"%s\"" % (variant)) + "\n") else: sys.stdout.write(line) else: sys.stdout.write(line) else: sys.stdout.write(line) if layout: if os.path.exists(os.path.join(self.target, "usr/sbin/install-keymap")): if self.target is not "/": core.sexec("chroot %s install-keymap %s" % (self.target,layout)) else: core.sexec("install-keymap %s" % (layout))
def set(self, locale, generateonly=False): """ Sets specified locale in the system's configuration. """ if not generateonly: with open(os.path.join(self.target, "etc/default/locale"),"w") as f: f.write("LANG=\"%s\"\n" % (locale)) for _file in (os.path.join(self.target, "etc/locale.gen"), os.path.join(self.target, "etc/locale-gen.conf")): append = True with open(_file,"a+") as f: for line in f.readlines(): line = line.split(" ")[0] if locale in line: # We found the locale: locale-gen knows of it. Then we do not need to append it. append = False break if append: f.write("%s %s\n" % (locale, self.codepages[locale])) # Generating locales if self.target is not "/": core.sexec("chroot %s /usr/sbin/locale-gen" % (self.target)) else: core.sexec("/usr/sbin/locale-gen")