Generate same API.txt under Python 2 and 3

Use Python 3's reprlib with customizations to create same API.txt under
Python 2 and 3. Some plugins have been slightly altered to use stable
sorting for dynamically created parameter lists.

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Christian Heimes
2018-02-14 16:59:50 +01:00
parent 86a6fdcc43
commit 8ffa33c24e
8 changed files with 111 additions and 60 deletions

View File

@@ -2973,7 +2973,7 @@ option: Int('ipabaserid?', cli_name='rid_base')
option: Int('ipaidrangesize', cli_name='range_size') option: Int('ipaidrangesize', cli_name='range_size')
option: Str('ipanttrusteddomainname?', cli_name='dom_name') option: Str('ipanttrusteddomainname?', cli_name='dom_name')
option: Str('ipanttrusteddomainsid?', cli_name='dom_sid') option: Str('ipanttrusteddomainsid?', cli_name='dom_sid')
option: StrEnum('iparangetype?', cli_name='type', values=[u'ipa-ad-trust-posix', u'ipa-ad-trust', u'ipa-local']) option: StrEnum('iparangetype?', cli_name='type', values=[u'ipa-ad-trust', u'ipa-ad-trust-posix', u'ipa-local'])
option: Int('ipasecondarybaserid?', cli_name='secondary_rid_base') option: Int('ipasecondarybaserid?', cli_name='secondary_rid_base')
option: Flag('raw', autofill=True, cli_name='raw', default=False) option: Flag('raw', autofill=True, cli_name='raw', default=False)
option: Str('setattr*', cli_name='setattr') option: Str('setattr*', cli_name='setattr')
@@ -2998,7 +2998,7 @@ option: Int('ipabaseid?', autofill=False, cli_name='base_id')
option: Int('ipabaserid?', autofill=False, cli_name='rid_base') option: Int('ipabaserid?', autofill=False, cli_name='rid_base')
option: Int('ipaidrangesize?', autofill=False, cli_name='range_size') option: Int('ipaidrangesize?', autofill=False, cli_name='range_size')
option: Str('ipanttrusteddomainsid?', autofill=False, cli_name='dom_sid') option: Str('ipanttrusteddomainsid?', autofill=False, cli_name='dom_sid')
option: StrEnum('iparangetype?', autofill=False, cli_name='type', values=[u'ipa-ad-trust-posix', u'ipa-ad-trust', u'ipa-local']) option: StrEnum('iparangetype?', autofill=False, cli_name='type', values=[u'ipa-ad-trust', u'ipa-ad-trust-posix', u'ipa-local'])
option: Int('ipasecondarybaserid?', autofill=False, cli_name='secondary_rid_base') option: Int('ipasecondarybaserid?', autofill=False, cli_name='secondary_rid_base')
option: Flag('pkey_only?', autofill=True, default=False) option: Flag('pkey_only?', autofill=True, default=False)
option: Flag('raw', autofill=True, cli_name='raw', default=False) option: Flag('raw', autofill=True, cli_name='raw', default=False)
@@ -3255,7 +3255,7 @@ option: Str('groupignoreobjectclass*', autofill=True, cli_name='group_ignore_obj
option: Str('groupobjectclass+', autofill=True, cli_name='group_objectclass', default=[u'groupOfUniqueNames', u'groupOfNames']) option: Str('groupobjectclass+', autofill=True, cli_name='group_objectclass', default=[u'groupOfUniqueNames', u'groupOfNames'])
option: Flag('groupoverwritegid', autofill=True, cli_name='group_overwrite_gid', default=False) option: Flag('groupoverwritegid', autofill=True, cli_name='group_overwrite_gid', default=False)
option: StrEnum('schema?', autofill=True, cli_name='schema', default=u'RFC2307bis', values=[u'RFC2307bis', u'RFC2307']) option: StrEnum('schema?', autofill=True, cli_name='schema', default=u'RFC2307bis', values=[u'RFC2307bis', u'RFC2307'])
option: StrEnum('scope', autofill=True, cli_name='scope', default=u'onelevel', values=[u'base', u'subtree', u'onelevel']) option: StrEnum('scope', autofill=True, cli_name='scope', default=u'onelevel', values=[u'base', u'onelevel', u'subtree'])
option: Bool('use_def_group?', autofill=True, cli_name='use_default_group', default=True) option: Bool('use_def_group?', autofill=True, cli_name='use_default_group', default=True)
option: DNParam('usercontainer', autofill=True, cli_name='user_container', default=ipapython.dn.DN('ou=people')) option: DNParam('usercontainer', autofill=True, cli_name='user_container', default=ipapython.dn.DN('ou=people'))
option: Str('userignoreattribute*', autofill=True, cli_name='user_ignore_attribute', default=[]) option: Str('userignoreattribute*', autofill=True, cli_name='user_ignore_attribute', default=[])
@@ -5721,7 +5721,7 @@ option: Int('base_id?', cli_name='base_id')
option: Bool('bidirectional?', cli_name='two_way', default=False) option: Bool('bidirectional?', cli_name='two_way', default=False)
option: Bool('external?', cli_name='external', default=False) option: Bool('external?', cli_name='external', default=False)
option: Int('range_size?', cli_name='range_size') option: Int('range_size?', cli_name='range_size')
option: StrEnum('range_type?', cli_name='range_type', values=[u'ipa-ad-trust-posix', u'ipa-ad-trust']) option: StrEnum('range_type?', cli_name='range_type', values=[u'ipa-ad-trust', u'ipa-ad-trust-posix'])
option: Flag('raw', autofill=True, cli_name='raw', default=False) option: Flag('raw', autofill=True, cli_name='raw', default=False)
option: Str('realm_admin?', cli_name='admin') option: Str('realm_admin?', cli_name='admin')
option: Password('realm_passwd?', cli_name='password', confirm=False) option: Password('realm_passwd?', cli_name='password', confirm=False)

View File

@@ -25,6 +25,7 @@ import six
from ipalib.plugable import ReadOnly, lock from ipalib.plugable import ReadOnly, lock
from ipalib.capabilities import client_has_capability from ipalib.capabilities import client_has_capability
from ipalib.text import _ from ipalib.text import _
from ipalib.util import apirepr
if six.PY3: if six.PY3:
unicode = str unicode = str
@@ -98,7 +99,7 @@ class Output(ReadOnly):
if not value: if not value:
continue continue
if isinstance(value, tuple): if isinstance(value, tuple):
value = repr(list(value)) value = apirepr(list(value))
else: else:
value = repr(value) value = repr(value)
yield '%s=%s' % (key, value) yield '%s=%s' % (key, value)

View File

@@ -123,7 +123,7 @@ from ipalib.text import Gettext, FixMe
from ipalib.util import json_serialize, validate_idna_domain from ipalib.util import json_serialize, validate_idna_domain
from ipalib.x509 import ( from ipalib.x509 import (
load_der_x509_certificate, IPACertificate, default_backend) load_der_x509_certificate, IPACertificate, default_backend)
from ipalib.util import strip_csr_header from ipalib.util import strip_csr_header, apirepr
from ipapython import kerberos from ipapython import kerberos
from ipapython.dn import DN from ipapython.dn import DN
from ipapython.dnsutil import DNSName from ipapython.dnsutil import DNSName
@@ -600,9 +600,12 @@ class Param(ReadOnly):
elif isinstance(value, six.integer_types): elif isinstance(value, six.integer_types):
value = str(value) value = str(value)
elif isinstance(value, (tuple, set, frozenset)): elif isinstance(value, (tuple, set, frozenset)):
value = repr(list(value)) value = apirepr(list(value))
else: elif key == 'cli_name':
# always represented as native string
value = repr(value) value = repr(value)
else:
value = apirepr(value)
yield '%s=%s' % (key, value) yield '%s=%s' % (key, value)
def __call__(self, value, **kw): def __call__(self, value, **kw):

View File

@@ -66,6 +66,11 @@ from ipapython.dnsutil import DNSName
from ipapython.dnsutil import resolve_ip_addresses from ipapython.dnsutil import resolve_ip_addresses
from ipapython.admintool import ScriptError from ipapython.admintool import ScriptError
if sys.version_info >= (3, 2):
import reprlib # pylint: disable=import-error
else:
reprlib = None
if six.PY3: if six.PY3:
unicode = str unicode = str
@@ -1213,3 +1218,36 @@ def open_in_pager(data):
pager_process.communicate() pager_process.communicate()
except IOError: except IOError:
pass pass
if reprlib is not None:
class APIRepr(reprlib.Repr):
builtin_types = {
bool, int, float,
str, bytes,
dict, tuple, list, set, frozenset,
type(None),
}
def __init__(self):
super(APIRepr, self).__init__()
# no limitation
for k, v in self.__dict__.items():
if isinstance(v, int):
setattr(self, k, sys.maxsize)
def repr_str(self, x, level):
"""Output with u'' prefix"""
return 'u' + repr(x)
def repr_type(self, x, level):
if x is str:
return "<type 'unicode'>"
if x in self.builtin_types:
return "<type '{}'>".format(x.__name__)
else:
return repr(x)
apirepr = APIRepr().repr
else:
apirepr = repr

View File

@@ -239,18 +239,19 @@ class idrange(LDAPObject):
cli_name='dom_name', cli_name='dom_name',
flags=('no_search', 'virtual_attribute', 'no_update'), flags=('no_search', 'virtual_attribute', 'no_update'),
label=_('Name of the trusted domain'), label=_('Name of the trusted domain'),
), ),
StrEnum('iparangetype?', StrEnum('iparangetype?',
label=_('Range type'), label=_('Range type'),
cli_name='type', cli_name='type',
doc=(_('ID range type, one of {vals}' doc=(_('ID range type, one of {vals}'
.format(vals=', '.join(range_types.keys())))), .format(vals=', '.join(sorted(range_types))))),
values=tuple(range_types.keys()), values=sorted(range_types),
flags=['no_update'], flags=['no_update'],
) )
) )
def handle_iparangetype(self, entry_attrs, options, keep_objectclass=False): def handle_iparangetype(self, entry_attrs, options,
keep_objectclass=False):
if not any((options.get('pkey_only', False), if not any((options.get('pkey_only', False),
options.get('raw', False))): options.get('raw', False))):
range_type = entry_attrs['iparangetype'][0] range_type = entry_attrs['iparangetype'][0]

