Skip to content

Commit

Permalink
log info instead of raising error
Browse files Browse the repository at this point in the history
  • Loading branch information
UrszulaNeuman committed Jan 10, 2024
1 parent c0024d3 commit 5e3f073
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pmac_motorhome/plc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ def __init__(
self.groups: List[Group] = []
self.motors: "OrderedDict[int, Motor]" = OrderedDict()
self.generator = PlcGenerator(self.controller)
if not self.filepath.parent.exists():
log.error(f"Cant find parent of {self.filepath} from dir {Path.cwd()}")
raise ValueError(
f"bad file path {self.filepath.parent}\
from dir {Path.cwd()}"
)
directory_name = self.filepath.parts[0]
other_parts = self.filepath.parts[1:]
if (any(directory_name in i for i in Path.cwd().parts)):
self.filepath = Path(other_parts[0], other_parts[1])
log.info(f"New file path {self.filepath} from dir {Path.cwd()}")
if (
self.plc_num < 8 # PLCs 1-8 are reserved
or self.plc_num > 32 # highest PLC number possible
Expand Down Expand Up @@ -89,8 +88,11 @@ def __exit__(self, exception_type, exception_value, traceback):

# write out PLC
plc_text = self.generator.render("plc.pmc.jinja", plc=self)
with self.filepath.open("w") as stream:
stream.write(plc_text)
try:
with self.filepath.open("w") as stream:
stream.write(plc_text)
except FileNotFoundError: # important when there is one motorhome.py for all controllers
pass

@classmethod
def instance(cls) -> "Plc":
Expand Down

0 comments on commit 5e3f073

Please sign in to comment.