catch control-c action.

This commit is contained in:
Yoshihiro OKUMURA 2023-05-23 11:48:09 +09:00
parent 9d62d3fb6a
commit 9ed9c4d0f2
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
3 changed files with 5 additions and 1 deletions

View File

@ -50,6 +50,8 @@ def main() -> None:
except MDRSException as e: except MDRSException as e:
print(f"Error: {e}") print(f"Error: {e}")
sys.exit(2) sys.exit(2)
except KeyboardInterrupt:
sys.exit(130)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -6,6 +6,7 @@ import validators
from mdrsclient.exceptions import IllegalArgumentException from mdrsclient.exceptions import IllegalArgumentException
from mdrsclient.settings import CONFIG_DIRNAME from mdrsclient.settings import CONFIG_DIRNAME
from mdrsclient.utils import FileLock
class ConfigFile: class ConfigFile:
@ -70,7 +71,9 @@ class ConfigFile:
def __save(self) -> None: def __save(self) -> None:
self.__ensure_cache_dir() self.__ensure_cache_dir()
with open(self.__config_path, "w") as f: with open(self.__config_path, "w") as f:
FileLock.lock(f)
self.__config.write(f) self.__config.write(f)
FileLock.unlock(f)
os.chmod(self.__config_path, 0o600) os.chmod(self.__config_path, 0o600)
def __ensure_cache_dir(self) -> None: def __ensure_cache_dir(self) -> None:

View File

@ -3,7 +3,6 @@ from typing import IO, Any
if os.name == "nt": if os.name == "nt":
import msvcrt import msvcrt
elif os.name == "posix": elif os.name == "posix":
import fcntl import fcntl