def var_replacer(self, line, c='$'): vars = self.var_finder(line, c=c) for v in vars["normal"]: value = str(Var.get(v)) line = line.replace(c + v, value) # replace in line the variable $v with value for v in vars["os"]: name = v.replace('os.', '') if name in os.environ: value = os.environ[name] line = line.replace(c + v, value) else: Console.error("can not find environment variable {}".format( v)) if c + v in line: value = os.environ(v) # replace in line the variable $v with value for v in vars["dot"]: try: config = ConfigDict("cloudmesh.yaml") print(config["cloudmesh.profile"]) value = config[v] line = line.replace(c + v, value) except Exception as e: Console.error("can not find variable {} in cloudmesh.yaml".format(value)) return line
def var_replacer(self, line, c='$'): vars = self.var_finder(line, c=c) for v in vars["normal"]: value = str(Var.get(v)) line = line.replace(c + v, value) # replace in line the variable $v with value for v in vars["os"]: name = v.replace('os.', '') if name in os.environ: value = os.environ[name] line = line.replace(c + v, value) else: Console.error("can not find environment variable {}".format(v)) if c + v in line: value = os.environ(v) # replace in line the variable $v with value for v in vars["dot"]: try: config = ConfigDict("cloudmesh.yaml") print(config["cloudmesh.profile"]) value = config[v] line = line.replace(c + v, value) except Exception as e: Console.error( "can not find variable {} in cloudmesh.yaml".format(value)) return line
def do_var(self, arg, arguments): """ Usage: var list var delete NAMES var NAME=VALUE var NAME Arguments: NAME Name of the variable NAMES Names of the variable separated by spaces VALUE VALUE to be assigned special vars date and time are defined """ if arguments['list'] or arg == '' or arg is None: # self._list_variables() print(Var.list()) return "" elif arguments['NAME=VALUE'] and "=" in arguments["NAME=VALUE"]: (variable, value) = arg.split('=', 1) if value == "time" or value == "now": value = datetime.datetime.now().strftime("%H:%M:%S") elif value == "date": value = datetime.datetime.now().strftime("%Y-%m-%d") elif value.startswith("default."): name = value.replace("default.", "") value = Default.get(name=name, category="general") elif "." in value: try: config = ConfigDict("cloudmesh.yaml") value = config[value] except Exception as e: Console.error( "can not find variable {} in cloudmesh.yaml".format( value)) value = None # self._add_variable(variable, value) Var.set(variable, value) return "" elif arguments['NAME=VALUE'] and "=" not in arguments["NAME=VALUE"]: try: v = arguments['NAME=VALUE'] # Console.ok(str(self.variables[v])) Console.ok(str(Var.get(v))) except: Console.error('variable {:} not defined'.format( arguments['NAME=VALUE'])) elif arg.startswith('delete'): variable = arg.split(' ')[1] Var.delete(variable) # self._delete_variable(variable) return ""
def test_002(self): """ set default variable :return: """ HEADING() name = "myvar" value = "myvalue" Var.set(name, value) print (Var.list()) assert Var.get(name) == value self._check(value)
def test_002(self): """ set default variable :return: """ HEADING() name = "myvar" value = "myvalue" Var.set(name, value) print(Var.list()) assert Var.get(name) == value self._check(value)
def do_var(self, arg, arguments): """ Usage: var list var delete NAMES var NAME=VALUE var NAME Arguments: NAME Name of the variable NAMES Names of the variable separated by spaces VALUE VALUE to be assigned special vars date and time are defined """ if arguments['list'] or arg == '' or arg is None: # self._list_variables() print(Var.list()) return "" elif arguments['NAME=VALUE'] and "=" in arguments["NAME=VALUE"]: (variable, value) = arg.split('=', 1) if value == "time" or value == "now": value = datetime.datetime.now().strftime("%H:%M:%S") elif value == "date": value = datetime.datetime.now().strftime("%Y-%m-%d") elif value.startswith("default."): name = value.replace("default.", "") value = Default.get(name=name, category="general") elif "." in value: try: config = ConfigDict("cloudmesh.yaml") value = config[value] except Exception as e: Console.error("can not find variable {} in cloudmesh.yaml".format(value)) value = None # self._add_variable(variable, value) Var.set(variable, value) return "" elif arguments['NAME=VALUE'] and "=" not in arguments["NAME=VALUE"]: try: v = arguments['NAME=VALUE'] # Console.ok(str(self.variables[v])) Console.ok(str(Var.get(v))) except: Console.error('variable {:} not defined'.format(arguments['NAME=VALUE'])) elif arg.startswith('delete'): variable = arg.split(' ')[1] Var.delete(variable) # self._delete_variable(variable) return ""