Skip to content

Commit 5c33c1a

Browse files
Merge pull request #6 from sdmlua/dev
updating the permission issues
2 parents b6114b1 + 4db4e98 commit 5c33c1a

6 files changed

Lines changed: 55 additions & 1 deletion

File tree

CIROH_DevCon25.zip

-21.1 MB
Binary file not shown.
34.6 KB
Binary file not shown.

dist/fimeval-0.1.49.tar.gz

35.2 KB
Binary file not shown.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fimeval"
3-
version = "0.1.48"
3+
version = "0.1.49"
44
description = "A Framework for Automatic Evaluation of Flood Inundation Mapping Predictions Evaluation"
55
authors = [
66
"Surface Dynamics Modeling Lab",

src/fimeval/ContingencyMap/evaluationFIM.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import geopandas as gpd
55
import rasterio
66
import shutil
7+
import subprocess
8+
import platform
79
import pandas as pd
810
from rasterio.warp import reproject, Resampling
911
from rasterio.io import MemoryFile
@@ -19,6 +21,30 @@
1921
from .PWBs3 import get_PWB
2022
from ..utilis import MakeFIMsUniform
2123

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+
2248
# Function for the evalution of the model
2349
def evaluateFIM(
2450
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
351377
gdf = get_PWB()
352378
else:
353379
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)
354384

385+
#runt the process
355386
def process_TIFF(tif_files, folder_dir):
356387
benchmark_path = None
357388
candidate_path = []
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
DIR="$1"
4+
5+
if [ -z "$DIR" ]; then
6+
echo "No directory provided."
7+
exit 1
8+
fi
9+
echo "Fixing permissions for: $DIR"
10+
11+
UNAME=$(uname)
12+
if [[ "$UNAME" == "Darwin" || "$UNAME" == "Linux" ]]; then
13+
chmod -R u+rwX "$DIR"
14+
echo "Permissions granted for user (u+rwX)"
15+
16+
elif [[ "$UNAME" == *"MINGW"* || "$UNAME" == *"MSYS"* || "$UNAME" == *"CYGWIN"* ]]; then
17+
icacls "$DIR" /grant Everyone:F /T > /dev/null
18+
echo "Permissions granted for working folder"
19+
20+
else
21+
echo "Unsupported OS: $UNAME"
22+
exit 1
23+
fi

0 commit comments

Comments
 (0)