Ñò Ã#xPc @sšdZddkZddkZddkZddklZddklZddklZddkl Z de fd„ƒYZ d e fd „ƒYZ dS( sA common framework for command-line admin tools, e.g. install scripts Handles common operations like option parsing and logging iÿÿÿÿN(t OptionGroup(tversion(tconfig(tipa_log_managert ScriptErrorcBs&eZdZddd„Zd„ZRS(sBAn exception that records an error message and a return value ticCs-|djo d}n||_||_dS(NR(tNonetmsgtrval(tselfRR((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyt__init__&s   cCs|iS(N(R(R ((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyt__str__,s(t__name__t __module__t__doc__R R (((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyR#st AdminToolcBsËeZdZdZdZeZdZe ƒZ e d„ƒZ e d„ƒZ e d„ƒZe d„ƒZe d„ƒZd„Zd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„ZRS(sYBase 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 needs_root - if true, non-root users can't run the tool usage - text shown in help cCsDtidtid|idtiƒƒ}||_|i|ƒdS(sACreate an option parser shared across all instances of this classRtusaget formatterN(RtIPAOptionParserRtVERSIONRt IPAFormattert option_parsert add_options(tclstparser((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyt make_parserYs c Cs,|idddddtdddd ƒd S( s1Add command-specific options to the option parsers-ds--debugtdesttdebugtdefaulttactiont store_truethelpsprint debugging informationN(t add_optiontFalse(RR((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyRascCsti|itiƒƒdS(sKRun this command with sys.argv, exit process with the return value N(tsystexittmaintargv(R((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pytrun_cligscCsu||ijo|iƒ|i|i|RtdictR't classmethodRRR&R$R)R R*R1R2R3R7R4R8R9(((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyR0s(!     (RR"R?R<toptparseRt ipapythonRRRt StandardErrorRtobjectR(((s7/usr/lib/python2.6/site-packages/ipapython/admintool.pyts