3 ©ft`l&ã@sˆddlmZddlmZmZddlZddlZddlZddlZddl Z ddl Z ddl Z e j dƒZ Gdd„deƒZGdd„dejejƒZdS) é)Úcommands)Ú_ÚucdNÚdnfc@seZdZdZdZdZdZdS)ÚShellDemandSheetTN)Ú__name__Ú __module__Ú __qualname__Zavailable_reposZ resolvingZ root_userZsack_activation©r r ú/usr/lib/python3.6/shell.pyr%src @sÀeZdZd*Zedƒjejjd�Z dddddddd d d d œ Z d d„Z e dd„ƒZ dd„Zdd„Zdd„Zdd„Zd+dd„Zd,dd„Zd-dd„Zd.d d!„Zd"d#„Zd/d$d%„Zd0d&d'„Zd1d(d)„ZdS)2Ú ShellCommandÚshellÚshzrun an interactive {prog} shell)ÚprogÚrepoÚquitZts_runÚ transactionÚconfigÚresolveÚhelp) rÚ repositoryÚexitrÚrunÚtsrrÚ resolvedeprcCs$tjj||ƒtjj|ƒd|_dS)Nz> )rÚCommandÚ__init__ÚcmdÚCmdÚprompt)ÚselfÚclir r r r=s zShellCommand.__init__cCs*|jddtdƒtdƒjtjjd�d�dS)NÚscriptú?ZSCRIPTzScript to run in {prog} shell)r)ÚnargsÚmetavarr)Ú add_argumentrÚformatrÚutilÚMAIN_PROG_UPPER)Úparserr r r Ú set_argparserBszShellCommand.set_argparserc Csr|jj}tƒ|j_xZt|ƒD]N}|jdƒr,qyt|jj|ƒWqtk rht|jj|t||ƒƒYqXqWdS)NÚ__)r!ÚdemandsrÚdirÚ startswithÚgetattrÚAttributeErrorÚsetattr)r Zdefault_demandsÚattrr r r Ú configureHs  zShellCommand.configurecCs$|jjr|j|jjƒn|jƒdS)N)Úoptsr"Ú _run_scriptZcmdloop)r r r r rUszShellCommand.runcCs |jjƒd|j_|jjƒdS)N)ÚbaseZ_finalize_baseÚ _transactionÚ fill_sack)r r r r Ú_clean[s zShellCommand._cleancCs`| s|dkrdS|dkrd}ytj|ƒ}Wn|jƒdS|jjjdd�|jjj|ƒ}|jdkrldS|j|jkrœt |d|j|jƒ|dd…ƒnÀ|jj j |jƒ}|dk �rT||jƒ}y|jjj ||ƒ}Wnt k rèdSXy&tj|jjƒ|j_|jƒ|jƒWn@tjjk �rP}ztjtd ƒd t|ƒƒdSd}~XnXn|jƒdS) NÚ ZEOFrF)Z reset_usager rézError:ú )ÚshlexÚsplitÚ_helpr!Ú optparserrZparse_main_argsZcommandÚMAPPINGr0Z cli_commandsÚgetZparse_command_argsÚ SystemExitÚcopyÚdeepcopyr-r4rrÚ exceptionsÚErrorÚloggerÚerrorrr)r ÚlineZs_liner5Zcmd_clsrÚer r r Úonecmd`s<  $   zShellCommand.onecmdNc CsÈdd„}| st|ƒdkr(|jdƒdS|d}t|ƒdkrD|dnd}|jdƒ}|d kr´|d|…}||dd…}|jjj|ƒ}x|D]}||||ƒqŠW|sÄtjtdƒ|ƒn||||jj ƒdS) Nc SsP|rt|||ƒn:ytdj|t|t|ƒƒƒƒWntjtdƒƒYnXdS)Nz{}: {}zUnsupported key value.)r2Úprintr'r0ÚstrrIÚwarningr)ÚkeyÚvalÚconfr r r Ú print_or_set‡s z*ShellCommand._config..print_or_setérrr<Ú.zCould not find repository: %séÿÿÿÿ) Úlenr@Úfindr7ÚreposÚ get_matchingrIrPrrS) r ÚargsrTrQrRZperiodZ repo_namerZrr r r Ú_config†s"      zShellCommand._configcCsøt|tƒrt|ƒdkr|dn|}d}|rÐ|dkrBtdƒj|ƒ}nŽ|dkrZtdƒj|ƒ}nv|dkrrtd ƒj|ƒ}n^|d krŠtd ƒj|ƒ}nF|dkr¢tdƒj|ƒ}n.|dkrºtdƒj|ƒ}n|dkrÐtdƒj|ƒ}|sè|jjjƒtdƒ}td|ƒdS)z¤Output help information. :param args: the command to output help information about. If *args* is an empty, general help will be output. rNrzà{} arg [value] arg: debuglevel, errorlevel, obsoletes, gpgcheck, assumeyes, exclude, repo_id.gpgcheck, repo_id.exclude If no value is given it prints the current value. If value is given it sets that value.rz{} [command] print helprrzÅ{} arg [option] list: lists repositories and their status. option = [all | id | glob] enable: enable repositories. option = repository id disable: disable repositories. option = repository idrz"{} resolve the transaction setrrzy{} arg list: lists the contents of the transaction reset: reset (zero-out) the transaction run: run the transactionrz{} run the transactionrrz{} exit the shella‚Shell specific arguments: config set config options help print help repository (or repo) enable, disable or list repositories resolvedep resolve the transaction set transaction (or ts) list, reset or run the transaction set run resolve and run the transaction set exit (or quit) exit the shellr;)rr)rr)rr) Ú isinstanceÚlistrXrr'r!rAZ print_helprN)r r\ÚargÚmsgr r r r@£s:"  zShellCommand._helpcCsÐ|r |dnd}|d kr6|jddj|dd…ƒƒn–|dkrÂ|jjj}d}x\|dd…D]L}|j|ƒ}|r~t||ƒƒd }qZtjt d ƒdt d ƒ|jj j j |ƒƒqZW|r¸|jj ƒd|j_n |jd ƒdS)Nrr_z repolist r=r<ÚenableÚdisableFTzError:zUnknown repo: '%s'r)r_N)rbrc)rMÚjoinr!r7rZr[r0rIZcriticalrÚoutputÚtermÚboldr9Z_compsr@)r r\rrZr9rÚrr r r Ú_repoÞs"     zShellCommand._repocCsLy|jjj|jjjƒWn.tjjk rF}zt|ƒWYdd}~XnXdS)N) r!r7rr-Z allow_erasingrrGZ DepsolveErrorrN)r r\rLr r r Ú_resolveøszShellCommand._resolvecCs„yDt|dƒ�0}|jƒ}x |D]}|jdƒs|j|ƒqWWdQRXWn:tk r~tjtdƒ|jj j j |ƒƒt j dƒYnXdS)Nrhú#z!Error: Cannot open %s for readingr<)ÚopenÚ readlinesr/rMÚIOErrorrIÚinforr7rerfrgÚsysr)r ÚfileÚfdÚlinesrKr r r r6þs   zShellCommand._run_scriptcCsØ|r |dnd}|dkr$|jƒdS|jƒ|d krZ|jjrÔ|jjj|jjƒ}tj|ƒnz|dkrÊy|jjƒWn@t j j k r°}z tj t dƒdt|ƒƒWYdd}~XnXtjt dƒƒ|jƒn |jdƒdS) NrÚresetr_rzError:r=z Complete!r)r_N)r:rjr7r8reZlist_transactionrIroZdo_transactionrrGrHrJrrr@)r r\rÚoutrLr r r r8 s" , zShellCommand._transactioncCs|jdgƒdS)Nr)r8)r r\r r r Ú_ts_run"szShellCommand._ts_runcCstjtdƒƒtjdƒdS)Nz Leaving Shellr)rIrorrpr)r r\r r r Ú_quit%szShellCommand._quit)r r)N)N)N)N)N)N)N)rrr Úaliasesrr'rr(r)ZsummaryrBrÚ staticmethodr+r4rr:rMr]r@rirjr6r8rvrwr r r r r ,s4  &  ;    r )Zdnf.clirZdnf.i18nrrZdnf.utilrrrEZloggingr>rpZ getLoggerrIÚobjectrrrr r r r r Ús