Example #1
1
def addUserRequest(user, project):
    """Add 'project join' requests"""

    db = openDB()
    c = db.cursor()

    c.execute("insert into project_requests values (%s, %s)", (user, project))

    db.close()
Example #2
1
def listUsers():
    """Return list of ids for all users"""

    db = openDB()
    c = db.cursor()

    res = c.execute("select login from users")
    db.close()

    return [x[0] for x in c.fetchall()]
Example #3
1
def getCapabilities(user):

    db = openDB()
    c = db.cursor()

    res = c.execute("select action, scope from capabilities where user = %s", (user,))

    db.close()

    return c.fetchall()
Example #4
1
def valid_password(env, username, password):
    """Check given auth data against DB; env may be None"""

    db = openDB()
    c = db.cursor()

    res = c.execute("select password from users where login=%s limit 1", (username,))

    if not res:
        return False

    res = c.fetchone()[0]
    db.close()

    return res == htpasswd(password, res[0] + res[1])
Example #5
1
def userProjects(id):
    """Returns all project for user with given _id_"""

    db = openDB()
    c = db.cursor()

    c.execute(
        "select project from user_project where \
            user=%s",
        (id,),
    )

    db.close()

    return c.fetchall()
Example #6
1
def getAdmin(project):
    """Returns admin for given _project_"""

    db = openDB()
    c = db.cursor()

    res = c.execute("select admin from projects where id=%s limit 1", (project,))

    if not res:
        return False

    res = c.fetchone()[0]

    db.close()

    return res
Example #7
0
def getUserData(id):
    """Get all public user data (without pass hashs)"""

    db = openDB()
    c = db.cursor()

    if not findUser(id):
        raise ScalakError("User doesn't exists")

    c.execute(
        "select login, name, last_name, email, note from users where \
            login=%s limit 1",
        (id,),
    )

    db.close()

    return c.fetchone()
Example #8
0
def findUser(id, project=None):
    """Check if user with given _id_ exists globally or in _project_ if given"""

    db = openDB()
    c = db.cursor()

    if not project:
        res = c.execute("select login from users where login=%s limit 1", (id,))

    else:
        res = c.execute(
            "select login from users, user_project where login=%s \
                and login=user and project=%s limit 1",
            (id, project),
        )

    db.close()

    if not res:
        return False

    return True
Example #9
0
def getUserRequests(user=None, project=None):
    """Returns 'project join' requests for given data or all requests"""

    db = openDB()
    cur = db.cursor()

    if project and user:
        res = cur.execute(
            "select * from project_requests where user=%s and \
                project=%s limit 1",
            (user, project),
        )

    elif not project and not user:
        res = cur.execute(
            "select * from project_requests where user=%s \
                limit 1",
            (id,),
        )

    elif project and not user:
        res = cur.execute(
            "select * from project_requests where \
                project=%s limit 1",
            (project,),
        )

    elif not project and user:
        res = cur.execute(
            "select * from project_requests where user=%s and \
                limit 1",
            (user,),
        )

    db.close()

    return cur.fetchall()
#!/usr/bin/python
# -*- coding: utf-8 -*-

import MySQLdb as mdb
import sys

con = mdb.connect("localhost", "testuser", "test623", "testdb")

with con:

    cur = con.cursor()
    cur.execute(
        "CREATE TABLE IF NOT EXISTS \
    Writers(Id INT PRIMARY KEY AUTO_INCREMENT, Name VARCHAR(25))"
    )
    cur.execute("INSERT INTO Writers(Name) VALUES('Jack London')")
    cur.execute("INSERT INTO Writers(Name) VALUES('Honore de Balzac')")
    cur.execute("INSERT INTO Writers(Name) VALUES('Lion Feuchtwanger')")
    cur.execute("INSERT INTO Writers(Name) VALUES('Emile Zola')")
    cur.execute("INSERT INTO Writers(Name) VALUES('Truman Capote')")

# Safety first... or last.
mdb.close()
 def disconnectToMySQL(self):
     mysql.close(self.conn)
    zipcode,
)

query2 = []
rows = cur.fetchall()
for row in rows:
    query2.append(row)

top_ten = []
# specific to this query
for i in range(0, len(query2)):
    if i < 11:
        temp_dic = {
            "city": query2[i][2],
            "zipcode": query2[i][0],
            "match_latitude": query2[i][7],
            "match_longitude": query2[i][8],
        }
        top_ten.append(temp_dic)
    else:
        break


# display choices on a map and let user pick the best


cur.close()
db.close()

if __name__ == "__main__":
    main()
Example #13
0
File: ssh.py Project: iory1987/WORK
    str(MEMORI)

    s.sendline("cat /proc/cpuinfo")
    s.prompt()
    CPU = s.before
    str(CPU)

    s.sendline("service --status-all")
    s.prompt()
    SERVICE = s.before
    str(SERVICE)

    s.logout()
except pxssh.ExceptionPxssh, e:
    print "falha ao logar no ssh"
    print str(e)


try:
    con = my.connect("localhost", "root", "djjb022000", "assesment")
    cur = con.cursor()
    sql = "INSERT INTO pxssh(py_hostname, py_uname, py_user, py_dfh, py_dfi, py_iptables, py_uptime, py_free, py_cpu, py_services) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    args = (hostname, UNAME, username, DISK, INODE, FIREWALL, UPTIME, MEMORI, CPU, SERVICE)

    # Inserindo os dados na DATABASE
    cur.execute(sql, args)
    con.commit()
    my.close()

except:
    print "Erro ao tentar inserir os dados"