<s> from distutils . errors import DistutilsOptionError <EOL> from setuptools . command . setopt import edit_config , option_base , config_file <EOL> def shquote ( arg ) : <EOL> """<STR_LIT>""" <EOL> for c in '<STR_LIT:">' , "<STR_LIT:'>" , "<STR_LIT:\\>" , "<STR_LIT:#>" : <EOL> if c in arg : <EOL> return repr ( arg ) <EOL> if arg . split ( ) != [ arg ] : <EOL> return repr ( arg ) <EOL> return arg <EOL> class alias ( option_base ) : <EOL> """<STR_LIT>""" <EOL> description = "<STR_LIT>" <EOL> command_consumes_arguments = True <EOL> user_options = [ <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 . args = None <EOL> self . remove = None <EOL> def finalize_options ( self ) : <EOL> option_base . finalize_options ( self ) <EOL> if self . remove and len ( self . args ) != <NUM_LIT:1> : <EOL> raise DistutilsOptionError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def run ( self ) : <EOL> aliases = self . distribution . get_option_dict ( '<STR_LIT>' ) <EOL> if not self . args : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> for alias in aliases : <EOL> print ( "<STR_LIT>" , format_alias ( alias , aliases ) ) <EOL> return <EOL> elif len ( self . args ) == <NUM_LIT:1> : <EOL> alias , = self . args <EOL> if self . remove : <EOL> command = None <EOL> elif alias in aliases : <EOL> print ( "<STR_LIT>" , format_alias ( alias , aliases ) ) <EOL> return <EOL> else : <EOL> print ( "<STR_LIT>" % alias ) <EOL> return <EOL> else : <EOL> alias = self . args [ <NUM_LIT:0> ] <EOL> command = '<STR_LIT:U+0020>' . join ( map ( shquote , self . args [ <NUM_LIT:1> : ] ) ) <EOL> edit_config ( self . filename , { '<STR_LIT>' : { alias : command } } , self . dry_run ) <EOL> def format_alias ( name , aliases ) : <EOL> source , command = aliases [ name ] <EOL> if source == config_file ( '<STR_LIT>' ) : <EOL> source = '<STR_LIT>' <EOL> elif source == config_file ( '<STR_LIT:user>' ) : <EOL> source = '<STR_LIT>' <EOL> elif source == config_file ( '<STR_LIT>' ) : <EOL> source = '<STR_LIT>' <EOL> else : <EOL> source = '<STR_LIT>' % source <EOL> return source + name + '<STR_LIT:U+0020>' + command </s>
