Skip to content

Commit

Permalink
Merge pull request #74 from JedMeister/finish-typing
Browse files Browse the repository at this point in the history
Finish typing
  • Loading branch information
JedMeister authored Jun 28, 2023
2 parents c814701 + 1b55e24 commit cc665da
Show file tree
Hide file tree
Showing 12 changed files with 766 additions and 264 deletions.
19 changes: 13 additions & 6 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@

import re
import os
from typing import Optional


class Error(Exception):
pass


def path(filename):
def path(filename: str) -> str:
for dir in ("conf", "/etc/confconsole"):
path = os.path.join(dir, filename)
if os.path.exists(path):
return path

raise Error('could not find configuration file: %s' % path)
raise Error(f'could not find configuration file: {filename}')


class Conf:
def _load_conf(self):
default_nic: Optional[str]
publicip_cmd: Optional[str]
networking: bool
copy_paste: bool
conf_file: str

def _load_conf(self) -> None:
if not self.conf_file or not os.path.exists(self.conf_file):
return

Expand All @@ -44,16 +51,16 @@ def _load_conf(self):
else:
raise Error("illegal configuration line: " + line)

def __init__(self):
def __init__(self) -> None:
self.default_nic = None
self.publicip_cmd = None
self.networking = True
self.copy_paste = True
self.conf_file = path("confconsole.conf")
self._load_conf()

def set_default_nic(self, ifname):
def set_default_nic(self, ifname: str) -> None:
self.default_nic = ifname

with open(self.conf_file, 'w') as fob:
fob.write("default_nic %s\n" % ifname)
fob.write(f"default_nic {ifname}\n")
Loading

0 comments on commit cc665da

Please sign in to comment.