apd
Advanced tools
| #!/#usr/bin/env python | ||
| ############################################################################### | ||
| # (c) Copyright 2000-2024 CERN for the benefit of the LHCb Collaboration # | ||
| # # | ||
| # This software is distributed under the terms of the GNU General Public # | ||
| # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # | ||
| # # | ||
| # In applying this licence, CERN does not waive the privileges and immunities # | ||
| # granted to it by virtue of its status as an Intergovernmental Organization # | ||
| # or submit itself to any jurisdiction. # | ||
| ############################################################################### | ||
| import argparse | ||
| import xml.etree.ElementTree as ET | ||
| import apd | ||
| ########################################################### | ||
| # # | ||
| # The function of this script is to add authentication # | ||
| # tokens to the paths in the file catalog xml file. # | ||
| # This is necessary for the CI to have access to the data # | ||
| # # | ||
| ########################################################### | ||
| ######################################################## | ||
| # Functions to do all of the dirty authentication work # | ||
| ######################################################## | ||
| def append_token(pfn): | ||
| print(f"Appending token for {pfn!r}") | ||
| token = apd.auth(pfn) # Replace the pfn with the tokened pfns. | ||
| return token | ||
| # Use this guy to process the pfn, obstaining the mdf prepend for the xrootd protocol, and then putting it back | ||
| def process_pfn(string): | ||
| if string.startswith("mdf:"): | ||
| temp_string = string[4:] | ||
| else: | ||
| temp_string = string | ||
| new_string = append_token(temp_string) | ||
| if string.startswith("mdf:"): | ||
| new_string = "mdf:" + new_string | ||
| return new_string | ||
| def replace_elements_in_xml(file_path): | ||
| # Load XML file | ||
| tree = ET.parse(file_path) | ||
| root = tree.getroot() | ||
| # Iterate over each old element and its corresponding replacement | ||
| for element in root.iter("pfn"): | ||
| element.set("name", process_pfn(element.get("name"))) | ||
| # Modify the pool catalog file | ||
| xml_string = ( | ||
| '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n' | ||
| + '<!DOCTYPE POOLFILECATALOG SYSTEM "InMemory">\n' | ||
| + ET.tostring(root).decode("utf-8") | ||
| ) | ||
| with open(file_path, "wt") as fh: | ||
| fh.write(xml_string) | ||
| print(f"XML file {file_path!r} modified and saved as {file_path!r}.") | ||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("pool_xml_fn") | ||
| args = parser.parse_args() | ||
| # Create a new XML file to use in the test | ||
| replace_elements_in_xml(args.pool_xml_fn) | ||
| if __name__ == "__main__": | ||
| main() |
| ############################################################################### | ||
| # (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration # | ||
| # # | ||
| # This software is distributed under the terms of the GNU General Public # | ||
| # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # | ||
| # # | ||
| # In applying this licence, CERN does not waive the privileges and immunities # | ||
| # granted to it by virtue of its status as an Intergovernmental Organization # | ||
| # or submit itself to any jurisdiction. # | ||
| ############################################################################### | ||
| from xml.etree import ElementTree as ET | ||
| import pytest | ||
| from apd.pool_xml import replace_elements_in_xml | ||
| @pytest.fixture | ||
| def sample_xml_file(tmp_path): | ||
| # Create a temporary XML file with sample content in the pytest-provided temporary directory | ||
| sample_xml_content = """<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
| <POOLFILECATALOG> | ||
| <File ID="sample-id"> | ||
| <physical> | ||
| <pfn filetype="ROOT_All" name="root://example.com//path/to/file" se="Example-SE"/> | ||
| </physical> | ||
| <logical> | ||
| <lfn name="/path/to/logical/file"/> | ||
| </logical> | ||
| </File> | ||
| </POOLFILECATALOG> | ||
| """ | ||
| file_path = tmp_path / "sample.xml" | ||
| file_path.write_text(sample_xml_content) | ||
| return file_path | ||
| def test_replace_elements_in_xml(monkeypatch, sample_xml_file): | ||
| # Mock the apd.pool_xml.apd.auth function to return a tokenized PFN | ||
| monkeypatch.setattr("apd.pool_xml.apd.auth", lambda x: f"{x}?token=12345") | ||
| replace_elements_in_xml(str(sample_xml_file)) | ||
| # Load the modified XML to verify changes | ||
| tree = ET.parse(sample_xml_file) | ||
| root = tree.getroot() | ||
| # Assert that the PFN has been updated with a token | ||
| pfn_element = root.find(".//pfn") | ||
| assert pfn_element is not None | ||
| assert pfn_element.get("name") == "root://example.com//path/to/file?token=12345" |
+1
-0
@@ -142,1 +142,2 @@ # Byte-compiled / optimized / DLL files | ||
| /lb-check-copyright | ||
| tests/cache-dir |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: apd | ||
| Version: 0.7.1 | ||
| Version: 0.8.0 | ||
| Summary: Tool to access the Analysis production Data | ||
@@ -5,0 +5,0 @@ License: BSD-3-Clause |
+1
-0
@@ -48,2 +48,3 @@ [metadata] | ||
| apd-dump-info = apd.command:cmd_dump_info | ||
| apd-add-tokens-pool-xml = apd.pool_xml:main | ||
@@ -50,0 +51,0 @@ [flake8] |
| [console_scripts] | ||
| apd-add-tokens-pool-xml = apd.pool_xml:main | ||
| apd-cache-files = apd.command:cmd_cache_ap_files | ||
@@ -3,0 +4,0 @@ apd-cache-info = apd.command:cmd_cache_ap_info |
| Metadata-Version: 2.1 | ||
| Name: apd | ||
| Version: 0.7.1 | ||
| Version: 0.8.0 | ||
| Summary: Tool to access the Analysis production Data | ||
@@ -5,0 +5,0 @@ License: BSD-3-Clause |
@@ -16,2 +16,3 @@ .gitignore | ||
| src/apd/eos.py | ||
| src/apd/pool_xml.py | ||
| src/apd/rich_console.py | ||
@@ -30,2 +31,3 @@ src/apd/snakemake.py | ||
| tests/test_data_cache.py | ||
| tests/test_pool_xml.py | ||
| tests/cache-dir/b2oc/b02dkpi.json | ||
@@ -32,0 +34,0 @@ tests/cache-dir/b2oc/b02dkpi/tags.json |
@@ -312,4 +312,3 @@ ############################################################################### | ||
| """Iterate on the samples in the info member.""" | ||
| for s in self.info: | ||
| yield s | ||
| yield from self.info | ||
@@ -316,0 +315,0 @@ def itertags(self): |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
3010371
0.17%35
6.06%55077
0.19%