From d59733533b364060afb821731a14bc3050c71992 Mon Sep 17 00:00:00 2001 From: nukeop Date: Mon, 2 Jan 2017 02:19:54 +0100 Subject: [PATCH] Remove unneeded files --- smash/database.py | 57 ------------------------------- smash/database_postgresql.py | 66 ------------------------------------ smash/models.py | 53 ----------------------------- 3 files changed, 176 deletions(-) delete mode 100644 smash/database.py delete mode 100644 smash/database_postgresql.py delete mode 100644 smash/models.py diff --git a/smash/database.py b/smash/database.py deleted file mode 100644 index 2fa86e1..0000000 --- a/smash/database.py +++ /dev/null @@ -1,57 +0,0 @@ -import sqlite3 - -class Database(object): - """Interface to a local database that stores data for the website. - """ - def __init__(self, dbname): - self.dbname = dbname - - - @property - def conn(self): - return sqlite3.connect(self.dbname) - - - @property - def cursor(self): - return self.conn.cursor() - - - def select(self, table, fields, condition=None): - cur = self.cursor - - if condition is not None: - cur.execute("SELECT {} FROM {} WHERE {}".format(fields, table, - condition)) - else: - cur.execute("SELECT {} FROM {}".format(fields, table)) - - return cur.fetchall() - - - def create_table(self, table, cols): - conn = self.conn - cur = conn.cursor() - - query = "CREATE TABLE {}({})".format(table, cols) - cur.execute(query) - conn.commit() - - - def insert(self, table, columns, values, params): - conn = self.conn - cur = conn.cursor() - - query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, values) - cur.execute(query, params) - conn.commit() - return cur - - - def delete(self, table, condition): - conn = self.conn - cur = conn.cursor() - - query = "DELETE FROM {} WHERE {}".format(table, condition) - cur.execute(query) - conn.commit() diff --git a/smash/database_postgresql.py b/smash/database_postgresql.py deleted file mode 100644 index 8679afb..0000000 --- a/smash/database_postgresql.py +++ /dev/null @@ -1,66 +0,0 @@ -import os -import psycopg2 -import urlparse - -class DatabasePostgreSQL(object): - """Interface to the heroku PostgreSQL database plugin. - """ - def __init__(self): - urlparse.uses_netloc.append("postgres") - self.url = urlparse.urlparse(os.environ["DATABASE_URL"]) - - - @property - def conn(self): - return psycopg2.connect( - database=self.url.path[1:], - user=self.url.username, - password=self.url.password, - host=self.url.hostname, - port=self.url.port - ) - - - @property - def cursor(self): - return self.conn.cursor() - - - def select(self, table, fields, condition=None): - cur = self.cursor - - if condition is not None: - cur.execute("SELECT {} FROM {} WHERE {}".format(fields, table, - condition)) - else: - cur.execute("SELECT {} FROM {}".format(fields, table)) - - return cur.fetchall() - - - def create_table(self, table, cols): - conn = self.conn - cur = conn.cursor() - - query = "CREATE TABLE {}({})".format(table, cols) - cur.execute(query) - conn.commit() - - - def insert(self, table, columns, values, params): - conn = self.conn - cur = conn.cursor() - - query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, values) - cur.execute(query, params) - conn.commit() - return cur - - - def delete(self, table, condition): - conn = self.conn - cur = conn.cursor() - - query = "DELETE FROM {} WHERE {}".format(table, condition) - cur.execute(query) - conn.commit() diff --git a/smash/models.py b/smash/models.py deleted file mode 100644 index d8f46d3..0000000 --- a/smash/models.py +++ /dev/null @@ -1,53 +0,0 @@ -class Model(object): - #Name of the table to be created - tablename = "abstractmodel" - - #Attributes are tuples - attribute name, data type, other requirements - id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT") - - -class Quote(Model): - tablename = "quotes" - - id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT") - rating = ("rating", "INTEGER", "NOT NULL") - content = ("content", "TEXT", "NOT NULL") - approved = ("approved", "BOOLEAN", "NOT NULL") - author_ip = ("author_ip", "TEXT", "NOT NULL") - time = ("time", "TEXT", "NOT NULL") - - -class Tag(Model): - tablename = "tags" - - id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT") - name = ("name", "TEXT", "UNIQUE NOT NULL") - - -class TagsToQuotes(Model): - tablename = "tagsToQuotes" - - id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT") - tag_id = ("tagid", "INTEGER", "NOT NULL") - quote_id = ("quoteid", "INTEGER", "NOT NULL") - - -def init_models(db): - import logging - logger = logging.getLogger(__name__) - - for model in Model.__subclasses__(): - columns = [x for x in model.__dict__ if '__' not in x and x != - 'tablename'] - - try: - db.create_table( - model.tablename, - ','.join([' '.join(model.__dict__[x]) for x in columns]) - ) - logger.info("Created table in the database:" - " {}".format(model.tablename)) - except: - #If we can't create a table here, it means it's already in the - #database, so we can skip it - pass