3 ft`4]@sddlmZddlmZddlmZddlZddlZddlZddl Zddl Zddl Z ddl Z ddlZddlZe jdZGdddejZGdd d ejZdS) )unicode_literals)_) _parse_specsNdnfcseZdZfddZZS)MultilineHelpFormattercs"d|kr|jStt|j||S)N ) splitlinessuperr _split_lines)selftextwidth) __class__#/usr/lib/python3.6/option_parser.pyr 'sz#MultilineHelpFormatter._split_lines)__name__ __module__ __qualname__r __classcell__rr)rrr&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|_|j|r:i|_t|_ dS)NF)add_helpZformatter_class) r r__init__rcommand_positional_parser command_group_add_general_options _cmd_usageset _cmd_groups)r Z reset_usage)rrrr/s zOptionParser.__init__cCs&|jtjtd|tjddS)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}|jfddtjd|DdS)Nz --disablerepodisableenablec3s|]}|fVqdS)Nr).0x) operationrr Hsz6OptionParser._RepoCallback.__call__..z \s*[,\s]\s*)getattrdestextendresplit)r parser namespacevaluesopt_strlr)r)r__call__Es z#OptionParser._RepoCallback.__call__N)rrrr5rrrr _RepoCallbackDsr6c@seZdZddZdS)z OptionParser._RepoCallbackEnablecCs$|jj|ddft|d|dS)Nrr&Zreponame)repos_edappendsetattr)r r0r1r2r3rrrr5Ksz)OptionParser._RepoCallbackEnable.__call__N)rrrr5rrrr_RepoCallbackEnableJsr:cs$eZdZdZdZfddZZS)zOptionParser._SplitCallbackzN Split all strings in seq, at "," and whitespace. Returns a new list. z \s*[,\s]\s*csDd}x:tj|j|D](}|s |r8ttj|j||||d}qWdS)NTF)r.r/SPLITTERr r_SplitCallbackr5)r r0r1r2r3firstval)rrrr5Ts z$OptionParser._SplitCallback.__call__)rrr__doc__r;r5rrr)rrr<Osr<c@seZdZdZddZdS)z%OptionParser._SplitExtendDictCallbackz[ Split string at "," or whitespace to (key, value). Extends dict with {key: value}.c Cshy"|jd\}}| s| r tWn,tk rNtd|}tj||YnXt||j}|||<dS)N,zbad format: %s)r/ ValueErrorrargparseZ ArgumentErrorr+r,) r r0r1r2r3keyr>r#Zdctrrrr5bs   z.OptionParser._SplitExtendDictCallback.__call__N)rrrr?r5rrrr_SplitExtendDictCallback_srDc@seZdZdZddZdS)zOptionParser._SetoptsCallbackzY Parse setopts arguments and put them into main_ and repo_.c Cs|jd}t|dkr*tjtd|dSt|dkrJtjtd|dS|\}}|jd}|d kr|d|} ||dd}t|dr|j} ni} | j| ij|gj |t |d|j | n:t|d r|j } ni} | j|gj |t |d |j | dS) N=z'Setopt argument has multiple values: %sz Setopt argument has no value: %s.r repo_setoptsZrepo_ main_setoptsZmain_) r/lenr ZwarningrrfindhasattrrH setdefaultr8r9r,rI) r r0r1r2r3valskvZperiodrepoZrepooptsZmainoptsrrrr5ps,       z&OptionParser._SetoptsCallback.__call__N)rrrr?r5rrrr_SetoptsCallbackmsrSc@seZdZddZdS)z'OptionParser.ParseSpecGroupFileCallbackcCst||dS)N)r)r r0r1r2r3rrrr5sz0OptionParser.ParseSpecGroupFileCallback.__call__N)rrrr5rrrrParseSpecGroupFileCallbacksrTcs$eZdZfddZddZZS)zOptionParser.PkgNarrowCallbackcsi|_y&x dD]}|||j|<||=qWWn6tk rb}ztd|jj|fWYdd}~XnXg|d<ttj|j||dS)Nchoicesdefaultz"%s() missing mandatory argument %s)rUrV) pkgnarrowKeyError TypeErrorrrr rPkgNarrowCallbackr)r argskwargsrPe)rrrrs "z'OptionParser.PkgNarrowCallback.__init__cCsV|jd}| s"|d|jdkr.|jd}n |jd}t|||t||j|dS)NZ_actionrrUrV)r,rWpopr9)r r0r1r2r3Z dest_actionZnarrowrrrr5s     z'OptionParser.PkgNarrowCallback.__call__)rrrrr5rrr)rrrZs rZc@seZdZddZdS)zOptionParser.ForceArchActioncCsd|_||_dS)NT)Z ignorearchZarch)r r0r1r2r3rrrr5sz%OptionParser.ForceArchAction.__call__N)rrrr5rrrrForceArchActionsr_c Cs|jtdjtjjd}|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/|jd0d1g|jtd2d3|jd4d5d dtd6d|jd7d8d9d d:td;d<|jd=d dtd>d|j }|jd?d@d dAdtdBdC|jdDd!dAtdEd<|jdFdGdHd dtdId|jdJdKdLt ddMtdNdO|jdPdQdRdSdtdTt dU|jdVd dtdWd|jdXdYd dtdZd|jd[d\dt td]d^|jd_dd`d tdajtjj ddb|jdcdtdddedf|jdgdhd dtdid|jdjd dtdkd|jdl|j dmgdntdodp|j }|jdq|j dmgdntdrdp|jdsdtdndu|jgtdvdw|j }|jdxdydzd td{db|jd|dyd}d td~db|jdddgd|jtddd|jddgd|jtddnd|jdi|j dtdd|jdd!ddtdd$|jdd!ddtdd$|jdddtdd|jddd tdd|jdddtdddd|jdddtdddd|jddddtdd|jddd dytdd|jdddtdd|jdd tdd|jdd tdd|jdd tdd|jdd tdd|jdddg|jtdd3|jddgd|jtddb|jddgd|jtdƒdb|jddddddggd|jtdʃdˍ|jddtj|jttjjjtd΃dύ|jddtjdҍdS)z0 Standard options known to all dnf subcommands. zGeneral {prog} options)progz-cz--configZconfig_file_pathNz [config file]zconfig file location)r,rVmetavarhelpz-qz--quietquiet store_truezquiet operation)r,actionrVrbz-vz --verbosezverbose operation)rerVrbz --versionzshow {prog} version and exitz --installrootzset install rootz[path])rbraz--nodocs store_constZnodocsZtsflagszdo not install documentations)reconstr,rbz --nopluginsZ store_falseZpluginszdisable all plugins)rerVr,rbz--enablepluginZ enablepluginzenable plugins by namez[plugin])r,rVrerbraz--disablepluginZ disablepluginzdisable plugins by namez --releaseverz:override the value of $releasever in config and repo files)rVrbz--setoptZsetoptsz%set arbitrary config and repo options)r,rVrerbz --skip-brokenZ skip_brokenz.resolve depsolve problems by skipping packagesz-hz--helpz --help-cmdrbzshow command help)rer,rbz--allowerasingz;allow erasing of installed packages to resolve dependenciesz-bz--bestZbestz8try the best available package versions in transactions.)rer,rVrbz--nobestz2do not limit the transaction to the best candidatez-Cz --cacheonlyZ cacheonlyz2run entirely from system cache, don't update cachez-Rz --randomwaitZ sleeptimez [minutes]zmaximum command wait time)r,typerVrarbz-dz --debuglevelZ debuglevelz [debug level]zdebugging output level)r,rarVrbrhz --debugsolverz)dumps detailed solving results into filesz--showduplicatesZshowdupesfromreposz2show duplicates, in repos, in list/search commandsz-ez --errorlevelzerror output level)rVrhrbz --obsoletesZ obsoleteszenables {prog}'s obsoletes processing logic for upgrade or display capabilities that the package obsoletes for info, list and repoquery)rVr,rerbz--rpmverbosityzdebugging output level for rpmz[debug level name])rVrbraz-yz --assumeyesz*automatically answer yes for all questionsz --assumenoz)automatically answer no for all questionsz --enablerepor7z[repo]z]Enable additional repositories. List option. Supports globs, can be specified multiple times.)rer,rVrarbz --disablerepozSDisable repositories. List option. Supports globs, can be specified multiple times.z--repoz--repoidrRzUenable just specific repositories by an id or a glob, can be specified multiple times)rar,rerVrbz--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 globz [package])rVr,rerbraz--disableexcludesz--disableexcludepkgsZdisable_excludeszdisable excludepkgsz--repofrompathz [repo,path]zolabel and path to an additional repository to use (same path as in a baseurl), can be specified multiple times.)rVrerarbz--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)r,rVrbz --refreshZfreshest_metadataz2set metadata as expired before running the command)r,rerbz-4Z ip_resolvezresolve to IPv4 addresses onlyZipv4)r,rVrbrergz-6zresolve to IPv6 addresses onlyZipv6z --destdirz --downloaddirZdestdirz!set directory to copy packages toz--downloadonlyZ downloadonlyzonly download packagesz --commentZcommentzadd a comment to transactionz--bugfixz,Include bugfix relevant packages, in updates)rerbz --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 --secseverityZCriticalZ ImportantZModerateZLowZseverityzDInclude security relevant packages matching the severity, in updates)rUrVr,rerbz --forcearchZARCHz Force the use of an architecture)rar,rerUrbcommand?)nargsrb)add_argument_grouprformatrutilZMAIN_PROG_UPPER add_argumentr<rSZadd_mutually_exclusive_groupint MAIN_PROGr6rDrBZSUPPRESSr_sortedZrpmZ _BASEARCH_MAPkeys)r Z general_grpZ best_groupZ repo_groupZ enable_grouprrrrs:                                                                     z!OptionParser._add_general_optionscCsHtjj|j}tjj|jd}||jkrD||f|j|<|jj|dS)z- store usage info about a single dnf command.rN)rZi18nZucdsummaryaliasesrradd)r cmdgrouprtnamerrr_add_cmd_usageds  zOptionParser._add_cmd_usagecCs&x t|jD]}|j||qWdS)z store name & summary for dnf commands The stored information is used build usage information grouped by build-in & plugin commands. N)rr2rz)r Zcli_cmdsrxrwrrr add_commandslszOptionParser.add_commandscCstdtdd}dtjj}xfd D]^}||jkr4q$|d||7}xsz1OptionParser.cmd_add_argument..)allrhrror)r r[r\r)r rrszOptionParser.cmd_add_argumentcCs`xZ|D]R}y|jdWqtk rV}z"tjjtd|t|fWYdd}~XqXqWdS)Nzutf-8zCannot encode argument '%s': %s)encodeUnicodeEncodeErrorr exceptionsZ ConfigErrorrstr)r r[rr]rrr_check_encodings  zOptionParser._check_encodingcCs|j||j|\}}|S)N)rparse_known_args)r r[r1Z _unused_argsrrrparse_main_argss zOptionParser.parse_main_argscCs2|j||j|\}}|jj||}||_|jS)N)rrr parse_argsZopts)r rir[r1Z unused_argsrrrparse_command_argss  zOptionParser.parse_command_argsNcs,|jr|j|jj7_tt|j|dS)N)r_actionsr rr)r Zfile_)rrrrszOptionParser.print_usagecsd|rH|j s|jj|jkr$|j||j|jj7_|jj|jjn |j |_ t t |j dS)N)rrrrrrZ_action_groupsr8rrr~r r print_help)r ri)rrrrs  zOptionParser.print_help)T)N)N)rrrr?rr$rBZActionr6r:Z _AppendActionr<rDrSrTrZr_rrzr{rrrrrrrrrrr)rrr,s.  ;  r)Z __future__rZdnf.i18nrZdnf.utilrrBZdnf.exceptionsrZdnf.rpmZ dnf.yum.miscZloggingZos.pathosr.r!Z getLoggerr Z HelpFormatterrrrrrrrs