Ñò ìÿÒXc@sdZddkZddkZddklZlZlZddklZl Z ddk l Z l Z l Z lZlZlZddklZlZlZddklZlZddklZlZlZlZlZlZlZdd kl Z dd k!l"Z"dd k#l$Z$dd k%l&Z&d Z'd„Z(d„Z)d„Z*defd„ƒYZ+de+fd„ƒYZ,de,fd„ƒYZ-de,fd„ƒYZ.de+fd„ƒYZ/defd„ƒYZ0de0e,fd„ƒYZ1de0fd „ƒYZ2d!e1fd"„ƒYZ3dS(#s) Base classes for all front-end plugins. iÿÿÿÿN(tlockt check_namet NameSpace(tPlugintis_production_mode(t create_paramtparse_param_spectParamtStrtFlagtPassword(tOutputtEntryt ListOfEntries(t_tngettext(tZeroArgumentErrortMaxArgumentErrort OverlapErrort RequiresRoott VersionErrortRequirementErrort OptionError(tInvocationError(t TYPE_ERROR(t API_VERSION(tversiontvalidation_rulecCs,t|tƒ pt‚t|ttƒ|S(N(thasattrt RULE_FLAGtAssertionErrortsetattrtTrue(tobj((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytrule*scCs#t|ƒot|ttƒtjS(N(tcallabletgetattrRtFalseR (R!((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytis_rule/scCs^d}xQ|D]I}t||ƒtjo|t||ƒ}q |t||ƒ}q W|S(sÑ Return the number of entries in an entry. This is primarly for the failed output parameter so we don't print empty values. We also use this to determine if a non-zero return value is needed. i(ttypetdictt entry_counttlen(tentryt num_entriestf((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR)3stHasParamcBs8eZdZeZdd„Zdd„Zdd„ZRS(s¢ Base class for plugins that have `Param` `NameSpace` attributes. Subclasses of `HasParam` will on one or more attributes store `NameSpace` instances containing zero or more `Param` instances. These parameters might describe, for example, the arguments and options a command takes, or the attributes an LDAP entry can include, or whatever else the subclass sees fit. Although the interface a subclass must implement is very simple, it must conform to a specific naming convention: if you want a namespace ``SubClass.foo``, you must define a ``Subclass.takes_foo`` attribute and a ``SubCLass.get_foo()`` method, and you may optionally define a ``SubClass.check_foo()`` method. A quick big-picture example =========================== Say you want the ``options`` instance attribute on your subclass to be a `Param` `NameSpace`... then according to the enforced naming convention, your subclass must define a ``takes_options`` attribute and a ``get_options()`` method. For example: >>> from ipalib import Str, Int >>> class Example(HasParam): ... ... options = None # This will be replaced with your namespace ... ... takes_options = (Str('one'), Int('two')) ... ... def get_options(self): ... return self._get_param_iterable('options') ... >>> eg = Example() The ``Example.takes_options`` attribute is a ``tuple`` defining the parameters you want your ``Example.options`` namespace to contain. Your ``Example.takes_options`` attribute will be accessed via `HasParam._get_param_iterable()`, which, among other things, enforces the ``('takes_' + name)`` naming convention. For example: >>> eg._get_param_iterable('options') (Str('one'), Int('two')) The ``Example.get_options()`` method simply returns ``Example.takes_options`` by calling `HasParam._get_param_iterable()`. Your ``Example.get_options()`` method will be called via `HasParam._filter_param_by_context()`, which, among other things, enforces the ``('get_' + name)`` naming convention. For example: >>> list(eg._filter_param_by_context('options')) [Str('one'), Int('two')] At this point, the ``eg.options`` instance attribute is still ``None``: >>> eg.options is None True `HasParam._create_param_namespace()` will create the ``eg.options`` namespace from the parameters yielded by `HasParam._filter_param_by_context()`. For example: >>> eg._create_param_namespace('options') >>> eg.options NameSpace(<2 members>, sort=False) >>> list(eg.options) # Like dict.__iter__() ['one', 'two'] Your subclass can optionally define a ``check_options()`` method to perform sanity checks. If it exists, the ``check_options()`` method is called by `HasParam._create_param_namespace()` with a single value, the `NameSpace` instance it created. For example: >>> class Example2(Example): ... ... def check_options(self, namespace): ... for param in namespace(): # Like dict.itervalues() ... if param.name == 'three': ... raise ValueError("I dislike the param 'three'") ... print ' ** Looks good! **' # Note output below ... >>> eg = Example2() >>> eg._create_param_namespace('options') ** Looks good! ** >>> eg.options NameSpace(<2 members>, sort=False) However, if we subclass again and add a `Param` named ``'three'``: >>> class Example3(Example2): ... ... takes_options = (Str('one'), Int('two'), Str('three')) ... >>> eg = Example3() >>> eg._create_param_namespace('options') Traceback (most recent call last): ... ValueError: I dislike the param 'three' >>> eg.options is None # eg.options was not set True The Devil and the details ========================= In the above example, ``takes_options`` is a ``tuple``, but it can also be a param spec (see `create_param()`), or a callable that returns an iterable containing one or more param spec. Regardless of how ``takes_options`` is defined, `HasParam._get_param_iterable()` will return a uniform iterable, conveniently hiding the details. The above example uses the simplest ``get_options()`` method possible, but you could instead implement a ``get_options()`` method that would, for example, produce (or withhold) certain parameters based on the whether certain plugins are loaded. Think of ``takes_options`` as declarative, a simple definition of *what* parameters should be included in the namespace. You should only implement a ``takes_options()`` method if a `Param` must reference attributes on your plugin instance (for example, for validation rules); you should not use a ``takes_options()`` method to filter the parameters or add any other procedural behaviour. On the other hand, think of the ``get_options()`` method as imperative, a procedure for *how* the parameters should be created and filtered. In the example above the *how* just returns the *what* unchanged, but arbitrary logic can be implemented in the ``get_options()`` method. For example, you might filter certain parameters from ``takes_options`` base on some criteria, or you might insert additional parameters provided by other plugins. The typical use case for using ``get_options()`` this way is to procedurally generate the arguments and options for all the CRUD commands operating on a specific LDAP object: the `Object` plugin defines the possible LDAP entry attributes (as `Param`), and then the CRUD commands intelligently build their ``args`` and ``options`` namespaces based on which attribute is the primary key. In this way new LDAP attributes (aka parameters) can be added to the single point of definition (the `Object` plugin), and all the corresponding CRUD commands pick up these new parameters without requiring modification. For an example of how this is done, see the `ipalib.crud.Create` base class. However, there is one type of filtering you should not implement in your ``get_options()`` method, because it's already provided at a higher level: you should not filter parameters based on the value of ``api.env.context`` nor (preferably) on any values in ``api.env``. `HasParam._filter_param_by_context()` already does this by calling `Param.use_in_context()` for each parameter. Although the base `Param.use_in_context()` implementation makes a decision solely on the value of ``api.env.context``, subclasses can override this with implementations that consider arbitrary ``api.env`` values. ttakescCs |d|}t||dƒ}t|ƒtjo|St|ttfƒo|fSt|ƒo|ƒS|djotƒStd|i ||fƒ‚dS(sà Return an iterable of params defined by the attribute named ``name``. A sequence of params can be defined one of three ways: as a ``tuple``; as a callable that returns an iterable; or as a param spec (a `Param` or ``str`` instance). This method returns a uniform iterable regardless of how the param sequence was defined. For example, when defined with a tuple: >>> class ByTuple(HasParam): ... takes_args = (Param('foo'), Param('bar')) ... >>> by_tuple = ByTuple() >>> list(by_tuple._get_param_iterable('args')) [Param('foo'), Param('bar')] Or you can define your param sequence with a callable when you need to reference attributes on your plugin instance (for validation rules, etc.). For example: >>> class ByCallable(HasParam): ... def takes_args(self): ... yield Param('foo', self.validate_foo) ... yield Param('bar', self.validate_bar) ... ... def validate_foo(self, _, value, **kw): ... if value != 'Foo': ... return _("must be 'Foo'") ... ... def validate_bar(self, _, value, **kw): ... if value != 'Bar': ... return _("must be 'Bar'") ... >>> by_callable = ByCallable() >>> list(by_callable._get_param_iterable('args')) [Param('foo', validate_foo), Param('bar', validate_bar)] Lastly, as a convenience for when a param sequence contains a single param, your defining attribute may a param spec (either a `Param` or an ``str`` instance). For example: >>> class BySpec(HasParam): ... takes_args = Param('foo') ... takes_options = 'bar?' ... >>> by_spec = BySpec() >>> list(by_spec._get_param_iterable('args')) [Param('foo')] >>> list(by_spec._get_param_iterable('options')) ['bar?'] For information on how an ``str`` param spec is interpreted, see the `create_param()` and `parse_param_spec()` functions in the `ipalib.parameters` module. Also see `HasParam._filter_param_by_context()`. Rs0%s.%s must be a tuple, callable, or spec; got %rN( R$tNoneR'ttuplet isinstanceRtstrR#t TypeErrortname(tselfR5tverbtsrc_nametsrc((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt_get_param_iterableâs;  ccst|d|ƒ}d|}t||ƒptd|i|fƒ‚nt||ƒ}t|ƒp td|i||fƒ‚nxx|ƒD]m}t|ƒ}|djp|i|ƒo>|dj o(t|dƒ ot i |d|ƒn|VqqWdS(sK Filter params on attribute named ``name`` by environment ``env``. For example: >>> from ipalib.config import Env >>> class Example(HasParam): ... ... takes_args = ( ... Str('foo_only', include=['foo']), ... Str('not_bar', exclude=['bar']), ... 'both', ... ) ... ... def get_args(self): ... return self._get_param_iterable('args') ... ... >>> eg = Example() >>> foo = Env(context='foo') >>> bar = Env(context='bar') >>> another = Env(context='another') >>> (foo.context, bar.context, another.context) (u'foo', u'bar', u'another') >>> list(eg._filter_param_by_context('args', foo)) [Str('foo_only', include=['foo']), Str('not_bar', exclude=['bar']), Str('both')] >>> list(eg._filter_param_by_context('args', bar)) [Str('both')] >>> list(eg._filter_param_by_context('args', another)) [Str('not_bar', exclude=['bar']), Str('both')] tenvtget_s%s.%s()s %s.%s must be a callable; got %rN( R$RtNotImplementedErrorR5R#R4RR0tuse_in_contexttobjectt __setattr__(R6R5R;tget_nametgettspectparam((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt_filter_param_by_context-s     cCstt|i||ƒdtƒ}t|ƒp5t|d|dƒ}t|ƒo||ƒq`nt|||ƒdS(Ntsorttcheck_(RRER%RR$R0R#R(R6R5R;t namespacetcheck((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt_create_param_namespaceds   N( t__name__t __module__t__doc__R%tNO_CLIR:R0RERJ(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR.Ds ™ K 7tCommandcBsâeZdZeZeƒZeƒZei dƒZ ei dƒZ ei dƒZ ei dƒZ d2ZeZei dƒZd3Zei dƒZeƒZeƒZd2ZedƒZd „Zd „Zd „Zd „Zd „Zd„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%d„Z&d„Z'd„Z(d„Z)d„Z*d„Z+d„Z,d„Z-d„Z.d„Z/d„Z0d „Z1d!„Z2d"„Z3d#„Z4d$„Z5d%„Z6d&„Z7d4Z8d5Z9d0„Z:d1„Z;RS(6sF A public IPA atomic operation. All plugins that subclass from `Command` will be automatically available as a CLI command and as an XML-RPC method. Plugins that subclass from Command are registered in the ``api.Command`` namespace. For example: >>> from ipalib import create_api >>> api = create_api() >>> class my_command(Command): ... pass ... >>> api.register(my_command) >>> api.finalize() >>> list(api.Command) ['my_command'] >>> api.Command.my_command # doctest:+ELLIPSIS ipalib.frontend.my_command() targstoptionstparamstparams_by_defaulttoutputtresultt output_paramss1Results are truncated, try a more specific searchcOs¾|iƒd|j}|o|it|dƒƒn|i||Ž}|id|idi|i|ƒƒ|i|i |ƒ|i |}|i |}|id|idi|i|ƒƒ|i i i od|jot|d>> class my_cmd(Command): ... takes_args = ('login',) ... takes_options=(Password('passwd'),) ... >>> c = my_cmd() >>> c.finalize() >>> list(c._repr_iter(login=u'Okay.', passwd=u'Private!')) ["u'Okay.'", "passwd=u'********'"] s%s=%rN(RPRBR5R0treprt safe_valueRQ(R6RRtargRqtoption((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR^Ñs   cOsþ|idj o[t|ƒ|ijoE|idjotd|iƒ‚ntd|id|iƒ‚nt|i|ƒƒ}t|ƒdjogt|i|ƒƒ}t |ƒi |ƒ}t|ƒdjot dt |ƒƒ‚n|i |ƒn|S(s4 Merge (args, options) into params. iR5tcounttnamesN(tmax_argsR0R*RR5RR(t_Command__options_2_paramst_Command__args_2_paramstsett intersectionRtsortedR_(R6RPRQRRtarg_kwR~((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR[ís&ccsÖt}xÉt|iƒƒD]µ\}}| pt‚t|ƒ|jo†|ioft}t|ƒ|djo3t||ƒtt fjo|i ||fVqÉ|i ||fVqÎ|i ||fVqPqWdS(Ni( R%t enumerateRPRR*t multivalueR R'tlistR1R5(R6RnR‚tiRv((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__args_2_paramsþs  4ccs‹x6|iD]+}||jo||i|ƒfVq q Wt|ƒi|iƒ}|idƒ|o"ttdƒd|iƒƒ‚ndS(NRsUnknown option: %(option)sRw(RRtpopR}t differencetinternal_optionstdiscardRR(R6RQR5t unused_keys((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__options_2_paramss   cOs%|i||Ž}t|i|ƒƒS(sK Creates a LDAP entry from attributes in args and options. (R[R(t_Command__attributes_2_entry(R6RPRQtkw((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytargs_options_2_entrysccsx†|iD]{}|i|iod||joW||}t|tƒo*|g}|D] }||qV~fVq…|||fVq q WdS(N(RRt attributeR2R1(R6RR5Rqt_[1]tv((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__attributes_2_entry s  *c s>t‡fd†|iDƒƒ}t|iˆƒƒ}||fS(s4 Split params into (args, options). c3s%x|]}ˆi|dƒVqWdS(N(RBR0(t.0R5(RR(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys -s (R1RPR(t_Command__params_2_options(R6RRRPRQ((RRs3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRf)sccs8x1|iD]&}||jo|||fVq q WdS(N(RQ(R6RRR5((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__params_2_options1s  c s t‡fd†|iƒDƒƒS(s§ Return a dictionary of values where values are decoded from CSV. For example: >>> class my_command(Command): ... takes_options = ( ... Param('flags', multivalue=True, csv=True), ... ) ... >>> c = my_command() >>> c.finalize() >>> c.split_csv(flags=u'public,replicated') {'flags': (u'public', u'replicated')} c3s5x.|]'\}}|ˆi|i|ƒfVqWdS(N(RRt split_csv(R“tkR‘(R6(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys Gs (R(t iteritems(R6R((R6s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR–6sc s t‡fd†|iƒDƒƒS(s½ Return a dictionary of normalized values. For example: >>> class my_command(Command): ... takes_options = ( ... Param('first', normalizer=lambda value: value.lower()), ... Param('last'), ... ) ... >>> c = my_command() >>> c.finalize() >>> c.normalize(first=u'JOHN', last=u'DOE') {'last': u'DOE', 'first': u'john'} c3s5x.|]'\}}|ˆi|i|ƒfVqWdS(N(RRRa(R“R—R‘(R6(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys \s (R(R˜(R6R((R6s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRaJsc s t‡fd†|iƒDƒƒS(s‡ Return a dictionary of values converted to correct type. >>> from ipalib import Int >>> class my_command(Command): ... takes_args = ( ... Int('one'), ... 'two', ... ) ... >>> c = my_command() >>> c.finalize() >>> c.convert(one=1, two=2) {'two': u'2', 'one': 1} c3s5x.|]'\}}|ˆi|i|ƒfVqWdS(N(RRRb(R“R—R‘(R6(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys ps (R(R˜(R6R((R6s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRb_scCs>x7|iƒD])}|i|idƒdjoq q q WdS(N(RRRBR5R0(R6RRD((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__convert_iterss cKshg}|iƒD]8}|i|jo"|ip |io||iqq~}t|i||ƒƒS(s› Return a dictionary of defaults for all missing required values. For example: >>> from ipalib import Str >>> class my_command(Command): ... takes_args = Str('color', default=u'Red') ... >>> c = my_command() >>> c.finalize() >>> c.get_default() {'color': u'Red'} >>> c.get_default(color=u'Yellow') {} (RRR5trequiredtautofillR(t_Command__get_default_iter(R6RRRpRR((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR`xsRcKs(t|i|g|ƒƒ}|i|ƒS(s< Return default value for parameter `name`. (R(RœRB(R6R5Rtdefault((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_default_ofŒsccsntƒ}xvt|iƒD]e}|i|jp|i|jo?|idjoqnx%|iiD]}|i|ƒqcWqqWxå|iƒD]×}d}t}|i|joh|i|jo!|||i|||i>> class user_add(Command): ... def execute(self, **kw): ... return self.api.Backend.ldap.add(**kw) ... s %s.execute()N(R=R5(R6RPR((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR´ñs cOs|iii|i||ŽS(sK Forward call over XML-RPC to this same command on server. (tBackendt xmlclientRµR5(R6RPR((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRµsc Cs«|idƒt|iƒdjp|idi ot|iƒ|_n d |_|idƒt|iƒƒt|iƒƒ}d„}tt |d|ƒdt ƒ|_ g}x¡|D]™}t|ƒ}xt|D]l}|i d joqÓn|i |i ijoqÓnyt||i|ƒƒ}WqÓtj oqÓXqÓW|i||ƒqºWt|dt ƒ|_t|iƒdt ƒ|_|idƒtt|ƒiƒd S( s‰ Finalize plugin initialization. This method creates the ``args``, ``options``, and ``params`` namespaces. This is not done in `Command.__init__` because subclasses (like `crud.Add`) might need to access other plugins loaded in self.api to determine what their custom `Command.get_args` and `Command.get_options` methods should yield. RPiiÿÿÿÿRQcSs@|io2|idjo|iS|idjodSdSdS(Niii(Ršt sortorderR R0(Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_keys tkeyRFRVN(RJR*RPR‚RzR0R1RQRRR%RRR R5R¡tmintindext ValueErrortinsertRSt _iter_outputRTtsuperROt _on_finalize(R6t params_nosortR¹RRR„tpostj((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÁs: (  "     ccsÐt|iƒtj o/td|itt|iƒ|ifƒ‚nx„t|iƒD]s\}}t|tƒot|ƒ}nt|tƒp2td|i|ttft|ƒ|fƒ‚n|VqUWdS(Ns&%s.has_output: need a %r; got a %r: %rs*%s.has_output[%d]: need a %r; got a %r: %r( R't has_outputR1R4R5RR2R3R (R6R„to((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR¿8s) ,ccs#x|idƒD] }|VqWdS(sM Iterate through parameters for ``Command.args`` namespace. This method gets called by `HasParam._create_param_namespace()`. Subclasses can override this to customize how the arguments are determined. For an example of why this can be useful, see the `ipalib.crud.Create` subclass. RPN(R:(R6Rv((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_argsFs cCs’t}t}x|ƒD]t}|o!|iotd|iƒ‚n|otd|iƒ‚n|ip t}n|io t}qqWdS(s{ Sanity test for args namespace. This method gets called by `HasParam._create_param_namespace()`. s$%s: required argument after optionals)%s: only final argument can be multivalueN(R%RšR½R5R R‚(R6RPtoptionalR‚Rv((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt check_argsSs    c csÓx|idƒD] }|VqWx­|iD]¢}t|ttfƒo†tddddtdƒdddd gƒVtd dd dtd ƒdddd gƒVtd dtd ƒddddd gƒVdSq)WdS(s' Iterate through parameters for ``Command.options`` namespace. This method gets called by `HasParam._create_param_namespace()`. For commands that return entries two special options are generated: --all makes the command retrieve/display all attributes --raw makes the command display attributes as they are stored Subclasses can override this to customize how the arguments are determined. For an example of why this can be useful, see the `ipalib.crud.Create` subclass. RQtalltcli_nametdocsJRetrieve and print all attributes from the server. Affects command output.texcludetwebuitflagst no_outputtrawsBPrint entries as stored on the server. Only affects output format.sversion?s@Client version. Used to determine if server will accept request.t no_optionN(R:RÅR2R R R RR(R6RwRÆ((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt get_optionsis*          c Csud|i}t|tƒp&td|tt|ƒ|fƒ‚nt|iƒ}t|ƒ}||jol||}|o#td|t|ƒ|fƒ‚n||}|o#td|t|ƒ|fƒ‚q×nx—|iƒD]‰}||i}|idjpt||iƒp/td||i|it|ƒ|fƒ‚nt |i ƒo|i ||ƒqäqäWdS(sY Validate the return value to make sure it meets the interface contract. s%s.validate_output()s%s: need a %r; got a %r: %rs%s: missing keys %r in %rs%s: unexpected keys %r in %rs%%s: output[%r]: need %r; got %r: %rN( R5R2R(R4R'R}RTR½RR0R#Re( R6RTtnicet expected_sett actual_settmissingtextraRÆRq((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRjŽs.      !  #)ccsqx"|idddƒD] }|VqW|idjodSx0|iƒD]"}d|ijoqGn|VqGWdS(NRVR7thasRÐ(R:RRR0RÏ(R6RD((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_output_params­s  c Os¹t|tƒpdSd}g}|iƒD]}||iq,~}|idtƒo|iddƒt} nt} |idtƒo d} ntd„|iƒDƒƒ} td„|iƒDƒƒ} xå|i D]Ú} |i | } d| i joq×n|| }| i ƒd jo|djo d }n8| i ƒd jo$t |ƒdjoq×qld }nt| t ƒo|i||| | | ƒq×t|ttfƒo|i||| | | ƒq×t| tƒo|i||| | | ƒq×t|tƒo|i||| | | ƒq×t|tƒo/| d jo|i|ƒq±|i|ƒq×t|tƒoq×t|tƒo(|i|d t|i | iƒƒq×q×W|S(s Generic output method. Prints values the output argument according to their type and self.output. Entry attributes are labeled and printed in the order specified in self.output_params. Attributes that aren't present in self.output_params are not printed unless the command was invokend with the --all option. Attribute labelling is disabled if the --raw option was given. Subclasses can override this method, if custom output is needed. NiRÊtdnRÑcss+x$|]}|it|iƒfVqWdS(N(R5RZtlabel(R“Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys Ós css%x|]}|i|ifVqWdS(N(R5RÏ(R“Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys Ôs t no_displayRxitfailedRWs%s %%d(R2R(RVR5RBR%R¾R R0RTRÏtlowerR)R t print_entriesR1RƒR t print_entryRZt print_summarytprint_indentedtbooltintt print_countRÌ(R6ttextuiRTRPRQtrvRRptordert print_alltlabelsRÏRÆtoutpRU((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytoutput_for_cli·sR *         ,R5t takes_argsRÊRÑtattrstaddattrtdelattrRRccsFx?|iƒD]1}|i|ijo |Vq h|id6Vq WdS(s; Get only options we want exported to JSON R5N(RÓR5tjson_only_presence_options(R6Rw((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_json_optionss   cs9t‡fd†ˆiDƒƒ}tˆiƒƒ|d<|S(Nc3s(x!|]}|tˆ|ƒfVqWdS(N(R$(R“ta(R6(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys s t takes_options(R(tjson_friendly_attributesRƒRó(R6t json_dict((R6s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__json__sN(sresult(snames takes_args(sallsrawRïRðsdelattrssetattrsversion(<RKRLRMR%tfinalize_earlyR1RõRîRt finalize_attrRPRQRRRSR0R!R RiRTRÅRVthas_output_paramsRˆRhRt msg_truncatedRmRsR^R[R|R{RŽRŒRfR”R–RaRbt_Command__convert_iterR`RžRœReRYRgR´RµRÁR¿RÇRÉRÓRjRÚRíRöRòRóRø(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyROpsf      '             (     2   %  F t LocalOrRemotecBs2eZdZeddedƒƒfZd„ZRS(s[ A command that is explicitly executed locally or remotely. This is for commands that makes sense to execute either locally or remotely to return a perhaps different result. The best example of this is the `ipalib.plugins.f_misc.env` plugin which returns the key/value pairs describing the configuration state: it can be sserver?RÌs,Forward to server instead of running locallycOs:|do|ii o|i||ŽS|i||ŽS(sw Dispatch to forward() or execute() based on ``server`` option. When running in a client context, this command is executed remotely if ``options['server']`` is true; otherwise it is executed locally. When running in a server context, this command is always executed locally and the value of ``options['server']`` is ignored. Rª(R;RdRµR´(R6RPRQ((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRg)s (RKRLRMR RRõRg(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRþs tLocalcBseZdZd„ZRS(s™ A command that is explicitly executed locally. This is for commands that makes sense to execute only locally such as the help command. cOs|i||ŽS(s. Dispatch to forward() onlly. (Rµ(R6RPRQ((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRg@s(RKRLRMRg(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÿ8stObjectcBs¤eZeZeidƒZeidƒZeidƒZeidƒZ eidƒZ eidƒZ d Z eƒZd„Zd„Zd„Zd „Zd „ZRS( tbackendtmethodst propertiesRRt primary_keytparams_minus_pkcCsgt|idƒdtddƒ|_t|idƒdtddƒ|_|idƒtd„|iƒƒ}t|ƒdjo0t d |i d i d „|Dƒƒfƒ‚nt|ƒdjo8|d |_ ttd „|iƒƒdtƒ|_ nd|_ |i|_ d|ijo0|i|iijo|ii|i|_ntt|ƒiƒdS(NtMethodRFt name_attrt attr_nametPropertyRRcSs|iS((R(Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt^sis)%s (Object) has multiple primary keys: %ss, cssx|]}|iVqWdS(N(R5(R“Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys cs icSs|i S((R(Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR isR¶(Rt_Object__get_attrsR%RRRJtfilterRRR*R½R5R]RRR0Rct backend_nameR¶RRÀRRÁ(R6tpkeys((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÁVs(!! $ (  &cgsŒt|ƒdjo)t|dttfƒ o|d}nt|ƒ}x=|iƒD]/}|i|jp ||joqUn|VqUWdS(sA Yield all Param whose name is not in ``names``. iiN(R*R2RR3t frozensetRRR5(R6RytminusRD((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt params_minusts.  cOstd|iƒ‚dS(s' Construct an LDAP DN. s %s.get_dn()N(R=R5(R6RPtkwargs((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_dn€sccsp||ijodS|i|}t|ƒtjpt‚x-|ƒD]"}|i|ijo |VqFqFWdS(N(RcR'RRtobj_nameR5(R6R5RHtplugin((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __get_attrs†s  ccsÔ|iiƒ}xŠ|idƒD]y}t|ƒtjo|idƒ}n!t|tƒpt‚|i }||jo|i |ƒi Vqt |ƒVqWd„}x(t |iƒd|ƒD]}|i Vq¾WdS(sR This method gets called by `HasParam._create_param_namespace()`. RRs?*+cSs.|iio|iidjodSdSdS(Niii(RDRšR R0(Rp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR¹žs  RºN(Rt __todict__R:R'R3trstripR2RRR5R†RDRRt itervalues(R6tpropsRCRºR¹tprop((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt get_paramss   N(RKRLR%RùRRúRRRRRRRR0R R1t takes_paramsRÁRRR R(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRGs    t AttributecBsƒeZdZeZeidƒZei dƒZ d„Z d„Z e e ƒZd„Ze eƒZd„Ze eƒZd„ZRS(sr Base class implementing the attribute-to-object association. `Attribute` plugins are associated with an `Object` plugin to group a common set of commands that operate on a common set of parameters. The association between attribute and object is done using a simple naming convention: the first part of the plugin class name (up to the first underscore) is the object name, and rest is the attribute name, as this table shows: =============== =========== ============== Class name Object name Attribute name =============== =========== ============== noun_verb noun verb user_add user add user_first_name user first_name =============== =========== ============== For example: >>> class user_add(Attribute): ... pass ... >>> instance = user_add() >>> instance.obj_name 'user' >>> instance.attr_name 'add' In practice the `Attribute` class is not used directly, but rather is only the base class for the `Method` and `Property` classes. Also see the `Object` class. sF^(?P[a-z][a-z0-9]+)_(?P[a-z][a-z0-9]+(?:_[a-z][a-z0-9]+)*)$t_Attribute__objcCsd|iit|ƒiƒ}|pt‚|idƒ|_|idƒ|_tt |ƒi ƒdS(NR!tattr( t NAME_REGEXtmatchR'RKRtgroupt_Attribute__obj_namet_Attribute__attr_nameRÀRt__init__(R6tm((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR&Ôs cCs|iS(N(R$(R6((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__get_obj_nameÛscCs|iS(N(R%(R6((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__get_attr_nameßscCs|iS(s} Returns the obj instance this attribute is associated with, or None if no association has been set. (R(R6((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __get_objãscCs-|ii|i|_tt|ƒiƒdS(N(RcRRRRÀRRÁ(R6((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÁës(RKRLRMR%RùtretcompileR!RRúRR&t_Attribute__get_obj_nametpropertyRt_Attribute__get_attr_nameRt_Attribute__get_objR!RÁ(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR¨s"        RcBs,eZdZeZeZd„Zd„ZRS(s" A command with an associated object. A `Method` plugin must have a corresponding `Object` plugin. The association between object and method is done through a simple naming convention: the first part of the method name (up to the first under score) is the object name, as the examples in this table show: ============= =========== ============== Method name Object name Attribute name ============= =========== ============== user_add user add noun_verb noun verb door_open_now door open_now ============= =========== ============== There are three different places a method can be accessed. For example, say you created a `Method` plugin and its corresponding `Object` plugin like this: >>> from ipalib import create_api >>> api = create_api() >>> class user_add(Method): ... def run(self): ... return dict(result='Added the user!') ... >>> class user(Object): ... pass ... >>> api.register(user_add) >>> api.register(user) >>> api.finalize() First, the ``user_add`` plugin can be accessed through the ``api.Method`` namespace: >>> list(api.Method) ['user_add'] >>> api.Method.user_add() # Will call user_add.run() {'result': 'Added the user!'} Second, because `Method` is a subclass of `Command`, the ``user_add`` plugin can also be accessed through the ``api.Command`` namespace: >>> list(api.Command) ['user_add'] >>> api.Command.user_add() # Will call user_add.run() {'result': 'Added the user!'} And third, ``user_add`` can be accessed as an attribute on the ``user`` `Object`: >>> list(api.Object) ['user'] >>> list(api.Object.user.methods) ['add'] >>> api.Object.user.methods.add() # Will call user_add.run() {'result': 'Added the user!'} The `Attribute` base class implements the naming convention for the attribute-to-object association. Also see the `Object` and the `Property` classes. cCstt|ƒiƒdS(N(RÀRR&(R6((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR&3sccs²x3|iiƒD]"}d|ijoqn|VqWxP|iƒD]B}|it|iiƒjo d|ijoqCn|VqCqCWx"|idddƒD] }|VqŸWdS(NRÐRVR7RÙ(R!RRRÏR5RƒR:(R6RD((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÚ6s   (RKRLRMR%textra_options_firsttextra_args_firstR&RÚ(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRðs ? R cBs;eZeZdZdZdZd„Zd„Z d„Z RS(cCs•tt|ƒiƒd|_tt|iƒdd„ƒƒ|_tt|i ƒdd„ƒƒ|_ t |i ƒ}|i |i |i|Ž|_dS(NRºcSs t|dƒS(RK(R$(R-((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR PscSs|dS(i((tkeyvalue((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR Ss(RÀR R&R0RÜR1Rt_Property__rules_itertrulest_Property__kw_iterRR(tklassRRD(R6R((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR&Js !!ccsUxN|iiD]@\}}}t||dƒdj o|t||ƒfVq q WdS(N(R7RR$R0(R6RºtkindR((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __kw_iterXs ccs}xvt|iƒD]e}|idƒoqnt|i|ƒ}t|ƒo)t||ƒ}t|ƒo |VquqqWdS(s Iterates through the attributes in this instance to retrieve the methods implementing validation rules. RN(tdirt __class__t startswithR$R&(R6R5t base_attrR ((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __rules_iter]s  N( RKRLRR7R0RR t normalizerR&R6R4(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR Ds  tUpdatercBs eZdZd„Zd„ZRS(sš An LDAP update with an associated object (always update). All plugins that subclass from `Updater` will be automatically available as a server update function. Plugins that subclass from Updater are registered in the ``api.Updater`` namespace. For example: >>> from ipalib import create_api >>> api = create_api() >>> class my(Object): ... pass ... >>> api.register(my) >>> class my_update(Updater): ... pass ... >>> api.register(my_update) >>> api.finalize() >>> list(api.Updater) ['my_update'] >>> api.Updater.my_update # doctest:+ELLIPSIS ipalib.frontend.my_update() cCstt|ƒiƒdS(N(RÀR@R&(R6((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR&…scKs |id|iƒ|i|S(Nsraw: %s(R\R5R´(R6RQ((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRmˆs (RKRLRMR&Rm(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR@ks (4RMR+tinspecttbaseRRRtplugableRRt parametersRRRRR R RTR R R ttextRRRoRRRRRRRRt constantsRtipapython.versionRt distutilsRRR"R&R)R.RORþRÿRRRR R@(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyts8  .4   ÿ-ÿÿ«aHT'