View File

@@ -632,24 +632,24 @@ class migrate_ds(Command):
doc=_('Load CA certificate of LDAP server from FILE'), doc=_('Load CA certificate of LDAP server from FILE'),
default=None, default=None,
noextrawhitespace=False, noextrawhitespace=False,
), ),
Bool('use_def_group?', Bool('use_def_group?',
cli_name='use_default_group', cli_name='use_default_group',
label=_('Add to default group'), label=_('Add to default group'),
doc=_('Add migrated users without a group to a default group ' doc=_('Add migrated users without a group to a default group '
'(default: true)'), '(default: true)'),
default=True, default=True,
autofill=True, autofill=True,
), ),
StrEnum('scope', StrEnum('scope',
cli_name='scope', cli_name='scope',
label=_('Search scope'), label=_('Search scope'),
doc=_('LDAP search scope for users and groups: base, onelevel, or ' doc=_('LDAP search scope for users and groups: base, '
'subtree. Defaults to onelevel'), 'onelevel, or subtree. Defaults to onelevel'),
values=tuple(_supported_scopes.keys()), values=sorted(_supported_scopes),
default=_default_scope, default=_default_scope,
autofill=True, autofill=True,
), ),
) )
has_output = ( has_output = (

View File

@@ -657,48 +657,52 @@ ipa idrange-del before retrying the command with the desired range type.
Str('realm_admin?', Str('realm_admin?',
cli_name='admin', cli_name='admin',
label=_("Active Directory domain administrator"), label=_("Active Directory domain administrator"),
), ),
Password('realm_passwd?', Password('realm_passwd?',
cli_name='password', cli_name='password',
label=_("Active Directory domain administrator's password"), label=_("Active Directory domain administrator's password"),
confirm=False, confirm=False,
), ),
Str('realm_server?', Str('realm_server?',
cli_name='server', cli_name='server',
label=_('Domain controller for the Active Directory domain (optional)'), label=_('Domain controller for the Active Directory domain '
), '(optional)'),
),
Password('trust_secret?', Password('trust_secret?',
cli_name='trust_secret', cli_name='trust_secret',
label=_('Shared secret for the trust'), label=_('Shared secret for the trust'),
confirm=False, confirm=False,
), ),
Int('base_id?', Int('base_id?',
cli_name='base_id', cli_name='base_id',
label=_('First Posix ID of the range reserved for the trusted domain'), label=_('First Posix ID of the range reserved for the '
), 'trusted domain'),
),
Int('range_size?', Int('range_size?',
cli_name='range_size', cli_name='range_size',
label=_('Size of the ID range reserved for the trusted domain'), label=_('Size of the ID range reserved for the trusted domain')
), ),
StrEnum('range_type?', StrEnum('range_type?',
label=_('Range type'), label=_('Range type'),
cli_name='range_type', cli_name='range_type',
doc=(_('Type of trusted domain ID range, one of {vals}' doc=(_('Type of trusted domain ID range, one of {vals}'
.format(vals=', '.join(range_types.keys())))), .format(vals=', '.join(sorted(range_types))))),
values=tuple(range_types.keys()), values=sorted(range_types),
), ),
Bool('bidirectional?', Bool('bidirectional?',
label=_('Two-way trust'), label=_('Two-way trust'),
cli_name='two_way', cli_name='two_way',
doc=(_('Establish bi-directional trust. By default trust is inbound one-way only.')), doc=(_('Establish bi-directional trust. By default trust is '
'inbound one-way only.')),
default=False, default=False,
), ),
Bool('external?', Bool('external?',
label=_('External trust'), label=_('External trust'),
cli_name='external', cli_name='external',
doc=(_('Establish external trust to a domain in another forest. The trust is not transitive beyond the domain.')), doc=_('Establish external trust to a domain in another forest. '
'The trust is not transitive beyond the domain.'),
default=False, default=False,
), ),
) )
msg_summary = _('Added Active Directory trust for realm "%(value)s"') msg_summary = _('Added Active Directory trust for realm "%(value)s"')

View File

@@ -53,14 +53,18 @@ class test_Output(ClassChecker):
o = self.cls('aye') o = self.cls('aye')
assert repr(o) == "Output('aye')" assert repr(o) == "Output('aye')"
o = self.cls('aye', type=int, doc='An A, aye?') o = self.cls('aye', type=int, doc='An A, aye?')
assert repr(o) == "Output('aye', type=[%r], doc='An A, aye?')" % int assert repr(o) == (
"Output('aye', type=[<type 'int'>], doc='An A, aye?')"
)
class Entry(self.cls): class Entry(self.cls):
pass pass
o = Entry('aye') o = Entry('aye')
assert repr(o) == "Entry('aye')" assert repr(o) == "Entry('aye')"
o = Entry('aye', type=int, doc='An A, aye?') o = Entry('aye', type=int, doc='An A, aye?')
assert repr(o) == "Entry('aye', type=[%r], doc='An A, aye?')" % int assert repr(o) == (
"Entry('aye', type=[<type 'int'>], doc='An A, aye?')"
)
class test_ListOfEntries(ClassChecker): class test_ListOfEntries(ClassChecker):