blob: 502674ee480b4ce33d73fdbf7c3b381552b26e81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import errno
import os
import time
import yaml
import cliapp
from yarnutils import *
import distixapi
datadir = os.environ['DATADIR']
srcdir = os.environ['SRCDIR']
vars = Variables(datadir)
MAX_CAT_TIME = 5 # seconds
def cat(filename):
start = time.time()
while time.time() - start < MAX_CAT_TIME:
try:
with open(filename) as f:
data = f.read()
if len(data) == 0:
continue
return data
except (IOError, OSError) as e:
if e.errno == errno.ENOENT:
continue
raise
raise Exception("cat took more then %s seconds" % MAX_CAT_TIME)
def load_users():
if os.path.exists('users.yaml'):
with open('users.yaml') as f:
return yaml.safe_load(f)
return {'users': {}}
def save_users(users):
print 'saving', repr(users)
with open('users.yaml', 'w') as f:
yaml.safe_dump(users, stream=f)
|