Changeset: 3288ed349f26 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3288ed349f26 Modified Files: clients/python/monetdb/control.py Branch: default Log Message:
added doc, added defaults and neighbours methods & tests diffs (147 lines): diff --git a/clients/python/monetdb/control.py b/clients/python/monetdb/control.py --- a/clients/python/monetdb/control.py +++ b/clients/python/monetdb/control.py @@ -6,7 +6,7 @@ def parse_statusline(line): info = {} info['path'] = split[0] info['name'] = info['path'].split("/")[-1] - info['locked'] = True if split[1] == ("1") else False + info['locked'] = split[1] == ("1") info['state'] = int(split[2]) info['scenarios'] = split[3].split("'") info['connections'] = split[4].split("'") @@ -18,12 +18,16 @@ def parse_statusline(line): info['min_uptime'] = int(split[10]) info['last_crash'] = int(split[11]) info['lastStart'] = int(split[12]) - info['crash_avg1'] = True if split[1] == ("1") else False + info['crash_avg1'] = split[1] == ("1") info['crash_avg10'] = float(split[14]) info['crash_avg30'] = float(split[15]) return info class Control: + """ + Use this module to manage your MonetDB databases. You can create, start, stop, + lock, unlock, destroy your databases and request status information. + """ def __init__(self, hostname, port, passphrase): self.server = mapi.Server() self.server.connect(hostname, port, 'monetdb', passphrase, 'merovingian', 'control') @@ -32,38 +36,87 @@ class Control: return self.server.cmd("%s %s\n" % (database_name, command)) def create(self, database_name): + """ + Initialises a new database or multiplexfunnel in the MonetDB Server. + A database created with this command makes it available for use, + however in maintenance mode (see monetdb lock). + """ return self._send_command(database_name, "create") def destroy(self, database_name): + """ + Removes the given database, including all its data and + logfiles. Once destroy has completed, all data is lost. + Be careful when using this command. + """ return self._send_command(database_name, "destroy") def lock(self, database_name): + """ + Puts the given database in maintenance mode. A database + under maintenance can only be connected to by the DBA. + A database which is under maintenance is not started + automatically. Use the "release" command to bring + the database back for normal usage. + """ return self._send_command(database_name, "lock") def release(self, database_name): + """ + Brings back a database from maintenance mode. A released + database is available again for normal use. Use the + "lock" command to take a database under maintenance. + """ return self._send_command(database_name, "release") - def status(self, database_name): - raw = self._send_command(database_name, "status") - return parse_statusline(raw) - - def statuses(self): - raw = self._send_command("#all", "status") - return [parse_statusline(line) for line in raw.split("\n")] + def status(self, database_name=False): + """ + Shows the state of a given glob-style database match, or + all known if none given. Instead of the normal mode, a + long and crash mode control what information is displayed. + """ + if database_name: + raw = self._send_command(database_name, "status") + return parse_statusline(raw) + else: + raw = self._send_command("#all", "status") + return [parse_statusline(line) for line in raw.split("\n")] def start(self, database_name): + """ + Starts the given database, if the MonetDB Database Server + is running. + """ return self._send_command(database_name, "start") def stop(self, database_name): + """ + Stops the given database, if the MonetDB Database Server + is running. + """ return self._send_command(database_name, "stop") def kill(self, database_name): + """ + Kills the given database, if the MonetDB Database Server + is running. Note: killing a database should only be done + as last resort to stop a database. A database being + killed may end up with data loss. + """ return self._send_command(database_name, "kill") def set(self, database_name, property_, value): + """ + sets property to value for the given database + for a list of properties, use `monetdb get all` + """ return self._send_command(database_name, "%s=%s" % (property_, value)) def get(self, database_name): + """ + gets value for property for the given database, or + retrieves all properties for the given database + """ properties = self._send_command(database_name, "get") values = {} for dirty_line in properties.split("\n"): @@ -75,7 +128,17 @@ class Control: return values def inherit(self, database_name, property_): + """ + unsets property, reverting to its inherited value from + the default configuration for the given database + """ return self._send_command(database_name, property_ + "=") - def version(self, database_name): - self._send_command(database_name, "version") \ No newline at end of file + def rename(self, old, new): + return self.set(old, "name", new) + + def defaults(self): + return self.get("#defaults") + + def neighbours(self): + return self._send_command("anelosimus", "eximius") \ No newline at end of file _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list