-
Notifications
You must be signed in to change notification settings - Fork 0
Get DS file structure with serviceX tool #4
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
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
afccc4b
servicex token ignore
ArturU043 ae69520
adding get_structure utility function and dependencies
ArturU043 b8d737f
adding suppport for multiple files
ArturU043 d5e37ca
adding cli option, save_to_text and print flags
ArturU043 04bed65
CI tests for helper functions + .txt file
ArturU043 fe6c414
Split get_structure into more helpers
ArturU043 139708e
adding more tests for deliver spec builder
ArturU043 e71a01e
Comments on helpers
ArturU043 7d87a47
docstrings & error msg improvements
ArturU043 2c88a67
helper test for raw decoding into array - should be in file_peeking.p…
ArturU043 e1954db
remove unused raw arg
ArturU043 054e4a6
Removing decode-raw and implementing it in file_peeking
ArturU043 d987b41
Add tests for str_to_array
ArturU043 fb4914e
return type instead of array
ArturU043 a827352
json-based file structure enconding and decoding
ArturU043 61c7114
simplify serivex import
ArturU043 95803a6
miniopy dependencie to fix CI importError
ArturU043 30e0955
Removing --save-to-txt arg on CLI
ArturU043 01c49a2
logging and better exception handling
ArturU043 9bfc039
adding handle function for dataset CLI argument
ArturU043 ae4d039
Adding flake8 in CI - Issue 5
ArturU043 f21e92e
Pipe line fail if flake8 fail - issue 5
ArturU043 20361c3
run black instead of flake8
ArturU043 3289625
Fix black format name
ArturU043 b1b6bb1
CLI Typer replcement of arg parser , improved sample name display
ArturU043 c5464d6
Update __init__.py for versioning - resolved merge conflict
ArturU043 58ba6ae
black-format __init__.py
ArturU043 ef67554
Merge branch 'main' into fille_peek_dev
ArturU043 9b55e7f
format after conflict resolve
ArturU043 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
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 |
---|---|---|
|
@@ -7,3 +7,10 @@ servicex.yaml | |
|
||
#Distribution | ||
dist/ | ||
|
||
#ServiceX | ||
servicex.yaml | ||
|
||
#Testing | ||
samples_structure.txt | ||
|
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
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,73 @@ | ||
import sys | ||
import json | ||
import os | ||
import logging | ||
from .file_peeking import get_structure | ||
import typer | ||
from typing import List | ||
|
||
app = typer.Typer() | ||
|
||
|
||
def make_dataset_list(dataset_arg): | ||
""" | ||
Helper to handle the user input daset argument. | ||
Loads to dict if input is .json else returns default input | ||
Output is given to get_structure() | ||
|
||
Parameters: | ||
dataset_arg (str, [str]): Single DS identifier, list of multiple identifiers or path/to/.json containig identifiers and sample names. | ||
|
||
Returns: | ||
dataset (str, [str], dict): dictionary loaded from the json | ||
""" | ||
if len(dataset_arg) == 1 and dataset_arg[0].endswith(".json"): | ||
dataset_file = dataset_arg[0] | ||
|
||
if not os.path.isfile(dataset_file): | ||
logging.error(f"Error: JSON file '{dataset_file}' not found.") | ||
sys.exit(1) | ||
|
||
try: | ||
with open(dataset_file, "r") as f: | ||
dataset = json.load(f) | ||
|
||
if not isinstance(dataset, dict): | ||
logging.error(f"Error: The JSON file must contain a dictionary.") | ||
sys.exit(1) | ||
|
||
except json.JSONDecodeError: | ||
gordonwatts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logging.error( | ||
f"Error: '{dataset_file}' is not a valid JSON file.", exc_info=True | ||
) | ||
sys.exit(1) | ||
|
||
else: | ||
# If DS is provided in CLI instead of json, use it as a list (default) | ||
dataset = dataset_arg | ||
|
||
return dataset | ||
|
||
|
||
@app.command() | ||
def run_from_command( | ||
dataset: List[str] = typer.Argument( | ||
..., | ||
help="Input datasets (Rucio DID) or path to JSON file containing datasets in a dict.", | ||
), | ||
filter_branch: str = typer.Option( | ||
"", "--filter-branch", help="Only display branches containing this string." | ||
), | ||
): | ||
""" | ||
Calls the get_structure function and sends results to stdout. | ||
To run on command line: servicex-get-structure -dataset --filter-branch | ||
""" | ||
ds_format = make_dataset_list(dataset) | ||
result = get_structure(ds_format, filter_branch=filter_branch, do_print=False) | ||
|
||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
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.