Permalink
Browse files

conf: accept override keywords in from_conf()

  • Loading branch information...
1 parent 397f338 commit ff1690fc45b14da43e11ce38c2f79da479d1b16d @mk-fg committed with Oct 14, 2012
Showing with 51 additions and 12 deletions.
  1. +20 −0 doc/api.md
  2. +2 −1 doc/api.rst
  3. +14 −4 doc/sphinx_local_hooks.py
  4. +1 −0 doc/sphinx_text_to_md.py
  5. +1 −1 setup.py
  6. +13 −6 skydrive/conf.py
View
@@ -1,3 +1,4 @@
+
* **class skydrive.api\_v5.SkyDriveHTTPClient**
Bases: "object"
@@ -10,6 +11,7 @@
Can be overidden to use different http module (e.g. urllib2,
twisted, etc).
+
* **class skydrive.api\_v5.SkyDriveAuth(\*\*config)**
Bases: "skydrive.api\_v5.SkyDriveHTTPClient"
@@ -92,6 +94,7 @@
Refresh or acquire access_token.
+
* **class skydrive.api\_v5.SkyDriveAPIWrapper(\*\*config)**
Bases: "skydrive.api\_v5.SkyDriveAuth"
@@ -225,6 +228,7 @@
comment_id can be acquired by listing comments for an object.
+
* **class skydrive.api\_v5.SkyDriveAPI(\*\*config)**
Bases: "skydrive.api\_v5.SkyDriveAPIWrapper"
@@ -273,25 +277,41 @@
Get a list of comments (message + metadata) for an object.
+
* **class skydrive.api\_v5.PersistentSkyDriveAPI(\*\*config)**
Bases: "skydrive.api\_v5.SkyDriveAPI", "skydrive.conf.ConfigMixin"
+ * conf\_path\_default = '~/.lcrc'
+
+ * conf\_update\_keys = {'client': set(['secret', 'id']), 'auth': set(['access\_token', 'code', 'access\_expires', 'refresh\_token'])}
+
+
+ * classmethod from\_conf(path=None, \*\*overrides)
+
+ Initialize instance from YAML configuration file, writing
+ updates (only to keys, specified by "conf_update_keys") back to
+ it.
+
+
* **exception skydrive.api\_v5.SkyDriveInteractionError**
Bases: "exceptions.Exception"
+
* **exception skydrive.api\_v5.ProtocolError(code, msg)**
Bases: "skydrive.api\_v5.SkyDriveInteractionError"
* \_\_init\_\_(code, msg)
+
* **exception skydrive.api\_v5.AuthenticationError**
Bases: "skydrive.api\_v5.SkyDriveInteractionError"
+
* **exception skydrive.api\_v5.DoesNotExists**
Bases: "skydrive.api\_v5.SkyDriveInteractionError"
View
@@ -8,4 +8,5 @@
.. autoclass:: SkyDriveAPI
.. autoclass:: PersistentSkyDriveAPI
- :exclude-members: auth_get_token
+ :exclude-members: rx:^from_conf|conf_(path_default|update_keys)$
+ :inherited-members:
View
@@ -1,8 +1,9 @@
#-*- coding: utf-8 -*-
+from __future__ import print_function
import itertools as it, operator as op, functools as ft
from collections import Iterable
-import types
+import os, sys, types, re
from sphinx.ext.autodoc import Documenter
@@ -15,7 +16,7 @@ def autodoc_add_line(self, line, *argz, **kwz):
if tee:
tee_line = self.indent + line
if isinstance(tee, file): tee.write(tee_line + '\n')
- elif tee is True: print tee_line
+ elif tee is True: print(tee_line)
else:
raise ValueError( 'Unrecognized'
' value for "autodoc_dump_rst" option: {!r}'.format(tee) )
@@ -52,11 +53,20 @@ def process_line(i):
def skip_override(app, what, name, obj, skip, options):
+ if options.get('exclude-members'):
+ include_only = set( re.compile(k[3:])
+ for k in options['exclude-members'] if k.startswith('rx:') )
+ if include_only:
+ for pat in include_only:
+ if pat.search(name): break
+ else: return True
if what == 'exception':
return False if name == '__init__'\
and isinstance(obj, types.UnboundMethodType) else True
- elif what == 'class' and name in ['__init__', '__call__']\
- and isinstance(obj, types.UnboundMethodType): return False
+ elif what == 'class':
+ if name in ['__init__', '__call__']\
+ and isinstance(obj, types.UnboundMethodType): return False
+ elif getattr(obj, 'im_class', None) is type: return False
return skip
def setup(app):
View
@@ -50,6 +50,7 @@ def main():
if not line_indent:
if len(lp) > 2 and lp[0] == lp[1]:
if lp[0] in ('exception', 'class'): # class, exception
+ out('\n'*1, end='')
out('* **{}**'.format(' '.join(lse.split()[1:])))
else:
View
@@ -12,7 +12,7 @@
setup(
name = 'python-skydrive',
- version = '12.10.13',
+ version = '12.10.14',
author = 'Mike Kazantsev',
author_email = 'mk.fraggod@gmail.com',
license = 'WTFPL',
View
@@ -12,11 +12,15 @@
class ConfigMixin(object):
+ #: Path to configuration file to use in from_conf() by default.
conf_path_default = b'~/.lcrc'
- conf_save = False # if set to some path, state will be written back to it
- # Only keys listed here will be checked and (possibly) added
- conf_keys = dict(
+ #: If set to some path, updates will be written back to it.
+ conf_save = False
+
+ #: Hierarchical list of keys to write back
+ #: to configuration file (preserving the rest) on updates.
+ conf_update_keys = dict(
client={'id', 'secret'},
auth={'code', 'refresh_token', 'access_expires', 'access_token'} )
@@ -26,7 +30,9 @@ def __init__(self, **kwz):
@classmethod
- def from_conf(cls, path=None):
+ def from_conf(cls, path=None, **overrides):
+ '''Initialize instance from YAML configuration file,
+ writing updates (only to keys, specified by "conf_update_keys") back to it.'''
import yaml
if path is None:
@@ -39,10 +45,11 @@ def from_conf(cls, path=None):
conf.setdefault('conf_save', path)
conf_cls = dict()
- for ns, keys in cls.conf_keys.viewitems():
+ for ns, keys in cls.conf_update_keys.viewitems():
for k in keys:
if conf.get(ns, dict()).get(k) is not None:
conf_cls['{}_{}'.format(ns, k)] = conf[ns][k]
+ conf_cls.update(overrides)
self = cls(**conf_cls)
self.conf_save = conf['conf_save']
@@ -60,7 +67,7 @@ def sync(self):
conf = yaml.load(io.BytesIO(conf_raw)) if conf_raw else dict()
conf_updated = False
- for ns, keys in self.conf_keys.viewitems():
+ for ns, keys in self.conf_update_keys.viewitems():
for k in keys:
v = getattr(self, '{}_{}'.format(ns, k), None)
if isinstance(v, unicode): v = v.encode('utf-8')

0 comments on commit ff1690f

Please sign in to comment.