diff --git a/python/mocha-shell.py b/python/mocha-shell.py index 1615846..1f705ec 100644 --- a/python/mocha-shell.py +++ b/python/mocha-shell.py @@ -191,8 +191,6 @@ class MochaShell (REPLApplication): return prompt def process_input(self, value): - print(value) - parms = value.split(' ') if len(parms) > 0: @@ -367,9 +365,13 @@ class MochaShell (REPLApplication): ik_User = self.oms.get_instance_by_global_identifier(KnownClassGuids.User) ik_UserName = self.oms.get_instance_by_global_identifier(KnownAttributeGuids.UserName) + users = self.oms.get_instances(ik_User) + if users is None: + self.print_error_not_open() + return + print ("user name ") print ("---------------------") - users = self.oms.get_instances(ik_User) for user in users: user_name = self.oms.get_attribute_value(user, ik_UserName) print(user_name) diff --git a/python/mocha/oms/Oms.py b/python/mocha/oms/Oms.py index 92bf07d..c6fc348 100644 --- a/python/mocha/oms/Oms.py +++ b/python/mocha/oms/Oms.py @@ -8,6 +8,7 @@ class Oms: pass def get_user_by_username(self, username : str): + ik_User = self.get_instance_by_global_identifier(KnownClassGuids.User) if ik_User is None: print ("error: class `User` is not defined") diff --git a/python/mocha/oms/db/sqlite/SQLiteDatabaseOms.py b/python/mocha/oms/db/sqlite/SQLiteDatabaseOms.py index 33dfd3d..e36dd25 100644 --- a/python/mocha/oms/db/sqlite/SQLiteDatabaseOms.py +++ b/python/mocha/oms/db/sqlite/SQLiteDatabaseOms.py @@ -214,6 +214,9 @@ class SQLiteDatabaseOms (DatabaseOms): def get_instances(self, of_class : InstanceReference = None): + + if self.conn is None: + return None if of_class is not None: @@ -244,6 +247,9 @@ class SQLiteDatabaseOms (DatabaseOms): return InstanceReference(int(result[0]), InstanceKey(int(result[1]), int(result[2])), Guid.parse(result[3])) def get_instance_by_global_identifier(self, global_identifier : Guid): + if self.conn is None: + return None + cursor = self.conn.execute("SELECT * FROM instances WHERE global_identifier = ?", [ global_identifier.strip() ]) results = cursor.fetchall() if len(results) > 0: