Correction du lock de la sqlite

This commit is contained in:
guimoz 2017-01-31 12:06:02 +01:00
parent 6d9a993d0a
commit e7383cfc0e
2 changed files with 33 additions and 13 deletions

View file

@ -1,5 +1,5 @@
import sqlite3
from users.models import user
from users.models import User
from machines.models import Machine,Interface
SQLITE_FILENAME = '/var/www/re2o/players.db'
@ -8,15 +8,25 @@ def connect_sqlite():
return sqlite3.connect(SQLITE_FILENAME)
# Connexion à la base SQLite locale
con_sqlite = connect_sqlite()
cur_sqlite = con_sqlite.cursor()
# cur_sqlite.execute('''create table players (id,prenom,nom, etat)''')
# cur_sqlite.execute('''create table machines (id,uid_user,ip)''')
con = connect_sqlite()
cur = con.cursor()
# cur.execute('''create table players (id,prenom,nom, etat)''')
# cur.execute('''create table machines (id,uid_user,ip)''')
cur.execute("""select id from players""")
players = cur.fetchall()
players = [player[0] for player in players]
cur.execute("""select ip from machines""")
machines = cur.fetchall()
machines = [machine[0] for machine in machines]
for user in User.objects.filter(school=1):
if user.has_access() and user.is_adherent():
cur_sqlite.execute("""insert into players values (?,?,?,?)""",(user.uid_number, user.name, user.surname, 0))
if user.has_access() and (user.is_adherent() or user.end_adhesion()):
if user.uid_number not in players:
cur.execute("""insert into players values (?,?,?,?)""",(user.uid_number, user.name, user.surname, 0))
for m in Machine.objects.filter(user= user):
for i in Interface.objects.filter(machine = m):
cur_sqlite.execute("""insert into machines values (?,?,?) """,(i.id, user.uid_number, i.ipv4.ipv4))
con_sqlite.commit()
con_sqlite.close()
if i.ipv4.ipv4 not in machines:
cur.execute("""insert into machines values (?,?,?) """,(i.id, user.uid_number, i.ipv4.ipv4))
con.commit()
con.close()

View file

@ -244,18 +244,28 @@ def ban(player_id, target_id, success):
cur.execute("""select id,ban_end from players
where id=(?)""", [banned_player['id']])
con.commit()
con.close()
con = connect_sqlite()
cur = con.cursor()
ban_end = cur.fetchone()[0]
ban_end = time() + BAN_DURATION
cur.execute("""update players set ban_end=(?)
where id=(?)""", [ban_end, banned_player['id']])
cur.execute("""insert into bans (player_id,target_id,success,time)
values (?,?,?,?)""", [player['id'], target['id'], \
success and 1 or 0, time()])
con.commit()
con.close()
con = connect_sqlite()
cur = con.cursor()
cur.execute("""insert into bans (player_id,target_id,success,time)
values (?,?,?,?)""", [player['id'], target['id'], \
success and 1 or 0, time()])
con.commit()
con.close()
def unban(player_id):
con = connect_sqlite()