Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 65 lines (53 sloc) 2.059 kB
680119a @zalun use argparse to parse arguments
zalun authored
1 import argparse
803b669 @zalun adds -v for verbose mode
zalun authored
2 import logging
634d360 @zalun moved the stuff a little so it was possible to create something in fo…
zalun authored
3 import sys
502712b @zalun A little bit of a refactoring
zalun authored
4
3e6d3ce @zalun license added
zalun authored
5 import commands
ea3da86 @zalun pylint fixes
zalun authored
6 import config
502712b @zalun A little bit of a refactoring
zalun authored
7
3e6d3ce @zalun license added
zalun authored
8 import marketplace
634d360 @zalun moved the stuff a little so it was possible to create something in fo…
zalun authored
9
803b669 @zalun adds -v for verbose mode
zalun authored
10 logger = logging.getLogger()
11 ch = logging.StreamHandler()
12 logger.addHandler(ch)
13
ea3da86 @zalun pylint fixes
zalun authored
14 COMMANDS = {'validate_manifest': commands.validate_manifest,
803b669 @zalun adds -v for verbose mode
zalun authored
15 'is_manifest_valid': commands.is_manifest_valid,
16 'create': commands.create,
bcb0463 @bobsilverberg Add delete method to client.py
bobsilverberg authored
17 'delete': commands.delete,
803b669 @zalun adds -v for verbose mode
zalun authored
18 'list_webapps': commands.list_webapps,
19 'status': commands.status,
20 'update': commands.update,
21 'add_screenshot': commands.add_screenshot,
22 'get_screenshot': commands.get_screenshot,
23 'del_screenshot': commands.del_screenshot,
5416643 @bobsilverberg Add add_content_ratings method to client.py
bobsilverberg authored
24 'add_content_ratings': commands.add_content_ratings,
12c008c @zalun Merge branch 'verbose_mode'
zalun authored
25 'get_categories': commands.get_categories,
26 'app_state': commands.app_state}
803b669 @zalun adds -v for verbose mode
zalun authored
27
634d360 @zalun moved the stuff a little so it was possible to create something in fo…
zalun authored
28
ea3da86 @zalun pylint fixes
zalun authored
29 def main():
30 parser = argparse.ArgumentParser(
803b669 @zalun adds -v for verbose mode
zalun authored
31 description='Command line Marketplace client')
ea3da86 @zalun pylint fixes
zalun authored
32 parser.add_argument('method', type=str,
803b669 @zalun adds -v for verbose mode
zalun authored
33 help='command to be run on arguments',
34 choices=COMMANDS.keys())
ea3da86 @zalun pylint fixes
zalun authored
35 parser.add_argument('attrs', metavar='attr', type=str, nargs='*',
803b669 @zalun adds -v for verbose mode
zalun authored
36 help='command arguments')
37 parser.add_argument('-v', action='store_true', default=False,
38 dest='verbose',
39 help='Switch to verbose mode')
40
ea3da86 @zalun pylint fixes
zalun authored
41 args = parser.parse_args()
42
43 client = marketplace.Client(
803b669 @zalun adds -v for verbose mode
zalun authored
44 domain=config.MARKETPLACE_DOMAIN,
45 protocol=config.MARKETPLACE_PROTOCOL,
46 port=config.MARKETPLACE_PORT,
47 consumer_key=config.CONSUMER_KEY,
48 consumer_secret=config.CONSUMER_SECRET)
49
50 if args.verbose:
51 logger.setLevel(logging.DEBUG)
ea3da86 @zalun pylint fixes
zalun authored
52 if args.attrs:
53 result = COMMANDS[args.method](client, *args.attrs)
54 else:
55 result = COMMANDS[args.method](client)
56
57 if result['success']:
58 sys.stdout.write('%s\n' % result['message'])
59 else:
60 sys.stderr.write('%s\n' % result['message'])
61 sys.exit(1)
62
63 if __name__ == "__main__":
64 main()
Something went wrong with that request. Please try again.