B4BY.588
Home
Terminal
Upload
information
Create File
Create Folder
About
Tools
:
/
lib
/
python2.7
/
site-packages
/
ipapython
/
Filename :
admintool.pyo
back
Copy
� $��^c @ s� d Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d Z d Z d Z e j e � Z d e f d � � YZ d e f d � � YZ d S( s� A common framework for command-line admin tools, e.g. install scripts Handles common operations like option parsing and logging i����N( t OptionGroup( t version( t config( t standard_logging_setupi i i t ScriptErrorc B s, e Z d Z d d d � Z e d � � Z RS( sB An exception that records an error message and a return value t i c C s8 | d k r d } n t t | � j | � | | _ d S( NR ( t Nonet superR t __init__t rval( t selft msgR ( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR - s c C s t | � S( N( t str( R ( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR 3 s ( t __name__t __module__t __doc__R t propertyR ( ( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR * s t AdminToolc B s� e Z d Z d Z d Z d Z d Z e � Z e d � � Z e e d � � Z e d � � Z e d � � Z e d � � Z d � Z d � Z e d � Z d � Z d d � Z d e d � Z d � Z d � Z d � Z d � Z RS( s~ Base class for command-line admin tools To run the tool, call the main() classmethod with a list of command-line arguments. Alternatively, call run_cli() to run with command-line arguments in sys.argv, and call sys.exit() with the return value. Some commands actually represent multiple related tools, e.g. ``ipa-server-install`` and ``ipa-server-install --uninstall`` would be represented by separate classes. Only their options are the same. To handle this, AdminTool provides classmethods for option parsing and selecting the appropriate command class. A class-wide option parser is made by calling add_options. The options are then parsed into options and arguments, and get_command_class is called with those to retrieve the class. That class is then instantiated and run. Running consists of a few steps: - validating options or the environment (validate_options) - setting up logging (setup_logging) - running the actual command (run) Any unhandled exceptions are handled in handle_error. And at the end, either log_success or log_failure is called. Class attributes to define in subclasses: command_name - shown in logs log_file_name - if None, logging is to stderr only usage - text shown in help description - text shown in help See the setup_logging method for more info on logging. c C sM t j d t j d | j d t j � d | j � } | | _ | j | � d S( sA Create an option parser shared across all instances of this classR t usaget formattert descriptionN( R t IPAOptionParserR t VERSIONR t IPAFormatterR t option_parsert add_options( t clst parser( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyt make_parserc s c C s� t | d � } | j d d d d d t d d d d �| rh | j d d d d d t d d d d �n | j d d d d d t d d d d �| j d d d d d d d d d �| j | � d S( s� Add command-specific options to the option parser :param parser: The parser to add options to :param debug_option: Add a --debug option as an alias to --verbose s Logging and output optionss -vs --verboset destt verboset defaultt actiont store_truet helps print debugging informations -ds --debugs alias for --verbose (deprecated)s -qs --quiett quiets output only errorss --log-filet log_filet metavart FILEs log to the given fileN( R t add_optiont FalseR t add_option_group( R R t debug_optiont group( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR l s c C s t j | j t j � � d S( sK Run this command with sys.argv, exit process with the return value N( t syst exitt maint argv( R ( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyt run_cli s c C ss | | j k r, | j � | j | j | <n | j j | d � \ } } | j | | � } | | | � } | j � S( s� The main entry point Parses command-line arguments, selects the actual command class to use based on them, and runs that command. :param argv: Command-line arguments. :return: Command exit code i ( t _option_parsersR R t parse_argst get_command_classt execute( R R/ t optionst argst command_classt command( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR. � s c C s | S( N( ( R R5 R6 ( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR3 � s c C s+ | | _ | | _ | j j | � | _ d S( N( R5 R6 R t get_safe_optst safe_options( R R5 R6 ( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR � s c C s� | j d t � d } y. | j � | j � | j � | j � } WnX t k r� } t j � d } | j | � \ } } | r� | j | | | | � | Sn X| j � | S( s� Do everything needed after options are parsed This includes validating options, setting up logging, doing the actual work, and handling the result. t no_filei i ( t _setup_loggingt Truet validate_optionst ask_for_optionst setup_loggingt runt BaseExceptionR, t exc_infot handle_errort log_failuret log_success( R t return_valuet exceptiont tracebackt error_message( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR4 � s c C s\ | r1 t j � d k r1 t d | j d � � n | j j rX | j j rX t d � � n d S( s� Validate self.options It's also possible to compute and store information that will be useful later, but no changes to the system should be made here. i s Must be root to run %si s8 The --quiet and --verbose options are mutually exclusiveN( t ost getegidR t command_nameR5 R R# ( R t needs_root( ( s7 /usr/lib/python2.7/site-packages/ipapython/admintool.pyR>