moth/teams.py

44 lines
857 B
Python
Raw Normal View History

#! /usr/bin/env python3
import fcntl
2009-09-02 14:25:31 -06:00
from urllib.parse import quote, unquote
house = 'dirtbags'
teams = None
def build_teams():
global teams
teams = {}
try:
f = open('passwd')
for line in f:
2009-09-02 14:25:31 -06:00
line = line.strip()
team, passwd = [unquote(v) for v in line.strip().split('\t')]
teams[team] = passwd
except IOError:
pass
2009-09-02 14:25:31 -06:00
def validate(team):
if teams is None:
build_teams()
2009-09-02 14:25:31 -06:00
def chkpasswd(team, passwd):
validate(team)
if teams.get(team) == passwd:
return True
else:
return False
def exists(team):
2009-09-02 14:25:31 -06:00
validate(team)
if team == house:
return True
return team in teams
def add(team, passwd):
f = open('passwd', 'a')
fcntl.lockf(f, fcntl.LOCK_EX)
f.seek(0, 2)
2009-09-02 14:25:31 -06:00
f.write('%s\t%s\n' % (quote(team), quote(passwd)))