diff options
author | Mike Crute <mcrute@gmail.com> | 2013-12-30 22:55:29 -0500 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2013-12-30 22:55:29 -0500 |
commit | 4b3a53747e6ef36e19cd60c3a096c9d9b1ab343c (patch) | |
tree | 836f4b4cbd34a4163c102bc7dc9368df09c84091 /pydora | |
parent | e87352abe7dab29a6255cce3bff41bdb57cfa204 (diff) | |
download | pydora-4b3a53747e6ef36e19cd60c3a096c9d9b1ab343c.tar.bz2 pydora-4b3a53747e6ef36e19cd60c3a096c9d9b1ab343c.tar.xz pydora-4b3a53747e6ef36e19cd60c3a096c9d9b1ab343c.zip |
Move config file loading to APIClient
Diffstat (limited to 'pydora')
-rwxr-xr-x | pydora/player.py | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/pydora/player.py b/pydora/player.py index 5ab69b5..2b00ad3 100755 --- a/pydora/player.py +++ b/pydora/player.py | |||
@@ -8,7 +8,6 @@ directly from Pandora's servers. | |||
8 | """ | 8 | """ |
9 | import os | 9 | import os |
10 | import sys | 10 | import sys |
11 | from ConfigParser import SafeConfigParser | ||
12 | 11 | ||
13 | from pandora import APIClient | 12 | from pandora import APIClient |
14 | from pandora.player import Player | 13 | from pandora.player import Player |
@@ -31,12 +30,12 @@ class PlayerApp: | |||
31 | } | 30 | } |
32 | 31 | ||
33 | def __init__(self): | 32 | def __init__(self): |
34 | settings, self.credentials = self._load_settings() | 33 | self.client = None |
35 | self.client = APIClient.from_settings_dict(settings) | ||
36 | self.player = Player(self, sys.stdin) | 34 | self.player = Player(self, sys.stdin) |
37 | 35 | ||
38 | def _load_settings(self): | 36 | @property |
39 | """Load settings from config file | 37 | def config_path(self): |
38 | """Find the config file | ||
40 | 39 | ||
41 | Config file exists in either ~/.pydora.cfg or is pointed to by an | 40 | Config file exists in either ~/.pydora.cfg or is pointed to by an |
42 | environment variable PYDORA_CFG. | 41 | environment variable PYDORA_CFG. |
@@ -48,12 +47,7 @@ class PlayerApp: | |||
48 | Screen.print_error('No settings at {!r}'.format(path)) | 47 | Screen.print_error('No settings at {!r}'.format(path)) |
49 | sys.exit(1) | 48 | sys.exit(1) |
50 | 49 | ||
51 | cfg = SafeConfigParser() | 50 | return path |
52 | cfg.read(path) | ||
53 | |||
54 | return ( | ||
55 | dict((k.upper(), v) for k, v in cfg.items('api')), | ||
56 | [i[1] for i in cfg.items('user')]) | ||
57 | 51 | ||
58 | def station_selection_menu(self): | 52 | def station_selection_menu(self): |
59 | """Format a station menu and make the user select a station | 53 | """Format a station menu and make the user select a station |
@@ -131,7 +125,7 @@ class PlayerApp: | |||
131 | Screen.set_echo(True) | 125 | Screen.set_echo(True) |
132 | 126 | ||
133 | def run(self): | 127 | def run(self): |
134 | self.client.login(*self.credentials) | 128 | self.client = APIClient.from_config_file(self.config_path) |
135 | self.stations = self.client.get_station_list() | 129 | self.stations = self.client.get_station_list() |
136 | 130 | ||
137 | while True: | 131 | while True: |