Ñò ìÿÒ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_rulecCst|ttƒ|S(N(tsetattrt RULE_FLAGtTrue(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(tselfR3tverbtsrc_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"thasattrtNotImplementedErrorR3R!R2RR.tuse_in_contexttobjectt __setattr__(R4R3R9tget_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_(RRDR#RR"R.R!R(R4R3R9t namespacetcheck((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt_create_param_namespaceds   N( t__name__t __module__t__doc__R#tNO_CLIR8R.RDRI(((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(RORAR3R.treprt safe_valueRP(R4RQtargRptoption((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. iR3tcounttnamesN(tmax_argsR.R(RR3RR&t_Command__options_2_paramst_Command__args_2_paramstsett intersectionRtsortedR^(R4RORPRQtarg_kwR}((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRZís&ccsÇt}xºt|iƒƒD]¦\}}t|ƒ|jo†|ioft}t|ƒ|djo3t||ƒttfjo|i ||fVqº|i ||fVq¿|i ||fVqPqWdS(Ni( R#t enumerateROR(t multivalueRR%tlistR/R3(R4RmRtiRu((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)sRv(RQtpopR|t differencetinternal_optionstdiscardRR(R4RPR3t 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. (RZR&t_Command__attributes_2_entry(R4RORPtkw((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(RQt attributeR0R/(R4RŒR3Rpt_[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(RAR.(t.0R3(RQ(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys -s (R/ROR&t_Command__params_2_options(R4RQRORP((RQs3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRe)sccs8x1|iD]&}||jo|||fVq q WdS(N(RP(R4RQR3((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(RQt split_csv(R’tkR(R4(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys Gs (R&t iteritems(R4RŒ((R4s3/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(RQR`(R’R–R(R4(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys \s (R&R—(R4RŒ((R4s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR`Jsc 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(RQRa(R’R–R(R4(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys ps (R&R—(R4RŒ((R4s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRa_scCs>x7|iƒD])}|i|idƒdjoq q q WdS(N(RQRAR3R.(R4RŒRC((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') {} (RQR3trequiredtautofillR&t_Command__get_default_iter(R4RŒRRoRQ((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›RA(R4R3RŒtdefault((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<R3(R4RORŒ((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´R3(R4RORŒ((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. ROiiÿÿÿÿRPcSs@|io2|idjo|iS|idjodSdSdS(Niii(R™t sortorderRŸR.(Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_keys tkeyRERUN(RIR(RORRyR.R/RPRR~R#RQRŸR3R tmintindext ValueErrortinsertRRt _iter_outputRStsuperRNt _on_finalize(R4t params_nosortR¸RQRƒ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_outputR/R2R3R€R0R1R (R4Rƒ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. RON(R8(R4Ru((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¼R3RR(R4ROtoptionalRRu((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. RPtalltcli_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(R8RÄR0R R R RR(R4RvRÅ((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( R3R0R&R2R%R|RSR¼R~R.R!Rd( R4RStnicet expected_sett actual_settmissingtextraRÅRp((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRiŽs.      !  #)ccsqx"|idddƒD] }|VqW|idjodSx0|iƒD]"}d|ijoqGn|VqGWdS(NRUR5thasRÏ(R8RQR.RÎ(R4RC((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(R3RYtlabel(R’Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys Ós css%x|]}|i|ifVqWdS(N(R3RÎ(R’Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys Ôs t no_displayRwitfailedRVs%s %%d(R0R&RUR3RAR#R½RR.RSRÎtlowerR'R t print_entriesR/R‚R t print_entryRYt print_summarytprint_indentedtbooltintt print_countRË(R4ttextuiRSRORPtrvRRotordert print_alltlabelsRÎRÅtoutpRT((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytoutput_for_cli·sR *         ,R3t takes_argsRÉRÐtattrstaddattrtdelattrRRccsFx?|iƒD]1}|i|ijo |Vq h|id6Vq WdS(s; Get only options we want exported to JSON R3N(RÒR3tjson_only_presence_options(R4Rv((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(R4(s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys s t takes_options(R&tjson_friendly_attributesR‚Rò(R4t json_dict((R4s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__json__sN(sresult(snames takes_args(sallsrawRîRïsdelattrssetattrsversion(<RJRKRLR#tfinalize_earlyR/RôRíRt finalize_attrRORPRQRRR.RRRhRSRÄRUthas_output_paramsR‡RgRt msg_truncatedRlRrR]RZR{RzRR‹ReR“R•R`Rat_Command__convert_iterR_RR›RdRXRfR³R´RÀR¾RÆRÈRÒRiRÙRìRõRñRòR÷(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRNpsf      '             (     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©(R9RcR´R³(R4RORP((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRf)s (RJRKRLR RRôRf(((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´(R4RORP((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRf@s(RJRKRLRf(((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 propertiesRQt 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(NtMethodREt name_attrt attr_nametPropertyRQcSs|iS((R(Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt^sis)%s (Object) has multiple primary keys: %ss, cssx|]}|iVqWdS(N(R3(R’Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pys cs icSs|i S((R(Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR isRµ(Rt_Object__get_attrsR#RRRItfilterRQR(R¼R3R\RRR.Rbt backend_nameRµRR¿RÿRÀ(R4tpkeys((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(R0RR1t frozensetRQR3(R4RxtminusRC((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<R3(R4ROtkwargs((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pytget_dn€sccsV||ijodS|i|}x-|ƒD]"}|i|ijo |Vq,q,WdS(N(Rbtobj_nameR3(R4R3RGtplugin((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __get_attrs†s  ccs½|iiƒ}xs|idƒD]b}t|ƒtjo|idƒ}n |i}||jo|i|ƒiVqt |ƒVqWd„}x(t |i ƒd|ƒD]}|iVq§WdS(sR This method gets called by `HasParam._create_param_namespace()`. RQs?*+cSs.|iio|iidjodSdSdS(Niii(RCR™RŸR.(Ro((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR¸žs  R¹N( Rt __todict__R8R%R1trstripR3R…RCRR~t itervalues(R4tpropsRBR¹R¸tprop((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt get_paramss   N(RJRKR#RøRRùRRRRQRRR.R R/t takes_paramsRÀRRR R(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÿGs    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__objcCsV|iit|ƒiƒ}|idƒ|_|idƒ|_tt|ƒi ƒdS(NRtattr( t NAME_REGEXtmatchR%RJtgroupt_Attribute__obj_namet_Attribute__attr_nameR¿Rt__init__(R4tm((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR%ÔscCs|iS(N(R#(R4((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt__get_obj_nameÛscCs|iS(N(R$(R4((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(R4((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __get_objãscCs-|ii|i|_tt|ƒiƒdS(N(RbRÿRRR¿RRÀ(R4((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÀës(RJRKRLR#RøtretcompileR RRùRR%t_Attribute__get_obj_nametpropertyRt_Attribute__get_attr_nameRt_Attribute__get_objRRÀ(((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%(R4((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ÏRUR5RØ(RRQRÎR3R‚R8(R4RC((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRÙ6s   (RJRKRLR#textra_options_firsttextra_args_firstR%RÙ(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRðs ? RcBs;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(RJ(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¿RR%R.RÛR/R~t_Property__rules_itertrulest_Property__kw_iterRR&tklassRRC(R4RŒ((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR%Js !!ccsUxN|iiD]@\}}}t||dƒdj o|t||ƒfVq q WdS(N(R6RR"R.(R4R¹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$(R4R3t base_attrR((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyt __rules_iter]s  N( RJRKRR6R.RœRŸt normalizerR%R5R3(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRDs  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%(R4((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR%…scKs |id|iƒ|i|S(Nsraw: %s(R[R3R³(R4RP((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyRlˆs (RJRKRLR%Rl(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyR?ks (4RLR*tinspecttbaseRRRtplugableRRt parametersRRRRR R RSR R R ttextRRRnRRRRRRRRt constantsRtipapython.versionRt distutilsRRR R$R'R,RNRýRþRÿRRRR?(((s3/usr/lib/python2.6/site-packages/ipalib/frontend.pyts8  .4   ÿ-ÿÿ«aHT'