diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-04 20:35:46 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-04 20:35:46 (GMT) |
commit | 61fb626170831140b6305b9da4a50ccd91c6b715 (patch) | |
tree | 05bfb5690b5e6a55df00bec0ded1c0d50cb91b0c | |
parent | 5e0e38b4817089c60cd4af76ee5aa0a96877b00c (diff) |
Easy to parse output from sugar-network utility
-rwxr-xr-x | sugar-network | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sugar-network b/sugar-network index 078d2ab..e2f2856 100755 --- a/sugar-network +++ b/sugar-network @@ -39,6 +39,12 @@ anonymous = Option( default=False, type_cast=Option.bool_cast, action='store_true', name='anonymous') +porcelain = Option( + 'give the output in an easy-to-parse format for scripts', + default=False, type_cast=Option.bool_cast, action='store_true', + name='porcelain') + + _ESCAPE_VALUE_RE = re.compile('([^\[\]\{\}0-9][^\]\[\{\}]+)') @@ -105,6 +111,7 @@ class Application(application.Application): sugar.uid = lambda: 'anonymous' sugar.nickname = lambda: 'anonymous' sugar.color = lambda: '#000000,#000000' + sugar.privkey_path = lambda: '/fake/path' else: toolkit.ensure_dsa_pubkey(sugar.profile_path('owner.key')) volume = Volume(local.db_path()) @@ -128,7 +135,15 @@ class Application(application.Application): os.unlink(pid_path) if result: - if reply: + if porcelain.value: + if type(result) in (list, tuple): + for i in result: + # TODO + print i + else: + # TODO + print i + elif reply: for key in reply: key = _ESCAPE_VALUE_RE.sub("'\\1'", key) print eval('result%s' % key) @@ -138,7 +153,7 @@ class Application(application.Application): # New defaults application.debug.value = sugar.logger_level() -Option.seek('main', [application.debug, anonymous]) +Option.seek('main', [application.debug, anonymous, porcelain]) Option.seek('local', [local.api_url, local.layers, local.ipc_port]) locale.setlocale(locale.LC_ALL, '') |