|
4 | 4 | import geopandas as gpd |
5 | 5 | import rasterio |
6 | 6 | import shutil |
| 7 | +import subprocess |
| 8 | +import platform |
7 | 9 | import pandas as pd |
8 | 10 | from rasterio.warp import reproject, Resampling |
9 | 11 | from rasterio.io import MemoryFile |
|
19 | 21 | from .PWBs3 import get_PWB |
20 | 22 | from ..utilis import MakeFIMsUniform |
21 | 23 |
|
| 24 | +#giving the permission to the folder |
| 25 | +def is_writable(path): |
| 26 | + """Check if the directory and its contents are writable.""" |
| 27 | + path = Path(path) |
| 28 | + return os.access(path, os.W_OK) |
| 29 | + |
| 30 | +def fix_permissions(path): |
| 31 | + path = Path(path).resolve() |
| 32 | + script_path = Path(__file__).parent / "fix_permissions.sh" |
| 33 | + |
| 34 | + if not script_path.exists(): |
| 35 | + raise FileNotFoundError(f"Shell script not found: {script_path}") |
| 36 | + |
| 37 | + if is_writable(path): |
| 38 | + return |
| 39 | + |
| 40 | + try: |
| 41 | + result = subprocess.run(["bash", str(script_path), str(path)], |
| 42 | + check=True, capture_output=True, text=True) |
| 43 | + print(result.stdout) |
| 44 | + except subprocess.CalledProcessError as e: |
| 45 | + print(f"Shell script failed:\n{e.stderr}") |
| 46 | + |
| 47 | + |
22 | 48 | # Function for the evalution of the model |
23 | 49 | def evaluateFIM( |
24 | 50 | benchmark_path, candidate_paths, gdf, folder, method, output_dir, shapefile=None |
@@ -351,7 +377,12 @@ def EvaluateFIM(main_dir, method_name, output_dir, PWB_dir=None, shapefile_dir=N |
351 | 377 | gdf = get_PWB() |
352 | 378 | else: |
353 | 379 | gdf = gpd.read_file(PWB_dir) |
| 380 | + |
| 381 | + #Grant the permission to the main directory |
| 382 | + print(f"Fixing permissions for {main_dir}...") |
| 383 | + fix_permissions(main_dir) |
354 | 384 |
|
| 385 | + #runt the process |
355 | 386 | def process_TIFF(tif_files, folder_dir): |
356 | 387 | benchmark_path = None |
357 | 388 | candidate_path = [] |
|
0 commit comments