diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Control.py | 10 | ||||
| -rw-r--r-- | src/LockFile.py | 14 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/Control.py b/src/Control.py index b57c9048..57f48ea4 100644 --- a/src/Control.py +++ b/src/Control.py @@ -39,11 +39,11 @@ class ControlClient(object): class Control(PollSource.PollSource): - def __init__(self, bot: IRCBot.Bot, database_location: str): + def __init__(self, bot: IRCBot.Bot, filename: str): self._bot = bot self._bot.log.hook(self._on_log) - self._socket_location = "%s.sock" % database_location + self._filename = filename self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self._clients = {} @@ -53,9 +53,9 @@ class Control(PollSource.PollSource): self._send_action(client, "log", line) def bind(self): - if os.path.exists(self._socket_location): - os.remove(self._socket_location) - self._socket.bind(self._socket_location) + if os.path.exists(self._filename): + os.remove(self._filename) + self._socket.bind(self._filename) self._socket.listen(1) def get_readables(self) -> typing.List[int]: diff --git a/src/LockFile.py b/src/LockFile.py index 3436eddf..4bb07726 100644 --- a/src/LockFile.py +++ b/src/LockFile.py @@ -4,14 +4,14 @@ from src import PollHook, utils EXPIRATION = 60 # 1 minute class LockFile(PollHook.PollHook): - def __init__(self, database_location: str): - self._lock_location = "%s.lock" % database_location + def __init__(self, filename: str): + self._filename = filename self._next_lock = None def available(self): now = utils.datetime_utcnow() - if os.path.exists(self._lock_location): - with open(self._lock_location, "r") as lock_file: + if os.path.exists(self._filename): + with open(self._filename, "r") as lock_file: timestamp_str = lock_file.read().strip().split(" ", 1)[0] timestamp = utils.iso8601_parse(timestamp_str) @@ -22,7 +22,7 @@ class LockFile(PollHook.PollHook): return True def lock(self): - with open(self._lock_location, "w") as lock_file: + with open(self._filename, "w") as lock_file: last_lock = utils.datetime_utcnow() lock_file.write("%s" % utils.iso8601_format(last_lock)) self._next_lock = last_lock+datetime.timedelta( @@ -34,5 +34,5 @@ class LockFile(PollHook.PollHook): self.lock() def unlock(self): - if os.path.isfile(self._lock_location): - os.remove(self._lock_location) + if os.path.isfile(self._filename): + os.remove(self._filename) |
