예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
0
파일: file.py 프로젝트: pikulak/pywdbms
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)
예제 #5
0
파일: app.py 프로젝트: pikulak/pywdbms
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)
예제 #6
0
    def decorated_function(*args, **kwargs):
        if not DatabaseContainer.get(kwargs["shortname"]):
            abort(404)
        if BindContainer.get(kwargs["shortname"]):

            if not check_connection(DatabaseContainer.get(
                    kwargs["shortname"])):
                BindContainer.delete(kwargs["shortname"])
            else:
                return f(*args, **kwargs)

        url = url_for("blueprint.database_connect",
                      host=kwargs["host"],
                      shortname=kwargs["shortname"])
        return make_response(
            render_template("database/error.html",
                            host=kwargs["host"],
                            url=url), 200)
예제 #7
0
파일: forms.py 프로젝트: pikulak/pywdbms
    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
        return True
예제 #8
0
파일: app.py 프로젝트: pikulak/pywdbms
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)
예제 #9
0
파일: app.py 프로젝트: pikulak/pywdbms
def database_add():
    error = False
    form = DatabaseAddForm(request.form)
    if request.method == 'POST':
        if form.validate():
            if check_connection(form.data):
                DatabaseContainer.add(form.data)
                update()
                return redirect(url_for("blueprint.dashboard"))
            else:
                error = "Unable connect to database. Maybe you provided bad data?"
        else:
            if len(form.shortname.errors) > 0:
                error = "Shortname already exists. Please specify another one."
            if len(form.database.errors) > 0:
                error = "Specifed database already exists."
            else:
                error = "Please provide correct data."
    return make_response(
        render_template('database/add.html', form=form, error=error), 200)
예제 #10
0
파일: app.py 프로젝트: pikulak/pywdbms
def database_view_operations(host, shortname):
    error = False
    c = request.args.get("c")
    act_db_properties = DatabaseContainer.get(shortname)
    form = DatabaseEditForm(request.form)
    if c is not None:
        if COMMANDS[c](host=host, shortname=shortname):
            return redirect(
                url_for("blueprint.server_view_databases", host=host))
        else:
            return redirect('/')
    if request.method == 'POST':
        if form.validate():
            if check_connection(form.data):
                DatabaseContainer.add(form.data)
                DatabaseContainer.delete([shortname])
                BindContainer.delete([shortname])
                BindContainer.add(form.shortname.data)
                update()
                return redirect(
                    url_for("blueprint.database_view_operations",
                            host=host,
                            shortname=form.shortname.data))
            else:
                error = "Unable connect to database."
        else:
            if len(form.shortname.errors) > 0:
                error = "Shortname already exists. Please specify another one."
            if len(form.database.errors) > 0:
                error = "Specifed database already exists."
            else:
                error = "Please provide correct data."
    return make_response(
        render_template('database/operations.html',
                        host=host,
                        form=form,
                        error=error,
                        act_db_properties=act_db_properties), 200)
예제 #11
0
파일: decorators.py 프로젝트: jxub/pywdbms
    def decorated_function(host, shortname, table_name=None, section=None):
        if BindContainer.get(shortname):

            if not check_connection(DatabaseContainer.get(shortname)):
                BindContainer.delete(shortname)
            else:
                if table_name == None:
                    return f(host, shortname)
                return f(host, shortname, table_name)

        url = url_for("blueprint.database_connect",
                      host=host,
                      shortname=shortname)
        return make_response(
            render_template("database/error.html", host=host, url=url), 200)
예제 #12
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)
예제 #13
0
파일: file.py 프로젝트: pikulak/pywdbms
def load_databases_from_file(filename='databases.json', dir=default_dir):
    with codecs.open(os.path.join(dir, filename), mode='r',
                     encoding="utf-8") as f:
        json_str = f.read()
        DatabaseContainer.load_databases(json.loads(json_str))
예제 #14
0
파일: app.py 프로젝트: pikulak/pywdbms
def hosts():
    hosts = sorted(DatabaseContainer.get_uniquehosts())
    return dict(hosts=hosts)
예제 #15
0
파일: app.py 프로젝트: pikulak/pywdbms
 def databases(host):
     databases = list(DatabaseContainer.get_databases(host=host))
     return databases