-
Notifications
You must be signed in to change notification settings - Fork 2
add harpy view #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
add harpy view #166
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8eb7c93
fix name
pdimens f2e03ee
slean up
pdimens 335b683
add view
pdimens c4259f6
much more convenient build
pdimens 111121a
add harpy view
pdimens 84e2600
add read access check
pdimens 1475a93
improve phrasing
pdimens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,72 @@ | ||
"""View the latest log or snakefile of a workflow""" | ||
|
||
import os | ||
import sys | ||
import glob | ||
import subprocess | ||
import rich_click as click | ||
from ._printing import print_error | ||
from ._validations import is_gzip | ||
|
||
@click.command(no_args_is_help = True, context_settings=dict(allow_interspersed_args=False)) | ||
@click.option('-s', '--snakefile', is_flag = True, show_default = True, default = False, help = "View the snakefile, not the log file") | ||
@click.argument('directory', required=True, type=click.Path(exists=True, file_okay=False)) | ||
def view(directory, snakefile): | ||
""" | ||
View a workflow log file or snakefile | ||
|
||
This convenience command lets you view the latest workflow log file | ||
of a Harpy output directory. You can use `--snakefile` to view the workflow | ||
snakefile instead. Output is printed to the screen via `less` and | ||
accepts the typical keyboard shortcuts to navigate the output, e.g.: | ||
|
||
| key | function | | ||
| :---------------------- | :------------------------- | | ||
| `up arrow`/`down arrow` | scroll up/down | | ||
| `Page Up`/`Page Down` | scroll up/down, but faster | | ||
| `q` | exit | | ||
""" | ||
# check if there is a workflow or log folder | ||
# and whether the expected files are in there | ||
err = 0 | ||
if snakefile: | ||
files = [i for i in glob.iglob(f"{directory}/workflow/*.smk")] | ||
err_dir = f"{directory}/workflow/" | ||
err_file = "snakefiles" | ||
if not os.path.exists(f"{directory}/workflow"): | ||
err = 1 | ||
elif not files: | ||
err = 2 | ||
else: | ||
files = [i for i in glob.iglob(f"{directory}/logs/snakemake/*.log*")] | ||
err_dir = f"{directory}/logs/snakemake/" | ||
err_file = "log files" | ||
if not os.path.exists(f"{directory}/logs/snakemake"): | ||
err = 1 | ||
elif not files: | ||
err = 2 | ||
if err == 1: | ||
print_error( | ||
"Directory not found", | ||
f"The file you are trying to view is expected to be in [blue]{err_dir}[/blue], but that directory was not found. Please check that this is the correct folder." | ||
) | ||
sys.exit(1) | ||
elif err == 2: | ||
print_error( | ||
"File not found", | ||
f"There are no {err_file} in [blue]{err_dir}[/blue]. Please check that this is the correct folder." | ||
) | ||
sys.exit(1) | ||
# sort and pull only the most recent file (based on modification time) | ||
file = sorted(files, key = os.path.getmtime)[-1] | ||
if not os.access(file, os.R_OK): | ||
print_error( | ||
"Incorrect permissions", | ||
f"[blue]{file}[/blue] does not have read access. Please check the file permissions." | ||
) | ||
sys.exit(1) | ||
|
||
cat_cmd = "zcat" if is_gzip(file) else "cat" | ||
stream = subprocess.Popen([cat_cmd, file], stdout=subprocess.PIPE) | ||
pygment = subprocess.Popen(["pygmentize", "-l", "yaml"], stdin = stream.stdout, stdout = subprocess.PIPE) | ||
subprocess.run(["less", "-R"], stdin = pygment.stdout) | ||
pdimens marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.