def runner(): args = prepare() loop = asyncio.get_event_loop() # wrap asyncio to suppress stacktraces if args.debug: loop.run_until_complete(main(args)) else: try: loop.run_until_complete(main(args)) except Exception as e: print(e.message) loop.close()
def config(self, key=None, **kw): args = prepare() contents = yield From(self.list_backend(prefix=self.prefixify(key))) contents = contents.get('Contents', []) kw.setdefault('in_group_check', False) kw.setdefault('no_files', True) tasks = [self._get(key=obj['Key'], **kw) for obj in contents] try: results = yield From(asyncio.gather(*tasks)) except ValueError as e: raise Return({}) result = OrderedDict() project_env = "{}/{}".format(args.project, args.env) for k, v in enumerate(results): if kw.get('in_group_check'): # for grouped keys strip prefixes key_ = contents[k]['Key'].split('/')[-1] else: # otherwise full key key_ = contents[k]['Key'].replace(project_env, '').lstrip('/') if args.skip_files and v['is_file']: continue result[key_] = v['data'] raise Return(result)
import logging, os, sys from pprint import pprint as pp from secret.project import get_project from secret.cli import prepare def trollius_log(level=logging.CRITICAL): os.environ['TROLLIUSDEBUG'] = "1" # more informative tracebacks logging.basicConfig(level=level) if sys.version_info.major == 2: trollius_log() if __name__ == '__main__': """ Basic actions before imports for a responsive CLI """ prepare() from secret.storage import S3 import boto3 import six import trollius as asyncio from trollius import From, Return from tabulate import tabulate def prettyprint(result): def is_str(result): try: return isinstance(result, basestring) except NameError: return isinstance(result, str)