<s> import argparse <EOL> import errno <EOL> import sys <EOL> import os <EOL> import json <EOL> from urlparse import urlparse <EOL> from snakebite . client import HAClient <EOL> from snakebite . errors import FileNotFoundException <EOL> from snakebite . errors import DirectoryException <EOL> from snakebite . errors import FileException <EOL> from snakebite . errors import RequestError <EOL> from snakebite . formatter import format_listing <EOL> from snakebite . formatter import format_results <EOL> from snakebite . formatter import format_counts <EOL> from snakebite . formatter import format_fs_stats <EOL> from snakebite . formatter import format_stat <EOL> from snakebite . formatter import format_du <EOL> from snakebite . config import HDFSConfig <EOL> from snakebite . version import version <EOL> from snakebite . namenode import Namenode <EOL> from snakebite . platformutils import get_current_username <EOL> def print_error_exit ( msg , fd = sys . stderr ) : <EOL> print >> fd , "<STR_LIT>" % msg <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> def print_info ( msg , fd = sys . stderr ) : <EOL> print >> fd , "<STR_LIT>" % msg <EOL> def exitError ( exc_info ) : <EOL> exc_type , exc_value , exc_traceback = exc_info <EOL> if isinstance ( <EOL> exc_value , ( FileNotFoundException , DirectoryException , FileException ) , <EOL> ) : <EOL> print str ( exc_value ) <EOL> elif isinstance ( exc_value , RequestError ) : <EOL> print "<STR_LIT>" % str ( exc_value ) <EOL> else : <EOL> raise exc_type , exc_value , exc_traceback <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> def command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = "<STR_LIT>" , visible = True ) : <EOL> def wrap ( f ) : <EOL> Commands . methods [ f . func_name ] = { "<STR_LIT>" : f , <EOL> "<STR_LIT:args>" : args , <EOL> "<STR_LIT>" : descr , <EOL> "<STR_LIT>" : allowed_opts , <EOL> "<STR_LIT>" : visible } <EOL> return wrap <EOL> class Commands ( object ) : <EOL> methods = { } <EOL> class ArgumentParserError ( Exception ) : <EOL> def __init__ ( self , message , error_message , prog , stdout = None , stderr = None , error_code = None ) : <EOL> Exception . __init__ ( self , message , stdout , stderr ) <EOL> self . message = message <EOL> self . error_message = error_message <EOL> self . prog = prog <EOL> class Parser ( argparse . ArgumentParser ) : <EOL> def print_help ( self ) : <EOL> print '<STR_LIT>' . join ( [ self . usage , self . epilog ] ) <EOL> def error ( self , message ) : <EOL> raise ArgumentParserError ( "<STR_LIT>" , message , self . prog ) <EOL> class CommandLineParser ( object ) : <EOL> GENERIC_OPTS = { '<STR_LIT:D>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:n>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:type>" : str } , <EOL> '<STR_LIT>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' % Namenode . DEFAULT_VERSION , <EOL> "<STR_LIT:default>" : Namenode . DEFAULT_VERSION , <EOL> "<STR_LIT:type>" : float } , <EOL> '<STR_LIT:p>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' % Namenode . DEFAULT_PORT , <EOL> "<STR_LIT:type>" : int } , <EOL> '<STR_LIT:h>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:type>" : int } , <EOL> '<STR_LIT:v>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:type>" : int } <EOL> } <EOL> SUB_OPTS = { '<STR_LIT:R>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:d>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:s>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:S>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:default>" : False , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:T>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:z>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:e>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:f>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } , <EOL> '<STR_LIT:h>' : { "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT:action>" : '<STR_LIT:store_true>' } <EOL> } <EOL> def __init__ ( self ) : <EOL> usage = "<STR_LIT>" <EOL> epilog = "<STR_LIT>" <EOL> epilog += "<STR_LIT:\n>" . join ( sorted ( [ "<STR_LIT>" % ( "<STR_LIT>" % ( v [ '<STR_LIT>' ] , v [ '<STR_LIT>' ] ) , v [ '<STR_LIT>' ] ) for k , v in self . GENERIC_OPTS . iteritems ( ) ] ) ) <EOL> epilog += "<STR_LIT>" <EOL> epilog += "<STR_LIT:\n>" . join ( sorted ( [ "<STR_LIT>" % ( "<STR_LIT>" % ( k , v [ '<STR_LIT:args>' ] ) , v [ '<STR_LIT>' ] ) for k , v in Commands . methods . iteritems ( ) if v [ '<STR_LIT>' ] ] ) ) <EOL> epilog += "<STR_LIT>" <EOL> self . parser = Parser ( usage = usage , epilog = epilog , formatter_class = argparse . RawTextHelpFormatter , add_help = False ) <EOL> self . _build_parent_parser ( ) <EOL> self . _add_subparsers ( ) <EOL> self . namenodes = [ ] <EOL> self . user = None <EOL> self . use_sasl = False <EOL> def _build_parent_parser ( self ) : <EOL> for opt_name , opt_data in self . GENERIC_OPTS . iteritems ( ) : <EOL> if '<STR_LIT:action>' in opt_data : <EOL> self . parser . add_argument ( opt_data [ '<STR_LIT>' ] , opt_data [ '<STR_LIT>' ] , help = opt_data [ '<STR_LIT>' ] , action = opt_data [ '<STR_LIT:action>' ] ) <EOL> else : <EOL> if '<STR_LIT:default>' in opt_data : <EOL> self . parser . add_argument ( opt_data [ '<STR_LIT>' ] , opt_data [ '<STR_LIT>' ] , help = opt_data [ '<STR_LIT>' ] , type = opt_data [ '<STR_LIT:type>' ] , default = opt_data [ '<STR_LIT:default>' ] ) <EOL> else : <EOL> self . parser . add_argument ( opt_data [ '<STR_LIT>' ] , opt_data [ '<STR_LIT>' ] , help = opt_data [ '<STR_LIT>' ] , type = opt_data [ '<STR_LIT:type>' ] ) <EOL> def _add_subparsers ( self ) : <EOL> default_dir = os . path . join ( "<STR_LIT>" , get_current_username ( ) ) <EOL> arg_parsers = { } <EOL> for opt_name , opt_data in self . SUB_OPTS . iteritems ( ) : <EOL> arg_parsers [ opt_name ] = argparse . ArgumentParser ( add_help = False ) <EOL> arg_parsers [ opt_name ] . add_argument ( opt_data [ '<STR_LIT>' ] , opt_data [ '<STR_LIT>' ] , help = opt_data [ '<STR_LIT>' ] , <EOL> action = opt_data [ '<STR_LIT:action>' ] ) <EOL> subcommand_help_parser = argparse . ArgumentParser ( add_help = False ) <EOL> subcommand_help_parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> positional_arg_parsers = { } <EOL> positional_arg_parsers [ '<STR_LIT>' ] = argparse . ArgumentParser ( add_help = False ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , default = [ default_dir ] , help = "<STR_LIT>" ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] = argparse . ArgumentParser ( add_help = False ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:+>' , default = [ default_dir ] , help = "<STR_LIT>" ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] = argparse . ArgumentParser ( add_help = False ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] . add_argument ( '<STR_LIT>' , nargs = <NUM_LIT:2> , default = [ default_dir ] , help = "<STR_LIT>" ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] = argparse . ArgumentParser ( add_help = False ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , help = "<STR_LIT>" ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] = argparse . ArgumentParser ( add_help = False ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] . add_argument ( '<STR_LIT>' , default = default_dir , help = "<STR_LIT>" ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] = argparse . ArgumentParser ( add_help = False ) <EOL> positional_arg_parsers [ '<STR_LIT>' ] . add_argument ( '<STR_LIT>' , default = '<STR_LIT:0>' , help = "<STR_LIT>" , <EOL> type = int ) <EOL> subparsers = self . parser . add_subparsers ( ) <EOL> for cmd_name , cmd_info in Commands . methods . iteritems ( ) : <EOL> parents = [ arg_parsers [ opt ] for opt in cmd_info [ '<STR_LIT>' ] if opt in arg_parsers ] <EOL> parents += [ subcommand_help_parser ] <EOL> if '<STR_LIT>' in cmd_info and not cmd_info [ '<STR_LIT>' ] is None : <EOL> parents += [ positional_arg_parsers [ arg ] for arg in cmd_info [ '<STR_LIT>' ] ] <EOL> command_parser = subparsers . add_parser ( cmd_name , add_help = False , parents = parents ) <EOL> command_parser . set_defaults ( command = cmd_name ) <EOL> def init ( self ) : <EOL> self . read_config ( ) <EOL> self . _clean_args ( ) <EOL> self . setup_client ( ) <EOL> def _clean_args ( self ) : <EOL> for path in self . __get_all_directories ( ) : <EOL> if path . startswith ( '<STR_LIT>' ) : <EOL> parse_result = urlparse ( path ) <EOL> if '<STR_LIT>' in self . args and path in self . args . dir : <EOL> self . args . dir . remove ( path ) <EOL> self . args . dir . append ( parse_result . path ) <EOL> else : <EOL> self . args . single_arg = parse_result . path <EOL> def __usetrash_unset ( self ) : <EOL> return not '<STR_LIT>' in self . args or self . args . usetrash == False <EOL> def __use_cl_port_first ( self , alt ) : <EOL> return self . args . port if self . args . port else alt <EOL> def read_config ( self ) : <EOL> self . configs = HDFSConfig . get_external_config ( ) <EOL> if self . _read_config_cl ( ) : <EOL> return <EOL> config_file = os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> if os . path . exists ( config_file ) : <EOL> self . _read_config_snakebiterc ( ) <EOL> elif os . path . exists ( '<STR_LIT>' ) : <EOL> self . _read_config_snakebiterc ( '<STR_LIT>' ) <EOL> else : <EOL> if self . configs : <EOL> for config in self . configs [ '<STR_LIT>' ] : <EOL> nn = Namenode ( config [ '<STR_LIT>' ] , <EOL> self . __use_cl_port_first ( config [ '<STR_LIT:port>' ] ) ) <EOL> self . namenodes . append ( nn ) <EOL> if self . __usetrash_unset ( ) : <EOL> self . args . usetrash = self . configs [ '<STR_LIT>' ] <EOL> self . use_sasl = self . configs [ '<STR_LIT>' ] <EOL> if len ( self . namenodes ) : <EOL> return <EOL> else : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> for core_conf_path in HDFSConfig . core_try_paths : <EOL> print "<STR_LIT>" % core_conf_path <EOL> print "<STR_LIT>" <EOL> for hdfs_conf_path in HDFSConfig . hdfs_try_paths : <EOL> print "<STR_LIT>" % hdfs_conf_path <EOL> print "<STR_LIT>" <EOL> print '<STR_LIT:{>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( Namenode . DEFAULT_PORT , Namenode . DEFAULT_VERSION ) <EOL> print '<STR_LIT>' % ( Namenode . DEFAULT_PORT , Namenode . DEFAULT_VERSION ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT:}>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _read_config_snakebiterc ( self , path = os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , '<STR_LIT>' ) ) : <EOL> old_version_info = "<STR_LIT>" % ( path , version ( ) , '<STR_LIT>' if not self . configs [ '<STR_LIT>' ] else '<STR_LIT>' ) <EOL> with open ( path ) as config_file : <EOL> configs = json . load ( config_file ) <EOL> if isinstance ( configs , list ) : <EOL> for config in configs : <EOL> nn = Namenode ( config [ '<STR_LIT>' ] , <EOL> self . __use_cl_port_first ( config . get ( '<STR_LIT:port>' , Namenode . DEFAULT_PORT ) ) , <EOL> config . get ( '<STR_LIT:version>' , Namenode . DEFAULT_VERSION ) ) <EOL> self . namenodes . append ( nn ) <EOL> if self . __usetrash_unset ( ) : <EOL> print_info ( old_version_info ) <EOL> self . args . usetrash = self . configs [ '<STR_LIT>' ] <EOL> elif isinstance ( configs , dict ) : <EOL> if '<STR_LIT>' in configs : <EOL> for nn_config in configs [ '<STR_LIT>' ] : <EOL> nn = Namenode ( nn_config [ '<STR_LIT:host>' ] , <EOL> self . __use_cl_port_first ( nn_config . get ( '<STR_LIT:port>' , Namenode . DEFAULT_PORT ) ) , <EOL> nn_config . get ( '<STR_LIT:version>' , Namenode . DEFAULT_VERSION ) ) <EOL> self . namenodes . append ( nn ) <EOL> if self . __usetrash_unset ( ) : <EOL> self . args . usetrash = configs . get ( "<STR_LIT>" , self . configs [ '<STR_LIT>' ] ) <EOL> self . user = configs . get ( "<STR_LIT:user>" ) <EOL> else : <EOL> self . namenodes . append ( Namenode ( configs [ '<STR_LIT>' ] , <EOL> self . __use_cl_port_first ( configs . get ( '<STR_LIT:port>' , Namenode . DEFAULT_PORT ) ) , <EOL> configs . get ( '<STR_LIT:version>' , Namenode . DEFAULT_VERSION ) ) ) <EOL> if self . __usetrash_unset ( ) : <EOL> print_info ( old_version_info ) <EOL> self . args . usetrash = self . configs [ '<STR_LIT>' ] <EOL> else : <EOL> print_error_exit ( "<STR_LIT>" % path ) <EOL> def __get_all_directories ( self ) : <EOL> dirs_to_check = [ ] <EOL> if self . args . command in ( '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT>' ) : <EOL> if self . args . single_arg is not None : <EOL> dirs_to_check . append ( self . args . single_arg ) <EOL> if self . args and '<STR_LIT>' in self . args : <EOL> dirs_to_check += self . args . dir <EOL> return dirs_to_check <EOL> def _read_config_cl ( self ) : <EOL> '''<STR_LIT>''' <EOL> dirs_to_check = self . __get_all_directories ( ) <EOL> hosts , ports = [ ] , [ ] <EOL> for path in dirs_to_check : <EOL> if path . startswith ( '<STR_LIT>' ) : <EOL> parse_result = urlparse ( path ) <EOL> hosts . append ( parse_result . hostname ) <EOL> ports . append ( parse_result . port ) <EOL> hosts = filter ( lambda x : x != None , set ( hosts + [ self . args . namenode ] ) ) <EOL> if len ( hosts ) > <NUM_LIT:1> : <EOL> print_error_exit ( '<STR_LIT>' % str ( hosts ) ) <EOL> ports = filter ( lambda x : x != None , set ( ports + [ self . args . port ] ) ) <EOL> if len ( ports ) > <NUM_LIT:1> : <EOL> print_error_exit ( '<STR_LIT>' % str ( ports ) ) <EOL> if len ( ports ) == <NUM_LIT:1> : <EOL> self . args . port = ports [ <NUM_LIT:0> ] <EOL> if len ( hosts ) == <NUM_LIT:1> and len ( ports ) <= <NUM_LIT:1> : <EOL> self . args . namenode = hosts [ <NUM_LIT:0> ] <EOL> self . args . port = ports [ <NUM_LIT:0> ] if len ( ports ) == <NUM_LIT:1> else Namenode . DEFAULT_PORT <EOL> self . namenodes . append ( Namenode ( self . args . namenode , self . args . port ) ) <EOL> if self . __usetrash_unset ( ) : <EOL> self . args . usetrash = self . configs [ '<STR_LIT>' ] <EOL> return True <EOL> else : <EOL> return False <EOL> def parse ( self , non_cli_input = None ) : <EOL> if not sys . argv [ <NUM_LIT:1> : ] and not non_cli_input : <EOL> self . parser . print_help ( ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> try : <EOL> args = self . parser . parse_args ( non_cli_input ) <EOL> except ArgumentParserError , error : <EOL> if "<STR_LIT>" in sys . argv or "<STR_LIT>" in sys . argv : <EOL> commands = [ cmd for ( cmd , description ) in Commands . methods . iteritems ( ) if description [ '<STR_LIT>' ] is True ] <EOL> command = error . prog . split ( ) [ - <NUM_LIT:1> ] <EOL> if command in commands : <EOL> self . usage_helper ( command ) <EOL> else : <EOL> self . parser . print_help ( ) <EOL> self . parser . exit ( <NUM_LIT:2> ) <EOL> elif "<STR_LIT>" in sys . argv or "<STR_LIT>" in sys . argv : <EOL> print version ( ) <EOL> self . parser . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> self . parser . print_usage ( sys . stderr ) <EOL> self . parser . exit ( <NUM_LIT:2> , '<STR_LIT>' % ( error . error_message ) ) <EOL> self . cmd = args . command <EOL> self . args = args <EOL> return self . args <EOL> def setup_client ( self ) : <EOL> if '<STR_LIT>' in self . args : <EOL> use_trash = self . args . usetrash and not self . args . skiptrash <EOL> else : <EOL> use_trash = self . args . usetrash <EOL> self . client = HAClient ( self . namenodes , use_trash , self . user , self . use_sasl , self . configs [ '<STR_LIT>' ] ) <EOL> def execute ( self ) : <EOL> if self . args . help : <EOL> self . args . arg = [ self . cmd ] <EOL> return Commands . methods [ '<STR_LIT>' ] [ '<STR_LIT>' ] ( self ) <EOL> if not Commands . methods . get ( self . cmd ) : <EOL> self . parser . print_help ( ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> try : <EOL> return Commands . methods [ self . cmd ] [ '<STR_LIT>' ] ( self ) <EOL> except IOError as e : <EOL> if e . errno != errno . EPIPE : <EOL> exitError ( sys . exc_info ( ) ) <EOL> except Exception : <EOL> exitError ( sys . exc_info ( ) ) <EOL> def command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = "<STR_LIT>" , visible = True , req_args = None ) : <EOL> def wrap ( f ) : <EOL> Commands . methods [ f . func_name ] = { "<STR_LIT>" : f , <EOL> "<STR_LIT:args>" : args , <EOL> "<STR_LIT>" : descr , <EOL> "<STR_LIT>" : allowed_opts , <EOL> "<STR_LIT>" : visible , <EOL> "<STR_LIT>" : req_args } <EOL> return wrap <EOL> @ command ( visible = False ) <EOL> def commands ( self ) : <EOL> print "<STR_LIT:\n>" . join ( sorted ( [ k for k , v in Commands . methods . iteritems ( ) if v [ '<STR_LIT>' ] ] ) ) <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , visible = False , req_args = [ '<STR_LIT>' ] ) <EOL> def complete ( self ) : <EOL> self . args . summary = True <EOL> self . args . directory = False <EOL> self . args . recurse = False <EOL> self . args . human = False <EOL> try : <EOL> for line in self . _listing ( ) : <EOL> print line . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) <EOL> except FileNotFoundException : <EOL> pass <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ "<STR_LIT:d>" , "<STR_LIT:R>" , "<STR_LIT:s>" , "<STR_LIT:h>" ] , req_args = [ '<STR_LIT>' ] ) <EOL> def ls ( self ) : <EOL> for line in self . _listing ( ) : <EOL> print line <EOL> def _listing ( self ) : <EOL> if self . args . directory : <EOL> include_children = False <EOL> recurse = False <EOL> include_toplevel = True <EOL> else : <EOL> include_children = True <EOL> include_toplevel = False <EOL> recurse = self . args . recurse <EOL> listing = self . client . ls ( self . args . dir , recurse = recurse , <EOL> include_toplevel = include_toplevel , <EOL> include_children = include_children ) <EOL> for line in format_listing ( listing , json_output = self . args . json , <EOL> human_readable = self . args . human , <EOL> recursive = recurse , <EOL> summary = self . args . summary ) : <EOL> yield line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' ] ) <EOL> def mkdir ( self ) : <EOL> creations = self . client . mkdir ( self . args . dir ) <EOL> for line in format_results ( creations , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' ] ) <EOL> def mkdirp ( self ) : <EOL> creations = self . client . mkdir ( self . args . dir , create_parent = True ) <EOL> for line in format_results ( creations , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ "<STR_LIT:R>" ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def chown ( self ) : <EOL> owner = self . args . single_arg <EOL> try : <EOL> mods = self . client . chown ( self . args . dir , owner , recurse = self . args . recurse ) <EOL> for line in format_results ( mods , json_output = self . args . json ) : <EOL> print line <EOL> except FileNotFoundException : <EOL> exitError ( sys . exc_info ( ) ) <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ "<STR_LIT:R>" ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def chmod ( self ) : <EOL> mode = int ( str ( self . args . single_int_arg ) , <NUM_LIT:8> ) <EOL> mods = self . client . chmod ( self . args . dir , mode , recurse = self . args . recurse ) <EOL> for line in format_results ( mods , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ "<STR_LIT:R>" ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def chgrp ( self ) : <EOL> grp = self . args . single_arg <EOL> mods = self . client . chgrp ( self . args . dir , grp , recurse = self . args . recurse ) <EOL> for line in format_results ( mods , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT:h>' ] , req_args = [ '<STR_LIT>' ] ) <EOL> def count ( self ) : <EOL> counts = self . client . count ( self . args . dir ) <EOL> for line in format_counts ( counts , json_output = self . args . json , <EOL> human_readable = self . args . human ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT:h>' ] ) <EOL> def df ( self ) : <EOL> result = self . client . df ( ) <EOL> for line in format_fs_stats ( result , json_output = self . args . json , <EOL> human_readable = self . args . human ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ "<STR_LIT:s>" , "<STR_LIT:h>" ] , req_args = [ '<STR_LIT>' ] ) <EOL> def du ( self ) : <EOL> if self . args . summary : <EOL> include_children = False <EOL> include_toplevel = True <EOL> else : <EOL> include_children = True <EOL> include_toplevel = False <EOL> result = self . client . du ( self . args . dir , include_toplevel = include_toplevel , include_children = include_children ) <EOL> for line in format_du ( result , json_output = self . args . json , human_readable = self . args . human ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def mv ( self ) : <EOL> paths = self . args . dir <EOL> dst = self . args . single_arg <EOL> result = self . client . rename ( paths , dst ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ "<STR_LIT:R>" , "<STR_LIT:S>" , "<STR_LIT:T>" ] , req_args = [ '<STR_LIT>' ] ) <EOL> def rm ( self ) : <EOL> result = self . client . delete ( self . args . dir , recurse = self . args . recurse ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' ] ) <EOL> def touchz ( self ) : <EOL> result = self . client . touchz ( self . args . dir ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" ) <EOL> def serverdefaults ( self ) : <EOL> print self . client . serverdefaults ( ) <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' ] ) <EOL> def rmdir ( self ) : <EOL> result = self . client . rmdir ( self . args . dir ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT:R>' ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def setrep ( self ) : <EOL> rep_factor = int ( self . args . single_int_arg ) <EOL> result = self . client . setrep ( self . args . dir , rep_factor , recurse = self . args . recurse ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' ] ) <EOL> def usage ( self ) : <EOL> if not '<STR_LIT>' in self . args or self . args . arg == [ ] : <EOL> self . parser . print_help ( ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> for sub_cmd in self . args . arg : <EOL> self . usage_helper ( sub_cmd ) <EOL> def usage_helper ( self , command ) : <EOL> cmd_entry = Commands . methods . get ( command ) <EOL> if not cmd_entry : <EOL> self . parser . print_help ( ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> cmd_args = [ ] <EOL> cmd_descriptions = "<STR_LIT>" <EOL> allowed_opts = cmd_entry . get ( '<STR_LIT>' ) <EOL> if allowed_opts : <EOL> cmd_args += [ "<STR_LIT>" % o for o in allowed_opts ] <EOL> cmd_descriptions += "<STR_LIT:\n>" . join ( sorted ( [ "<STR_LIT>" % ( "<STR_LIT>" % ( self . SUB_OPTS [ o ] [ '<STR_LIT>' ] , self . SUB_OPTS [ o ] [ '<STR_LIT>' ] ) , self . SUB_OPTS [ o ] [ '<STR_LIT>' ] ) for o in allowed_opts ] ) ) <EOL> args = cmd_entry . get ( '<STR_LIT:args>' ) <EOL> if args : <EOL> cmd_args . append ( args ) <EOL> print "<STR_LIT>" % ( command , "<STR_LIT:U+0020>" . join ( cmd_args ) ) <EOL> general_opts = "<STR_LIT>" <EOL> general_opts += "<STR_LIT:\n>" . join ( sorted ( [ "<STR_LIT>" % ( "<STR_LIT>" % ( v [ '<STR_LIT>' ] , v [ '<STR_LIT>' ] ) , v [ '<STR_LIT>' ] ) for k , v in self . GENERIC_OPTS . iteritems ( ) ] ) ) <EOL> print general_opts <EOL> if allowed_opts : <EOL> print cmd_descriptions <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' ] ) <EOL> def stat ( self ) : <EOL> print format_stat ( self . client . stat ( self . args . dir ) , json_output = self . args . json ) <EOL> @ command ( args = "<STR_LIT:path>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT:d>' , '<STR_LIT:z>' , '<STR_LIT:e>' ] , req_args = [ '<STR_LIT>' ] ) <EOL> def test ( self ) : <EOL> path = self . args . single_arg <EOL> try : <EOL> result = self . client . test ( path , exists = self . args . exists , directory = self . args . directory , zero_length = self . args . zero ) <EOL> except FileNotFoundException : <EOL> result = False <EOL> if result : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT>' ] , req_args = [ '<STR_LIT>' ] ) <EOL> def cat ( self ) : <EOL> for file_to_read in self . client . cat ( self . args . dir , check_crc = self . args . checkcrc ) : <EOL> for load in file_to_read : <EOL> sys . stdout . write ( load ) <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] , visible = False ) <EOL> def copyFromLocal ( self ) : <EOL> src = self . args . dir <EOL> dst = self . args . single_arg <EOL> result = self . client . copyFromLocal ( src , dst ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT>' ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def copyToLocal ( self ) : <EOL> paths = self . args . dir <EOL> dst = self . args . single_arg <EOL> result = self . client . copyToLocal ( paths , dst , check_crc = self . args . checkcrc ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT>' ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] , visible = False ) <EOL> def cp ( self ) : <EOL> paths = self . args . dir <EOL> dst = self . args . single_arg <EOL> result = self . client . cp ( paths , dst , checkcrc = self . args . checkcrc ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT>' ] , req_args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def get ( self ) : <EOL> paths = self . args . dir <EOL> dst = self . args . single_arg <EOL> result = self . client . copyToLocal ( paths , dst , check_crc = self . args . checkcrc ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT>' ] , req_args = [ '<STR_LIT>' ] ) <EOL> def getmerge ( self ) : <EOL> source = self . args . src_dst [ <NUM_LIT:0> ] <EOL> dst = self . args . src_dst [ <NUM_LIT:1> ] <EOL> result = self . client . getmerge ( source , dst , newline = self . args . newline ) <EOL> for line in format_results ( result , json_output = self . args . json ) : <EOL> print line <EOL> @ command ( args = "<STR_LIT:path>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT:f>' ] , req_args = [ '<STR_LIT>' ] ) <EOL> def tail ( self ) : <EOL> path = self . args . single_arg <EOL> result = self . client . tail ( path , append = self . args . append ) <EOL> for line in result : <EOL> print line <EOL> @ command ( args = "<STR_LIT>" , descr = "<STR_LIT>" , allowed_opts = [ '<STR_LIT>' ] , req_args = [ '<STR_LIT>' ] ) <EOL> def text ( self ) : <EOL> paths = self . args . dir <EOL> result = self . client . text ( paths ) <EOL> for line in result : <EOL> print line </s>
