a 2ha@sddlmZddlmZddlmZddlZddlZddlZddl Zddl Zddl Z ddl Z ddlZddlZe dZGdddejZGdd d ejZdS) )unicode_literals)_ _parse_specsNdnfcseZdZfddZZS)MultilineHelpFormattercs"d|vr|Stt|||S)N ) splitlinessuperr _split_lines)selftextwidth __class__9/usr/lib/python3.9/site-packages/dnf/cli/option_parser.pyr 'sz#MultilineHelpFormatter._split_lines)__name__ __module__ __qualname__r __classcell__rrrrr&srcseZdZdZd.fdd ZddZGdddejZGd d d ejZ Gd d d ej Z Gd ddejZ GdddejZ GdddejZGdddejZGdddejZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd/fd*d+ Zd0fd,d- ZZS)1 OptionParserz5ArgumentParser like class to do things the "yum way".Tcs>tt|jdtdd|_d|_||r:i|_t|_ dS)NF)add_helpformatter_class) r r__init__rcommand_positional_parser command_group_add_general_options _cmd_usageset _cmd_groups)r Z reset_usagerrrr/s zOptionParser.__init__cCs&|ttd|tddS)zOutput an error message, and exit the program. This method overrides standard argparser's error so that error output goes to the logger. :param msg: the error message to output zCommand line error: %sN) print_usageloggerZcriticalrsysexit)r msgrrrerror9szOptionParser.errorc@seZdZddZdS)zOptionParser._RepoCallbackcs@|dkr dndt||j}|fddtd|DdS)N --disablerepodisableenablec3s|]}|fVqdSNr).0xZ operationrr Hz6OptionParser._RepoCallback.__call__.. \s*[,\s]\s*)getattrdestextendresplit)r parser namespacevaluesopt_strlrr.r__call__Es z#OptionParser._RepoCallback.__call__Nrrrr<rrrr _RepoCallbackDsr>c@seZdZddZdS)z OptionParser._RepoCallbackEnablecCs$|j|ddft|d|dS)Nrr*Zreponame)repos_edappendsetattrr r7r8r9r:rrrr<Ksz)OptionParser._RepoCallbackEnable.__call__Nr=rrrr_RepoCallbackEnableJsrCcs$eZdZdZdZfddZZS)zOptionParser._SplitCallbackzN Split all strings in seq, at "," and whitespace. Returns a new list. r1cs@d}t|j|D](}|s|r6ttj|||||d}qdS)NTF)r5r6SPLITTERr r_SplitCallbackr<)r r7r8r9r:firstvalrrrr<Tsz$OptionParser._SplitCallback.__call__)rrr__doc__rDr<rrrrrrEOsrEc@seZdZdZddZdS)z%OptionParser._SplitExtendDictCallbackz[ Split string at "," or whitespace to (key, value). Extends dict with {key: value}.c Csbz|d\}}|r|stWn*tyHtd|}t||Yn0t||j}|||<dS)N,zbad format: %s)r6 ValueErrorrargparse ArgumentErrorr2r3) r r7r8r9r:keyrGr&Zdctrrrr<bs   z.OptionParser._SplitExtendDictCallback.__call__NrrrrHr<rrrr_SplitExtendDictCallback_srOc@seZdZdZddZdS)zOptionParser._SetoptsCallbackzY Parse setopts arguments and put them into main_ and repo_.c Cs|d}t|dkr*ttd|dSt|dkrJttd|dS|\}}|d}|dkr|d|} ||dd}t|dr|j} ni} | | i|g |t |d |j | n:t|d r|j } ni} | |g |t |d |j | dS) N=z'Setopt argument has multiple values: %sz Setopt argument has no value: %s.r! repo_setoptsZrepo_ main_setoptsZmain_) r6lenr#ZwarningrrfindhasattrrT setdefaultr@rAr3rU) r r7r8r9r:ZvalskvZperiodrepoZrepooptsZmainoptsrrrr<ps,       z&OptionParser._SetoptsCallback.__call__NrNrrrr_SetoptsCallbackmsr]c@seZdZddZdS)z'OptionParser.ParseSpecGroupFileCallbackcCst||dSr+rrBrrrr<sz0OptionParser.ParseSpecGroupFileCallback.__call__Nr=rrrrParseSpecGroupFileCallbacksr^cs$eZdZfddZddZZS)zOptionParser.PkgNarrowCallbackc si|_z"dD]}|||j|<||=q Wn8ty`}z td|jj|fWYd}~n d}~00g|d<ttj|j|i|dS)N)choicesdefaultz"%s() missing mandatory argument %sr`) pkgnarrowKeyError TypeErrorrrr rPkgNarrowCallbackr)r argskwargsrZerrrrs  z'OptionParser.PkgNarrowCallback.__init__cCsT|jd}|r |d|jdvr,|jd}n |d}t|||t||j|dS)N_actionrr_r`)r3rapoprA)r r7r8r9r:Z dest_actionZnarrowrrrr<s     z'OptionParser.PkgNarrowCallback.__call__)rrrrr<rrrrrrds rdc@seZdZddZdS)zOptionParser.ForceArchActioncCsd|_||_dS)NT)Z ignorearchZarchrBrrrr<sz%OptionParser.ForceArchAction.__call__Nr=rrrrForceArchActionsrjc Cs|tdjtjjd}|jdddddtdd |jd d d d dtdd|jddd dtdd|jdd dtdjtjjdd|jdtddd|jdddgdtdd|jd d!dd"td#d$|jd%d&g|jtd'd(d)|jd*d+g|jtd,d(d)|jd-dtd.d/|jd0dtd1d/|jd2dtd3d/|jd4d5g|jtd6d7|jd8d9d dtd:d|jd;dtd?d@|jdAd dtdBd| }|jdCdDd dEdtdFdG|jdHd!dEtdId@|jdJdKdLd dtdMd|jdNdOdPt ddQtdRdS|jdTdUdVdWdtdXt dY|jdZd dtd[d|jd\d]d dtd^d|jd_d`dt tdadb|jdcdddd tdejtjj ddf|jdgdtdhdidj|jdkdld dtdmd|jdnd dtdod|jdp|j dqgdrtdsdt| }|jdu|j dqgdrtdvdt|jdwdxdrdy|jgtdzd{| }|jd|d}d~d tddf|jdd}dd tddf|jdddgd|jtddd|jddgd|jtddd|jdi|j dtdd|jdd!ddtdd$|jdd!ddtdd$|jdddtdd|jddd tdd|jdddtdddd|jdddtdddd|jddddtdd|jddd d}tdd|jdddddtdd|jdddtdd|jdd tdd|jdd tdd|jdd tdd|jdd tdd|jdddg|jtdăd7|jddgd|jtdȃdf|jddgd|jtd̃df|jddgdϢgd|jtdуdҍ|jddtj|jttjjtdՃd֍|jddtjdٍdS)z0 Standard options known to all dnf subcommands. zGeneral {prog} options)progz-cz--configZconfig_file_pathNZ CONFIG_FILEzconfig file location)r3r`metavarhelpz-qz--quietquiet store_truezquiet operation)r3actionr`rmz-vz --verbosezverbose operation)rpr`rmz --versionzshow {prog} version and exitz --installrootzset install rootPATH)rmrlz--nodocs store_constZnodocsZtsflagszdo not install documentations)rpconstr3rmz --noplugins store_falseZpluginszdisable all plugins)rpr`r3rmz--enablepluginZ enablepluginzenable plugins by nameZPLUGIN)r3r`rprmrlz--disablepluginZ disablepluginzdisable plugins by namez --releaseverz:override the value of $releasever in config and repo files)r`rmz--releasever-majorz@override the value of $releasever_major in config and repo filesz--releasever-minorz@override the value of $releasever_minor in config and repo filesz--setoptZsetoptsz%set arbitrary config and repo options)r3r`rprmz --skip-brokenZ skip_brokenz.resolve depsolve problems by skipping packagesz-hz--helpz --help-cmdrmzshow command help)rpr3rmz--allowerasingz;allow erasing of installed packages to resolve dependenciesz-bz--bestZbestz8try the best available package versions in transactions.)rpr3r`rmz--nobestz2do not limit the transaction to the best candidatez-Cz --cacheonlyZ cacheonlyz2run entirely from system cache, don't update cachez-Rz --randomwaitZ sleeptimeZMINUTESzmaximum command wait time)r3typer`rlrmz-dz --debuglevelZ debuglevelZ DEBUG_LEVELzdebugging output level)r3rlr`rmruz --debugsolverz)dumps detailed solving results into filesz--showduplicatesZshowdupesfromreposz2show duplicates, in repos, in list/search commandsz-ez --errorlevelzerror output level)r`rurmz --obsoletesZ obsoleteszenables {prog}'s obsoletes processing logic for upgrade or display capabilities that the package obsoletes for info, list and repoquery)r`r3rprmz--rpmverbosityzdebugging output level for rpmZDEBUG_LEVEL_NAME)r`rmrlz-yz --assumeyesz*automatically answer yes for all questionsz --assumenoz)automatically answer no for all questionsz --enablerepor?ZREPOzTemporarily enable repositories for the purpose of the current dnf command. Accepts an id, a comma-separated list of ids, or a glob of ids. This option can be specified multiple times.)rpr3r`rlrmr(zTemporarily disable active repositories for the purpose of the current dnf command. Accepts an id, a comma-separated list of ids, or a glob of ids. This option can be specified multiple times, but is mutually exclusive with `--repo`.z--repoz--repoidr\zUenable just specific repositories by an id or a glob, can be specified multiple times)rlr3rpr`rmz--enableFZ set_enabledz>enable repos with config-manager command (automatically saves)z --disableZ set_disabledz?disable repos with config-manager command (automatically saves)z-xz --excludez --excludepkgsZ excludepkgsz exclude packages by name or globZPACKAGE)r`r3rprmrlz--disableexcludesz--disableexcludepkgsZdisable_excludeszdisable excludepkgsz{all, main, REPOID}z--repofrompathz REPO,PATHzolabel and path to an additional repository to use (same path as in a baseurl), can be specified multiple times.)r`rprlrmz--noautoremoveZclean_requirements_on_removez7disable removal of dependencies that are no longer usedz --nogpgcheckZgpgcheckz5disable gpg signature checking (if RPM policy allows)z--colorZcolorzcontrol whether color is used)r3r`rmz --refreshZfreshest_metadataz2set metadata as expired before running the command)r3rprmz-4Z ip_resolvezresolve to IPv4 addresses onlyZipv4)r3r`rmrprsz-6zresolve to IPv6 addresses onlyZipv6z --destdirz --downloaddirZdestdirz!set directory to copy packages toz--downloadonlyZ downloadonlyzonly download packagesz --transientZ persistenceZ transientz2Use a transient overlay which will reset on reboot)r3rprsr`rmz --commentZcommentzadd a comment to transactionz--bugfixz,Include bugfix relevant packages, in updates)rprmz --enhancementz1Include enhancement relevant packages, in updatesz --newpackagez0Include newpackage relevant packages, in updatesz --securityz.Include security relevant packages, in updatesz --advisoryz --advisoriesZadvisoryz=Include packages needed to fix the given advisory, in updatesz--bzz--bzsZbugzillaz7Include packages needed to fix the given BZ, in updatesz--cvez--cvesZcvesz8Include packages needed to fix the given CVE, in updatesz--sec-severityz --secseverity)ZCriticalZ ImportantZModerateZLowZseverityzDInclude security relevant packages matching the severity, in updates)r_r`r3rprmz --forcearchZARCHz Force the use of an architecture)rlr3rpr_rmcommand?)nargsrm)add_argument_grouprformatrutilZMAIN_PROG_UPPER add_argumentrEr]add_mutually_exclusive_groupint MAIN_PROGr>rOrKSUPPRESSrjsortedZrpmZ _BASEARCH_MAPkeys)r Z general_grpZ best_groupZ repo_groupZ enable_grouprrrrs                             z!OptionParser._add_general_optionscCsHtj|j}tj|jd}||jvrD||f|j|<|j|dS)z- store usage info about a single dnf command.rN)rZi18nZucdsummaryaliasesrr add)r cmdgrouprnamerrr_add_cmd_usagers  zOptionParser._add_cmd_usagecCs"t|D]}|||q dS)z store name & summary for dnf commands The stored information is used build usage information grouped by build-in & plugin commands. N)rr9r)r Zcli_cmdsrrrrr add_commandszszOptionParser.add_commandscCstdtdd}dtjj}dD]Z}||jvr2q"|d||7}t|jD]*}|j|\}}||krP|d||f7}qPq"|S)z- get the usage information to show the user. zList of Main Commands:zList of Plugin Commands:)mainZpluginz%s [options] COMMAND z %s z %-25s %s )rrr{rr rrr)r Zdescusagegrprrrrrr get_usages  zOptionParser.get_usagecCs~dtjj|jf|_|j|_tj|jdd|_ |j |j _ d|j j _ | d|j|_|j|j_|j|j_||jdS)Nz%s %sF)rz{} command-specific options)rr{r_basecmdrkr descriptionrKArgumentParserrr" _positionalstitleryrz capitalizercmd_add_argumentr|_commandZ set_argparserr rvrrr_add_command_optionss    z!OptionParser._add_command_optionscsLtfdd|Dr6tjjjg|Ri|Sjj|i|SdS)Ncsg|]}|djvqS)r) prefix_chars)r,argr rr r0z1OptionParser.cmd_add_argument..)allrurr|r)r rerfrrrrs zOptionParser.cmd_add_argumentc Cs^|D]T}z|dWqtyV}z(tjtd|t|fWYd}~qd}~00qdS)Nzutf-8zCannot encode argument '%s': %s)encodeUnicodeEncodeErrorr exceptionsZ ConfigErrorrstr)r rerrgrrr_check_encodingszOptionParser._check_encodingcCs||||\}}|Sr+)rparse_known_args)r rer8Z _unused_argsrrrparse_main_argss zOptionParser.parse_main_argscCs2||||\}}|j||}||_|jSr+)rrr parse_argsZopts)r rvrer8Z unused_argsrrrparse_command_argss  zOptionParser.parse_command_argsNcs,|jr|j|jj7_tt||dSr+)r_actionsr rr")r Zfile_rrrr"szOptionParser.print_usagecsb|rF|jr|jj|jkr"|||j|jj7_|j|jjn | |_ t t | dSr+)rrrrrr_action_groupsr@rrrr r print_helprrrrrs  zOptionParser.print_help)T)N)N)rrrrHrr'rKActionr>rC _AppendActionrErOr]r^rdrjrrrrrrrrrr"rrrrrrr,s.  I  r)Z __future__rZdnf.i18nrZdnf.utilrrKZdnf.exceptionsrZdnf.rpmZ dnf.yum.miscZloggingZos.pathosr5r$Z getLoggerr# HelpFormatterrrrrrrrs