예제 #1
0
def insert_editor(filename, username):
    conn = connect()
    cursor = conn.cursor()
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = cursor.fetchall()
    if not ('editor',) in tables:
        cursor.execute('CREATE TABLE editor ('
                       'id  INTEGER PRIMARY KEY AUTOINCREMENT, '
                       'filename    TEXT    NOT NULL, '
                       'username    TEXT    NOT NULL);')
        conn.commit()

    s = "SELECT name FROM editor WHERE username='******' filename='" + filename + "';"
    cursor.execute(s)
    editor_list = cursor.fetchall()
    if len(editor_list) > 0:
        return 0

    s = "INSERT INTO editor (filename, username) " + "values ('" + filename + "', '" + username + "');"
    # print s
    cursor.execute(s)
    conn.commit()
    print 'Insert editor (filename, username): ', filename, username
    cursor.close()
    conn.close()
    return 1
예제 #2
0
def change(filename, username, auth, myname):
    if auth == -1:
        for user in Users.all_users():
            if user[0] != myname:
                change(filename, user[0], 1, myname)
        return

    if auth == -2:
        for user in Users.all_users():
            if user[0] != myname:
                change(filename, user[0], 0, myname)
        return

    conn = connect()
    cursor = conn.cursor()
    s = "SELECT auth FROM authorization WHERE filename='" + filename + "' AND username='******';"
    # print s
    cursor.execute(s)
    ret = cursor.fetchall()
    if len(ret) == 0:
        s = "INSERT INTO authorization (filename, username, auth) " + \
            "values ('" + filename + "', '" + username + "', " + str(auth) + ");"
        cursor.execute(s)
        conn.commit()
    else:
        s = "UPDATE authorization SET auth=" + str(auth) + \
            " WHERE filename='" + filename + "' AND username='******';"
        # print s
        cursor.execute(s)
        conn.commit()
예제 #3
0
def get_edit_list(username):
    conn = connect()
    cursor = conn.cursor()
    s = "SELECT filename FROM authorization WHERE username='******';"
    cursor.execute(s)
    ret = cursor.fetchall()
    cursor.close()
    conn.close()
    return ret
예제 #4
0
def have_manage_auth(filename, username):
    conn = connect()
    cursor = conn.cursor()
    s = "SELECT auth FROM authorization WHERE filename='" + filename + "' AND username='******';"
    cursor.execute(s)
    ret = cursor.fetchall()
    cursor.close()
    conn.close()
    if len(ret) == 0:
        return 0
    return ret[0][0] >= 2
예제 #5
0
def query_editor(filename, username):
    conn = connect()
    cursor = conn.cursor()
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = cursor.fetchall()
    if not ('editor',) in tables:
        return 0

    s = "SELECT name FROM editor WHERE username='******' filename='" + filename + "';"
    cursor.execute(s)
    editor_list = cursor.fetchall()
    if len(editor_list) > 0:
        return 1

    return 0
예제 #6
0
def create_table():
    conn = connect()
    cursor = conn.cursor()
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = cursor.fetchall()
    if not ('authorization',) in tables:
        cursor.execute('CREATE TABLE authorization ('
                       'id  INTEGER PRIMARY KEY AUTOINCREMENT, '
                       'filename    TEXT    NOT NULL, '
                       'username    TEXT    NOT NULL,'
                       'auth    INTEGER);')
        conn.commit()
    cursor.close()
    conn.close()
    return