Browse files

Merge branch 'verbose_mode'

Conflicts:
	example/main.py
  • Loading branch information...
2 parents 568f3a4 + 803b669 commit 12c008c7d4e748adc5c8ea4bb2d7ffc019f0234f @zalun zalun committed Dec 4, 2012
Showing with 44 additions and 20 deletions.
  1. +9 −0 example/README.rst
  2. +32 −19 example/main.py
  3. +2 −1 marketplace/client.py
  4. +1 −0 marketplace/connection.py
View
9 example/README.rst
@@ -37,4 +37,13 @@ Usage
python main.py add_screenshot your_app_id ~/data/some.jpg
+Options
+-------
+
+``-v`` to show all responses::
+
+ python main.py -v validate_manifest http://mozilla.github.com/Marketplace.Python/manifest.webapp
+
+ {'cookies': <<class 'requests.cookies.RequestsCookieJar'>[Cookie(version=0, name='lang', value='"en-US\\054"', port=None, port_specified=False, domain='marketplace-dev.allizom.org', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='multidb_pin_writes', value='y', port=None, port_specified=False, domain='marketplace-dev.allizom.org', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=1354189187, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='region', value='us', port=None, port_specified=False, domain='marketplace-dev.allizom.org', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False)]>, '_content': False, 'headers': {'via': 'Moz-pp-zlb09', 'x-content-security-policy-report-only': 'policy-uri /services/csp/policy?build=8585', 'transfer-encoding': 'chunked', 'set-cookie': 'lang="en-US\\054"; Path=/, region=us; Path=/, multidb_pin_writes=y; expires=Thu, 29-Nov-2012 11:36:18 GMT; Max-Age=15; Path=/', 'strict-transport-security': 'max-age=2592000', 'vary': 'X-Requested-With, Accept-Language, Cookie, X-Mobile, User-Agent', 'server': 'gunicorn/0.15.0', 'connection': 'keep-alive', 'location': 'https://marketplace-dev.allizom.org/api/apps/validation/05a4c5f051e94754a762c8ca9b958434/', 'date': 'Thu, 29 Nov 2012 11:36:03 GMT', 'x-frame-options': 'DENY', 'content-type': 'application/json; charset=utf-8'}, 'url': u'https://marketplace-dev.allizom.org:443/api/apps/validation/', 'status_code': 201, '_content_consumed': False, 'encoding': 'utf-8', 'request': <Request [POST]>, 'raw': <requests.packages.urllib3.response.HTTPResponse object at 0xb6d3d0ec>, 'error': None, 'config': {'safe_mode': False, 'pool_connections': 10, 'verbose': None, 'keep_alive': True, 'strict_mode': False, 'max_retries': 0, 'store_cookies': True, 'trust_env': True, 'base_headers': {'Accept-Encoding': 'identity, deflate, compress, gzip', 'Accept': '*/*', 'User-Agent': 'python-requests/0.13.1'}, 'pool_maxsize': 10, 'danger_mode': False, 'encode_uri': True, 'max_redirects': 30}, 'history': []}
+ Validation issued, id: 05a4c5f051e94754a762c8ca9b958434
View
51 example/main.py
@@ -1,39 +1,52 @@
import argparse
+import logging
import sys
import commands
import config
import marketplace
+logger = logging.getLogger()
+ch = logging.StreamHandler()
+logger.addHandler(ch)
+
COMMANDS = {'validate_manifest': commands.validate_manifest,
- 'is_manifest_valid': commands.is_manifest_valid,
- 'create': commands.create,
- 'list_webapps': commands.list_webapps,
- 'status': commands.status,
- 'update': commands.update,
- 'add_screenshot': commands.add_screenshot,
- 'get_screenshot': commands.get_screenshot,
- 'del_screenshot': commands.del_screenshot,
- 'get_categories': commands.get_categories,
- 'app_state': commands.app_state}
+ 'is_manifest_valid': commands.is_manifest_valid,
+ 'create': commands.create,
+ 'list_webapps': commands.list_webapps,
+ 'status': commands.status,
+ 'update': commands.update,
+ 'add_screenshot': commands.add_screenshot,
+ 'get_screenshot': commands.get_screenshot,
+ 'del_screenshot': commands.del_screenshot,
+ 'get_categories': commands.get_categories,
+ 'app_state': commands.app_state}
+
def main():
parser = argparse.ArgumentParser(
- description='Command line Marketplace client')
+ description='Command line Marketplace client')
parser.add_argument('method', type=str,
- help='command to be run on arguments', choices=COMMANDS.keys())
+ help='command to be run on arguments',
+ choices=COMMANDS.keys())
parser.add_argument('attrs', metavar='attr', type=str, nargs='*',
- help='command arguments')
+ help='command arguments')
+ parser.add_argument('-v', action='store_true', default=False,
+ dest='verbose',
+ help='Switch to verbose mode')
+
args = parser.parse_args()
client = marketplace.Client(
- domain=config.MARKETPLACE_DOMAIN,
- protocol=config.MARKETPLACE_PROTOCOL,
- port=config.MARKETPLACE_PORT,
- consumer_key=config.CONSUMER_KEY,
- consumer_secret=config.CONSUMER_SECRET)
-
+ domain=config.MARKETPLACE_DOMAIN,
+ protocol=config.MARKETPLACE_PROTOCOL,
+ port=config.MARKETPLACE_PORT,
+ consumer_key=config.CONSUMER_KEY,
+ consumer_secret=config.CONSUMER_SECRET)
+
+ if args.verbose:
+ logger.setLevel(logging.DEBUG)
if args.attrs:
result = COMMANDS[args.method](client, *args.attrs)
else:
View
3 marketplace/client.py
@@ -72,7 +72,8 @@ def validate_manifest(self, manifest_url):
# there is a bug request to make this synchronous on Marketplace side
# this will return the same as :method:`get_manifest_validation_result`
return self.conn.fetch('POST',
- self.url('validate'), {'manifest': manifest_url})
+ self.url('validate'),
+ {'manifest': manifest_url})
def get_manifest_validation_result(self, manifest_id):
"""Check if the manifest is processed and if it's valid
View
1 marketplace/connection.py
@@ -78,6 +78,7 @@ def fetch(self, method, url, data=None, expected_status_code=None):
"""
kwargs = self.prepare_request(method, url, data)
response = getattr(requests, method.lower())(url, **kwargs)
+ log.debug(str(response.__dict__))
if response.status_code >= 400:
response.raise_for_status()
if (expected_status_code

0 comments on commit 12c008c

Please sign in to comment.