示例#1
0
文件: config.py 项目: zyhong/calibre
    def refresh(self, clear_current=True):
        d = {}
        migrate = False
        if clear_current:
            self.clear()
        if os.path.exists(self.file_path):
            with ExclusiveFile(self.file_path) as f:
                raw = f.read()
            if raw:
                try:
                    d = json_loads(raw)
                except Exception as err:
                    print(
                        'Failed to de-serialize JSON representation of stored dynamic data for {} with error: {}'
                        .format(self.name, err))
            else:
                d = self.read_old_serialized_representation()
                migrate = bool(d)
        else:
            d = self.read_old_serialized_representation()
            migrate = bool(d)
        if migrate and d:
            raw = json_dumps(d, ignore_unserializable=True)
            with ExclusiveFile(self.file_path) as f:
                f.seek(0), f.truncate()
                f.write(raw)

        self.update(d)
示例#2
0
    def refresh(self, clear_current=True):
        d = {}
        migrate = False
        if clear_current:
            self.clear()
        if os.path.exists(self.file_path):
            with ExclusiveFile(self.file_path) as f:
                raw = f.read()
            if raw:
                try:
                    d = json_loads(raw)
                except Exception as err:
                    print('Failed to de-serialize JSON representation of stored dynamic data for {} with error: {}'.format(
                        self.name, err))
            else:
                d = self.read_old_serialized_representation()
                migrate = bool(d)
        else:
            d = self.read_old_serialized_representation()
            migrate = bool(d)
        if migrate and d:
            raw = json_dumps(d, ignore_unserializable=True)
            with ExclusiveFile(self.file_path) as f:
                f.seek(0), f.truncate()
                f.write(raw)

        self.update(d)
示例#3
0
    def refresh(self, clear_current=True):
        d = {}
        migrate = False
        if clear_current:
            self.clear()
        try:
            raw = read_data(self.file_path)
        except FileNotFoundError:
            d = self.read_old_serialized_representation()
            migrate = bool(d)
        else:
            if raw:
                try:
                    d = json_loads(raw)
                except Exception as err:
                    print(
                        'Failed to de-serialize JSON representation of stored dynamic data for {} with error: {}'
                        .format(self.name, err))
            else:
                d = self.read_old_serialized_representation()
                migrate = bool(d)
        if migrate and d:
            raw = json_dumps(d, ignore_unserializable=True)
            commit_data(self.file_path, raw)

        self.update(d)
示例#4
0
 def commit(self):
     if not getattr(self, 'name', None):
         return
     if not os.path.exists(self.file_path):
         make_config_dir()
     raw = json_dumps(self)
     with ExclusiveFile(self.file_path) as f:
         f.seek(0)
         f.truncate()
         f.write(raw)
示例#5
0
 def _manage_lru(self):
     current_text = self.search_textbox.currentText()
     for i in range(self.search_textbox.count()):
         if self.search_textbox.itemText(i) == current_text:
             self.search_textbox.removeItem(i)
             break
     if self.search_textbox.count() >= SEARCH_HISTORY_ITEMS:
         self.search_textbox.removeItem(self.search_textbox.count() - 1)
     self.search_textbox.setEditText(current_text)
     self.search_textbox.insertItem(0, current_text)
     search_lru = {}
     for i in range(self.search_textbox.count()):
         try:
             text = self.search_textbox.itemText(i)
             json_dumps(text)
             search_lru[i] = text
         except TypeError as ex:
             pass
     prefs['search_lru'] = search_lru
示例#6
0
文件: config.py 项目: zyhong/calibre
 def commit(self):
     if not getattr(self, 'name', None):
         return
     if not os.path.exists(self.file_path):
         make_config_dir()
     raw = json_dumps(self)
     with ExclusiveFile(self.file_path) as f:
         f.seek(0)
         f.truncate()
         f.write(raw)
示例#7
0
 def to_raw(self):
     return json_dumps(self)
示例#8
0
文件: config.py 项目: zyhong/calibre
 def to_raw(self):
     return json_dumps(self)
示例#9
0
 def commit(self):
     if not getattr(self, 'name', None):
         return
     raw = json_dumps(self)
     commit_data(self.file_path, raw)