mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: misc fixes. calibre GUI now starts under python 3
This commit is contained in:
parent
d6b6d4c892
commit
8569717d98
@ -152,8 +152,11 @@ class DBPrefs(dict): # {{{
|
|||||||
def write_serialized(self, library_path):
|
def write_serialized(self, library_path):
|
||||||
try:
|
try:
|
||||||
to_filename = os.path.join(library_path, 'metadata_db_prefs_backup.json')
|
to_filename = os.path.join(library_path, 'metadata_db_prefs_backup.json')
|
||||||
|
data = json.dumps(self, indent=2, default=to_json)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with open(to_filename, "wb") as f:
|
with open(to_filename, "wb") as f:
|
||||||
f.write(json.dumps(self, indent=2, default=to_json))
|
f.write(data)
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -75,7 +75,7 @@ class Tag(object):
|
|||||||
|
|
||||||
|
|
||||||
def find_categories(field_metadata):
|
def find_categories(field_metadata):
|
||||||
for category, cat in iteritems(field_metadata):
|
for category, cat in field_metadata.iter_items():
|
||||||
if (cat['is_category'] and cat['kind'] not in {'user', 'search'}):
|
if (cat['is_category'] and cat['kind'] not in {'user', 'search'}):
|
||||||
yield (category, cat['is_multiple'].get('cache_to_list', None), False)
|
yield (category, cat['is_multiple'].get('cache_to_list', None), False)
|
||||||
elif (cat['datatype'] == 'composite' and
|
elif (cat['datatype'] == 'composite' and
|
||||||
|
@ -632,7 +632,7 @@ class Parser(SearchQueryParser): # {{{
|
|||||||
text_fields = set()
|
text_fields = set()
|
||||||
field_metadata = {}
|
field_metadata = {}
|
||||||
|
|
||||||
for x, fm in iteritems(self.field_metadata):
|
for x, fm in self.field_metadata.iter_items():
|
||||||
if x.startswith('@'):
|
if x.startswith('@'):
|
||||||
continue
|
continue
|
||||||
if fm['search_terms'] and x not in {'series_sort', 'id'}:
|
if fm['search_terms'] and x not in {'series_sort', 'id'}:
|
||||||
|
@ -128,13 +128,19 @@ class USBMS(CLI, Device):
|
|||||||
driveinfo = None
|
driveinfo = None
|
||||||
driveinfo = self._update_driveinfo_record(driveinfo, prefix,
|
driveinfo = self._update_driveinfo_record(driveinfo, prefix,
|
||||||
location_code, name)
|
location_code, name)
|
||||||
|
data = json.dumps(driveinfo, default=to_json)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with lopen(os.path.join(prefix, self.DRIVEINFO), 'wb') as f:
|
with lopen(os.path.join(prefix, self.DRIVEINFO), 'wb') as f:
|
||||||
f.write(json.dumps(driveinfo, default=to_json))
|
f.write(data)
|
||||||
fsync(f)
|
fsync(f)
|
||||||
else:
|
else:
|
||||||
driveinfo = self._update_driveinfo_record({}, prefix, location_code, name)
|
driveinfo = self._update_driveinfo_record({}, prefix, location_code, name)
|
||||||
|
data = json.dumps(driveinfo, default=to_json)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with lopen(os.path.join(prefix, self.DRIVEINFO), 'wb') as f:
|
with lopen(os.path.join(prefix, self.DRIVEINFO), 'wb') as f:
|
||||||
f.write(json.dumps(driveinfo, default=to_json))
|
f.write(data)
|
||||||
fsync(f)
|
fsync(f)
|
||||||
return driveinfo
|
return driveinfo
|
||||||
|
|
||||||
|
@ -132,8 +132,10 @@ class JsonCodec(object):
|
|||||||
self.field_metadata = field_metadata or FieldMetadata()
|
self.field_metadata = field_metadata or FieldMetadata()
|
||||||
|
|
||||||
def encode_to_file(self, file_, booklist):
|
def encode_to_file(self, file_, booklist):
|
||||||
file_.write(json.dumps(self.encode_booklist_metadata(booklist),
|
data = json.dumps(self.encode_booklist_metadata(booklist), indent=2, encoding='utf-8')
|
||||||
indent=2, encoding='utf-8'))
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
|
file_.write(data)
|
||||||
|
|
||||||
def encode_booklist_metadata(self, booklist):
|
def encode_booklist_metadata(self, booklist):
|
||||||
result = []
|
result = []
|
||||||
|
@ -45,7 +45,7 @@ def get_plugin_updates_available(raise_error=False):
|
|||||||
return None
|
return None
|
||||||
display_plugins = read_available_plugins(raise_error=raise_error)
|
display_plugins = read_available_plugins(raise_error=raise_error)
|
||||||
if display_plugins:
|
if display_plugins:
|
||||||
update_plugins = filter(filter_upgradeable_plugins, display_plugins)
|
update_plugins = list(filter(filter_upgradeable_plugins, display_plugins))
|
||||||
if len(update_plugins) > 0:
|
if len(update_plugins) > 0:
|
||||||
return update_plugins
|
return update_plugins
|
||||||
return None
|
return None
|
||||||
@ -589,7 +589,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
|
|||||||
|
|
||||||
def _finished(self, *args):
|
def _finished(self, *args):
|
||||||
if self.model:
|
if self.model:
|
||||||
update_plugins = filter(filter_upgradeable_plugins, self.model.display_plugins)
|
update_plugins = list(filter(filter_upgradeable_plugins, self.model.display_plugins))
|
||||||
self.gui.recalc_update_label(len(update_plugins))
|
self.gui.recalc_update_label(len(update_plugins))
|
||||||
|
|
||||||
def _plugin_current_changed(self, current, previous):
|
def _plugin_current_changed(self, current, previous):
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.icu import sort_key
|
|||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.date import now
|
from calibre.utils.date import now
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from polyglot.builtins import iteritems, unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
|
||||||
box_values = {}
|
box_values = {}
|
||||||
last_matchkind = CONTAINS_MATCH
|
last_matchkind = CONTAINS_MATCH
|
||||||
@ -174,7 +174,7 @@ def create_date_tab(self, db):
|
|||||||
w.h1 = h = QHBoxLayout()
|
w.h1 = h = QHBoxLayout()
|
||||||
l.addLayout(h)
|
l.addLayout(h)
|
||||||
self.date_field = df = add(_("&Search the"), QComboBox(w))
|
self.date_field = df = add(_("&Search the"), QComboBox(w))
|
||||||
vals = [((v['search_terms'] or [k])[0], v['name'] or k) for k, v in iteritems(db.field_metadata) if v.get('datatype', None) == 'datetime']
|
vals = [((v['search_terms'] or [k])[0], v['name'] or k) for k, v in db.field_metadata.iter_items() if v.get('datatype', None) == 'datetime']
|
||||||
for k, v in sorted(vals, key=lambda k_v: sort_key(k_v[1])):
|
for k, v in sorted(vals, key=lambda k_v: sort_key(k_v[1])):
|
||||||
df.addItem(v, k)
|
df.addItem(v, k)
|
||||||
h.addWidget(df)
|
h.addWidget(df)
|
||||||
|
@ -202,7 +202,7 @@ def get_val_for_textlike_columns(index_):
|
|||||||
class RatingDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
|
class RatingDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
QStyledItemDelegate.__init__(self, *args, **kwargs)
|
QStyledItemDelegate.__init__(self, *args)
|
||||||
self.is_half_star = kwargs.get('is_half_star', False)
|
self.is_half_star = kwargs.get('is_half_star', False)
|
||||||
self.table_widget = args[0]
|
self.table_widget = args[0]
|
||||||
self.rf = QFont(rating_font())
|
self.rf = QFont(rating_font())
|
||||||
|
@ -1090,8 +1090,11 @@ class EditRules(QWidget): # {{{
|
|||||||
'type': self.model.pref_name,
|
'type': self.model.pref_name,
|
||||||
'rules': self.model.rules_as_list(for_export=True)
|
'rules': self.model.rules_as_list(for_export=True)
|
||||||
}
|
}
|
||||||
|
data = json.dumps(rules, indent=2)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with lopen(path, 'wb') as f:
|
with lopen(path, 'wb') as f:
|
||||||
f.write(json.dumps(rules, indent=2))
|
f.write(data)
|
||||||
|
|
||||||
def import_rules(self):
|
def import_rules(self):
|
||||||
files = choose_files(self, 'import-coloring-rules', _('Choose file to import from'),
|
files = choose_files(self, 'import-coloring-rules', _('Choose file to import from'),
|
||||||
|
@ -129,9 +129,11 @@ class ThreadedJob(BaseJob):
|
|||||||
if not os.path.exists(log_dir):
|
if not os.path.exists(log_dir):
|
||||||
os.makedirs(log_dir)
|
os.makedirs(log_dir)
|
||||||
fd, path = tempfile.mkstemp(suffix='.json', prefix='log-', dir=log_dir)
|
fd, path = tempfile.mkstemp(suffix='.json', prefix='log-', dir=log_dir)
|
||||||
|
data = json.dumps(logs, ensure_ascii=False, indent=2)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with os.fdopen(fd, 'wb') as f:
|
with os.fdopen(fd, 'wb') as f:
|
||||||
f.write(json.dumps(logs, ensure_ascii=False,
|
f.write(data)
|
||||||
indent=2).encode('utf-8'))
|
|
||||||
self.consolidated_log = path
|
self.consolidated_log = path
|
||||||
self.log = None
|
self.log = None
|
||||||
|
|
||||||
|
@ -200,8 +200,11 @@ class BookmarkManager(QWidget):
|
|||||||
self, 'export-viewer-bookmarks', _('Export bookmarks'),
|
self, 'export-viewer-bookmarks', _('Export bookmarks'),
|
||||||
filters=[(_('Saved bookmarks'), ['calibre-bookmarks'])], all_files=False, initial_filename='bookmarks.calibre-bookmarks')
|
filters=[(_('Saved bookmarks'), ['calibre-bookmarks'])], all_files=False, initial_filename='bookmarks.calibre-bookmarks')
|
||||||
if filename:
|
if filename:
|
||||||
|
data = json.dumps(self.get_bookmarks(), indent=True)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with lopen(filename, 'wb') as fileobj:
|
with lopen(filename, 'wb') as fileobj:
|
||||||
fileobj.write(json.dumps(self.get_bookmarks(), indent=True))
|
fileobj.write(data)
|
||||||
|
|
||||||
def import_bookmarks(self):
|
def import_bookmarks(self):
|
||||||
files = choose_files(self, 'export-viewer-bookmarks', _('Import bookmarks'),
|
files = choose_files(self, 'export-viewer-bookmarks', _('Import bookmarks'),
|
||||||
|
@ -493,13 +493,14 @@ class FieldMetadata(object):
|
|||||||
def iteritems(self):
|
def iteritems(self):
|
||||||
for key in self._tb_cats:
|
for key in self._tb_cats:
|
||||||
yield (key, self._tb_cats[key])
|
yield (key, self._tb_cats[key])
|
||||||
|
iter_items = iteritems
|
||||||
|
|
||||||
def custom_iteritems(self):
|
def custom_iteritems(self):
|
||||||
for key, meta in iteritems(self._tb_custom_fields):
|
for key, meta in iteritems(self._tb_custom_fields):
|
||||||
yield (key, meta)
|
yield (key, meta)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
return list(iteritems(self))
|
return list(self.iter_items())
|
||||||
|
|
||||||
def is_custom_field(self, key):
|
def is_custom_field(self, key):
|
||||||
return key.startswith(self.custom_field_prefix)
|
return key.startswith(self.custom_field_prefix)
|
||||||
|
@ -81,8 +81,11 @@ class DBPrefs(dict):
|
|||||||
def write_serialized(self, library_path):
|
def write_serialized(self, library_path):
|
||||||
try:
|
try:
|
||||||
to_filename = os.path.join(library_path, 'metadata_db_prefs_backup.json')
|
to_filename = os.path.join(library_path, 'metadata_db_prefs_backup.json')
|
||||||
|
data = json.dumps(self, indent=2, default=to_json)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with open(to_filename, "wb") as f:
|
with open(to_filename, "wb") as f:
|
||||||
f.write(json.dumps(self, indent=2, default=to_json))
|
f.write(data)
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -230,8 +230,11 @@ class Container(ContainerBase):
|
|||||||
self.commit()
|
self.commit()
|
||||||
for name in excluded_names:
|
for name in excluded_names:
|
||||||
os.remove(self.name_path_map[name])
|
os.remove(self.name_path_map[name])
|
||||||
|
data = json.dumps(self.book_render_data, ensure_ascii=False)
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
with lopen(os.path.join(self.root, 'calibre-book-manifest.json'), 'wb') as f:
|
with lopen(os.path.join(self.root, 'calibre-book-manifest.json'), 'wb') as f:
|
||||||
f.write(json.dumps(self.book_render_data, ensure_ascii=False).encode('utf-8'))
|
f.write(data)
|
||||||
|
|
||||||
def create_cover_page(self, input_fmt):
|
def create_cover_page(self, input_fmt):
|
||||||
templ = '''
|
templ = '''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user