|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | 3 | import yaml |
4 | | -import svn.remote as sr |
| 4 | +import subprocess |
5 | 5 | from check_input_data_list import ( |
6 | 6 | get_input_files_in_MOM_input, |
7 | 7 | get_input_data_list_files, |
8 | 8 | ) |
9 | 9 |
|
| 10 | + |
| 11 | +def get_repo_files_with_curl(base_url): |
| 12 | + """ |
| 13 | + Get file list from repository using curl and HTML parsing instead of SVN. |
| 14 | + |
| 15 | + The server provides HTML directory listings that we can parse to find files. |
| 16 | + This function recursively traverses directories to find all files. |
| 17 | + |
| 18 | + Parameters |
| 19 | + ---------- |
| 20 | + base_url : str |
| 21 | + The base URL of the repository |
| 22 | + |
| 23 | + Returns |
| 24 | + ------- |
| 25 | + set |
| 26 | + Set of file names found in the repository |
| 27 | + """ |
| 28 | + import re |
| 29 | + |
| 30 | + def parse_html_directory_listing(html_content, current_url): |
| 31 | + """Parse HTML directory listing to find files and directories.""" |
| 32 | + files = [] |
| 33 | + directories = [] |
| 34 | + |
| 35 | + # Look for href links in the HTML |
| 36 | + href_pattern = r'<a href="([^"]+)"[^>]*>([^<]+)</a>' |
| 37 | + matches = re.findall(href_pattern, html_content) |
| 38 | + |
| 39 | + for href, text in matches: |
| 40 | + # Skip parent directory links and external URLs |
| 41 | + if href.startswith('..') or href.startswith('http'): |
| 42 | + continue |
| 43 | + |
| 44 | + if href.endswith('/'): |
| 45 | + # This is a directory |
| 46 | + directories.append(href.rstrip('/')) |
| 47 | + else: |
| 48 | + # This is a file - include ALL files (no filtering) |
| 49 | + files.append(href) |
| 50 | + |
| 51 | + return files, directories |
| 52 | + |
| 53 | + def get_directory_content(url): |
| 54 | + """Get HTML content from a directory URL.""" |
| 55 | + try: |
| 56 | + result = subprocess.run( |
| 57 | + ["curl", "-s", "-L", url], |
| 58 | + capture_output=True, |
| 59 | + text=True, |
| 60 | + timeout=20 |
| 61 | + ) |
| 62 | + if result.returncode == 0: |
| 63 | + return result.stdout |
| 64 | + else: |
| 65 | + print(f"Error fetching {url}: {result.stderr}") |
| 66 | + return None |
| 67 | + except Exception as e: |
| 68 | + print(f"Error fetching {url}: {e}") |
| 69 | + return None |
| 70 | + |
| 71 | + try: |
| 72 | + all_files = set() |
| 73 | + directories_to_visit = [base_url.rstrip('/')] |
| 74 | + visited_dirs = set() |
| 75 | + |
| 76 | + # Process directories with full recursive discovery |
| 77 | + while directories_to_visit: |
| 78 | + current_dir = directories_to_visit.pop(0) |
| 79 | + if current_dir in visited_dirs: |
| 80 | + continue |
| 81 | + |
| 82 | + visited_dirs.add(current_dir) |
| 83 | + html_content = get_directory_content(current_dir) |
| 84 | + if not html_content: |
| 85 | + continue |
| 86 | + |
| 87 | + files, subdirs = parse_html_directory_listing(html_content, current_dir) |
| 88 | + |
| 89 | + # Add ALL files to our collection (no filtering) |
| 90 | + for file in files: |
| 91 | + filename = file.split('/')[-1] # Extract just the filename |
| 92 | + all_files.add(filename) |
| 93 | + |
| 94 | + # Add all discovered subdirectories to visit list |
| 95 | + for subdir in subdirs: |
| 96 | + if subdir.startswith('/'): |
| 97 | + # Absolute path - construct full URL |
| 98 | + full_subdir_url = f"https://osdf-director.osg-htc.org{subdir}/" |
| 99 | + else: |
| 100 | + # Relative path |
| 101 | + full_subdir_url = f"{current_dir.rstrip('/')}/{subdir}/" |
| 102 | + |
| 103 | + if full_subdir_url not in visited_dirs: |
| 104 | + directories_to_visit.append(full_subdir_url) |
| 105 | + |
| 106 | + print(f"Found {len(all_files)} files total in repository") |
| 107 | + return all_files |
| 108 | + |
| 109 | + except Exception as e: |
| 110 | + print(f"Unexpected error getting repository files: {e}") |
| 111 | + return set() |
| 112 | + |
| 113 | + |
10 | 114 | if __name__ == "__main__": |
11 | 115 |
|
12 | 116 | # Read in the MOM_input.yaml file and extract all input file names |
|
22 | 126 | ) |
23 | 127 |
|
24 | 128 | # all mom input file names in gdex inputdata repository |
25 | | - r = sr.RemoteClient( |
26 | | - "https://osdf-data.gdex.ucar.edu/ncar/gdex/d651077/cesmdata/inputdata/ocn/mom/" |
27 | | - ) |
28 | | - repo_files = {f["name"] for relpath, f in r.list_recursive() if f["kind"] == "file"} |
| 129 | + repo_url = "https://osdf-data.gdex.ucar.edu/ncar/gdex/d651077/cesmdata/inputdata/ocn/mom/" |
| 130 | + repo_files = get_repo_files_with_curl(repo_url) |
| 131 | + |
| 132 | + if not repo_files: |
| 133 | + print("WARNING: Could not retrieve file list from repository.") |
| 134 | + print("This may be due to connectivity issues or changes in repository structure.") |
| 135 | + print("Repository validation will be skipped.") |
| 136 | + exit(0) # Exit successfully since this is likely an infrastructure issue |
29 | 137 |
|
30 | 138 | # File names missing in the repository |
31 | 139 | missing_files = ( |
|
0 commit comments