Transmission support
This commit is contained in:
1 parent
a71f84522d
commit
da63eca623
11 files changed
+1612
No files matched your search
Executable
+44
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2008-2010 Erik Svensson <erik.public@gmail.com>
|
||||
# Licensed under the MIT license.
|
||||
|
||||
class Session(object):
|
||||
"""
|
||||
Session is a class holding the session data for a Transmission daemon.
|
||||
|
||||
Access the session field can be done through attributes.
|
||||
The attributes available are the same as the session arguments in the
|
||||
Transmission RPC specification, but with underscore instead of hypen.
|
||||
``download-dir`` -> ``download_dir``.
|
||||
"""
|
||||
|
||||
def __init__(self, fields=None):
|
||||
self.fields = {}
|
||||
if fields != None:
|
||||
self.update(fields)
|
||||
|
||||
def update(self, other):
|
||||
"""Update the session data from a session arguments dictinary"""
|
||||
|
||||
fields = None
|
||||
if isinstance(other, dict):
|
||||
fields = other
|
||||
elif isinstance(other, Session):
|
||||
fields = other.fields
|
||||
else:
|
||||
raise ValueError('Cannot update with supplied data')
|
||||
|
||||
for key, value in fields.iteritems():
|
||||
self.fields[key.replace('-', '_')] = value
|
||||
|
||||
def __getattr__(self, name):
|
||||
try:
|
||||
return self.fields[name]
|
||||
except KeyError:
|
||||
raise AttributeError('No attribute %s' % name)
|
||||
|
||||
def __str__(self):
|
||||
text = ''
|
||||
for key in sorted(self.fields.keys()):
|
||||
text += "% 32s: %s\n" % (key[-32:], self.fields[key])
|
||||
return text
|
||||
Reference in new issue
Block a user