From 370282819d7839e6e5091c019d6ff1b606add066 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Sun, 20 Jul 2008 03:32:22 +0000 Subject: 13: Starting playing around with 'ipa' cli script --- ipa | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 ipa (limited to 'ipa') diff --git a/ipa b/ipa new file mode 100755 index 00000000..e536e341 --- /dev/null +++ b/ipa @@ -0,0 +1,49 @@ +#!/usr/bin/python + +# Authors: +# Jason Gerard DeRose +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +Command Line Interface to IPA. +""" + +import sys +from ipalib.startup import api + +def print_commands(): + print 'Commands:' + m = api.max_cmd_len + for c in api.commands: + c = c.replace('_', '-') + print ' %s The help on %s' % (c.ljust(m), c) + +def print_help(cmd): + print 'Help on %s' % cmd + +if len(sys.argv) < 2: + print_commands() + print 'Usage: ipa COMMAND [OPTIONS]' + sys.exit(2) + +cmd = sys.argv[1] + +if cmd not in api.commands: + print_commands() + print 'ipa: ERROR: unknown command %r' % cmd + sys.exit(2) -- cgit From 14339cfae01b843949d0f9972670f56f952a5faa Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Sun, 20 Jul 2008 18:36:02 +0000 Subject: 20: Updated example plugins, added '_api_' command to ipa script with prints the api --- ipa | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index e536e341..91bdc021 100755 --- a/ipa +++ b/ipa @@ -36,14 +36,30 @@ def print_commands(): def print_help(cmd): print 'Help on %s' % cmd +def print_api(): + print '\nCommands:' + for n in api.commands: + print ' %s' % n + + print '\nObjects:' + for obj in api.objects(): + print ' %s' % obj.name + for n in obj.commands: + print ' .%s()' % n + + print '%d objects' % len(api.objects) + print '%d commands' % len(api.commands) + + if len(sys.argv) < 2: print_commands() print 'Usage: ipa COMMAND [OPTIONS]' sys.exit(2) - cmd = sys.argv[1] - -if cmd not in api.commands: +if cmd == '_api_': + print_api() +elif cmd not in api.commands: print_commands() print 'ipa: ERROR: unknown command %r' % cmd sys.exit(2) +api.commands[cmd]() -- cgit From 97a3520d3737d10717956ad6fff1e558e7261a2d Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Sun, 20 Jul 2008 18:50:40 +0000 Subject: 21: ipa script: improved print_api(); added missing sys.exit() after print_api() call --- ipa | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 91bdc021..50ea082f 100755 --- a/ipa +++ b/ipa @@ -47,8 +47,9 @@ def print_api(): for n in obj.commands: print ' .%s()' % n - print '%d objects' % len(api.objects) - print '%d commands' % len(api.commands) + print '\nStats:' + print ' %d objects' % len(api.objects) + print ' %d commands' % len(api.commands) if len(sys.argv) < 2: @@ -58,6 +59,7 @@ if len(sys.argv) < 2: cmd = sys.argv[1] if cmd == '_api_': print_api() + sys.exit() elif cmd not in api.commands: print_commands() print 'ipa: ERROR: unknown command %r' % cmd -- cgit From 48c7da47c78c5b5f97dc01a7593313943aef7b6e Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Sun, 20 Jul 2008 23:43:16 +0000 Subject: 25: Updated plugin examples, ipa script --- ipa | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index 50ea082f..c253abee 100755 --- a/ipa +++ b/ipa @@ -44,8 +44,10 @@ def print_api(): print '\nObjects:' for obj in api.objects(): print ' %s' % obj.name - for n in obj.commands: + for n in obj.methods: print ' .%s()' % n + for n in obj.properties: + print ' .%s' % n print '\nStats:' print ' %d objects' % len(api.objects) -- cgit From 7273d48169a6c0dabc1bfb0f42bafb06515fdac9 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 21 Jul 2008 01:44:59 +0000 Subject: 26: Added AbstractCommand.get_doc() method to return the gettext translated summary of command; added get_doc() method to all example --- ipa | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index c253abee..6faa1648 100755 --- a/ipa +++ b/ipa @@ -21,37 +21,46 @@ """ Command Line Interface to IPA. + +Just proof of concept stuff in here right now. """ import sys from ipalib.startup import api +def _(msg): + """ + Dummy gettext function for testing. + """ + return msg + + def print_commands(): print 'Commands:' m = api.max_cmd_len - for c in api.commands: - c = c.replace('_', '-') - print ' %s The help on %s' % (c.ljust(m), c) + for cmd in api.commands(): + print ' %s %s' % (cmd.cli_name.ljust(m), cmd.get_doc(_)) def print_help(cmd): print 'Help on %s' % cmd def print_api(): - print '\nCommands:' - for n in api.commands: - print ' %s' % n + print 'Commands:' + for cmd in api.commands(): + print ' %s [%s]' % (cmd.name, cmd.loc) - print '\nObjects:' + print 'Objects:' for obj in api.objects(): - print ' %s' % obj.name - for n in obj.methods: - print ' .%s()' % n - for n in obj.properties: - print ' .%s' % n + print ' %s [%s]' % (obj.name, obj.loc) + for meth in obj.methods(): + print ' .%s() [%s]' % (meth.attr_name, meth.loc) + for prop in obj.properties(): + print ' .%s [%s]' % (prop.attr_name, prop.loc) - print '\nStats:' - print ' %d objects' % len(api.objects) + print 'Stats:' print ' %d commands' % len(api.commands) + print ' %d objects' % len(api.objects) + if len(sys.argv) < 2: -- cgit From 0c574d830062d7957c2c65081e3e66fc0bb41759 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 21 Jul 2008 01:58:22 +0000 Subject: 27: Added quick hack for replace('-', '_') problem I'm having --- ipa | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 6faa1648..128eed38 100755 --- a/ipa +++ b/ipa @@ -68,11 +68,12 @@ if len(sys.argv) < 2: print 'Usage: ipa COMMAND [OPTIONS]' sys.exit(2) cmd = sys.argv[1] +pcmd = cmd.replace('-', '_') if cmd == '_api_': print_api() sys.exit() -elif cmd not in api.commands: +elif pcmd not in api.commands: print_commands() print 'ipa: ERROR: unknown command %r' % cmd sys.exit(2) -api.commands[cmd]() +api.commands[pcmd]() -- cgit From 159207514fadfacb6e1df9713abd2c61c24d7b77 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 5 Aug 2008 22:21:57 +0000 Subject: 52: Got cli working against new framework --- ipa | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 128eed38..18474d03 100755 --- a/ipa +++ b/ipa @@ -38,42 +38,35 @@ def _(msg): def print_commands(): print 'Commands:' m = api.max_cmd_len - for cmd in api.commands(): - print ' %s %s' % (cmd.cli_name.ljust(m), cmd.get_doc(_)) + for cmd in api.cmd: + print ' %s %s' % (str(cmd).ljust(m), cmd.get_doc(_)) def print_help(cmd): print 'Help on %s' % cmd def print_api(): - print 'Commands:' - for cmd in api.commands(): - print ' %s [%s]' % (cmd.name, cmd.loc) - - print 'Objects:' - for obj in api.objects(): - print ' %s [%s]' % (obj.name, obj.loc) - for meth in obj.methods(): - print ' .%s() [%s]' % (meth.attr_name, meth.loc) - for prop in obj.properties(): - print ' .%s [%s]' % (prop.attr_name, prop.loc) - - print 'Stats:' - print ' %d commands' % len(api.commands) - print ' %d objects' % len(api.objects) + def print_ns(name): + ns = getattr(api, name) + print '%d %s:' % (len(ns), name) + m = max(len(i.name) for i in ns) + for i in ns: + print ' %s %r' % (i.name.ljust(m), i) + for n in ['cmd', 'obj', 'prop']: + print_ns(n) + print '' if len(sys.argv) < 2: print_commands() print 'Usage: ipa COMMAND [OPTIONS]' sys.exit(2) -cmd = sys.argv[1] -pcmd = cmd.replace('-', '_') -if cmd == '_api_': +name= sys.argv[1] +if name == '_api_': print_api() sys.exit() -elif pcmd not in api.commands: +elif name not in api.cmd: print_commands() - print 'ipa: ERROR: unknown command %r' % cmd + print 'ipa: ERROR: unknown command %r' % name sys.exit(2) -api.commands[pcmd]() +api.cmd[name]() -- cgit From f31f7813febf0665a072d474166ea883bc7365dc Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 5 Aug 2008 23:34:59 +0000 Subject: 53: Changed plugable.Registar so the same plugin can be added to in the ns for more than one base (for cmd and mthd) --- ipa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index 18474d03..a4bc2cb0 100755 --- a/ipa +++ b/ipa @@ -52,7 +52,7 @@ def print_api(): for i in ns: print ' %s %r' % (i.name.ljust(m), i) - for n in ['cmd', 'obj', 'prop']: + for n in ['cmd', 'obj', 'mthd', 'prop']: print_ns(n) print '' -- cgit From c6f69e1c66b86f8f375a3c561922a42fdc0b1afb Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 6 Aug 2008 02:00:18 +0000 Subject: 54: Added plugable.Proxy._clone() method; fleshed out public.obj; updated unit tests; port ipa script --- ipa | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 10 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index a4bc2cb0..77bdb6ce 100755 --- a/ipa +++ b/ipa @@ -28,12 +28,48 @@ Just proof of concept stuff in here right now. import sys from ipalib.startup import api +TAB_WIDTH = 2 + def _(msg): """ Dummy gettext function for testing. """ return msg +class row(object): + def __init__(self, tab, c1, c2=None): + assert type(tab) is int + assert type(c1) is str + assert type(c2) is str or c2 is None + self.tab = tab + self.c1 = c1 + self.c2 = c2 + + def __len__(self): + return len(str(self.c1)) + + def pretty_print(self, ljust): + tab = ' ' * (self.tab * TAB_WIDTH) + if self.c2 is None: + print '%s%s' % (tab, self.c1) + else: + print '%s%s %s' % (tab, self.c1.ljust(ljust), self.c2) + +def pretty_print(rows): + def at_tab(tab): + for r in rows: + if r.tab == tab: + yield len(r) + + _max_len = {} + def max_len(tab): + if tab not in _max_len: + _max_len[tab] = max(at_tab(tab)) + return _max_len[tab] + + for r in rows: + r.pretty_print(max_len(r.tab)) + def print_commands(): print 'Commands:' @@ -44,17 +80,36 @@ def print_commands(): def print_help(cmd): print 'Help on %s' % cmd + + + + + + + +def iter_ns(tab, name): + ns = getattr(api, name) + yield row( + tab, + '%d %s:' % (len(ns), name) + ) + for i in ns: + yield row( + tab + 1, + i.name, + repr(i) + ) + + + def print_api(): - def print_ns(name): - ns = getattr(api, name) - print '%d %s:' % (len(ns), name) - m = max(len(i.name) for i in ns) - for i in ns: - print ' %s %r' % (i.name.ljust(m), i) - - for n in ['cmd', 'obj', 'mthd', 'prop']: - print_ns(n) - print '' + rows = [] + for name in ['cmd', 'obj', 'mthd', 'prop']: + rows.extend(iter_ns(0, name)) + + pretty_print(rows) + + if len(sys.argv) < 2: -- cgit From 277685439c91f496df9510e02418da01160df0ea Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 6 Aug 2008 03:27:00 +0000 Subject: 55: Cleaned up print_api() function in ipa script --- ipa | 103 +++++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 29 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 77bdb6ce..5606b373 100755 --- a/ipa +++ b/ipa @@ -39,7 +39,7 @@ def _(msg): class row(object): def __init__(self, tab, c1, c2=None): assert type(tab) is int - assert type(c1) is str + assert type(c1) in (str, int) assert type(c2) is str or c2 is None self.tab = tab self.c1 = c1 @@ -48,27 +48,27 @@ class row(object): def __len__(self): return len(str(self.c1)) - def pretty_print(self, ljust): + def pretty_print(self, just): tab = ' ' * (self.tab * TAB_WIDTH) if self.c2 is None: print '%s%s' % (tab, self.c1) else: - print '%s%s %s' % (tab, self.c1.ljust(ljust), self.c2) + if type(self.c1) is int: + c1 = str(self.c1).rjust(just) + else: + c1 = self.c1.ljust(just) + print '%s%s %s' % (tab, c1, self.c2) def pretty_print(rows): - def at_tab(tab): + rows = tuple(rows) + def get_lengths(): + yield 0 for r in rows: - if r.tab == tab: + if r.c2 is not None: yield len(r) - - _max_len = {} - def max_len(tab): - if tab not in _max_len: - _max_len[tab] = max(at_tab(tab)) - return _max_len[tab] - + max_len = max(get_lengths()) for r in rows: - r.pretty_print(max_len(r.tab)) + r.pretty_print(max_len) def print_commands(): @@ -87,27 +87,72 @@ def print_help(cmd): -def iter_ns(tab, name): - ns = getattr(api, name) - yield row( - tab, - '%d %s:' % (len(ns), name) - ) - for i in ns: - yield row( - tab + 1, - i.name, - repr(i) - ) + + + def print_api(): - rows = [] - for name in ['cmd', 'obj', 'mthd', 'prop']: - rows.extend(iter_ns(0, name)) + def iter_api(tab): + for name in api: + ns = getattr(api, name) + yield row( + tab, + name, + repr(ns), + ) + for i in ns: + yield row( + tab + 1, + i.name, + repr(i) + ) + + def iter_obj(tab): + for obj in api.obj: + yield row( + tab, + obj.name, + repr(obj), + ) + for (n, f) in [('mthd', '.%s()'), ('prop', '.%s')]: + ns = getattr(obj, n) + yield row( + tab + 1, + n, + repr(ns), + ) + for attr in ns: + yield row( + tab + 2, + f % attr.name, + repr(attr), + ) + + def iter_summary(tab): + for name in api: + ns = getattr(api, name) + yield row( + tab, + len(ns), + name + ) + + def print_heading(h): + print '\n%s:' % h + print '-' * (len(h) + 1) + + tab = 1 + print_heading('API Overview') + pretty_print(iter_api(tab)) + + print_heading('Object Details') + pretty_print(iter_obj(tab)) + + print_heading('Summary') + pretty_print(iter_summary(tab)) - pretty_print(rows) -- cgit From 8e468248155947075689e6d01c3ab90fbd9f1643 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 8 Aug 2008 17:11:29 +0000 Subject: 81: Switch from tab to 4-space indentation --- ipa | 210 ++++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 105 insertions(+), 105 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 5606b373..626eb045 100755 --- a/ipa +++ b/ipa @@ -31,54 +31,54 @@ from ipalib.startup import api TAB_WIDTH = 2 def _(msg): - """ - Dummy gettext function for testing. - """ - return msg + """ + Dummy gettext function for testing. + """ + return msg class row(object): - def __init__(self, tab, c1, c2=None): - assert type(tab) is int - assert type(c1) in (str, int) - assert type(c2) is str or c2 is None - self.tab = tab - self.c1 = c1 - self.c2 = c2 - - def __len__(self): - return len(str(self.c1)) - - def pretty_print(self, just): - tab = ' ' * (self.tab * TAB_WIDTH) - if self.c2 is None: - print '%s%s' % (tab, self.c1) - else: - if type(self.c1) is int: - c1 = str(self.c1).rjust(just) - else: - c1 = self.c1.ljust(just) - print '%s%s %s' % (tab, c1, self.c2) + def __init__(self, tab, c1, c2=None): + assert type(tab) is int + assert type(c1) in (str, int) + assert type(c2) is str or c2 is None + self.tab = tab + self.c1 = c1 + self.c2 = c2 + + def __len__(self): + return len(str(self.c1)) + + def pretty_print(self, just): + tab = ' ' * (self.tab * TAB_WIDTH) + if self.c2 is None: + print '%s%s' % (tab, self.c1) + else: + if type(self.c1) is int: + c1 = str(self.c1).rjust(just) + else: + c1 = self.c1.ljust(just) + print '%s%s %s' % (tab, c1, self.c2) def pretty_print(rows): - rows = tuple(rows) - def get_lengths(): - yield 0 - for r in rows: - if r.c2 is not None: - yield len(r) - max_len = max(get_lengths()) - for r in rows: - r.pretty_print(max_len) + rows = tuple(rows) + def get_lengths(): + yield 0 + for r in rows: + if r.c2 is not None: + yield len(r) + max_len = max(get_lengths()) + for r in rows: + r.pretty_print(max_len) def print_commands(): - print 'Commands:' - m = api.max_cmd_len - for cmd in api.cmd: - print ' %s %s' % (str(cmd).ljust(m), cmd.get_doc(_)) + print 'Commands:' + m = api.max_cmd_len + for cmd in api.cmd: + print ' %s %s' % (str(cmd).ljust(m), cmd.get_doc(_)) def print_help(cmd): - print 'Help on %s' % cmd + print 'Help on %s' % cmd @@ -94,79 +94,79 @@ def print_help(cmd): def print_api(): - def iter_api(tab): - for name in api: - ns = getattr(api, name) - yield row( - tab, - name, - repr(ns), - ) - for i in ns: - yield row( - tab + 1, - i.name, - repr(i) - ) - - def iter_obj(tab): - for obj in api.obj: - yield row( - tab, - obj.name, - repr(obj), - ) - for (n, f) in [('mthd', '.%s()'), ('prop', '.%s')]: - ns = getattr(obj, n) - yield row( - tab + 1, - n, - repr(ns), - ) - for attr in ns: - yield row( - tab + 2, - f % attr.name, - repr(attr), - ) - - def iter_summary(tab): - for name in api: - ns = getattr(api, name) - yield row( - tab, - len(ns), - name - ) - - def print_heading(h): - print '\n%s:' % h - print '-' * (len(h) + 1) - - tab = 1 - print_heading('API Overview') - pretty_print(iter_api(tab)) - - print_heading('Object Details') - pretty_print(iter_obj(tab)) - - print_heading('Summary') - pretty_print(iter_summary(tab)) + def iter_api(tab): + for name in api: + ns = getattr(api, name) + yield row( + tab, + name, + repr(ns), + ) + for i in ns: + yield row( + tab + 1, + i.name, + repr(i) + ) + + def iter_obj(tab): + for obj in api.obj: + yield row( + tab, + obj.name, + repr(obj), + ) + for (n, f) in [('mthd', '.%s()'), ('prop', '.%s')]: + ns = getattr(obj, n) + yield row( + tab + 1, + n, + repr(ns), + ) + for attr in ns: + yield row( + tab + 2, + f % attr.name, + repr(attr), + ) + + def iter_summary(tab): + for name in api: + ns = getattr(api, name) + yield row( + tab, + len(ns), + name + ) + + def print_heading(h): + print '\n%s:' % h + print '-' * (len(h) + 1) + + tab = 1 + print_heading('API Overview') + pretty_print(iter_api(tab)) + + print_heading('Object Details') + pretty_print(iter_obj(tab)) + + print_heading('Summary') + pretty_print(iter_summary(tab)) if len(sys.argv) < 2: - print_commands() - print 'Usage: ipa COMMAND [OPTIONS]' - sys.exit(2) + print_commands() + print 'Usage: ipa COMMAND [OPTIONS]' + sys.exit(2) name= sys.argv[1] if name == '_api_': - print_api() - sys.exit() + print_api() + sys.exit() elif name not in api.cmd: - print_commands() - print 'ipa: ERROR: unknown command %r' % name - sys.exit(2) + print_commands() + print 'ipa: ERROR: unknown command %r' % name + sys.exit(2) api.cmd[name]() -- cgit From fdfa827a36df87fd6b228fc1560576e268413104 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Fri, 8 Aug 2008 21:40:03 +0000 Subject: 86: Actually change *all* tab indentation to 4-space: 'sed s/\t/ /g' --- ipa | 126 ++++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 626eb045..1dcef288 100755 --- a/ipa +++ b/ipa @@ -38,44 +38,44 @@ def _(msg): class row(object): def __init__(self, tab, c1, c2=None): - assert type(tab) is int - assert type(c1) in (str, int) - assert type(c2) is str or c2 is None - self.tab = tab - self.c1 = c1 - self.c2 = c2 + assert type(tab) is int + assert type(c1) in (str, int) + assert type(c2) is str or c2 is None + self.tab = tab + self.c1 = c1 + self.c2 = c2 def __len__(self): - return len(str(self.c1)) + return len(str(self.c1)) def pretty_print(self, just): - tab = ' ' * (self.tab * TAB_WIDTH) - if self.c2 is None: - print '%s%s' % (tab, self.c1) - else: - if type(self.c1) is int: - c1 = str(self.c1).rjust(just) - else: - c1 = self.c1.ljust(just) - print '%s%s %s' % (tab, c1, self.c2) + tab = ' ' * (self.tab * TAB_WIDTH) + if self.c2 is None: + print '%s%s' % (tab, self.c1) + else: + if type(self.c1) is int: + c1 = str(self.c1).rjust(just) + else: + c1 = self.c1.ljust(just) + print '%s%s %s' % (tab, c1, self.c2) def pretty_print(rows): rows = tuple(rows) def get_lengths(): - yield 0 - for r in rows: - if r.c2 is not None: - yield len(r) + yield 0 + for r in rows: + if r.c2 is not None: + yield len(r) max_len = max(get_lengths()) for r in rows: - r.pretty_print(max_len) + r.pretty_print(max_len) def print_commands(): print 'Commands:' m = api.max_cmd_len for cmd in api.cmd: - print ' %s %s' % (str(cmd).ljust(m), cmd.get_doc(_)) + print ' %s %s' % (str(cmd).ljust(m), cmd.get_doc(_)) def print_help(cmd): print 'Help on %s' % cmd @@ -95,53 +95,53 @@ def print_help(cmd): def print_api(): def iter_api(tab): - for name in api: - ns = getattr(api, name) - yield row( - tab, - name, - repr(ns), - ) - for i in ns: - yield row( - tab + 1, - i.name, - repr(i) - ) + for name in api: + ns = getattr(api, name) + yield row( + tab, + name, + repr(ns), + ) + for i in ns: + yield row( + tab + 1, + i.name, + repr(i) + ) def iter_obj(tab): - for obj in api.obj: - yield row( - tab, - obj.name, - repr(obj), - ) - for (n, f) in [('mthd', '.%s()'), ('prop', '.%s')]: - ns = getattr(obj, n) - yield row( - tab + 1, - n, - repr(ns), - ) - for attr in ns: - yield row( - tab + 2, - f % attr.name, - repr(attr), - ) + for obj in api.obj: + yield row( + tab, + obj.name, + repr(obj), + ) + for (n, f) in [('mthd', '.%s()'), ('prop', '.%s')]: + ns = getattr(obj, n) + yield row( + tab + 1, + n, + repr(ns), + ) + for attr in ns: + yield row( + tab + 2, + f % attr.name, + repr(attr), + ) def iter_summary(tab): - for name in api: - ns = getattr(api, name) - yield row( - tab, - len(ns), - name - ) + for name in api: + ns = getattr(api, name) + yield row( + tab, + len(ns), + name + ) def print_heading(h): - print '\n%s:' % h - print '-' * (len(h) + 1) + print '\n%s:' % h + print '-' * (len(h) + 1) tab = 1 print_heading('API Overview') -- cgit From 92824182911007ce3e9cf4f858f70434594ee5dd Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 11 Aug 2008 19:35:57 +0000 Subject: 110: Started fleshing out more in cli.py --- ipa | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ipa') diff --git a/ipa b/ipa index 1dcef288..c7168bfe 100755 --- a/ipa +++ b/ipa @@ -27,6 +27,12 @@ Just proof of concept stuff in here right now. import sys from ipalib.startup import api +from ipalib.cli import CLI + +cli = CLI(api) +cli.run() + +sys.exit() TAB_WIDTH = 2 -- cgit From 13a3de7442570c47da2ccc76c15a0e6b0d9edea1 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 13 Aug 2008 01:03:32 +0000 Subject: 130: Renamed startup.py to load_plugins.py --- ipa | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index c7168bfe..e9089d97 100755 --- a/ipa +++ b/ipa @@ -26,8 +26,9 @@ Just proof of concept stuff in here right now. """ import sys -from ipalib.startup import api +from ipalib.run import api from ipalib.cli import CLI +import ipalib.load_plugins cli = CLI(api) cli.run() -- cgit From c0b5069fa07889496786523c46b5b15181c26fee Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 13 Aug 2008 01:26:30 +0000 Subject: 133: Renamed run.py to api.py --- ipa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index e9089d97..5f532962 100755 --- a/ipa +++ b/ipa @@ -26,7 +26,7 @@ Just proof of concept stuff in here right now. """ import sys -from ipalib.run import api +from ipalib.api import api from ipalib.cli import CLI import ipalib.load_plugins -- cgit From 2fc3819beca86c3d19d85e2f5777af3566305175 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 25 Aug 2008 23:35:29 +0000 Subject: 191: Removed ipalib/api.py module; standard plugable.API instance is now in ipalib.__init__.py --- ipa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index 5f532962..2f4fdf70 100755 --- a/ipa +++ b/ipa @@ -26,7 +26,7 @@ Just proof of concept stuff in here right now. """ import sys -from ipalib.api import api +from ipalib import api from ipalib.cli import CLI import ipalib.load_plugins -- cgit From ac7bdf8790a6b18eccc72af5dc2c5b59133546cd Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 24 Sep 2008 08:07:20 +0000 Subject: 338: Removed depreciated code from ipa (CLI) script --- ipa | 150 +------------------------------------------------------------------- 1 file changed, 2 insertions(+), 148 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 2f4fdf70..31848f7b 100755 --- a/ipa +++ b/ipa @@ -20,160 +20,14 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -Command Line Interface to IPA. +Command Line Interface for IPA Administration. -Just proof of concept stuff in here right now. +The CLI functionality is implemented in ipalib/cli.py """ -import sys from ipalib import api from ipalib.cli import CLI import ipalib.load_plugins cli = CLI(api) cli.run() - -sys.exit() - -TAB_WIDTH = 2 - -def _(msg): - """ - Dummy gettext function for testing. - """ - return msg - -class row(object): - def __init__(self, tab, c1, c2=None): - assert type(tab) is int - assert type(c1) in (str, int) - assert type(c2) is str or c2 is None - self.tab = tab - self.c1 = c1 - self.c2 = c2 - - def __len__(self): - return len(str(self.c1)) - - def pretty_print(self, just): - tab = ' ' * (self.tab * TAB_WIDTH) - if self.c2 is None: - print '%s%s' % (tab, self.c1) - else: - if type(self.c1) is int: - c1 = str(self.c1).rjust(just) - else: - c1 = self.c1.ljust(just) - print '%s%s %s' % (tab, c1, self.c2) - -def pretty_print(rows): - rows = tuple(rows) - def get_lengths(): - yield 0 - for r in rows: - if r.c2 is not None: - yield len(r) - max_len = max(get_lengths()) - for r in rows: - r.pretty_print(max_len) - - -def print_commands(): - print 'Commands:' - m = api.max_cmd_len - for cmd in api.cmd: - print ' %s %s' % (str(cmd).ljust(m), cmd.get_doc(_)) - -def print_help(cmd): - print 'Help on %s' % cmd - - - - - - - - - - - - - - -def print_api(): - def iter_api(tab): - for name in api: - ns = getattr(api, name) - yield row( - tab, - name, - repr(ns), - ) - for i in ns: - yield row( - tab + 1, - i.name, - repr(i) - ) - - def iter_obj(tab): - for obj in api.obj: - yield row( - tab, - obj.name, - repr(obj), - ) - for (n, f) in [('mthd', '.%s()'), ('prop', '.%s')]: - ns = getattr(obj, n) - yield row( - tab + 1, - n, - repr(ns), - ) - for attr in ns: - yield row( - tab + 2, - f % attr.name, - repr(attr), - ) - - def iter_summary(tab): - for name in api: - ns = getattr(api, name) - yield row( - tab, - len(ns), - name - ) - - def print_heading(h): - print '\n%s:' % h - print '-' * (len(h) + 1) - - tab = 1 - print_heading('API Overview') - pretty_print(iter_api(tab)) - - print_heading('Object Details') - pretty_print(iter_obj(tab)) - - print_heading('Summary') - pretty_print(iter_summary(tab)) - - - - - -if len(sys.argv) < 2: - print_commands() - print 'Usage: ipa COMMAND [OPTIONS]' - sys.exit(2) -name= sys.argv[1] -if name == '_api_': - print_api() - sys.exit() -elif name not in api.cmd: - print_commands() - print 'ipa: ERROR: unknown command %r' % name - sys.exit(2) -api.cmd[name]() -- cgit From f189b02996668e5d600f1abed675cb20cd72290f Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 22 Oct 2008 17:52:32 -0400 Subject: Return a value to the shell that called ipa --- ipa | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index 31848f7b..5122af0a 100755 --- a/ipa +++ b/ipa @@ -25,9 +25,10 @@ Command Line Interface for IPA Administration. The CLI functionality is implemented in ipalib/cli.py """ +import sys from ipalib import api from ipalib.cli import CLI import ipalib.load_plugins cli = CLI(api) -cli.run() +sys.exit(cli.run()) -- cgit From fb441b2b1054de1ba0a99d01b9e1ea9700024aeb Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 22 Oct 2008 23:00:45 -0600 Subject: make-doc now includes the lite-* scripts, both with now check in __name__ == '__main__' before starting --- ipa | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 5122af0a..b202a5d0 100755 --- a/ipa +++ b/ipa @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Authors: # Jason Gerard DeRose @@ -20,7 +20,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -Command Line Interface for IPA Administration. +Command Line Interface for IPA administration. The CLI functionality is implemented in ipalib/cli.py """ @@ -30,5 +30,6 @@ from ipalib import api from ipalib.cli import CLI import ipalib.load_plugins -cli = CLI(api) -sys.exit(cli.run()) +if __name__ == '__main__': + cli = CLI(api) + sys.exit(cli.run()) -- cgit From c8b3f6516513dc3e5948fe8280c3f159ad122684 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 27 Oct 2008 00:41:37 -0600 Subject: Removed depreciated load_plugins.py module; changed all places where load_plugins was imported to now call api.load_plugins() --- ipa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index b202a5d0..9fb30201 100755 --- a/ipa +++ b/ipa @@ -28,7 +28,7 @@ The CLI functionality is implemented in ipalib/cli.py import sys from ipalib import api from ipalib.cli import CLI -import ipalib.load_plugins +api.load_plugins() if __name__ == '__main__': cli = CLI(api) -- cgit From 10026284dbf8f1b8a6eedf3b1c6ce05da568b4fa Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 27 Oct 2008 14:48:02 -0600 Subject: Started cleanup work on CLI class, added unit tests for CLI.parse_globals() --- ipa | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index 9fb30201..39ab81a3 100755 --- a/ipa +++ b/ipa @@ -31,5 +31,7 @@ from ipalib.cli import CLI api.load_plugins() if __name__ == '__main__': - cli = CLI(api) + cli = CLI(api, + (s.decode('utf-8') for s in sys.args[1:]) + ) sys.exit(cli.run()) -- cgit From 6e456cc7494bc00e905361f3e6d42dff99089c6b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 27 Oct 2008 23:30:55 -0600 Subject: More CLI cleanup, got all basics working again --- ipa | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ipa') diff --git a/ipa b/ipa index 39ab81a3..67e8d10c 100755 --- a/ipa +++ b/ipa @@ -28,10 +28,9 @@ The CLI functionality is implemented in ipalib/cli.py import sys from ipalib import api from ipalib.cli import CLI -api.load_plugins() if __name__ == '__main__': cli = CLI(api, - (s.decode('utf-8') for s in sys.args[1:]) + (s.decode('utf-8') for s in sys.argv[1:]) ) sys.exit(cli.run()) -- cgit From 014af24731ff39520a9635694ed99dc9d09669c9 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 12 Nov 2008 00:46:04 -0700 Subject: Changed calling signature of output_for_cli(); started work on 'textui' backend plugin --- ipa | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ipa') diff --git a/ipa b/ipa index 67e8d10c..cab12b6b 100755 --- a/ipa +++ b/ipa @@ -30,7 +30,12 @@ from ipalib import api from ipalib.cli import CLI if __name__ == '__main__': + # If we can't explicitly determin the encoding, we assume UTF-8: + if sys.stdin.encoding is None: + encoding = 'UTF-8' + else: + encoding = sys.stdin.encoding cli = CLI(api, - (s.decode('utf-8') for s in sys.argv[1:]) + (s.decode(encoding) for s in sys.argv[1:]) ) sys.exit(cli.run()) -- cgit