a !cl&@sddlmZddlmZmZddlZddlZddlZddlZddl Z ddl Z ddl Z e dZ GdddeZGdddejejZdS) )commands)_ucdNdnfc@seZdZdZdZdZdZdS)ShellDemandSheetTN)__name__ __module__ __qualname__Zavailable_reposZ resolvingZ root_userZsack_activationr r :/usr/lib/python3.9/site-packages/dnf/cli/commands/shell.pyr%src @seZdZdZedjejjdZ ddddddddd d d Z d d Z e ddZ ddZddZddZddZd)ddZd*ddZd+ddZd,dd Zd!d"Zd-d#d$Zd.d%d&Zd/d'd(ZdS)0 ShellCommand)shellshzrun an interactive {prog} shellprogrepoquitZts_run transactionconfigresolvehelp) r repositoryexitrruntsrr resolvedeprcCs$tj||tj|d|_dS)Nz> )rCommand__init__cmdCmdprompt)selfclir r r r=s zShellCommand.__init__cCs*|jddtdtdjtjjdddS)Nscript?ZSCRIPTzScript to run in {prog} shellr)nargsmetavarr) add_argumentrformatrutilMAIN_PROG_UPPER)parserr r r set_argparserBs zShellCommand.set_argparserc Csl|jj}t|j_t|D]L}|dr*qzt|jj|Wqtydt|jj|t||Yq0qdS)N__)r"demandsrdir startswithgetattrAttributeErrorsetattr)r!Zdefault_demandsattrr r r configureHs    zShellCommand.configurecCs$|jjr||jjn|dSN)optsr# _run_scriptZcmdloopr!r r r rUszShellCommand.runcCs |jd|j_|jdSr6)baseZ_finalize_base _transaction fill_sackr9r r r _clean[s zShellCommand._cleanc Csh|r |dkrdS|dkrd}zt|}Wn|YdS0|jjjdd|jj|}|jdkrndS|j|jvrt |d|j|j|ddn|jj |j}|dur\||j}z|jj ||}Wnt yYdS0z&t|jj|j_||WnFtjjyX}z(ttd d t|WYd}~dSd}~00n|dS) N ZEOFrF)Z reset_usager rError: )shlexsplit_helpr" optparserrZparse_main_argsZcommandMAPPINGr1Z cli_commandsgetZparse_command_args SystemExitcopydeepcopyr.r5rr exceptionsErrorloggererrorrr)r!lineZs_liner7Zcmd_clsrer r r onecmd`s<   $    zShellCommand.onecmdNc Csdd}|rt|dkr&|ddS|d}t|dkrB|dnd}|d}|dkr|d|}||dd}|jj|}|D]}||||q|sttd |n||||jj dS) NcSsP|rt|||n:ztd|t|t|WnttdYn0dS)Nz{}: {}zUnsupported key value.)r3printr(r1strrMwarningr)keyvalconfr r r print_or_sets z*ShellCommand._config..print_or_setrrr?.zCould not find repository: %s) lenrDfindr:repos get_matchingrMrTrrW) r!argsrXrUrVZperiodZ repo_namer^rr r r _configs$     zShellCommand._configcCst|trt|dkr|dn|}d}|r|dkrBtd|}n|dkrZtd|}nv|dvrrtd|}n^|d krtd |}nF|d vrtd |}n.|d krtd|}n|dvrtd|}|s|jjtd}td|dS)zOutput 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 help)rrz{} 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 set)rrzy{} arg list: lists the contents of the transaction reset: reset (zero-out) the transaction run: run the transactionrz{} run the transaction)rrz{} exit the shellaShell 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>) isinstancelistr\rr(r"rE print_helprR)r!r`argmsgr r r rDsF"  zShellCommand._helpcCs|r |dnd}|dvr6|dd|ddn|dvr|jjj}d}|ddD]L}||}|r|t||d}qXtt d dt d |jj j |qX|r|j d|j_n |d dS) NrrcNz repolist rAr?)enabledisableFTr@zUnknown repo: '%s'r)rQjoinr"r:r^r_r1rMZcriticalroutputtermboldr<Z_compsrD)r!r`rr^r<rrr r r _repos$     zShellCommand._repoc CsNz|jj|jjjWn0tjjyH}zt|WYd}~n d}~00dSr6) r"r:rr.Z allow_erasingrrKZ DepsolveErrorrR)r!r`rPr r r _resolveszShellCommand._resolvec CszTt|d6}|}|D]}|ds||qWdn1sH0YWn8tyttd|jj j |t dYn0dS)Nrn#z!Error: Cannot open %s for readingr?)open readlinesr0rQIOErrorrMinforr:rkrlrmsysr)r!filefdlinesrOr r r r8s  . zShellCommand._run_scriptc Cs|r |dnd}|dkr$|dS||dvrZ|jjr|jj|jj}t|n||dkrz|jWnBt j j y}z&t t ddt|WYd}~nd}~00tt d|n |ddS) Nrresetrgrr@rAz Complete!r)r=rpr:r;rkZlist_transactionrMruZdo_transactionrrKrLrNrrrD)r!r`routrPr r r r; s" 0 zShellCommand._transactioncCs|dgdS)Nr)r;r!r`r r r _ts_run"szShellCommand._ts_runcCsttdtddS)Nz Leaving Shellr)rMrurrvrr|r r r _quit%szShellCommand._quit)N)N)N)N)N)N)N)rrr aliasesrr(rr)r*ZsummaryrFr staticmethodr,r5rr=rQrarDrorpr8r;r}r~r r r r r ,s8   &  ;    r )Zdnf.clirZdnf.i18nrrZdnf.utilrrrIZloggingrBrvZ getLoggerrMobjectrrrr r r r r s