-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessList.py
More file actions
32 lines (26 loc) · 926 Bytes
/
AccessList.py
File metadata and controls
32 lines (26 loc) · 926 Bytes
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
import os
class AccessList:
def __init__(self, fname, owner):
self._filename = fname
self._list = []
if not os.path.isfile(self._filename):
open(self._filename, "w+").write(owner + "\n")
self._load()
def _load(self):
with open(self._filename, "r") as f:
self._list = f.read().split()
def _save(self):
with open(self._filename, "w") as f:
f.write("\n".join(self._list) + "\n")
def hasAccess(self, user):
""" Checks whether a given user (+ hostname) has access. """
return user in self._list
def add(self, user):
""" Adds a user to the access list. """
self._list.append(user)
with open(self._filename, "a") as f:
f.write(user)
def remove(self, user):
""" Removes a user from the access list. """
self._list.remove(user)
self._save()