Exemple #1
0
    def update(self, key: str, value=None, delete: bool = False):
        if not self.allow(key):
            to_screen(f"{key} is not a recognized default variable, ignored")
            return
        dic = self.values
        if delete:
            if key not in dic:
                to_screen(f"key {key} not found in {self.name}, ignored")
            elif not self.act_append(
                    key) or not value:  # delete the key when not append action
                del dic[key]
                to_screen(
                    f"key {key} removed completely from {self.name} successfully"
                )
            else:
                dic[key].remove(value)
                to_screen(
                    f"{value} removed in {key} under {self.name} successfully")
        else:
            if self.act_append(key):

                def _append(dic, key, value):
                    dic.setdefault(key, [])
                    if value not in dic[key]:
                        dic[key].append(value)

                _append(dic, key, value)
                to_screen(
                    f"{value} added to {key} under {self.name} successfully")
            else:
                dic[key] = value
                to_screen(
                    f"{key} set to {value} under {self.name} successfully")
        if self.file:
            to_file(self.values, self.file)
Exemple #2
0
 def do_action_set(self, args):
     defaults = get_defaults()
     if not args.contents:
         return defaults
     for kv in args.contents:
         key, value = kv.split('=')
         assert key is not None and value is not None, "must specify a key=value pair"
         defaults[key] = value
     to_file(defaults, __local_default_file__)
     return defaults
Exemple #3
0
 def do_action_unset(self, args):
     result = []
     defaults = get_defaults()
     for key in args.variables:
         if key not in defaults:
             result.append(
                 "cannot unset default variable %s because it doesn't exist"
                 % key)
             continue
         value = defaults.pop(key, None)
         result.append("default variable {} (previously {}) deleted".format(
             key, value))
     to_file(defaults, __local_default_file__)
     return result
Exemple #4
0
 def save(self):
     if self.name:
         to_file(self.protocol, Job.job_cache_file(self.name))
     return self
Exemple #5
0
 def save(self):
     if self.name:
         to_file(self.protocol, self.protocol_file)
     return self
Exemple #6
0
 def save(self):
     to_file(self.clusters, __cluster_config_file__)
Exemple #7
0
 def save(self):
     to_file(self.clusters.as_list, self.default_config_file)