diff options
Diffstat (limited to 'core/utils.py')
-rw-r--r-- | core/utils.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/core/utils.py b/core/utils.py index 7111c0c..5d2d262 100644 --- a/core/utils.py +++ b/core/utils.py @@ -138,8 +138,6 @@ nothing to commit, working tree clean def write_and_commit(files, message): """Writes the content to the filepath and adds and commits the file to git. If this fails, a WriteAndCommitError is raised. - This does not create any needed intermediate folders, which is what we do when writing survex files, so functionality here - is duplicated in only_commit() These need refactoring """ @@ -153,7 +151,10 @@ def write_and_commit(files, message): # GIT see also core/views/expo.py editexpopage() os.makedirs(os.path.dirname(filepath), exist_ok = True) if filepath.is_dir(): - return False + raise WriteAndCommitError( + f"CANNOT write this file {filepath} as this is an existing DIRECTORY." + ) + #return False if encoding: mode = "w" kwargs = {"encoding": encoding} @@ -164,10 +165,14 @@ def write_and_commit(files, message): with open(filepath, mode, **kwargs) as f: print(f"WRITING {cwd}/{filename} ") f.write(content) - except PermissionError: + except PermissionError as e: raise WriteAndCommitError( - f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filename}. Ask a nerd to fix this." + f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this: {e}" ) + except Exception as e: + raise WriteAndCommitError( + f"CANNOT write this file {filepath}. Ask a nerd to fix this: {e}" + ) cmd_diff = [git, "diff", filename] cp_diff = subprocess.run(cmd_diff, cwd=cwd, capture_output=True, text=True) commands.append(cmd_diff) @@ -242,7 +247,10 @@ class WriteAndCommitError(Exception): def writetrogglefile(filepath, filecontent): - """Commit the new saved file to git + """ + REPLACE with call to write_and_commit + any necessary setup + + Commit the new saved file to git Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly """ # GIT see also core/views/expo.py editexpopage() @@ -301,6 +309,10 @@ def height_from_utm(easting, northing): def find_nearest_point(points, target_point): """Returns the nearest point to a target point from a list of points. + TODO FIND OUT + 1. is this SRTM data ? + 2. what is the zero altitude datum? Geoid or ellisoid ? Do we need to subtract 47m ?? + In our dataset, the survey stations are all within 30m of an srtm reference point. So we can safely ignore points more than 100m away in either x or y directions. |