Beispiel #1
0
 def save(self):
     with open(self._config_path, 'w') as io:
         config = object_convert.object_to_dict(self)
         for f in self._protect_fields:
             config[f] = base64.b64encode(config[f].encode()).decode()[::-1]
         json.dump(config, io, indent='  ')
         Log.append('config_save', 'Info',
                    object_convert.object_to_dict(self))
Beispiel #2
0
    def append(src, tag='Info', *args):
        log_items = []
        for i in args:
            if isinstance(i, list) or isinstance(i, dict):
                log_items.append(object_convert.to_json(i))
            elif isinstance(i, tuple) or isinstance(i, set):
                log_items.append(object_convert.to_json(list(i)))
            elif isinstance(i, int) or isinstance(i, float) or isinstance(i, str) or isinstance(i, bool) or i is None:
                log_items.append(i)
            else:
                log_items.append(i)
                log_items.append(object_convert.to_json(object_convert.object_to_dict(i)))

        if isinstance(src, str):
            source = src
        else:
            source = src.__name__

        items_str = []
        for item in log_items:
            item_str = str(item)
            if len(Log.replaces) > 0:
                for k, v in Log.replaces.items():
                    if k is not None:
                        item_str = item_str.replace(k, v)

            items_str.append(item_str)

        items_str = ' '.join(items_str)

        with Log.lock_log:
            print('[%s] %s %s\n\t' % (tag, time.ctime(), source), items_str)
            Log.io_log.flush()
Beispiel #3
0
 def load(self):
     try:
         if os.path.exists(self._config_path):
             with open(self._config_path, 'r') as io:
                 config = json.load(io)
                 for f in self._protect_fields:
                     config[f] = base64.b64decode(
                         config[f][::-1].encode()).decode()
                 object_convert.dict_to_object(config,
                                               self,
                                               new_fields=False)
                 Log.set_replaces(
                     dict([(getattr(self, f), Const.protector)
                           for f in self._protect_fields]))
                 Log.append('config_load', 'Info',
                            object_convert.object_to_dict(self))
     except:
         self.save()
Beispiel #4
0
 def save_current_translate(self):
     language = object_convert.object_to_dict(self)
     with open(self._data_path, 'w', encoding='utf-8') as io:
         json.dump(language, io, ensure_ascii=False, indent=4)