Browse files

Merge pull request #227 from fedora-infra/feature/fedmsg-tail-query-c…

…ombined

Feature/fedmsg tail query combined
  • Loading branch information...
2 parents de60e1a + efd8d24 commit a11c83f948459e17a8a548f73c7a0db2c8b98f5e @ralphbean ralphbean committed Feb 25, 2014
Showing with 69 additions and 27 deletions.
  1. +14 −0 CHANGELOG.rst
  2. +1 −11 fedmsg/commands/config.py
  3. +2 −14 fedmsg/commands/tail.py
  4. +1 −1 fedmsg/encoding/__init__.py
  5. +50 −0 fedmsg/utils.py
  6. +1 −1 setup.py
View
14 CHANGELOG.rst
@@ -1,6 +1,20 @@
Changelog
=========
+0.7.6
+-----
+
+- Add a `disable_defaults` option to the config parser `2e564666a <https://github.com/fedora-infra/fedmsg/commit/2e564666aa19e95deb02d20fc500a4fc5db4203a>`_
+- Add some features to fedmsg-config `763798610 <https://github.com/fedora-infra/fedmsg/commit/763798610f4bb10e8963fb04ed7a1c078c427cb8>`_
+- Merge pull request #222 from olasd/feature/query-config `e5a3a1804 <https://github.com/fedora-infra/fedmsg/commit/e5a3a1804207ee21945343d14ab9045f8ffc68d8>`_
+- Avoid importing pkg_resources in fedmsg.meta `ffbc37615 <https://github.com/fedora-infra/fedmsg/commit/ffbc376155f475b4c4aaa12c715be91ea4d29fde>`_
+- Merge pull request #223 from fedora-infra/feature/avoid-pkg_resources `9bfe5ec79 <https://github.com/fedora-infra/fedmsg/commit/9bfe5ec79106e7cdcce83e5e8a056012712a2187>`_
+- Add the possibility to fedmsg-tail to only return the topics of the messages `97da58f9c <https://github.com/fedora-infra/fedmsg/commit/97da58f9ccce7c2dbbb2cde324ac48fd5b2c5486>`_
+- When printing only the topics, no need to clean the credentials `cb2124314 <https://github.com/fedora-infra/fedmsg/commit/cb2124314566133aaf8be2873dda590d478cbfb3>`_
+- Merge pull request #224 from fedora-infra/feature/tail_topics `619dc1e10 <https://github.com/fedora-infra/fedmsg/commit/619dc1e10bb8b083c8f5f6b718d19fd9dcf15a98>`_
+- Handle dates too. `1635c4911 <https://github.com/fedora-infra/fedmsg/commit/1635c49110a4145cedf2d105533b2adae4ff2422>`_
+- Merge pull request #225 from fedora-infra/feature/handle-dates-too `736f9394b <https://github.com/fedora-infra/fedmsg/commit/736f9394bbe320c124cc550c199a41e6c9c28187>`_
+
0.7.5
-----
View
12 fedmsg/commands/config.py
@@ -91,17 +91,7 @@ def config():
cur = config
if args.query:
- keys = args.query.split('.')
- curpath = []
- for key in keys:
- curpath.append(key)
- if key in cur:
- cur = cur[key]
- else:
- print >>sys.stderr, (
- "Key `%s` does not exist in config" % ".".join(curpath)
- )
- sys.exit(1)
+ cur = fedmsg.utils.dict_query(cur, args.query)
if isinstance(cur, list):
for i in cur:
View
16 fedmsg/commands/tail.py
@@ -132,20 +132,8 @@ def formatter(d):
if self.config['query']:
def formatter(d):
- def _browse(keys, dic):
- if keys[0] in dic:
- if isinstance(dic[keys[0]], dict):
- return _browse(keys[1:], dic[keys[0]])
- else:
- return dic[keys[0]]
-
- out = ''
- for filt in self.config['query'].split(','):
- keys = filt.split('.')
- tmp = _browse(keys, d)
- if tmp:
- out += "\n" + _browse(keys, d)
- return out
+ result = fedmsg.utils.dict_query(d, self.config['query'])
+ return ", ".join([unicode(value) for value in result.values()])
if self.config['terse']:
formatter = lambda d: "\n" + fedmsg.meta.msg2repr(d, **self.config)
View
2 fedmsg/encoding/__init__.py
@@ -65,7 +65,7 @@ class FedMsgEncoder(json.encoder.JSONEncoder):
def default(self, obj):
if hasattr(obj, '__json__'):
return obj.__json__()
- if isinstance(obj, datetime.datetime):
+ if isinstance(obj, (datetime.datetime, datetime.date)):
return time.mktime(obj.timetuple())
if isinstance(obj, time.struct_time):
return time.mktime(obj)
View
50 fedmsg/utils.py
@@ -22,6 +22,12 @@
import logging
import inspect
+try:
+ from collections import OrderedDict
+except ImportError:
+ from ordereddict import OrderedDict
+
+
_log = logging.getLogger('fedmsg')
@@ -102,3 +108,47 @@ def load_class(location):
return getattr(module, cls_name)
except AttributeError as e:
raise ImportError("%r not found in %r" % (cls_name, mod_name))
+
+
+def dict_query(dic, query):
+ """ Query a dict with 'dotted notation'. Returns an OrderedDict.
+
+ A query of "foo.bar.baz" would retrieve 'wat' from this::
+
+ dic = {
+ 'foo': {
+ 'bar': {
+ 'baz': 'wat',
+ }
+ }
+ }
+
+ Multiple queries can be specified if comma-separated. For instance, the
+ query "foo.bar.baz,foo.bar.something_else" would return this::
+
+ OrderedDict({
+ "foo.bar.baz": "wat",
+ "foo.bar.something_else": None,
+ })
+
+ """
+
+ def _browse(tokens, d):
+ """ Recurse through a dict to retrieve a value. """
+ current, rest = tokens[0], tokens[1:]
+
+ if not rest:
+ return d.get(current, None)
+
+ if current in d:
+ if isinstance(d[current], dict):
+ return _browse(rest, d[current])
+ elif rest:
+ return None
+ else:
+ return d[current]
+
+ keys = [key.strip().split('.') for key in query.split(',')]
+ return OrderedDict([
+ ('.'.join(tokens), _browse(tokens, dic)) for tokens in keys
+ ])
View
2 setup.py
@@ -95,7 +95,7 @@
setup(
name='fedmsg',
- version='0.7.5',
+ version='0.7.6',
description="Fedora Messaging Client API",
long_description=long_description,
author='Ralph Bean',

0 comments on commit a11c83f

Please sign in to comment.