<s> from distutils . util import convert_path <EOL> from distutils import log <EOL> from distutils . errors import DistutilsOptionError <EOL> import distutils <EOL> import os <EOL> from setuptools import Command <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def config_file ( kind = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if kind == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> if kind == '<STR_LIT>' : <EOL> return os . path . join ( <EOL> os . path . dirname ( distutils . __file__ ) , '<STR_LIT>' <EOL> ) <EOL> if kind == '<STR_LIT:user>' : <EOL> dot = os . name == '<STR_LIT>' and '<STR_LIT:.>' or '<STR_LIT>' <EOL> return os . path . expanduser ( convert_path ( "<STR_LIT>" % dot ) ) <EOL> raise ValueError ( <EOL> "<STR_LIT>" , kind <EOL> ) <EOL> def edit_config ( filename , settings , dry_run = False ) : <EOL> """<STR_LIT>""" <EOL> from setuptools . compat import ConfigParser <EOL> log . debug ( "<STR_LIT>" , filename ) <EOL> opts = ConfigParser . RawConfigParser ( ) <EOL> opts . read ( [ filename ] ) <EOL> for section , options in settings . items ( ) : <EOL> if options is None : <EOL> log . info ( "<STR_LIT>" , section , filename ) <EOL> opts . remove_section ( section ) <EOL> else : <EOL> if not opts . has_section ( section ) : <EOL> log . debug ( "<STR_LIT>" , section , filename ) <EOL> opts . add_section ( section ) <EOL> for option , value in options . items ( ) : <EOL> if value is None : <EOL> log . debug ( <EOL> "<STR_LIT>" , <EOL> section , option , filename <EOL> ) <EOL> opts . remove_option ( section , option ) <EOL> if not opts . options ( section ) : <EOL> log . info ( "<STR_LIT>" , <EOL> section , filename ) <EOL> opts . remove_section ( section ) <EOL> else : <EOL> log . debug ( <EOL> "<STR_LIT>" , <EOL> section , option , value , filename <EOL> ) <EOL> opts . set ( section , option , value ) <EOL> log . info ( "<STR_LIT>" , filename ) <EOL> if not dry_run : <EOL> with open ( filename , '<STR_LIT:w>' ) as f : <EOL> opts . write ( f ) <EOL> class option_base ( Command ) : <EOL> """<STR_LIT>""" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:g>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:u>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:f>' , <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> boolean_options = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> def initialize_options ( self ) : <EOL> self . global_config = None <EOL> self . user_config = None <EOL> self . filename = None <EOL> def finalize_options ( self ) : <EOL> filenames = [ ] <EOL> if self . global_config : <EOL> filenames . append ( config_file ( '<STR_LIT>' ) ) <EOL> if self . user_config : <EOL> filenames . append ( config_file ( '<STR_LIT:user>' ) ) <EOL> if self . filename is not None : <EOL> filenames . append ( self . filename ) <EOL> if not filenames : <EOL> filenames . append ( config_file ( '<STR_LIT>' ) ) <EOL> if len ( filenames ) > <NUM_LIT:1> : <EOL> raise DistutilsOptionError ( <EOL> "<STR_LIT>" , <EOL> filenames <EOL> ) <EOL> self . filename , = filenames <EOL> class setopt ( option_base ) : <EOL> """<STR_LIT>""" <EOL> description = "<STR_LIT>" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:c>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:o>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:s>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:r>' , '<STR_LIT>' ) , <EOL> ] + option_base . user_options <EOL> boolean_options = option_base . boolean_options + [ '<STR_LIT>' ] <EOL> def initialize_options ( self ) : <EOL> option_base . initialize_options ( self ) <EOL> self . command = None <EOL> self . option = None <EOL> self . set_value = None <EOL> self . remove = None <EOL> def finalize_options ( self ) : <EOL> option_base . finalize_options ( self ) <EOL> if self . command is None or self . option is None : <EOL> raise DistutilsOptionError ( "<STR_LIT>" ) <EOL> if self . set_value is None and not self . remove : <EOL> raise DistutilsOptionError ( "<STR_LIT>" ) <EOL> def run ( self ) : <EOL> edit_config ( <EOL> self . filename , { <EOL> self . command : { self . option . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) : self . set_value } <EOL> } , <EOL> self . dry_run <EOL> ) </s>
