def setUp(self):
     self.app = webtest.TestApp(front.app)
     self.plugin = bottle_sqlite.SQLitePlugin(dbfile=db_path)
     front.app.install(self.plugin)
     connection = sqlite3.connect(db_path)
     db = connection.cursor()
     db.execute("""
         INSERT OR IGNORE INTO circle (city, tag) VALUES ('10,10,10mi', 't')
         """)
     self.fix_circle = db.execute(
         "SELECT id FROM circle ORDER BY id DESC LIMIT 1").fetchone()[0]
     for user in ['first', 'second', 'third']:
         db.execute(
             """
             INSERT OR IGNORE INTO rank (circle, user) VALUES (?, ?)
             """, (self.fix_circle, user))
     db.close()
     connection.commit()
            bottle_headers[0] = headers
        bottle_out = self.bottle_app.wsgi(environ, bottle_start_response)
        bottle_status = bottle_status[0]
        bottle_headers = bottle_headers[0]
        # this might not scale well for large documents
        if hasattr(bottle_out, '__iter__'):
            bottle_out = [x for x in bottle_out]
        # do stuff here...
        for func in self.post_response:
            func(bottle_status, bottle_headers, bottle_out)
        start_response(bottle_status, bottle_headers)
        return bottle_out


app = bottle.Bottle()
app.install(bottle_sqlite.SQLitePlugin(dbfile=settings['dbfile']))
mserver_app = MserverMgmtApp(app)


@mserver_app.post_hook
def add_conditional_contentmd5(status, headers, out):
    add_contentmd5(status, headers, out, conditional=True)

def add_contentmd5(status, headers, out, conditional=False):
    index = -1
    for i in xrange(len(headers)):
        if headers[i][0].lower() == 'Content-MD5'.lower():
            index = i
    if index == -1 and not conditional:
        headers.append(None)
        index = len(headers) - 1
Exemple #3
0
    :param crc: Circle ID
    :param number: Number of the rank
    """
    db.execute(
        """
        INSERT OR IGNORE INTO spam (rank)
        VALUES (?)
        """,
        (number,)
    ).fetchall()
    bottle.redirect("/circle/%s" % crc)


@app.get('/xsl/<path:path>')
def xsl(path):
    """
    Show static XSL file.
    :param path: File path
    :return: XSL content
    """
    bottle.response.set_header('Content-Type', 'application/xsl')
    return bottle.static_file(path, root='xsl')


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("db")
    args = parser.parse_args()
    app.install(bottle_sqlite.SQLitePlugin(dbfile=args.db))
    bottle.run(app=app, host=socket.gethostname(), port=8081)
Exemple #4
0
import json
import re
import os

## bottle modules
import bottle
import bottle_sqlite
from collection_json import Collections

## bottle settings
app = application = bottle.Bottle()
if os.getenv('VMAILADMIN_ENV') == 'DEBUG':
    dbfile = 'vmailadmin_sample.db'
else:
    dbfile = 'vmailadmin_local.db'
sqlite_plugin = bottle_sqlite.SQLitePlugin(dbfile=dbfile, autocommit=True)
app.install(sqlite_plugin)


## common functions
def gen_crypt_password(password):
    crypt_password = crypt(password, mksalt(METHOD_SHA512))
    return crypt_password


def check_password_crypted(password):
    r = re.compile('^\$(1|5|6)\$[a-zA-Z0-9./]{,16}\$[a-zA-Z0-9./]+')
    if r.search(password):
        return password
    else:
        return gen_crypt_password(password)
Exemple #5
0
import os, hashlib, datetime, bottle, bottle_sqlite

dbfilepath = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'workingdiary.db')
bottle.install(bottle_sqlite.SQLitePlugin(dbfile = dbfilepath))

@bottle.route("/")
def hello(db):
    checkexist = db.execute("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = 'mobilephone_dict';").fetchone()
    if 1 != checkexist[0]:
        db.execute('''CREATE TABLE `workingdiary` (
            `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
            `mobilephone` INTEGER NOT NULL,
            `timestamp` TEXT NOT NULL,
            `projectname` TEXT NOT NULL,
            `taskname` TEXT NOT NULL,
            `timeinhour` REAL NOT NULL,
            `location` TEXT NOT NULL,
            `summary` TEXT);
            ''')
        db.execute('''CREATE TABLE `mobilephone_dict` (
            `mobilephone` INTEGER NOT NULL,
            `password` TEXT,
            PRIMARY KEY(mobilephone));
            ''')

    today = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")

    result = db.execute("SELECT DISTINCT projectname FROM workingdiary order by projectname asc;").fetchall()
    allprojects = [item[0] for item in result]

    result = db.execute("SELECT DISTINCT location FROM workingdiary order by location asc;").fetchall()