mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add the location code to the automatically generated device name
This commit is contained in:
parent
160e57ed54
commit
5d317eb534
@ -55,13 +55,13 @@ class USBMS(CLI, Device):
|
||||
METADATA_CACHE = 'metadata.calibre'
|
||||
DRIVEINFO = 'driveinfo.calibre'
|
||||
|
||||
def _update_driveinfo_record(self, dinfo, prefix, name=None):
|
||||
def _update_driveinfo_record(self, dinfo, prefix, location_code, name=None):
|
||||
if not isinstance(dinfo, dict):
|
||||
dinfo = {}
|
||||
if dinfo.get('device_store_uuid', None) is None:
|
||||
dinfo['device_store_uuid'] = unicode(uuid.uuid4())
|
||||
if dinfo.get('device_name') is None:
|
||||
dinfo['device_name'] = self.get_gui_name()
|
||||
dinfo['device_name'] = self.get_gui_name() + '_' + location_code
|
||||
if name is not None:
|
||||
dinfo['device_name'] = name
|
||||
dinfo['last_library_uuid'] = getattr(self, 'current_library_uuid', None)
|
||||
@ -70,18 +70,19 @@ class USBMS(CLI, Device):
|
||||
dinfo['prefix'] = prefix.replace('\\', '/')
|
||||
return dinfo
|
||||
|
||||
def _update_driveinfo_file(self, prefix, name=None):
|
||||
def _update_driveinfo_file(self, prefix, location_code, name=None):
|
||||
if os.path.exists(os.path.join(prefix, self.DRIVEINFO)):
|
||||
with open(os.path.join(prefix, self.DRIVEINFO), 'rb') as f:
|
||||
try:
|
||||
driveinfo = json.loads(f.read(), object_hook=from_json)
|
||||
except:
|
||||
driveinfo = None
|
||||
driveinfo = self._update_driveinfo_record(driveinfo, prefix, name)
|
||||
driveinfo = self._update_driveinfo_record(driveinfo, prefix,
|
||||
location_code, name)
|
||||
with open(os.path.join(prefix, self.DRIVEINFO), 'wb') as f:
|
||||
f.write(json.dumps(driveinfo, default=to_json))
|
||||
else:
|
||||
driveinfo = self._update_driveinfo_record({}, prefix, name)
|
||||
driveinfo = self._update_driveinfo_record({}, prefix, location_code, name)
|
||||
with open(os.path.join(prefix, self.DRIVEINFO), 'wb') as f:
|
||||
f.write(json.dumps(driveinfo, default=to_json))
|
||||
return driveinfo
|
||||
@ -90,20 +91,20 @@ class USBMS(CLI, Device):
|
||||
self.report_progress(1.0, _('Get device information...'))
|
||||
self.driveinfo = {}
|
||||
if self._main_prefix is not None:
|
||||
self.driveinfo['main'] = self._update_driveinfo_file(self._main_prefix)
|
||||
self.driveinfo['main'] = self._update_driveinfo_file(self._main_prefix, 'main')
|
||||
if self._card_a_prefix is not None:
|
||||
self.driveinfo['A'] = self._update_driveinfo_file(self._card_a_prefix)
|
||||
self.driveinfo['A'] = self._update_driveinfo_file(self._card_a_prefix, 'A')
|
||||
if self._card_b_prefix is not None:
|
||||
self.driveinfo['B'] = self._update_driveinfo_file(self._card_b_prefix)
|
||||
self.driveinfo['B'] = self._update_driveinfo_file(self._card_b_prefix, 'B')
|
||||
return (self.get_gui_name(), '', '', '', self.driveinfo)
|
||||
|
||||
def set_driveinfo_name(self, location_code, name):
|
||||
if location_code == 'main':
|
||||
self._update_driveinfo_file(self._main_prefix, name)
|
||||
self._update_driveinfo_file(self._main_prefix, location_code, name)
|
||||
elif location_code == 'A':
|
||||
self._update_driveinfo_file(self._card_a_prefix, name)
|
||||
self._update_driveinfo_file(self._card_a_prefix, location_code, name)
|
||||
elif location_code == 'B':
|
||||
self._update_driveinfo_file(self._card_b_prefix, name)
|
||||
self._update_driveinfo_file(self._card_b_prefix, location_code, name)
|
||||
|
||||
def books(self, oncard=None, end_session=True):
|
||||
from calibre.ebooks.metadata.meta import path_to_ext
|
||||
|
Loading…
x
Reference in New Issue
Block a user