Merge lp:~cprov/tanuki-agent/api-example-contrib into lp:tanuki-agent

Proposed by Celso Providelo
Status: Merged
Approved by: Roberto Alsina
Approved revision: 89
Merged at revision: 89
Proposed branch: lp:~cprov/tanuki-agent/api-example-contrib
Merge into: lp:tanuki-agent
Diff against target: 37 lines (+11/-5)
1 file modified
scripts/api_example.py (+11/-5)
To merge this branch: bzr merge lp:~cprov/tanuki-agent/api-example-contrib
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Paul Larson (community) Approve
Review via email: mp+272827@code.launchpad.net

Commit message

Contributed changes to allow passing JSON contents from a file.

Description of the change

Contributed changes to allow passing JSON contents from a file.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

+1 from me if that matters :)

review: Approve
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scripts/api_example.py'
--- scripts/api_example.py 2015-08-27 21:05:54 +0000
+++ scripts/api_example.py 2015-09-29 17:44:18 +0000
@@ -6,14 +6,15 @@
6 api_example.py [options] <configfile> <url>6 api_example.py [options] <configfile> <url>
77
8Options:8Options:
9 -h --help Show this screen9 -h --help Show this screen
10 -d, --data data POST Data10 -d, --data data|@<file> POST Data
11 -X method HTTP Method11 -X method HTTP Method
12 -v Verbose debug output12 -v Verbose debug output
13"""13"""
1414
15import json15import json
16import logging16import logging
17import os
17import sys18import sys
1819
19from configparser import ConfigParser20from configparser import ConfigParser
@@ -39,7 +40,12 @@
39 self.method = arguments.get('-X')40 self.method = arguments.get('-X')
40 self.url = arguments.get('<url>')41 self.url = arguments.get('<url>')
41 pd = arguments.get('--data')42 pd = arguments.get('--data')
42 self.post_data = json.loads(pd) if pd else None43 if pd and pd.startswith('@'):
44 # Filename specified, replace pd with data from the file
45 with open(os.path.expanduser(pd[1:])) as datafile:
46 self.post_data = json.load(datafile)
47 else:
48 self.post_data = json.loads(pd) if pd else None
4349
44 if arguments.get('-v'):50 if arguments.get('-v'):
45 logger.setLevel(logging.DEBUG)51 logger.setLevel(logging.DEBUG)

Subscribers

People subscribed via source and target branches

to all changes: