trackma 0.4__py2.7.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 (57) hide show
  1. EGG-INFO/PKG-INFO +19 -0
  2. EGG-INFO/SOURCES.txt +35 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/entry_points.txt +8 -0
  5. EGG-INFO/not-zip-safe +1 -0
  6. EGG-INFO/requires.txt +10 -0
  7. EGG-INFO/top_level.txt +1 -0
  8. trackma/__init__.py +0 -0
  9. trackma/__init__.pyc +0 -0
  10. trackma/accounts.py +110 -0
  11. trackma/accounts.pyc +0 -0
  12. trackma/data/anilist.jpg +0 -0
  13. trackma/data/hb.jpg +0 -0
  14. trackma/data/icon.png +0 -0
  15. trackma/data/mal.jpg +0 -0
  16. trackma/data/melative.jpg +0 -0
  17. trackma/data/vndb.jpg +0 -0
  18. trackma/data.py +585 -0
  19. trackma/data.pyc +0 -0
  20. trackma/engine.py +742 -0
  21. trackma/engine.pyc +0 -0
  22. trackma/extras/AnimeInfoExtractor.py +308 -0
  23. trackma/extras/AnimeInfoExtractor.pyc +0 -0
  24. trackma/extras/__init__.py +0 -0
  25. trackma/extras/__init__.pyc +0 -0
  26. trackma/extras/plex.py +100 -0
  27. trackma/extras/plex.pyc +0 -0
  28. trackma/lib/__init__.py +0 -0
  29. trackma/lib/__init__.pyc +0 -0
  30. trackma/lib/lib.py +162 -0
  31. trackma/lib/lib.pyc +0 -0
  32. trackma/lib/libanilist.py +355 -0
  33. trackma/lib/libanilist.pyc +0 -0
  34. trackma/lib/libhb.py +248 -0
  35. trackma/lib/libhb.pyc +0 -0
  36. trackma/lib/libmal.py +705 -0
  37. trackma/lib/libmal.pyc +0 -0
  38. trackma/lib/libmelative.py +213 -0
  39. trackma/lib/libmelative.pyc +0 -0
  40. trackma/lib/libvndb.py +373 -0
  41. trackma/lib/libvndb.pyc +0 -0
  42. trackma/messenger.py +42 -0
  43. trackma/messenger.pyc +0 -0
  44. trackma/tracker.py +301 -0
  45. trackma/tracker.pyc +0 -0
  46. trackma/ui/__init__.py +0 -0
  47. trackma/ui/__init__.pyc +0 -0
  48. trackma/ui/cli.py +712 -0
  49. trackma/ui/cli.pyc +0 -0
  50. trackma/ui/curses.py +1049 -0
  51. trackma/ui/curses.pyc +0 -0
  52. trackma/ui/gtkui.py +2360 -0
  53. trackma/ui/gtkui.pyc +0 -0
  54. trackma/ui/qtui.py +2120 -0
  55. trackma/ui/qtui.pyc +0 -0
  56. trackma/utils.py +299 -0
  57. trackma/utils.pyc +0 -0
