trackma 0.7.5__py3.6.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. EGG-INFO/PKG-INFO +22 -0
  2. EGG-INFO/SOURCES.txt +55 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/entry_points.txt +9 -0
  5. EGG-INFO/not-zip-safe +1 -0
  6. EGG-INFO/requires.txt +8 -0
  7. EGG-INFO/top_level.txt +1 -0
  8. trackma/__init__.py +0 -0
  9. trackma/__pycache__/__init__.cpython-36.pyc +0 -0
  10. trackma/__pycache__/accounts.cpython-36.pyc +0 -0
  11. trackma/__pycache__/data.cpython-36.pyc +0 -0
  12. trackma/__pycache__/engine.cpython-36.pyc +0 -0
  13. trackma/__pycache__/messenger.cpython-36.pyc +0 -0
  14. trackma/__pycache__/utils.cpython-36.pyc +0 -0
  15. trackma/accounts.py +145 -0
  16. trackma/data/anilist.jpg +0 -0
  17. trackma/data/icon.png +0 -0
  18. trackma/data/kitsu.png +0 -0
  19. trackma/data/mal.jpg +0 -0
  20. trackma/data/shikimori.jpg +0 -0
  21. trackma/data/vndb.jpg +0 -0
  22. trackma/data.py +620 -0
  23. trackma/engine.py +979 -0
  24. trackma/extras/AnimeInfoExtractor.py +317 -0
  25. trackma/extras/__init__.py +1 -0
  26. trackma/extras/__pycache__/AnimeInfoExtractor.cpython-36.pyc +0 -0
  27. trackma/extras/__pycache__/__init__.cpython-36.pyc +0 -0
  28. trackma/lib/__init__.py +0 -0
  29. trackma/lib/__pycache__/__init__.cpython-36.pyc +0 -0
  30. trackma/lib/__pycache__/lib.cpython-36.pyc +0 -0
  31. trackma/lib/__pycache__/libanilist.cpython-36.pyc +0 -0
  32. trackma/lib/__pycache__/libkitsu.cpython-36.pyc +0 -0
  33. trackma/lib/__pycache__/libmal.cpython-36.pyc +0 -0
  34. trackma/lib/__pycache__/libshikimori.cpython-36.pyc +0 -0
  35. trackma/lib/__pycache__/libvndb.cpython-36.pyc +0 -0
  36. trackma/lib/lib.py +162 -0
  37. trackma/lib/libanilist.py +474 -0
  38. trackma/lib/libkitsu.py +506 -0
  39. trackma/lib/libmal.py +707 -0
  40. trackma/lib/libshikimori.py +340 -0
  41. trackma/lib/libvndb.py +387 -0
  42. trackma/messenger.py +42 -0
  43. trackma/tracker/__init__.py +0 -0
  44. trackma/tracker/__pycache__/__init__.cpython-36.pyc +0 -0
  45. trackma/tracker/__pycache__/inotify.cpython-36.pyc +0 -0
  46. trackma/tracker/__pycache__/inotifyBase.cpython-36.pyc +0 -0
  47. trackma/tracker/__pycache__/plex.cpython-36.pyc +0 -0
  48. trackma/tracker/__pycache__/polling.cpython-36.pyc +0 -0
  49. trackma/tracker/__pycache__/pyinotify.cpython-36.pyc +0 -0
  50. trackma/tracker/__pycache__/tracker.cpython-36.pyc +0 -0
  51. trackma/tracker/__pycache__/win32.cpython-36.pyc +0 -0
  52. trackma/tracker/inotify.py +69 -0
  53. trackma/tracker/inotifyBase.py +107 -0
  54. trackma/tracker/plex.py +144 -0
  55. trackma/tracker/polling.py +55 -0
  56. trackma/tracker/pyinotify.py +90 -0
  57. trackma/tracker/tracker.py +226 -0
  58. trackma/tracker/win32.py +74 -0
  59. trackma/ui/__init__.py +0 -0
  60. trackma/ui/__pycache__/__init__.cpython-36.pyc +0 -0
  61. trackma/ui/__pycache__/cli-single.cpython-36.pyc +0 -0
  62. trackma/ui/__pycache__/cli.cpython-36.pyc +0 -0
  63. trackma/ui/__pycache__/curses.cpython-36.pyc +0 -0
  64. trackma/ui/__pycache__/gtkui.cpython-36.pyc +0 -0
  65. trackma/ui/__pycache__/qt4ui.cpython-36.pyc +0 -0
  66. trackma/ui/__pycache__/qtui.cpython-36.pyc +0 -0
  67. trackma/ui/cli-single.py +3 -0
  68. trackma/ui/cli.py +1035 -0
  69. trackma/ui/curses.py +1156 -0
  70. trackma/ui/gtkui.py +2847 -0
  71. trackma/ui/qt4ui.py +25 -0
  72. trackma/ui/qtui.py +3273 -0
  73. trackma/utils.py +416 -0
trackma/data.py ADDED
@@ -0,0 +1,620 @@
1
+ # This file is part of Trackma.
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ import os.path
18
+ import sys
19
+ import threading
20
+ import time
21
+
22
+ from trackma import messenger
23
+ from trackma import utils
24
+
25
+ class Data():
26
+ """
27
+ Data Handler Class
28
+
29
+ Class for keeping data in memory, handling list cache and
30
+ update queues. This module cares about keeping the data
31
+ safe and up to date, and it handles commands given by the engine,
32
+ and communicates with the API whenever it's necessary.
33
+
34
+ messenger: Messenger object to send useful messages to
35
+ config: Parsed configuration dictionary (given by the engine)
36
+
37
+ """
38
+ name = 'Data'
39
+ version = 5
40
+
41
+ msg = None
42
+ api = None
43
+ showlist = None
44
+ infocache = dict()
45
+ queue = list()
46
+ config = dict()
47
+ meta = {'lastget': 0, 'lastsend': 0, 'version': '', 'apiversion': '', 'altnames': {}, 'library': {}, 'library_cache': {}, }
48
+
49
+ autosend_timer = None
50
+
51
+ signals = {
52
+ 'show_synced': None,
53
+ 'sync_complete': None,
54
+ 'queue_changed': None,
55
+ }
56
+
57
+ def __init__(self, messenger, config, account, mediatype):
58
+ """Checks if the config is correct and creates an API object."""
59
+ self.msg = messenger
60
+ self.config = config
61
+ self.msg.info(self.name, "Initializing...")
62
+
63
+ # Get filenames
64
+ userfolder = "%s.%s" % (account['username'], account['api'])
65
+ self.userconfig_file = utils.get_filename(userfolder, 'user.json')
66
+
67
+ # Handle userconfig and media type to load
68
+ self._load_userconfig()
69
+ if mediatype:
70
+ self.userconfig['mediatype'] = mediatype
71
+ self._save_userconfig()
72
+
73
+ # Import the API
74
+ libbase = account['api']
75
+ libname = "lib{0}".format(libbase)
76
+ try:
77
+ modulename = "trackma.lib.{0}".format(libname)
78
+ __import__(modulename)
79
+ apimodule = sys.modules[modulename]
80
+ except ImportError as e:
81
+ raise utils.DataFatal("Couldn't import API module: %s" % e)
82
+
83
+ # Instance API
84
+ libclass = getattr(apimodule, libname)
85
+ self.api = libclass(self.msg, account, self.userconfig)
86
+
87
+ # Get API version
88
+ self.api_version = self.api.api_info['version']
89
+
90
+ # Set mediatype
91
+ mediatype = self.userconfig.get('mediatype')
92
+ self.msg.info(self.name, "Using %s (%s)" % (libname, mediatype))
93
+
94
+ # Get filenames
95
+ self.queue_file = utils.get_filename(userfolder, '%s.queue' % mediatype)
96
+ self.info_file = utils.get_filename(userfolder, '%s.info' % mediatype)
97
+ self.cache_file = utils.get_filename(userfolder, '%s.list' % mediatype)
98
+ self.meta_file = utils.get_filename(userfolder, '%s.meta' % mediatype)
99
+ self.lock_file = utils.get_filename(userfolder, 'lock')
100
+
101
+ # Connect signals
102
+ self.api.connect_signal('show_info_changed', self.info_update)
103
+ self.api.connect_signal('userconfig_changed', self.userconfig_update)
104
+
105
+ def _emit_signal(self, signal, *args):
106
+ if self.signals[signal]:
107
+ self.signals[signal](*args)
108
+
109
+ def _is_queue_ready(self):
110
+ # Checks if queue should be sent ASAP
111
+ # Note: Hours setting is DEPRECATED!
112
+ return (self.config['autosend'] == 'always' or
113
+ (self.config['autosend'] == 'hours' and time.time() - self.meta['lastsend'] >= self.config['autosend_hours']*3600) or
114
+ (self.config['autosend'] == 'minutes' and time.time() - self.meta['lastsend'] >= self.config['autosend_minutes']*60) or
115
+ (self.config['autosend'] == 'size' and len(self.queue) >= self.config['autosend_size']))
116
+
117
+ def connect_signal(self, signal, callback):
118
+ try:
119
+ self.signals[signal] = callback
120
+ except KeyError:
121
+ raise utils.DataFatal("Invalid signal.")
122
+
123
+ def set_message_handler(self, message_handler):
124
+ self.msg = message_handler
125
+ self.api.set_message_handler(self.msg)
126
+
127
+ def start(self):
128
+ """
129
+ Does all necessary tasks to start the data handler
130
+
131
+ This should be called before doing any other operation with the data handler,
132
+ as it loads the list cache (or downloads it if necessary) and queue.
133
+
134
+ """
135
+ # Lock the database
136
+ self.msg.debug(self.name, "Locking database...")
137
+ self._lock()
138
+
139
+ # Load different caches
140
+ if self._meta_exists():
141
+ self._load_meta()
142
+
143
+ if self._queue_exists() and self.meta.get('version') == self.version and self.meta.get('apiversion') == self.api_version:
144
+ self._load_queue()
145
+ self._emit_signal('queue_changed', self.queue)
146
+
147
+ if self._info_exists() and self.meta.get('version') == self.version and self.meta.get('apiversion') == self.api_version:
148
+ # Load info cache only if we're on the same database version
149
+ self._load_info()
150
+
151
+ # If there is a list cache, load from it
152
+ # otherwise query the API for a remote list
153
+ if self._cache_exists() and self.meta.get('version') == self.version and self.meta.get('apiversion') == self.api_version:
154
+ # Auto-send: Process the queue if we're beyond the auto-send time limit for some reason
155
+ if self._is_queue_ready():
156
+ self.process_queue()
157
+
158
+ # Auto-retrieve: Redownload list if any autoretrieve condition is met
159
+ if (self.config['autoretrieve'] == 'always' or
160
+ (self.config['autoretrieve'] == 'days' and
161
+ time.time() - self.meta['lastget'] > self.config['autoretrieve_days'] * 84600) or
162
+ self.meta.get('version') != self.version):
163
+ try:
164
+ # Make sure we process the queue first before overwriting the list
165
+ # We don't want users losing their changes
166
+ self.process_queue()
167
+ self.download_data()
168
+ except utils.APIError as e:
169
+ self.msg.warn(self.name, "Couldn't download list! Using cache.")
170
+ self._load_cache()
171
+ elif not self.showlist:
172
+ # If the cache wasn't loaded before, do it now
173
+ self._load_cache()
174
+ else:
175
+ try:
176
+ self.download_data()
177
+ except utils.APIError as e:
178
+ raise utils.APIFatal(str(e))
179
+
180
+ # Create autosend thread if needed
181
+ # Note: Hours setting is DEPRECATED!
182
+ if self.config['autosend'] in ('minutes', 'hours'):
183
+ self.autosend()
184
+
185
+ return (self.api.api_info, self.api.media_info())
186
+
187
+ def unload(self, force=False):
188
+ """
189
+ Does unloading of the data handler
190
+
191
+ This should be called whenever the data handler won't be used anymore,
192
+ as it does necessary operations to close the API and the data handler itself.
193
+
194
+ """
195
+ self.msg.debug(self.name, "Unloading...")
196
+
197
+ # Cancel autosend thread
198
+ if self.autosend_timer:
199
+ self.autosend_timer.cancel()
200
+
201
+ # We push changes if specified on config file
202
+ if not force:
203
+ if self.config['autosend_at_exit']:
204
+ self.process_queue()
205
+
206
+ self._save_meta()
207
+
208
+ self._unlock()
209
+
210
+ def get(self):
211
+ """Get list from memory"""
212
+ return self.showlist
213
+
214
+ def search(self, criteria):
215
+ # Tell API to search
216
+ results = self.api.search(criteria)
217
+ self.api.logout()
218
+ if results:
219
+ return results
220
+ else:
221
+ raise utils.DataError('No results.')
222
+
223
+ def queue_add(self, show):
224
+ """
225
+ Queues a show add
226
+
227
+ Calls this to add a show to the list, and the remote add
228
+ will be queued.
229
+
230
+ show: Show dictionary
231
+
232
+ """
233
+ showid = show['id']
234
+
235
+ # Add to the list
236
+ if self.showlist.get(showid):
237
+ raise utils.DataError("Show already in the list.")
238
+
239
+ self.showlist[showid] = show
240
+
241
+ # Check if the show add is already in queue
242
+ exists = False
243
+ for q in self.queue:
244
+ if q['id'] == showid and q['action'] == 'add':
245
+ # This shouldn't happen
246
+ raise utils.DataError("Show already in the queue.")
247
+
248
+ if not exists:
249
+ # Use the whole show as a queue item
250
+ item = show
251
+ item['action'] = 'add'
252
+ self.queue.append(item)
253
+
254
+ show['queued'] = True
255
+
256
+ self._save_queue()
257
+ self._save_cache()
258
+ self._emit_signal('queue_changed', self.queue)
259
+ self.msg.info(self.name, "Queued add for %s" % show['title'])
260
+
261
+ def queue_update(self, show, key, value):
262
+ """
263
+ Queues a show update
264
+
265
+ Call this to change anything of an item in the list, as it will be
266
+ modified locally and queued for update in the next remote sync.
267
+
268
+ show: Show dictionary
269
+ key: The key that will be modified (it must exist beforehand)
270
+ value: The value that it should be changed to
271
+ """
272
+ if key not in show:
273
+ raise utils.DataError('Invalid key for queue update.')
274
+
275
+ # Do update on memory
276
+ show[key] = value
277
+
278
+ # Check if the show update is already in queue
279
+ exists = False
280
+ for q in self.queue:
281
+ if q['id'] == show['id'] and q['action'] in ['add', 'update']:
282
+ # Add the changed value to the already existing queue item
283
+ q[key] = value
284
+ exists = True
285
+ break
286
+
287
+ if not exists:
288
+ # Create queue item and append it
289
+ item = {'id': show['id'],
290
+ 'my_id': show['my_id'],
291
+ 'action': 'update',
292
+ 'title': show['title'],
293
+ }
294
+ item[key] = value
295
+ self.queue.append(item)
296
+
297
+ show['queued'] = True
298
+
299
+ self._save_queue()
300
+ self._save_cache()
301
+ self._emit_signal('queue_changed', self.queue)
302
+ self.msg.info(self.name, "Queued update for %s" % show['title'])
303
+
304
+ # Immediately process the action if necessary
305
+ if self._is_queue_ready():
306
+ self.process_queue()
307
+
308
+ def queue_delete(self, show):
309
+ """
310
+ Queues a show delete
311
+
312
+ Calls this to delete a show from the list, and the remote delete
313
+ will be queued.
314
+
315
+ show: Show dictionary
316
+
317
+ """
318
+ showid = show['id']
319
+
320
+ # Delete from the list
321
+ if not self.showlist.get(showid):
322
+ raise utils.DataError("Show not in the list.")
323
+
324
+ item = self.showlist.pop(showid)
325
+
326
+ # Check if the show add is already in queue
327
+ exists = False
328
+ for q in self.queue:
329
+ if q['id'] == showid and q['action'] == 'delete':
330
+ # This shouldn't happen
331
+ raise utils.DataError("Show delete already in the queue.")
332
+
333
+ if not exists:
334
+ # Use the whole show as a queue item
335
+ item['action'] = 'delete'
336
+ self.queue.append(item)
337
+
338
+ show['queued'] = True
339
+
340
+ self._save_queue()
341
+ self._save_cache()
342
+ self._emit_signal('queue_changed', self.queue)
343
+ self.msg.info(self.name, "Queued delete for %s" % item['title'])
344
+
345
+ def queue_clear(self):
346
+ """Clears the queue completely."""
347
+ if self.queue:
348
+ self.queue = []
349
+ self._save_queue()
350
+ self._emit_signal('queue_changed', self.queue)
351
+ self.msg.info(self.name, "Cleared queue.")
352
+
353
+ def process_queue(self):
354
+ """
355
+ Send updates in queue to the API
356
+
357
+ It starts sending all the queued updates to the API for it to update
358
+ the remote list. Any successful updates get removed from the queue,
359
+ and failed updates stay there to be processed the next time.
360
+
361
+ """
362
+ if len(self.queue):
363
+ self.msg.info(self.name, 'Processing queue...')
364
+
365
+ # Load the cache if it wasn't loaded for some reason
366
+ if not self.showlist:
367
+ self._load_cache()
368
+
369
+ # Check log-in TODO
370
+ #try:
371
+ # self.api.check_credentials()
372
+ #except utils.APIError as e:
373
+ # raise utils.DataError("Can't process queue, will leave unsynced. Reason: %s" % e)
374
+
375
+ # Run through queue
376
+ items_processed = []
377
+ items_failed = []
378
+ while True:
379
+ try:
380
+ item = self.queue.pop(0)
381
+ except IndexError:
382
+ break
383
+
384
+ showid = item['id']
385
+
386
+ try:
387
+ show = self.showlist[showid]
388
+ except KeyError:
389
+ show = None
390
+
391
+ try:
392
+ # Call the API to do the requested operation
393
+ operation = item.get('action')
394
+ if operation == 'add':
395
+ my_id = self.api.add_show(item)
396
+
397
+ if my_id:
398
+ show['my_id'] = my_id
399
+ elif operation == 'update':
400
+ self.api.update_show(item)
401
+ elif operation == 'delete':
402
+ self.api.delete_show(item)
403
+ else:
404
+ self.msg.warn(self.name, "Unknown operation in queue (%s), skipping..." % repr(operation))
405
+
406
+ if self.showlist.get(showid):
407
+ self.showlist[showid]['queued'] = False
408
+ self._emit_signal('show_synced', show, item)
409
+
410
+ items_processed.append((show, item))
411
+ self._emit_signal('queue_changed', self.queue)
412
+ except utils.APIError as e:
413
+ self.msg.warn(self.name, "Can't process %s, will leave unsynced." % item['title'])
414
+ self.msg.debug(self.name, "Info: %s" % e)
415
+ items_failed.append(item)
416
+ except NotImplementedError:
417
+ self.msg.warn(self.name, "Operation not implemented in API. Skipping...")
418
+ items_failed.append(item)
419
+ #except TypeError:
420
+ # self.msg.warn(self.name, "%s not in list, unexpected. Not changing queued status." % showid)
421
+
422
+ if items_failed:
423
+ self.queue += items_failed
424
+
425
+ self.api.logout()
426
+ self._save_cache()
427
+ self._save_queue()
428
+ self._emit_signal('sync_complete', items_processed)
429
+ else:
430
+ self.msg.debug(self.name, 'No items in queue.')
431
+
432
+ self.meta['lastsend'] = time.time()
433
+
434
+ def info_get(self, show):
435
+ try:
436
+ showid = show['id']
437
+ return self.infocache[showid]
438
+ except KeyError:
439
+ return self.api.request_info([show])[0]
440
+
441
+ def info_update(self, shows):
442
+ for show in shows:
443
+ showid = show['id']
444
+ self.infocache[showid] = show
445
+
446
+ self._save_info()
447
+
448
+ def userconfig_update(self):
449
+ self._save_userconfig()
450
+
451
+ def altname_get(self, showid):
452
+ return self.meta['altnames'].get(showid, '')
453
+
454
+ def altname_set(self, showid, altname):
455
+ self.meta['altnames'][showid] = altname
456
+
457
+ def altname_clear(self, showid):
458
+ if showid in self.meta['altnames']:
459
+ del self.meta['altnames'][showid]
460
+
461
+ def altnames_get(self):
462
+ return self.meta['altnames']
463
+
464
+ def library_get(self):
465
+ return self.meta['library']
466
+
467
+ def library_save(self, library):
468
+ self.meta['library'] = library
469
+
470
+ def library_cache_get(self):
471
+ return self.meta['library_cache']
472
+
473
+ def library_cache_save(self, library_cache):
474
+ self.meta['library_cache'] = library_cache
475
+
476
+ def get_show_attr(self, show, key):
477
+ return show.get(key)
478
+
479
+ def set_show_attr(self, show, key, value):
480
+ show[key] = value
481
+
482
+ def get_show_titles(self, show):
483
+ if self.altname_get(show['id']):
484
+ return [ self.altname_get(show['id']) ]
485
+ else:
486
+ return [show['title']] + show['aliases']
487
+
488
+ def autosend(self):
489
+ # Check if we should autosend now
490
+ if self._is_queue_ready():
491
+ self.process_queue()
492
+
493
+ # Repeat check only if the settings are still on autosend
494
+ # Note: Hours setting is DEPRECATED!
495
+ if self.config['autosend'] in ('minutes', 'hours'):
496
+ self.autosend_timer = threading.Timer(3600 if self.config['autosend'] == 'hours' else 60, self.autosend)
497
+ self.autosend_timer.daemon = True
498
+ self.autosend_timer.start()
499
+
500
+ def _load_cache(self):
501
+ self.msg.debug(self.name, "Reading cache...")
502
+ self.showlist = utils.load_data(self.cache_file)
503
+
504
+ def _save_cache(self):
505
+ self.msg.debug(self.name, "Saving cache...")
506
+ utils.save_data(self.showlist, self.cache_file)
507
+
508
+ def _load_info(self):
509
+ self.msg.debug(self.name, "Reading info DB...")
510
+ self.infocache = utils.load_data(self.info_file)
511
+
512
+ def _save_info(self):
513
+ self.msg.debug(self.name, "Saving info DB...")
514
+ utils.save_data(self.infocache, self.info_file)
515
+
516
+ def _load_userconfig(self):
517
+ self.msg.debug(self.name, "Reading userconfig...")
518
+ self.userconfig = utils.parse_config(self.userconfig_file, utils.userconfig_defaults)
519
+
520
+ def _save_userconfig(self):
521
+ self.msg.debug(self.name, "Saving userconfig...")
522
+ utils.save_config(self.userconfig, self.userconfig_file)
523
+
524
+ def _load_queue(self):
525
+ self.msg.debug(self.name, "Reading queue...")
526
+ self.queue = utils.load_data(self.queue_file)
527
+
528
+ def _save_queue(self):
529
+ self.msg.debug(self.name, "Saving queue...")
530
+ utils.save_data(self.queue, self.queue_file)
531
+
532
+ def _load_meta(self):
533
+ self.msg.debug(self.name, "Reading metadata...")
534
+ loadedmeta = utils.load_data(self.meta_file)
535
+ self.meta.update(loadedmeta)
536
+
537
+ def _save_meta(self):
538
+ self.msg.debug(self.name, "Saving metadata...")
539
+ utils.save_data(self.meta, self.meta_file)
540
+
541
+ def download_data(self):
542
+ """Downloads the remote list and overwrites the cache"""
543
+ self.showlist = self.api.fetch_list()
544
+
545
+ if self.api.api_info['merge']:
546
+ # The API needs information to be merged from the
547
+ # info database
548
+ missing = []
549
+ for k, show in self.showlist.items():
550
+ # Here we search the information in the local
551
+ # info database. If it isn't available, add it
552
+ # to the missing list for them to be requested
553
+ # to the API later.
554
+ showid = show['id']
555
+
556
+ try:
557
+ info = self.infocache[showid]
558
+ except KeyError:
559
+ missing.append(show)
560
+ continue
561
+
562
+ self.api.merge(show, info)
563
+ #show['title'] = info['title']
564
+ #show['image'] = info['image']
565
+
566
+ # Here we request the missing items and merge them
567
+ # immedately with the list.
568
+ if len(missing) > 0:
569
+ infos = self.api.request_info(missing)
570
+ for info in infos:
571
+ showid = info['id']
572
+ self.api.merge(self.showlist[showid], info)
573
+
574
+ #self.showlist[showid]['title'] = info['title']
575
+ #self.showlist[showid]['image'] = info['image']
576
+
577
+ self._save_cache()
578
+ self.api.logout()
579
+
580
+ # Update last retrieved time
581
+ self.meta['lastget'] = time.time()
582
+ self.meta['version'] = self.version
583
+ self.meta['apiversion'] = self.api_version
584
+ self._save_meta()
585
+
586
+ def _cache_exists(self):
587
+ return os.path.isfile(self.cache_file)
588
+
589
+ def _info_exists(self):
590
+ return os.path.isfile(self.info_file)
591
+
592
+ def _queue_exists(self):
593
+ return os.path.isfile(self.queue_file)
594
+
595
+ def _meta_exists(self):
596
+ return os.path.isfile(self.meta_file)
597
+
598
+ def _lock(self):
599
+ """Creates the database lock, returns an exception if it
600
+ already exists"""
601
+ if self.config['debug_disable_lock']:
602
+ return
603
+
604
+ if os.path.isfile(self.lock_file):
605
+ raise utils.DataFatal("Database is locked by another process. "
606
+ "If you\'re sure there's no other process is using it, "
607
+ "remove the file ~/.trackma/lock")
608
+
609
+ f = open(self.lock_file, 'w')
610
+ f.close()
611
+
612
+ def _unlock(self):
613
+ """Removes the database lock"""
614
+ if self.config['debug_disable_lock']:
615
+ return
616
+
617
+ os.unlink(self.lock_file)
618
+
619
+ def get_api_info(self):
620
+ return (self.api.api_info, self.api.media_info())