Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Templating: replace os.path calls with pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
c-chroniko committed Jul 6, 2020
1 parent a17854b commit c2fa01f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/chutney/Templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
from __future__ import print_function
from __future__ import unicode_literals

from pathlib import Path

import string
import os

Expand Down Expand Up @@ -258,18 +260,18 @@ def _getitem(self, key, my):
if not key.startswith("include:"):
raise KeyError(key)

filename = key[len("include:"):]
if os.path.isabs(filename):
with open(filename, 'r') as f:
filename = Path(key[len("include:"):])
if filename.is_absolute():
with filename.open(mode='r') as f:
stat = os.fstat(f.fileno())
if stat.st_mtime > self._st_mtime:
self._st_mtime = stat.st_mtime
return f.read()

for elt in self._includePath:
fullname = os.path.join(elt, filename)
if os.path.exists(fullname):
with open(fullname, 'r') as f:
fullname = Path(elt, filename)
if fullname.exists():
with fullname.open(mode='r') as f:
stat = os.fstat(f.fileno())
if stat.st_mtime > self._st_mtime:
self._st_mtime = stat.st_mtime
Expand Down Expand Up @@ -298,9 +300,9 @@ def _getitem(self, key, my):
key = key[len("path:"):]

for location in self._path:
p = os.path.join(location, key)
p = Path(location, key)
try:
s = os.stat(p)
s = p.stat()
if s and s.st_mode & 0x111:
return p
except OSError:
Expand Down

0 comments on commit c2fa01f

Please sign in to comment.