trackma/ui/cli.py ADDED
@@ -0,0 +1,712 @@
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 sys
18
+ try:
19
+ import readline
20
+ except ImportError:
21
+ pass # readline is optional
22
+ import cmd
23
+ import shlex
24
+ import re
25
+ from operator import itemgetter # Used for sorting list
26
+
27
+ from trackma.engine import Engine
28
+ from trackma.accounts import AccountManager
29
+
30
+ import trackma.messenger as messenger
31
+ import trackma.utils as utils
32
+
33
+ _DEBUG = False
34
+ _COLOR_ENGINE = '\033[0;32m'
35
+ _COLOR_DATA = '\033[0;33m'
36
+ _COLOR_API = '\033[0;34m'
37
+ _COLOR_TRACKER = '\033[0;35m'
38
+ _COLOR_ERROR = '\033[0;31m'
39
+ _COLOR_FATAL = '\033[1;31m'
40
+ _COLOR_RESET = '\033[0m'
41
+
42
+ _COLOR_AIRING = '\033[0;34m'
43
+
44
+ class Trackma_cmd(cmd.Cmd):
45
+ """
46
+ Main program, inherits from the useful Cmd class
47
+ for interactive console
48
+ """
49
+ engine = None
50
+ filter_num = 1
51
+ sort = 'title'
52
+ completekey = 'Tab'
53
+ cmdqueue = []
54
+ stdout = sys.stdout
55
+ sortedlist = []
56
+ needed_args = {
57
+ 'filter': (0, 1),
58
+ 'sort': 1,
59
+ 'mediatype': (0, 1),
60
+ 'info': 1,
61
+ 'search': 1,
62
+ 'add': 1,
63
+ 'delete': 1,
64
+ 'play': (1, 2),
65
+ 'update': 2,
66
+ 'score': 2,
67
+ 'status': 2,
68
+ }
69
+
70
+ def __init__(self):
71
+ print 'Trackma v'+utils.VERSION+' Copyright (C) 2012 z411'
72
+ print 'This program comes with ABSOLUTELY NO WARRANTY; for details type `info\''
73
+ print 'This is free software, and you are welcome to redistribute it'
74
+ print 'under certain conditions; see the file COPYING for details.'
75
+ print
76
+
77
+ self.accountman = Trackma_accounts()
78
+ self.account = self.accountman.select_account(False)
79
+
80
+ def _update_prompt(self):
81
+ self.prompt = "{0}@{1}({2}) {3}> ".format(
82
+ self.engine.get_userconfig('username'),
83
+ self.engine.api_info['name'],
84
+ self.engine.api_info['mediatype'],
85
+ self.engine.mediainfo['statuses_dict'][self.filter_num]
86
+ )
87
+
88
+ def _load_list(self, *args):
89
+ showlist = self.engine.filter_list(self.filter_num)
90
+ self.sortedlist = sorted(showlist, key=itemgetter(self.sort))
91
+
92
+ def _get_show(self, title):
93
+ # Attempt parsing list index
94
+ # otherwise use title
95
+ try:
96
+ index = int(title)-1
97
+ return self.sortedlist[index]
98
+ except (ValueError, AttributeError, IndexError):
99
+ return self.engine.get_show_info_title(title)
100
+
101
+ def _ask_update(self, show, episode):
102
+ do_update = raw_input("Should I update %s to episode %d? [y/N] " % (show['title'].encode('utf-8'), episode))
103
+ if do_update.lower() == 'y':
104
+ self.engine.set_episode(show['id'], episode)
105
+
106
+ def start(self):
107
+ """
108
+ Initializes the engine
109
+
110
+ Creates an Engine object and starts it.
111
+ """
112
+ print 'Initializing engine...'
113
+ self.engine = Engine(self.account, self.messagehandler)
114
+ self.engine.connect_signal('show_added', self._load_list)
115
+ self.engine.connect_signal('show_deleted', self._load_list)
116
+ self.engine.connect_signal('status_changed', self._load_list)
117
+ self.engine.connect_signal('episode_changed', self._load_list)
118
+ self.engine.connect_signal('prompt_for_update', self._ask_update)
119
+ self.engine.start()
120
+
121
+ # Start with default filter selected
122
+ self.filter_num = self.engine.mediainfo['statuses'][0]
123
+ self._load_list()
124
+ self._update_prompt()
125
+
126
+ def do_account(self, args):
127
+ """
128
+ account - Switch to a different account
129
+
130
+ Usage: account
131
+ """
132
+
133
+ self.account = self.accountman.select_account(True)
134
+ self.engine.reload(account=self.account)
135
+
136
+ # Start with default filter selected
137
+ self.filter_num = self.engine.mediainfo['statuses'][0]
138
+ self._load_list()
139
+ self._update_prompt()
140
+
141
+ def do_filter(self, args):
142
+ """
143
+ filter - Changes the filtering of list by status; call with no arguments to see available filters
144
+
145
+ Usage: filter [filter type]
146
+ """
147
+ # Query the engine for the available statuses
148
+ # that the user can choose
149
+ if args:
150
+ try:
151
+ self.filter_num = self._guess_status(args[0].lower())
152
+ self._load_list()
153
+ self._update_prompt()
154
+ except KeyError:
155
+ print "Invalid filter."
156
+ else:
157
+ print "Available filters: %s" % ', '.join( v.lower().replace(' ', '') for v in self.engine.mediainfo['statuses_dict'].values() )
158
+
159
+ def do_sort(self, args):
160
+ """
161
+ sort - Change sort
162
+
163
+ Usage: sort <sort type>
164
+ Available types: id, title, my_progress, total, my_score
165
+ """
166
+ sorts = ('id', 'title', 'my_progress', 'total', 'my_score')
167
+ if args[0] in sorts:
168
+ self.sort = args[0]
169
+ self._load_list()
170
+ else:
171
+ print "Invalid sort."
172
+
173
+ def do_mediatype(self, args):
174
+ """
175
+ mediatype - Reloads engine with different mediatype; call with no arguments to see supported mediatypes
176
+
177
+ Usage: mediatype [mediatype]
178
+ """
179
+ if args:
180
+ if args[0] in self.engine.api_info['supported_mediatypes']:
181
+ self.engine.reload(mediatype=args[0])
182
+
183
+ # Start with default filter selected
184
+ self.filter_num = self.engine.mediainfo['statuses'][0]
185
+ self._load_list()
186
+ self._update_prompt()
187
+ else:
188
+ print "Invalid mediatype."
189
+ else:
190
+ print "Supported mediatypes: %s" % ', '.join(self.engine.api_info['supported_mediatypes'])
191
+
192
+ def do_list(self, args):
193
+ """
194
+ list - Lists all shows available in the local list as a nice formatted list.
195
+ """
196
+ # Show the list in memory
197
+ self._make_list(self.sortedlist)
198
+
199
+ def do_info(self, args):
200
+ """
201
+ info - Gets detailed information about a show in the local list.
202
+
203
+ Usage: info <show index or title>
204
+
205
+ """
206
+ try:
207
+ show = self._get_show(args[0])
208
+ details = self.engine.get_show_details(show)
209
+ except utils.TrackmaError, e:
210
+ self.display_error(e)
211
+ return
212
+
213
+ print "Title: %s" % details['title']
214
+ for line in details['extra']:
215
+ print "%s: %s" % line
216
+
217
+ def do_search(self, args):
218
+ """
219
+ search - Does a regex search on shows in the local lists and lists the matches.
220
+
221
+ Usage: search <pattern>
222
+
223
+ """
224
+ showlist = self.engine.regex_list(args[0])
225
+ sortedlist = sorted(showlist, key=itemgetter(self.sort))
226
+ self._make_list(sortedlist)
227
+
228
+ def do_add(self, args):
229
+ """
230
+ add - Searches for a show in the remote service and adds it to the local list.
231
+
232
+ Usage: add <pattern>
233
+
234
+ """
235
+ try:
236
+ entries = self.engine.search(args[0])
237
+ except utils.TrackmaError, e:
238
+ self.display_error(e)
239
+ return
240
+
241
+ for i, entry in enumerate(entries, start=1):
242
+ print "%d: (%s) %s" % (i, entry['type'], entry['title'])
243
+ do_update = raw_input("Choose show to add (blank to cancel): ")
244
+ if do_update != '':
245
+ try:
246
+ show = entries[int(do_update)-1]
247
+ except ValueError:
248
+ print "Choice must be numeric."
249
+ return
250
+ except IndexError:
251
+ print "Invalid show."
252
+ return
253
+
254
+ # Tell the engine to add the show
255
+ try:
256
+ self.engine.add_show(show, self.filter_num)
257
+ except utils.TrackmaError, e:
258
+ self.display_error(e)
259
+
260
+ def do_delete(self, args):
261
+ """
262
+ delete - Deltes a show from the local list.
263
+
264
+ Usage: delete <show index or title>
265
+
266
+ """
267
+ try:
268
+ show = self._get_show(args[0])
269
+
270
+ do_delete = raw_input("Delete %s? [y/N] " % show['title'].encode('utf-8'))
271
+ if do_delete.lower() == 'y':
272
+ self.engine.delete_show(show)
273
+ except utils.TrackmaError, e:
274
+ self.display_error(e)
275
+
276
+ def do_neweps(self, args):
277
+ """
278
+ neweps - Searches for new episodes in the configured search directory.
279
+
280
+ Usage: neweps
281
+ """
282
+ showlist = self.engine.filter_list(self.filter_num)
283
+ results = self.engine.get_new_episodes(showlist)
284
+ for show in results:
285
+ print show['title']
286
+
287
+ def do_scaneps(self, args):
288
+ self.engine.scan_library()
289
+
290
+ def do_play(self, args):
291
+ """
292
+ play - Starts the media player with the specified episode number.
293
+ If no episode is specified, the next will be played.
294
+
295
+ Usage: play <show index or title> [episode number]
296
+ """
297
+ try:
298
+ episode = 0
299
+ show = self._get_show(args[0])
300
+
301
+ # If the user specified an episode, play it
302
+ # otherwise play the next episode not watched yet
303
+ try:
304
+ episode = args[1]
305
+ if episode == (show['my_progress'] + 1):
306
+ playing_next = True
307
+ else:
308
+ playing_next = False
309
+ except IndexError:
310
+ playing_next = True
311
+
312
+ played_episode = self.engine.play_episode(show, episode)
313
+ except utils.TrackmaError, e:
314
+ self.display_error(e)
315
+
316
+ def do_update(self, args):
317
+ """
318
+ update - Updates the progress of a show to the specified episode.
319
+
320
+ Usage: update <show index or name> <episode number>
321
+ """
322
+ try:
323
+ show = self._get_show(args[0])
324
+ self.engine.set_episode(show['id'], args[1])
325
+ except IndexError:
326
+ print "Missing arguments."
327
+ except utils.TrackmaError, e:
328
+ self.display_error(e)
329
+
330
+ def do_score(self, args):
331
+ """
332
+ score - Changes the given score of a show to the specified score.
333
+
334
+ Usage: score <show id or name> <score>
335
+ """
336
+ try:
337
+ show = self._get_show(args[0])
338
+ self.engine.set_score(show['id'], args[1])
339
+ except IndexError:
340
+ print "Missing arguments."
341
+ except utils.TrackmaError, e:
342
+ self.display_error(e)
343
+
344
+ def do_status(self, args):
345
+ """
346
+ status - Changes the status of a show. Use the command `filter`
347
+ withotu arguments to see the available statuses.
348
+
349
+ Usage: status <show id or name> <status name>
350
+ """
351
+ try:
352
+ _showtitle = args[0]
353
+ _filter = args[1]
354
+ except IndexError:
355
+ print "Missing arguments."
356
+ return
357
+
358
+ try:
359
+ _filter_num = self._guess_status(_filter)
360
+ except KeyError:
361
+ print "Invalid filter."
362
+ return
363
+
364
+ try:
365
+ show = self._get_show(_showtitle)
366
+ self.engine.set_status(show['id'], _filter_num)
367
+ except utils.TrackmaError, e:
368
+ self.display_error(e)
369
+
370
+ def do_send(self, args):
371
+ """
372
+ send - Sends any queued changes in the local list to the remote
373
+ service.
374
+
375
+ Usage: send
376
+ """
377
+ try:
378
+ self.engine.list_upload()
379
+ except utils.TrackmaError, e:
380
+ self.display_error(e)
381
+
382
+ def do_retrieve(self, args):
383
+ """
384
+ retrieve - Retrieves the full remote list from the remove service
385
+ and overwrites the local list.
386
+
387
+ Usage: retrieve
388
+ """
389
+ try:
390
+ if self.engine.get_queue():
391
+ answer = raw_input("There are unqueued changes. Overwrite local list? [y/N] ")
392
+ if answer.lower() == 'y':
393
+ self.engine.list_download()
394
+ else:
395
+ self.engine.list_download()
396
+ self._load_list()
397
+ except utils.TrackmaError, e:
398
+ self.display_error(e)
399
+
400
+ def do_undoall(self, args):
401
+ """
402
+ undo - Undo all changes
403
+
404
+ Usage: undoall
405
+ """
406
+ try:
407
+ self.engine.undoall()
408
+ except utils.TrackmaError, e:
409
+ self.display_error(e)
410
+
411
+ def do_viewqueue(self, args):
412
+ """
413
+ viewqueue - Shows the queued changes.
414
+
415
+ Usage: viewqueue
416
+ """
417
+ queue = self.engine.get_queue()
418
+ if len(queue):
419
+ print "Queue:"
420
+ for show in queue:
421
+ print "- %s" % show['title'].encode('utf-8')
422
+ else:
423
+ print "Queue is empty."
424
+
425
+ def do_quit(self, args):
426
+ """Quits the program."""
427
+ try:
428
+ self.engine.unload()
429
+ except utils.TrackmaError, e:
430
+ self.display_error(e)
431
+
432
+ print 'Bye!'
433
+ sys.exit(0)
434
+
435
+ def do_EOF(self, args):
436
+ print
437
+ self.do_quit(args)
438
+
439
+ def complete_update(self, text, line, begidx, endidx):
440
+ if text:
441
+ return self.engine.regex_list_titles(text)
442
+
443
+ def complete_play(self, text, line, begidx, endidx):
444
+ if text:
445
+ return self.engine.regex_list_titles(text)
446
+
447
+ def complete_score(self, text, line, begidx, endidx):
448
+ if text:
449
+ return self.engine.regex_list_titles(text)
450
+
451
+ def complete_status(self, text, line, begidx, endidx):
452
+ if text:
453
+ return self.engine.regex_list_titles(text)
454
+
455
+ def complete_delete(self, text, line, begidx, endidx):
456
+ if text:
457
+ return self.engine.regex_list_titles(text)
458
+
459
+ def complete_filter(self, text, line, begidx, endidx):
460
+ return (v.lower().replace(' ', '') for v in self.engine.mediainfo['statuses_dict'].values())
461
+
462
+ def parse_args(self, arg):
463
+ if arg:
464
+ return shlex.split(arg)
465
+ else:
466
+ return []
467
+
468
+ def onecmd(self, line):
469
+ """ Override. """
470
+ cmd, arg, line = self.parseline(line)
471
+ if not line:
472
+ return self.emptyline()
473
+ if cmd is None:
474
+ return self.default(line)
475
+ self.lastcmd = line
476
+ if line == 'EOF' :
477
+ self.lastcmd = ''
478
+ if cmd == '':
479
+ return self.default(line)
480
+ elif cmd == 'help':
481
+ return self.do_help(arg)
482
+ else:
483
+ return self.execute(cmd, arg, line)
484
+
485
+ def execute(self, cmd, arg, line):
486
+ try:
487
+ func = getattr(self, 'do_' + cmd)
488
+ except AttributeError:
489
+ return self.default(line)
490
+
491
+ args = self.parse_args(arg)
492
+
493
+ try:
494
+ needed = self.needed_args[cmd]
495
+ except KeyError:
496
+ needed = 0
497
+
498
+ if isinstance(needed, int):
499
+ needed = (needed, needed)
500
+
501
+ if needed[0] <= len(args) <= needed[1]:
502
+ return func(args)
503
+ else:
504
+ print "Incorrent number of arguments. See `help %s`" % cmd
505
+
506
+ def display_error(self, e):
507
+ print "%s%s: %s%s" % (_COLOR_ERROR, type(e), e.message, _COLOR_RESET)
508
+
509
+ def messagehandler(self, classname, msgtype, msg):
510
+ """
511
+ Handles and shows messages coming from
512
+ the engine messenger to provide feedback.
513
+ """
514
+ color_escape = ''
515
+ color_reset = _COLOR_RESET
516
+
517
+ if classname == 'Engine':
518
+ color_escape = _COLOR_ENGINE
519
+ elif classname == 'Data':
520
+ color_escape = _COLOR_DATA
521
+ elif classname == 'Tracker':
522
+ color_escape = _COLOR_TRACKER
523
+ elif classname.startswith('lib'):
524
+ color_escape = _COLOR_API
525
+ else:
526
+ color_reset = ''
527
+
528
+ if msgtype == messenger.TYPE_INFO:
529
+ print "%s%s: %s%s" % (color_escape, classname, msg, color_reset)
530
+ elif msgtype == messenger.TYPE_WARN:
531
+ print "%s%s warning: %s%s" % (color_escape, classname, msg, color_reset)
532
+ elif _DEBUG and msgtype == messenger.TYPE_DEBUG:
533
+ print "%s%s: %s%s" % (color_escape, classname, msg, color_reset)
534
+
535
+ def _guess_status(self, string):
536
+ for k, v in self.engine.mediainfo['statuses_dict'].items():
537
+ if string.lower() == v.lower().replace(' ', ''):
538
+ return k
539
+ raise KeyError
540
+
541
+ def _make_list(self, showlist):
542
+ """
543
+ Helper function for printing a formatted show list
544
+ """
545
+ # Fixed column widths
546
+ col_id_length = 7
547
+ col_index_length = 6
548
+ col_title_length = 5
549
+ col_episodes_length = 9
550
+ col_score_length = 6
551
+
552
+ # Calculate maximum width for the title column
553
+ # based on the width of the terminal
554
+ (height, width) = utils.get_terminal_size()
555
+ max_title_length = width - col_id_length - col_episodes_length - col_score_length - col_index_length - 5
556
+
557
+ # Find the widest title so we can adjust the title column
558
+ for show in showlist:
559
+ if len(show['title']) > col_title_length:
560
+ if len(show['title']) > max_title_length:
561
+ # Stop if we exceeded the maximum column width
562
+ col_title_length = max_title_length
563
+ break
564
+ else:
565
+ col_title_length = len(show['title'])
566
+
567
+ # Print header
568
+ print "| {0:{1}} {2:{3}} {4:{5}} {6:{7}} |".format(
569
+ 'Index', col_index_length,
570
+ 'Title', col_title_length,
571
+ 'Progress', col_episodes_length,
572
+ 'Score', col_score_length)
573
+
574
+ # List shows
575
+ for index, show in enumerate(showlist, 1):
576
+ if self.engine.mediainfo['has_progress']:
577
+ episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total'])
578
+ else:
579
+ episodes_str = "-"
580
+
581
+ # Truncate title if needed
582
+ title_str = show['title'].encode('utf-8')
583
+ title_str = title_str[:max_title_length] if len(title_str) > max_title_length else title_str
584
+
585
+ # Color title according to status
586
+ if show['status'] == utils.STATUS_AIRING:
587
+ colored_title = _COLOR_AIRING + title_str + _COLOR_RESET
588
+ else:
589
+ colored_title = title_str
590
+
591
+ print "| {0:^{1}} {2}{3} {4:{5}} {6:^{7}} |".format(
592
+ index, col_index_length,
593
+ colored_title,
594
+ '.' * (col_title_length-len(show['title'])),
595
+ episodes_str, col_episodes_length,
596
+ show['my_score'], col_score_length)
597
+
598
+ # Print result count
599
+ print '%d results' % len(showlist)
600
+ print
601
+
602
+ class Trackma_accounts(AccountManager):
603
+ def _get_id(self, index):
604
+ if index < 1:
605
+ raise IndexError
606
+
607
+ return self.indexes[index-1]
608
+
609
+ def select_account(self, bypass):
610
+ if not bypass and self.get_default():
611
+ return self.get_default()
612
+ if self.get_default():
613
+ self.set_default(None)
614
+
615
+ while True:
616
+ print '--- Accounts ---'
617
+ self.list_accounts()
618
+ key = raw_input("Input account number ([r#]emember, [a]dd, [c]ancel, [d]elete, [q]uit): ")
619
+
620
+ if key.lower() == 'a':
621
+ available_libs = ', '.join(sorted(utils.available_libs.iterkeys()))
622
+
623
+ print "--- Add account ---"
624
+ import getpass
625
+ api = raw_input('Enter API (%s): ' % available_libs)
626
+ try:
627
+ selected_api = utils.available_libs[api]
628
+ except KeyError:
629
+ print "Invalid API."
630
+ continue
631
+
632
+ if selected_api[2] == utils.LOGIN_PASSWD:
633
+ username = raw_input('Enter username: ')
634
+ password = getpass.getpass('Enter password (no echo): ')
635
+ elif selected_api[2] == utils.LOGIN_OAUTH:
636
+ username = raw_input('Enter account name: ')
637
+ print 'OAuth Authentication'
638
+ print '--------------------'
639
+ print 'This website requires OAuth authentication.'
640
+ print 'Please go to the following URL with your browser,'
641
+ print 'follow the steps and paste the given PIN code here.'
642
+ print
643
+ print selected_api[3]
644
+ print
645
+ password = raw_input('PIN: ')
646
+
647
+ try:
648
+ self.add_account(username, password, api)
649
+ print 'Done.'
650
+ except utils.AccountError, e:
651
+ print 'Error: %s' % e.message
652
+ elif key.lower() == 'd':
653
+ print "--- Delete account ---"
654
+ num = raw_input('Account number to delete: ')
655
+ try:
656
+ num = int(num)
657
+ account_id = self._get_id(num)
658
+ confirm = raw_input("Are you sure you want to delete account %d (%s)? [y/N] " % (num, self.get_account(account_id)['username']))
659
+ if confirm.lower() == 'y':
660
+ self.delete_account(account_id)
661
+ print 'Account %d deleted.' % num
662
+ except ValueError:
663
+ print "Invalid value."
664
+ except IndexError:
665
+ print "Account doesn't exist."
666
+ elif key.lower() == 'q':
667
+ sys.exit(0)
668
+ else:
669
+ try:
670
+ if key[0] == 'r':
671
+ key = key[1:]
672
+ remember = True
673
+ else:
674
+ remember = False
675
+
676
+ num = int(key)
677
+ account_id = self._get_id(num)
678
+ if remember:
679
+ self.set_default(account_id)
680
+
681
+ return self.get_account(account_id)
682
+ except ValueError:
683
+ print "Invalid value."
684
+ except IndexError:
685
+ print "Account doesn't exist."
686
+
687
+ def list_accounts(self):
688
+ accounts = self.get_accounts()
689
+ self.indexes = []
690
+
691
+ print "Available accounts:"
692
+ i = 0
693
+ if accounts:
694
+ for k, account in accounts:
695
+ print "%i: %s (%s)" % (i+1, account['username'], account['api'])
696
+ self.indexes.append(k)
697
+ i += 1
698
+ else:
699
+ print "No accounts."
700
+
701
+
702
+ def main():
703
+ main_cmd = Trackma_cmd()
704
+ try:
705
+ main_cmd.start()
706
+ print
707
+ print "Ready. Type 'help' for a list of commands."
708
+ print "Press tab for autocompletion and up/down for command history."
709
+ print
710
+ main_cmd.cmdloop()
711
+ except utils.TrackmaFatal, e:
712
+ print "%s%s: %s%s" % (_COLOR_FATAL, type(e), e.message, _COLOR_RESET)
trackma/ui/cli.pyc ADDED
Binary file