-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b29644
commit 4cb062e
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import pathlib | ||
import stat | ||
import sys | ||
import textwrap | ||
|
||
|
||
def msgfmt(msg, prefix=""): | ||
lines = [] | ||
for line in msg.splitlines(): | ||
lines += textwrap.wrap(line, 80 - len(prefix)) | ||
return "\n".join([prefix + line for line in lines]) | ||
|
||
|
||
def warn(msg): | ||
print(msgfmt(msg, "warning: ")) | ||
|
||
|
||
def die(msg): | ||
sys.exit(msgfmt(msg, "error: ")) | ||
|
||
|
||
def mkdir_p(dir): | ||
try: | ||
pathlib.Path(dir).mkdir(parents=True, exist_ok=True) | ||
except FileExistsError: | ||
die("{} is not a directory".format(dir)) | ||
|
||
|
||
def is_group_or_other_writable(f): | ||
st = os.stat(f) | ||
return bool(st.st_mode & (stat.S_IWGRP | stat.S_IWOTH)) | ||
|
||
|
||
def is_group_or_other_readable(f): | ||
st = os.stat(f) | ||
return bool(st.st_mode & (stat.S_IRGRP | stat.S_IROTH)) | ||
|
||
|
||
def check_runtime_dir(dir): | ||
try: | ||
pathlib.Path(dir) | ||
except FileExistsError: | ||
die("{} is not a directory".format(dir)) |