This commit is contained in:
j 2011-01-14 16:18:51 +05:30
parent d4409a0411
commit a5e68aeaaa

View file

@ -52,11 +52,11 @@ class Client(object):
with open(config) as f: with open(config) as f:
self._config = json.load(f) self._config = json.load(f)
else: else:
self.config = config self._config = config
self.api = API(self._config['url'], media_cache=self.media_cache()) self.api = API(self._config['url'], media_cache=self.media_cache())
if 'username' in self._config: if 'username' in self._config:
r = self.api.login(username=self._config['username'], password=self._config['password']) r = self.api.signin(username=self._config['username'], password=self._config['password'])
if r['status']['code'] == 200: if r['status']['code'] == 200:
self.user = r['data']['user'] self.user = r['data']['user']
else: else:
@ -148,8 +148,9 @@ class Client(object):
filename = filename.decode('utf-8') filename = filename.decode('utf-8')
if not filename.startswith('._') and not filename in ('.DS_Store', ): if not filename.startswith('._') and not filename in ('.DS_Store', ):
file_path = os.path.join(dirpath, filename) file_path = os.path.join(dirpath, filename)
files.append(file_path) if os.path.exists(file_path):
self.scan_file(file_path) files.append(file_path)
self.scan_file(file_path)
conn, c = self._conn() conn, c = self._conn()
c.execute('SELECT path FROM file WHERE path LIKE ? AND deleted < 0', ["%s%%"%path]) c.execute('SELECT path FROM file WHERE path LIKE ? AND deleted < 0', ["%s%%"%path])
@ -295,8 +296,8 @@ class API(object):
self.media_cache = default_media_cache self.media_cache = default_media_cache
self.url = url self.url = url
r = self._request('apidoc', {}) r = self._request('api', {'docs': True})
self._doc = r['data']['actions'] self._properties = r['data']['actions']
self._actions = r['data']['actions'].keys() self._actions = r['data']['actions'].keys()
for a in r['data']['actions']: for a in r['data']['actions']:
self._add_action(a) self._add_action(a)
@ -314,11 +315,12 @@ class API(object):
else: else:
kw = None kw = None
return self._request(action, kw) return self._request(action, kw)
method.__doc__ = self._doc[action] method.__doc__ = self._properties[action]['doc']
method.func_name = str(action) method.func_name = str(action)
self._add_method(method, action) self._add_method(method, action)
def _json_request(self, url, form): def _json_request(self, url, form):
result = {}
try: try:
request = urllib2.Request(url) request = urllib2.Request(url)
request.add_header('User-agent', 'pandora_client/%s' % __version__) request.add_header('User-agent', 'pandora_client/%s' % __version__)
@ -347,9 +349,10 @@ class API(object):
if DEBUG: if DEBUG:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
with open('/tmp/error.html', 'w') as f: if result:
f.write(result) with open('/tmp/error.html', 'w') as f:
os.system('firefox /tmp/error.html') f.write(str(result))
webbrowser.open_new_tab('/tmp/error.html')
raise raise
def _request(self, action, data=None): def _request(self, action, data=None):