def set(self, value): logger.info("set env: %s=%s", self.__name, value) if sys.platform == 'win32': ret = run( "wmic ENVIRONMENT where \"name='%s'\" get UserName,VariableValue" % self.__name) if "No Instance(s) Available" in ret[1]: runex( 'wmic ENVIRONMENT create Name="%s",UserName="******",VariableValue="%s"' % (self.__name, value)) else: runex( "wmic ENVIRONMENT where \"name='%s' and username='******'\" set VariableValue=\"%s\"" % (self.__name, value)) runex("set %s=%s" % (self.__name, value)) elif sys.platform.startswith('linux'): runex("export %s=%s" % (self.__name, value)) txtedit = TextEditor("/etc/profile") txtedit.set_param(self.__name, value) txtedit.delete("export %s" % self.__name) txtedit.insert("export %s" % self.__name) txtedit.save() else: pass os.environ[self.__name] = value
def mount(source, target, fstype, fstab=False): logger.debug("mount: source=%s, target=%s, fstype=%s, fstab=%s", source, target, fstype, fstab) (retcode, mount_info) = oscommon.run("mount") if retcode != 0: raise Exception("can't run 'mount' command") if source in mount_info: logger.debug("%s is already mounted" % source) else: oscommon.runex("mount -t %s %s %s" % (fstype, source, target)) if fstab: txt = TextEditor("/etc/fstab") txt.delete(target) txt.insert("%s %s %s defaults 0 0" % (source, target, fstype)) txt.save()
def set(self, value): logger.info("set env: %s=%s", self.__name, value) if sys.platform == 'win32': ret = run("wmic ENVIRONMENT where \"name='%s'\" get UserName,VariableValue" % self.__name) if "No Instance(s) Available" in ret[1]: runex('wmic ENVIRONMENT create Name="%s",UserName="******",VariableValue="%s"' % (self.__name, value)) else: runex("wmic ENVIRONMENT where \"name='%s' and username='******'\" set VariableValue=\"%s\"" % (self.__name, value)) runex("set %s=%s" % (self.__name, value) ) elif sys.platform.startswith('linux'): runex("export %s=%s" % (self.__name, value) ) txtedit = TextEditor("/etc/profile") txtedit.set_param(self.__name, value) txtedit.delete("export %s" % self.__name) txtedit.insert("export %s" % self.__name) txtedit.save() else: pass os.environ[self.__name]=value