On Thu, 2015-08-13 at 07:49 +0930, William wrote:
> > >
> > > I hope this demonstrates how I want to tie together the other
> > > contributions I
> > > have made into tools, but also making it possible to test other
> > > aspects of
> > > 389ds.
> > >
> > > Comments and advice welcome.
> > Hi William,
> >
> > This looks good to me, it's definitely a good start. I see no reason
> > not to push the patch once you think it's ready and polished enough.
> > Don't forget to add the license text to new files. > needs
> > to be done for many of the files in lib389 - I'll open a ticket for
> > that>
>
> Thanks! I think that the main piece of polish is the helper.py library
> that backs the cli tools to make them a bit easier to write. I'll make
> this a bit nicer now and send this back in for another review.
>
> Thanks for your time,
>
> Sincerely,
>
Here is a slightly more polished CliTools helper, and the addition of a more
"interesting" command line tool example of an attribute query tool. You give it
an attribute type and it will provide a list of object classes that Must or May
take that attribute. I have found this a very useful tool in my work place where
we have a complex custom schema, so it's great to know what objectclass to put
on objects when you need to put certain attributes on them.
The biggest outstanding part for me now is how to best format the output of the
tool. Should I use the same logging tool as lib389? Or print things out in the
current form? Or something else.
Sincerely,
--
William Brown From 007118ee71651e1ba3af0ff502c0351a5c2d Mon Sep 17 00:00:00 2001
From: William Brown
Date: Thu, 6 Aug 2015 10:11:25 +0930
Subject: [PATCH] Example of commandline tools implementation for listing all
attribute types and instances
---
clitools/__init__.py | 43 +++
clitools/ds_list_instances.py | 18 ++
clitools/ds_schema_attributetype_list.py | 24 +
clitools/ds_schema_attributetype_query.py | 31 +
lib389/__init__.py| 58 ++-
lib389/_constants.py | 15
6 files changed, 180 insertions(+), 9 deletions(-)
create mode 100644 clitools/__init__.py
create mode 100644 clitools/ds_list_instances.py
create mode 100644 clitools/ds_schema_attributetype_list.py
create mode 100644 clitools/ds_schema_attributetype_query.py
diff --git a/clitools/__init__.py b/clitools/__init__.py
new file mode 100644
index 000..ecc708f
--- /dev/null
+++ b/clitools/__init__.py
@@ -0,0 +1,43 @@
+# Probably need some helpers for argparse and instance selection
+
+from argparse import ArgumentParser
+from getpass import getpass
+from lib389 import DirSrv
+from lib389._constants import *
+
+class CliTool(object):
+def __init__(self, args=None):
+self.ds = DirSrv()
+if args is not None:
+self.args = args
+
+def populate_instance_dict(self, instance):
+insts = self.ds.list(serverid=instance)
+if len(insts) != 1:
+# Raise an exception here?
+self.inst = None
+else:
+self.inst = insts[0]
+
+def get_rootdn_pass(self):
+#There is a dict get key thing somewhere ...
+if self.inst.get(SER_ROOT_PW, None) is None:
+self.inst[SER_ROOT_PW] = getpass('Enter password for %s on instance %s: ' % (self.inst[SER_ROOT_DN], self.inst[SER_SERVERID_PROP]))
+return
+
+def connect(self):
+self.get_rootdn_pass()
+self.ds.allocate(self.inst)
+self.ds.open()
+
+def disconnect(self):
+# Is there a ds unbind / disconnect?
+self.ds.close()
+
+def _clitools_parser():
+parser = ArgumentParser(add_help=False)
+parser.add_argument('--instance', '-i', help='The name of the DS instance to connect to and work upon.')
+return parser
+
+clitools_parser = _clitools_parser()
+
diff --git a/clitools/ds_list_instances.py b/clitools/ds_list_instances.py
new file mode 100644
index 000..8647187
--- /dev/null
+++ b/clitools/ds_list_instances.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+from lib389._constants import *
+from clitools import CliTool
+
+class ListTool(CliTool):
+def list_instances(self):
+# Remember, the prefix can be set with the os environment
+instances = self.ds.list(all=True)
+print('Instances on this system:')
+for instance in instances:
+print(instance[CONF_SERVER_ID])
+
+if __name__ == '__main__':
+listtool = ListTool()
+listtool.list_instances()
+
+
diff --git a/clitools/ds_schema_attributetype_list.py b/clitools/ds_schema_attributetype_list.py
new file mode 100644
index 000..0239ac3
--- /dev/null
+++ b/clitools/ds_schema_attributetype_list.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+#from clitools import clitools_parser, get_instance_dict, get_rootdn_pass
+from clitools import CliTool, clitools_parser
+#from