generated from sfarrens/pyralid-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from martinkilbinger/log
tests checking
- Loading branch information
Showing
6 changed files
with
72 additions
and
121 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
"""LOGGING. | ||
:Description: This script contains utility methods for job execution and progress logging. | ||
:Author: Martin Kilbinger <[email protected]> | ||
""" | ||
|
||
|
||
import sys | ||
|
||
|
||
def log_command(argv, name=None, close_no_return=True): | ||
"""Log Command. | ||
Write command with arguments to a file or stdout. | ||
Choose name = 'sys.stdout' or 'sys.stderr' for output on sceen. | ||
MKDEBUG copied from shapepipe:cfis | ||
Parameters | ||
---------- | ||
argv : list | ||
Command line arguments | ||
name : str | ||
Output file name (default: 'log_<command>') | ||
close_no_return : bool | ||
If True (default), close log file. If False, keep log file open | ||
and return file handler | ||
Returns | ||
------- | ||
filehandler | ||
log file handler (if close_no_return is False) | ||
""" | ||
if name is None: | ||
name = 'log_' + os.path.basename(argv[0]) | ||
|
||
if name == 'sys.stdout': | ||
f = sys.stdout | ||
elif name == 'sys.stderr': | ||
f = sys.stderr | ||
else: | ||
f = open(name, 'w') | ||
|
||
for a in argv: | ||
|
||
# Quote argument if special characters | ||
if '[' in a or ']' in a: | ||
a = f'\"{a}\"' | ||
|
||
print(a, end='', file=f) | ||
print(' ', end='', file=f) | ||
|
||
print('', file=f) | ||
|
||
if not close_no_return: | ||
return f | ||
|
||
if name != 'sys.stdout' and name != 'sys.stderr': | ||
f.close() |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
coverage | ||
nose | ||
isort | ||
jinja2==3.0 | ||
numpydoc | ||
pytest | ||
pytest-cov | ||
pytest-pep8 | ||
pytest-emoji | ||
pytest-flake8 | ||
wemake-python-styleguide | ||
pytest-pycodestyle | ||
pytest-pydocstyle |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
astropy | ||
datetime | ||
importlib_metadata | ||
numpy | ||
astropy | ||
matplotlib | ||
pycodestyle==2.9.0 | ||
vos | ||
datetime |
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
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