[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [chutney/master] Templating: replace os.path calls with pathlib
commit c2fa01fe4e0a4815b1097fdf6e1360ae07237af8
Author: c <c@xxxxxxxxxxx>
Date: Sun Jul 5 08:07:15 2020 +0000
Templating: replace os.path calls with pathlib
---
lib/chutney/Templating.py | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/chutney/Templating.py b/lib/chutney/Templating.py
index 43eb636..32724ef 100755
--- a/lib/chutney/Templating.py
+++ b/lib/chutney/Templating.py
@@ -81,6 +81,8 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
+from pathlib import Path
+
import string
import os
@@ -258,18 +260,18 @@ class IncluderDict(_DictWrapper):
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
@@ -298,9 +300,9 @@ class PathDict(_DictWrapper):
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:
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits