mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
Feeback from forum applied
This commit is contained in:
parent
7d2afdcec2
commit
84a3f8818d
@ -644,19 +644,19 @@ class MTP_DEVICE(BASE):
|
|||||||
|
|
||||||
def upload_apnx(self, parent, filename, storage, mi, filepath):
|
def upload_apnx(self, parent, filename, storage, mi, filepath):
|
||||||
from calibre.devices.kindle.apnx import APNXBuilder
|
from calibre.devices.kindle.apnx import APNXBuilder
|
||||||
import tempfile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
|
|
||||||
apnx_local_path = tempfile.NamedTemporaryFile(prefix='calibre-apnx-', suffix='.apnx', delete=False).name
|
apnx_local_file = PersistentTemporaryFile('.apnx')
|
||||||
|
apnx_local_path = apnx_local_file.name
|
||||||
|
apnx_local_file.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
apnx_builder = APNXBuilder()
|
|
||||||
|
|
||||||
custom_page_count = 0
|
custom_page_count = 0
|
||||||
cust_col_name = self.get_pref('apnx').get('custom_column_page_count', None)
|
cust_col_name = self.get_pref('apnx').get('custom_column_page_count', None)
|
||||||
if cust_col_name:
|
if cust_col_name:
|
||||||
try:
|
try:
|
||||||
custom_page_count = int(mi.get(cust_col_name, 0))
|
custom_page_count = int(mi.get(cust_col_name, 0))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
method = self.get_pref('apnx').get('method', 'fast')
|
method = self.get_pref('apnx').get('method', 'fast')
|
||||||
@ -668,23 +668,22 @@ class MTP_DEVICE(BASE):
|
|||||||
method = method.lower()
|
method = method.lower()
|
||||||
if method not in ('fast', 'accurate', 'pagebreak'):
|
if method not in ('fast', 'accurate', 'pagebreak'):
|
||||||
method = None
|
method = None
|
||||||
except:
|
except Exception:
|
||||||
prints(f'Invalid custom column method: {cust_col_method}, ignoring')
|
prints(f'Invalid custom column method: {cust_col_method}, ignoring')
|
||||||
|
|
||||||
|
apnx_builder = APNXBuilder()
|
||||||
apnx_builder.write_apnx(filepath, apnx_local_path, method=method, page_count=custom_page_count)
|
apnx_builder.write_apnx(filepath, apnx_local_path, method=method, page_count=custom_page_count)
|
||||||
|
|
||||||
apnx_size = os.path.getsize(apnx_local_path)
|
apnx_size = os.path.getsize(apnx_local_path)
|
||||||
apnx_stream = open(apnx_local_path, 'rb')
|
|
||||||
|
|
||||||
try:
|
with open(apnx_local_path, 'rb') as apnx_stream:
|
||||||
name = filename.rpartition('.')[0]
|
name = filename.rpartition('.')[0]
|
||||||
apnx_filename = f'{name[:-2]}.apnx'
|
apnx_filename = f'{name[:-2]}.apnx'
|
||||||
apnx_path = parent.name, f'{name[:-2]}.sdr', apnx_filename
|
apnx_path = parent.name, f'{name[:-2]}.sdr', apnx_filename
|
||||||
sdr_parent = self.ensure_parent(storage, apnx_path)
|
sdr_parent = self.ensure_parent(storage, apnx_path)
|
||||||
self.put_file(sdr_parent, apnx_filename, apnx_stream, apnx_size)
|
self.put_file(sdr_parent, apnx_filename, apnx_stream, apnx_size)
|
||||||
finally:
|
|
||||||
apnx_stream.close()
|
except Exception:
|
||||||
except:
|
|
||||||
print('Failed to generate APNX')
|
print('Failed to generate APNX')
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user