Пример #1
0
def update_databases_to_file(filename='databases.json', dir=default_dir):
    with codecs.open(os.path.join(dir, filename), mode='w+',
                     encoding="utf-8") as f:
        json_str = json.dumps(DatabaseContainer.get_databases(),
                              indent=4,
                              sort_keys=True)
        f.write(json_str)
Пример #2
0
def server_view_users(host):
    sorted_by_drivers = {}
    users = {}
    headers = {}
    _BINDS = BindContainer.get_all()

    for _driver in SUPPORTED_DRIVERS:
        sorted_by_drivers[_driver] = (DatabaseContainer.get_databases(
            host=host, drivername=_driver))
        for drivername, databases in sorted_by_drivers.items():
            for database in databases:
                for shortname, db_properties in database.items():
                    if shortname in _BINDS:
                        connection = _BINDS[shortname][0]  #connection
                        stmt = StatementsChooser.for_[
                            drivername].get_server_users()
                        result = connection.execute(stmt)
                        headers[drivername] = result.keys()
                        users[drivername] = result.fetchall()
                        break
                else:
                    continue
                break

    return make_response(
        render_template('server/users.html',
                        host=host,
                        headers=headers,
                        users=users), 200)
Пример #3
0
def delete_server(host=""):
	databases = DatabaseContainer.get_databases(host=host)
	shortnames = [list(database.keys())[0] for database in databases]
	DatabaseContainer.delete(shortnames)
	BindContainer.delete(shortnames)
	DatabaseContainer.UNIQUE_HOSTS.remove(host)
	update()
	return True
Пример #4
0
def delete_database(shortname="", host=""):
	DatabaseContainer.delete([shortname])
	BindContainer.delete([shortname])
	if len(DatabaseContainer.get_databases(host=host)) <= 0:
		DatabaseContainer.UNIQUE_HOSTS.remove(host)
		return True
	update()
	return False
Пример #5
0
def server_view_databases(host):
    sorted_by_drivers = {}
    versions = {}

    for _driver in SUPPORTED_DRIVERS:
        sorted_by_drivers[_driver] = (DatabaseContainer.get_databases(
            host=host, drivername=_driver))
    return make_response(
        render_template('server/databases.html',
                        sorted_by_drivers=sorted_by_drivers,
                        host=host), 200)
Пример #6
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        if DatabaseContainer.get(self.shortname.data):
            self.shortname.errors.append("Shortname exists")
            return False
        if len(DatabaseContainer.get_databases(host=self.host.data,\
                                               database=self.database.data,\
                                               port=self.port.data)) > 0:
            self.database.errors.append("Database exists")
            return False
        return True
Пример #7
0
 def decorated_function(*args, **kwargs):
     host = kwargs["host"]
     if len(DatabaseContainer.get_databases(host=host)) <= 0:
         return abort(404)
     else:
         return f(*args, **kwargs)
Пример #8
0
 def databases(host):
     databases = list(DatabaseContainer.get_databases(host=host))
     return databases