<s> import os <EOL> import configparser <EOL> import click <EOL> import keyring <EOL> from . . settings import USER_CONFIG , PROJECT_CONFIG <EOL> from . . utils import taskstatus <EOL> @ click . command ( ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = False ) <EOL> @ click . pass_context <EOL> def setup ( ctx , force ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( USER_CONFIG ) and not force : <EOL> click . secho ( <EOL> '<STR_LIT>' <EOL> . format ( USER_CONFIG ) , <EOL> fg = '<STR_LIT>' , bold = True <EOL> ) <EOL> click . secho ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ctx . exit ( <NUM_LIT:1> ) <EOL> click . echo ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> tracker_url = click . prompt ( '<STR_LIT>' ) <EOL> tracker_user = click . prompt ( '<STR_LIT>' . format ( tracker_url ) ) <EOL> click . echo ( ) <EOL> click . echo ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> timer_url = click . prompt ( '<STR_LIT>' ) <EOL> timer_user = click . prompt ( '<STR_LIT>' . format ( timer_url ) ) <EOL> click . echo ( ) <EOL> config = configparser . ConfigParser ( ) <EOL> config . add_section ( '<STR_LIT>' ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT:url>' , tracker_url ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT:username>' , tracker_user ) <EOL> config . add_section ( '<STR_LIT>' ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT:url>' , timer_url ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT:username>' , timer_user ) <EOL> with open ( USER_CONFIG , '<STR_LIT:w>' ) as fh : <EOL> config . write ( fh ) <EOL> click . secho ( '<STR_LIT>' <EOL> . format ( USER_CONFIG ) , fg = '<STR_LIT>' ) <EOL> @ click . command ( ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> @ click . pass_context <EOL> def init ( ctx , force ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( PROJECT_CONFIG ) and not force : <EOL> click . secho ( <EOL> '<STR_LIT>' <EOL> . format ( PROJECT_CONFIG ) , <EOL> fg = '<STR_LIT>' , bold = True <EOL> ) <EOL> click . secho ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ctx . exit ( <NUM_LIT:1> ) <EOL> project_key = click . prompt ( '<STR_LIT>' ) <EOL> base_branch = click . prompt ( '<STR_LIT>' , default = '<STR_LIT>' ) <EOL> virtualenvs = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for p in virtualenvs : <EOL> if os . path . exists ( os . path . join ( p , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> venv = p <EOL> break <EOL> else : <EOL> venv = '<STR_LIT>' <EOL> venv_path = click . prompt ( '<STR_LIT>' , default = venv ) <EOL> project_id = click . prompt ( '<STR_LIT>' , type = int ) <EOL> task_id = click . prompt ( '<STR_LIT>' , type = int ) <EOL> config = configparser . ConfigParser ( ) <EOL> config . add_section ( '<STR_LIT>' ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT>' , venv_path ) <EOL> config . add_section ( '<STR_LIT>' ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT>' , project_key ) <EOL> config . add_section ( '<STR_LIT>' ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT>' , str ( project_id ) ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT>' , str ( task_id ) ) <EOL> config . add_section ( '<STR_LIT>' ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT>' , base_branch ) <EOL> with open ( PROJECT_CONFIG , '<STR_LIT:w>' ) as fh : <EOL> config . write ( fh ) <EOL> click . secho ( '<STR_LIT>' <EOL> . format ( PROJECT_CONFIG ) , fg = '<STR_LIT>' ) <EOL> @ click . command ( ) <EOL> @ click . argument ( '<STR_LIT>' , required = False ) <EOL> @ click . pass_obj <EOL> def logout ( lancet , service ) : <EOL> """<STR_LIT>""" <EOL> if service : <EOL> services = [ service ] <EOL> else : <EOL> services = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for service in services : <EOL> url = lancet . config . get ( service , '<STR_LIT:url>' ) <EOL> key = '<STR_LIT>' . format ( url ) <EOL> username = lancet . config . get ( service , '<STR_LIT:username>' ) <EOL> with taskstatus ( '<STR_LIT>' , url ) as ts : <EOL> if keyring . get_password ( key , username ) : <EOL> keyring . delete_password ( key , username ) <EOL> ts . ok ( '<STR_LIT>' , url ) <EOL> else : <EOL> ts . ok ( '<STR_LIT>' , url ) <EOL> @ click . command ( ) <EOL> @ click . pass_obj <EOL> def _services ( lancet ) : <EOL> """<STR_LIT>""" <EOL> def get_services ( config ) : <EOL> for s in config . sections ( ) : <EOL> if config . has_option ( s , '<STR_LIT:url>' ) : <EOL> if config . has_option ( s , '<STR_LIT:username>' ) : <EOL> yield s <EOL> for s in get_services ( lancet . config ) : <EOL> click . echo ( '<STR_LIT>' . format ( s , lancet . config . get ( s , '<STR_LIT:url>' ) ) ) </s>
