3 iภf<8ใ@sยddlmZmZmZddlZddlZddlZddlZddlm Z ddl m Z m Z ddl mZddlZedƒZedƒZdd „Zd d „Zd d „Zdd„Zdd„Zdd„Zdd„Zddd„Zdd„ZdS)้)ฺprint_functionฺdivisionฺabsolute_importN)ฺ SyncedStore)ฺ in_containerฺ make_utf8)ฺugettextzzWarning: A {attr} of "{download_value}" was recently set for this system by the entitlement server administrator. {advice}zGIf you'd like to overwrite the server side change please run: {command}csศd}xbˆjD]X}|jˆj|ƒrDd}ttdƒjt|ƒtˆjƒdƒq ttdƒjt|ƒtˆjƒdƒq W|dkrtdStdƒjtˆjƒd}d jˆjƒ}d jˆjd |}t|‡fd d „||ˆjddS)aš Uses the syspurposestore to add one or more values to a particular property. :param args: The parsed args from argparse, expected attributes are: prop_name: the string name of the property to add to values: A list of the values to add to the given property (could be anything json-serializable) :param syspurposestore: An SyspurposeStore object to manipulate :return: None FTzAdded "{value}" to {prop_name}.)ฺvalueฺ prop_namez=Not adding value "{value}" to {prop_name}; it already exists.Nz{attr} updated.)ฺattrฺzsyspurpose add-{name} )ฺnamecst‡‡fdd„ˆjDƒƒS)Nc3s |]}|ˆjˆjgƒkVqdS)N)ฺgetr )ฺ.0ฺx)ฺargsฺresฉ๚/usr/lib/python3.6/cli.py๚ =sz0add_command....)ฺallฺvalues)r)r)rrฺ=szadd_command..)ฺ expectationฺ success_msgฺcommandr ) rฺaddr ฺprintฺ_ฺformatrฺjoinฺ check_result)rฺsyspurposestoreZany_prop_addedr rZto_addrr)rrฺ add_command"s&      r#csธxbˆjD]X}|jˆj|ƒr...)rr)r)r)rrrZsz remove_command..)rrrr ) rฺremover rrrrr r!)rr"r rZ to_removerr)rrฺremove_commandDs "   r'cs\|jˆjˆjƒtdƒjtˆjƒtˆjƒd}t|‡fdd„|djˆjˆjdˆjddS) ap Uses the syspurposestore to set the prop_name to value. :param args: The parsed args from argparse, expected attributes are: prop_name: the string name of the property to set value: An object to set the property to (could be anything json-serializable) :param syspurposestore: An SyspurposeStore object to manipulate :return: None z{attr} set to "{val}".)r r$cs|jˆjƒˆjkS)N)rr r )r)rrrroszset_command..zsyspurpose set {name} "{val}")r r$)rrrr N)ฺsetr r rrrr!)rr"rr)rrฺ set_commandas   r)csL|jˆjƒtdƒjtˆjƒd}t|‡fdd„|djˆjdˆjddS) a. Uses the syspurposestore to unset (clear entirely) the prop_name. :param args: The parsed args from argparse, expected attributes are: prop_name: the string name of the property to unset (clear) :param syspurposestore: An SyspurposeStore object to manipulate :return: None z {attr} unset.)r cs|jˆjƒddggkS)Nr )rr )r)rrrr„szunset_command..zsyspurpose unset {name})r )rrrr N)ฺunsetr rrrr!)rr"rr)rrฺ unset_commandws   r+cs:|jƒ}|j‰‡fdd„ˆDƒ‰ttjˆddddƒ|S)z? :param args: :param syspurposestore: :return: csi|]}ˆ|rˆ||“qSrr)rฺkey)ฺcontentsrr๚ “sz!show_contents..้FT)ฺindentZ ensure_asciiZ sort_keys)ฺsyncฺresultrฺjsonฺdumps)rr"Z sync_resultr)r-rฺ show_contents‹s r5cCs,tjdtdƒtdƒd}|jdd}tjdd}|jd td ƒd d |jtd dtjdd}|jd tdƒd d |jtd dtjdd}|jdtdƒdd|jtd dtjdd}|jt d d|j dtdƒd}|jddtdƒdd|jdtdƒdd|jtd d|j dtdƒ|gd}|jddtdƒdd|j dtdƒd}|jddtdƒdd|jd td ƒdd d |jtd d|j d!td"ƒd} | jddtdƒdd| jd tdƒdd d | jtd d|j d#td$ƒ|gd} | jd%d&|j d'td(ƒ|gd} | jd%d&|j d)td*ƒ|gd} | jd+d&|j d,td-ƒ|gd} | jd+d&|j d.td/ƒ|gd} | jd+d&|j d0td1ƒ|gd}|jd2d&|j d3td4ƒ|gd}|jd2d&|j d5td6ƒ|gd}|jd7d&|j d8td9ƒ|gd}|jd7d&|j d:td;ƒd}|jt dd|S)d|}t|tjƒrptjrptjj|j dƒƒtjjdƒq(tjj|ƒtjjdƒq(Wytj j ƒtjj ƒWnt k rธYnXtj |ƒdS)z๋ Exit with a code and optional message(s). Saved a few lines of code. Note: this method was copied from subscription_manager, because syspurpose should be independent on subscription_manager module as much as possible. z%sฺutf8ฺ N)ฺtypeฺ isinstanceฺ ExceptionฺsixZ text_typeZPY2rJrKฺwriteฺencodeฺstdoutฺflushฺIOErrorฺexit)ฺcodeฺmsgsฺmsgrrrฺ system_exitys"    r_cCsh|r|jƒ|jƒ}ni}|r\||ƒ r\tj|d}||}ttjttj|||dƒdnt |ƒdS)N)r)r Zdownload_valueฺadvice)r]) r1Zget_cached_contentsฺ SP_ADVICErr_ฺosฺ EX_SOFTWARErฺSP_CONFLICT_MESSAGEr)r"rrrr r2r`r rrrr!—s  r!)N)Z __future__rrrr@rbrJrUZsyspurpose.filesrZsyspurpose.utilsrrZsyspurpose.i18nrrr3rdrar#r'r)r+r5rDrOr_r!rrrrฺs(  " <&