|yMa[Jc@sdZddlZddlZddlZddlmZddlmZmZm Z m Z m Z ddlm Z GdddZ Gdd d e ZdS( utdistutils.cmd Provides the Command class, the base class for the command classes in the distutils.command package. iN(uDistutilsOptionError(uutiludir_utilu file_utilu archive_utiludep_util(ulogcBs|EeZdZdZgZddZddZddZdd Zd d Z dBd d dZ ddZ dddZ ddZdBddZdBddZddZdBddZddZd d!Zd"d#Zd$d%Zdd&d'Zd(d)d*Zd+d,Zd-d.Zd/d0ZdBdd1d2Zd3d4d5ZdddBdd6d7Zddd(dd8d9Zdd:d;Z ddd<d=Z!dBdBd>d?Z"dBdBdd@dAZ#dBS(CuCommandu}Abstract base class for defining command classes, the "worker bees" of the Distutils. A useful analogy for command classes is to think of them as subroutines with local variables called "options". The options are "declared" in 'initialize_options()' and "defined" (given their final values, aka "finalized") in 'finalize_options()', both of which must be defined by every command class. The distinction between the two is necessary because option values might come from the outside world (command line, config file, ...), and any options dependent on other options must be computed *after* these outside influences have been processed -- hence 'finalize_options()'. The "body" of the subroutine, where it does all its work based on the values of its options, is the 'run()' method, which must also be implemented by every command class. cCsddlm}t||s.tdn|jtkrLtdn||_|jd|_ |j |_ d|_ d|_ d|_dS(uCreate and initialize a new Command object. Most importantly, invokes the 'initialize_options()' method, which is the real initializer and depends on the actual command being instantiated. i(u Distributionu$dist must be a Distribution instanceuCommand is an abstract classN(udistutils.distu Distributionu isinstanceu TypeErroru __class__uCommandu RuntimeErroru distributionuinitialize_optionsuNoneu_dry_runuverboseuforceuhelpu finalized(uselfudistu Distribution((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu__init__/s     uCommand.__init__cCsR|dkrBt|d|}|dkr;t|j|S|Sn t|dS(Nudry_runu_(ugetattruNoneu distributionuAttributeError(uselfuattrumyval((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu __getattr___s   uCommand.__getattr__cCs#|js|jnd|_dS(Ni(u finalizedufinalize_options(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuensure_finalizedis  uCommand.ensure_finalizedcCstd|jdS(uSet default values for all the options that this command supports. Note that these defaults may be overridden by other commands, by the setup script, by config files, or by the command-line. Thus, this is not the place to code dependencies between options; generally, 'initialize_options()' implementations are just a bunch of "self.foo = None" assignments. This method must be implemented by all command classes. u,abstract method -- subclass %s must overrideN(u RuntimeErroru __class__(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuinitialize_options{s uCommand.initialize_optionscCstd|jdS(uSet final values for all the options that this command supports. This is always called as late as possible, ie. after any option assignments from the command-line or from other commands have been done. Thus, this is the place to code option dependencies: if 'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as long as 'foo' still has the same value it was assigned in 'initialize_options()'. This method must be implemented by all command classes. u,abstract method -- subclass %s must overrideN(u RuntimeErroru __class__(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyufinalize_optionss uCommand.finalize_optionsucCsddlm}|dkr/d|j}n|j||dtj|d}x|jD]t\}}}|j|}|d dkr|dd }nt ||}|j|d||fdtjq]WdS( Ni(u longopt_xlateucommand options for '%s':ulevelu iu=u%s = %sii( udistutils.fancy_getoptu longopt_xlateuNoneuget_command_nameuannounceuloguINFOu user_optionsu translateugetattr(uselfuheaderuindentu longopt_xlateuoptionu_uvalue((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu dump_optionss  uCommand.dump_optionscCstd|jdS(uA command's raison d'etre: carry out the action it exists to perform, controlled by the options initialized in 'initialize_options()', customized by other commands, the setup script, the command-line, and config files, and finalized in 'finalize_options()'. All terminal output and filesystem interaction should be done by 'run()'. This method must be implemented by all command classes. u,abstract method -- subclass %s must overrideN(u RuntimeErroru __class__(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuruns u Command.runicCstj||dS(umIf the current verbosity level is of greater than or equal to 'level' print 'msg' to stdout. N(ulog(uselfumsgulevel((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuannouncesuCommand.announcecCs4ddlm}|r0t|tjjndS(u~Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true. i(uDEBUGN(udistutils.debuguDEBUGuprintusysustdoutuflush(uselfumsguDEBUG((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu debug_prints uCommand.debug_printcCs^t||}|dkr/t||||St|tsZtd|||fn|S(Nu'%s' must be a %s (got `%s`)(ugetattruNoneusetattru isinstanceustruDistutilsOptionError(uselfuoptionuwhatudefaultuval((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu_ensure_stringlikes uCommand._ensure_stringlikecCs|j|d|dS(uWEnsure that 'option' is a string; if not defined, set it to 'default'. ustringN(u_ensure_stringlike(uselfuoptionudefault((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu ensure_stringsuCommand.ensure_stringcCst||}|dkrdSt|trMt||tjd|nPt|trxtdd|D}nd}|st d||fndS(uEnsure that 'option' is a list of strings. If 'option' is currently a string, we split it either on /,\s*/ or /\s+/, so "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become ["foo", "bar", "baz"]. Nu,\s*|\s+css|]}t|tVqdS(N(u isinstanceustr(u.0uv((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu su-Command.ensure_string_list..u''%s' must be a list of strings (got %r)F( ugetattruNoneu isinstanceustrusetattrureusplitulistualluFalseuDistutilsOptionError(uselfuoptionuvaluok((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuensure_string_lists uCommand.ensure_string_listcCsO|j|||}|dk rK|| rKtd|||fndS(Nuerror in '%s' option: (u_ensure_stringlikeuNoneuDistutilsOptionError(uselfuoptionutesteruwhatu error_fmtudefaultuval((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu_ensure_tested_strings uCommand._ensure_tested_stringcCs |j|tjjdddS(u5Ensure that 'option' is the name of an existing file.ufilenameu$'%s' does not exist or is not a fileN(u_ensure_tested_stringuosupathuisfile(uselfuoption((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuensure_filenamesuCommand.ensure_filenamecCs |j|tjjdddS(Nudirectory nameu)'%s' does not exist or is not a directory(u_ensure_tested_stringuosupathuisdir(uselfuoption((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuensure_dirnamesuCommand.ensure_dirnamecCs$t|dr|jS|jjSdS(Nu command_name(uhasattru command_nameu __class__u__name__(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuget_command_name suCommand.get_command_namecGsh|jj|}|jxE|D]=\}}t||dkr#t||t||q#q#WdS(u>Set the values of any "undefined" options from corresponding option values in some other command object. "Undefined" here means "is None", which is the convention used to indicate that an option has not been changed between 'initialize_options()' and 'finalize_options()'. Usually called from 'finalize_options()' for options that depend on some other command rather than another option of the same command. 'src_cmd' is the other command from which option values will be taken (a command object will be created for it if necessary); the remaining arguments are '(src_option,dst_option)' tuples which mean "take the value of 'src_option' in the 'src_cmd' command object, and copy it to 'dst_option' in the current command object". N(u distributionuget_command_objuensure_finalizedugetattruNoneusetattr(uselfusrc_cmdu option_pairsu src_cmd_obju src_optionu dst_option((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuset_undefined_optionss  uCommand.set_undefined_optionscCs#|jj||}|j|S(uWrapper around Distribution's 'get_command_obj()' method: find (create if necessary and 'create' is true) the command object for 'command', call its 'ensure_finalized()' method, and return the finalized command object. (u distributionuget_command_objuensure_finalized(uselfucommanducreateucmd_obj((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuget_finalized_command$s uCommand.get_finalized_commandicCs|jj||S(N(u distributionureinitialize_command(uselfucommandureinit_subcommands((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyureinitialize_command0s uCommand.reinitialize_commandcCs|jj|dS(uRun some other command: uses the 'run_command()' method of Distribution, which creates and finalizes the command object if necessary and then invokes its 'run()' method. N(u distributionu run_command(uselfucommand((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu run_command4suCommand.run_commandcCsLg}x?|jD]4\}}|dks4||r|j|qqW|S(ukDetermine the sub-commands that are relevant in the current distribution (ie., that need to be run). This is based on the 'sub_commands' class attribute: each tuple in that list may include a method that we call to determine if the subcommand needs to be run for the current distribution. Return a list of command names. N(u sub_commandsuNoneuappend(uselfucommandsucmd_nameumethod((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuget_sub_commands;s uCommand.get_sub_commandscCs!tjd|j|fdS(Nuwarning: %s: %s (uloguwarnuget_command_name(uselfumsg((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuwarnKs u Command.warncCs tj|||d|jdS(Nudry_run(uutiluexecuteudry_run(uselfufuncuargsumsgulevel((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuexecuteOsuCommand.executeicCstj||d|jdS(Nudry_run(udir_utilumkpathudry_run(uselfunameumode((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyumkpathRsuCommand.mkpathc Cs)tj|||||j |d|jS(uCopy a file respecting verbose, dry-run and force flags. (The former two default to whatever is in the Distribution object, and the latter defaults to false for commands that don't define it.)udry_run(u file_utilu copy_fileuforceudry_run(uselfuinfileuoutfileu preserve_modeupreserve_timesulinkulevel((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu copy_fileUsuCommand.copy_filec Cs)tj||||||j d|jS(u\Copy an entire directory tree respecting verbose, dry-run, and force flags. udry_run(udir_utilu copy_treeuforceudry_run(uselfuinfileuoutfileu preserve_modeupreserve_timesupreserve_symlinksulevel((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu copy_tree^suCommand.copy_treecCstj||d|jS(u$Move a file respecting dry-run flag.udry_run(u file_utilu move_fileudry_run(uselfusrcudstulevel((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu move_filegsuCommand.move_filecCs*ddlm}|||d|jdS(u2Spawn an external command respecting dry-run flag.i(uspawnudry_runN(udistutils.spawnuspawnudry_run(uselfucmdu search_pathuleveluspawn((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuspawnksu Command.spawncCstj||||d|jS(Nudry_run(u archive_utilu make_archiveudry_run(uselfu base_nameuformaturoot_dirubase_dir((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu make_archivepsuCommand.make_archivecCs|dkrd|}nt|tr4|f}n$t|ttfsXtdn|dkrd|dj|f}n|jstj ||r|j ||||n t j |dS(uSpecial case of 'execute()' for operations that process one or more input files and generate one output file. Works just like 'execute()', except the operation is skipped and a different message printed if 'outfile' already exists and is newer than all files listed in 'infiles'. If the command defined 'self.force', and it is true, then the command is unconditionally run -- does no timestamp checks. uskipping %s (inputs unchanged)u9'infiles' must be a string, or a list or tuple of stringsugenerating %s from %su, N( uNoneu isinstanceustrulistutupleu TypeErrorujoinuforceudep_utilu newer_groupuexecuteulogudebug(uselfuinfilesuoutfileufuncuargsuexec_msguskip_msgulevel((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu make_filets     uCommand.make_fileN($u__name__u __module__u __qualname__u__doc__u sub_commandsu__init__u __getattr__uensure_finalizeduinitialize_optionsufinalize_optionsuNoneu dump_optionsurunuannounceu debug_printu_ensure_stringlikeu ensure_stringuensure_string_listu_ensure_tested_stringuensure_filenameuensure_dirnameuget_command_nameuset_undefined_optionsuget_finalized_commandureinitialize_commandu run_commanduget_sub_commandsuwarnuexecuteumkpathu copy_fileu copy_treeu move_fileuspawnu make_archiveu make_file(u __locals__((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuCommand sD 0              uCommandcBsS|EeZdZdZdgZddZddZd d Zd d Zd S(u install_miscu{Common base class for installing some files in a subdirectory. Currently used by install_data and install_scripts. u install-dir=udu!directory to install the files tocCsd|_g|_dS(N(uNoneu install_diruoutfiles(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyuinitialize_optionss uinstall_misc.initialize_optionscCs|jd|dfdS(Nuinstallu install_dir(uset_undefined_options(uselfudirname((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu_install_dir_fromsuinstall_misc._install_dir_fromcCsmg|_|sdS|j|jxC|D];}|j||j|jjtjj|j|q*WdS(N(uoutfilesumkpathu install_diru copy_fileuappenduosupathujoin(uselfufilelistuf((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu _copy_filess  uinstall_misc._copy_filescCs|jS(N(uoutfiles(uself((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu get_outputssuinstall_misc.get_outputsN(u install-dir=udu!directory to install the files to( u__name__u __module__u __qualname__u__doc__u user_optionsuinitialize_optionsu_install_dir_fromu _copy_filesu get_outputs(u __locals__((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyu install_miscs     u install_misc(u__doc__usysuosureudistutils.errorsuDistutilsOptionErroru distutilsuutiludir_utilu file_utilu archive_utiludep_utiluloguCommandu install_misc(((u2/opt/alt/python33/lib64/python3.3/distutils/cmd.pyus$(