<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> from docopt import docopt <EOL> from pkg_resources import load_entry_point <EOL> from ckanapi . version import __version__ <EOL> from ckanapi . remoteckan import RemoteCKAN <EOL> from ckanapi . localckan import LocalCKAN <EOL> from ckanapi . errors import CLIError <EOL> from ckanapi . cli . load import load_things <EOL> from ckanapi . cli . dump import dump_things <EOL> from ckanapi . cli . action import action <EOL> def parse_arguments ( ) : <EOL> return docopt ( __doc__ , version = __version__ ) <EOL> def main ( running_with_paster = False ) : <EOL> """<STR_LIT>""" <EOL> arguments = parse_arguments ( ) <EOL> if not running_with_paster and not arguments [ '<STR_LIT>' ] : <EOL> return _switch_to_paster ( arguments ) <EOL> if arguments [ '<STR_LIT>' ] : <EOL> ckan = RemoteCKAN ( arguments [ '<STR_LIT>' ] , <EOL> apikey = arguments [ '<STR_LIT>' ] , <EOL> user_agent = "<STR_LIT>" . format ( <EOL> version = __version__ , <EOL> url = '<STR_LIT>' ) , <EOL> get_only = arguments [ '<STR_LIT>' ] , <EOL> ) <EOL> else : <EOL> ckan = LocalCKAN ( username = arguments [ '<STR_LIT>' ] ) <EOL> if arguments [ '<STR_LIT:action>' ] : <EOL> try : <EOL> for r in action ( ckan , arguments ) : <EOL> sys . stdout . write ( r ) <EOL> return <EOL> except CLIError , e : <EOL> sys . stderr . write ( e . args [ <NUM_LIT:0> ] + '<STR_LIT:\n>' ) <EOL> return <NUM_LIT:1> <EOL> things = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> thing = [ x for x in things if arguments [ x ] ] <EOL> if ( arguments [ '<STR_LIT>' ] or arguments [ '<STR_LIT>' ] <EOL> ) and arguments [ '<STR_LIT>' ] != '<STR_LIT:1>' and os . name == '<STR_LIT>' : <EOL> sys . stderr . write ( <EOL> "<STR_LIT>" ) <EOL> arguments [ '<STR_LIT>' ] = '<STR_LIT:1>' <EOL> if arguments [ '<STR_LIT>' ] : <EOL> assert len ( thing ) == <NUM_LIT:1> , thing <EOL> return load_things ( ckan , thing [ <NUM_LIT:0> ] , arguments ) <EOL> if arguments [ '<STR_LIT>' ] : <EOL> assert len ( thing ) == <NUM_LIT:1> , thing <EOL> return dump_things ( ckan , thing [ <NUM_LIT:0> ] , arguments ) <EOL> assert <NUM_LIT:0> , arguments <EOL> def _switch_to_paster ( arguments ) : <EOL> """<STR_LIT>""" <EOL> sys . argv [ <NUM_LIT:1> : <NUM_LIT:1> ] = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> sys . exit ( load_entry_point ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ( ) ) </s>
