<s> import json <EOL> import click <EOL> import mapbox <EOL> from mapboxcli . errors import MapboxCLIException <EOL> @ click . group ( short_help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def datasets ( ctx ) : <EOL> """<STR_LIT>""" <EOL> access_token = ( ctx . obj and ctx . obj . get ( '<STR_LIT>' ) ) or None <EOL> service = mapbox . Datasets ( access_token = access_token ) <EOL> ctx . obj [ '<STR_LIT>' ] = service <EOL> @ datasets . command ( short_help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def list ( ctx , output ) : <EOL> """<STR_LIT>""" <EOL> stdout = click . open_file ( output , '<STR_LIT:w>' ) <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . list ( ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text , file = stdout ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( short_help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , <EOL> help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def create ( ctx , name , description ) : <EOL> """<STR_LIT>""" <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . create ( name , description ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def read_dataset ( ctx , dataset , output ) : <EOL> """<STR_LIT>""" <EOL> stdout = click . open_file ( output , '<STR_LIT:w>' ) <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . read_dataset ( dataset ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text , file = stdout ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , <EOL> help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def update_dataset ( ctx , dataset , name , description ) : <EOL> """<STR_LIT>""" <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . update_dataset ( dataset , name , description ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . pass_context <EOL> def delete_dataset ( ctx , dataset ) : <EOL> """<STR_LIT>""" <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . delete_dataset ( dataset ) <EOL> if res . status_code != <NUM_LIT> : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , <EOL> help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def list_features ( ctx , dataset , reverse , start , limit , output ) : <EOL> """<STR_LIT>""" <EOL> stdout = click . open_file ( output , '<STR_LIT:w>' ) <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . list_features ( dataset , reverse , start , limit ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text , file = stdout ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def read_feature ( ctx , dataset , fid , output ) : <EOL> """<STR_LIT>""" <EOL> stdout = click . open_file ( output , '<STR_LIT:w>' ) <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . read_feature ( dataset , fid ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text , file = stdout ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . argument ( '<STR_LIT>' , required = False , default = None ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , <EOL> help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def put_feature ( ctx , dataset , fid , feature , input ) : <EOL> """<STR_LIT>""" <EOL> if feature is None : <EOL> stdin = click . open_file ( input , '<STR_LIT:r>' ) <EOL> feature = stdin . read ( ) <EOL> feature = json . loads ( feature ) <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . update_feature ( dataset , fid , feature ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . pass_context <EOL> def delete_feature ( ctx , dataset , fid ) : <EOL> """<STR_LIT>""" <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . delete_feature ( dataset , fid ) <EOL> if res . status_code != <NUM_LIT> : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( <EOL> name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . argument ( '<STR_LIT>' , required = False , default = None ) <EOL> @ click . argument ( '<STR_LIT>' , required = False , default = None ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , <EOL> help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def batch_update_features ( ctx , dataset , puts , deletes , input ) : <EOL> """<STR_LIT>""" <EOL> if puts : <EOL> puts = json . loads ( puts ) <EOL> if deletes : <EOL> deletes = json . loads ( deletes ) <EOL> if puts is None and deletes is None : <EOL> stdin = click . open_file ( input , '<STR_LIT:r>' ) <EOL> input = json . loads ( stdin . read ( ) ) <EOL> puts = input [ '<STR_LIT>' ] <EOL> deletes = input [ '<STR_LIT>' ] <EOL> service = ctx . obj . get ( '<STR_LIT>' ) <EOL> res = service . batch_update_features ( dataset , puts , deletes ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> click . echo ( res . text ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) <EOL> @ datasets . command ( name = "<STR_LIT>" , <EOL> short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . argument ( '<STR_LIT>' , required = True ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = None , help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def create_tileset ( ctx , dataset , tileset , name ) : <EOL> """<STR_LIT>""" <EOL> access_token = ( ctx . obj and ctx . obj . get ( '<STR_LIT>' ) ) or None <EOL> service = mapbox . Uploader ( access_token = access_token ) <EOL> uri = "<STR_LIT>" . format ( <EOL> username = tileset . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] , dataset = dataset ) <EOL> res = service . create ( uri , tileset , name ) <EOL> if res . status_code == <NUM_LIT> : <EOL> click . echo ( res . text ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) </s>
