2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 23:17:11 +00:00

Wallet edit now using refactored git add/commit system

This commit is contained in:
2024-12-29 19:35:20 +00:00
parent a3c7f165b9
commit e3a9498656
3 changed files with 34 additions and 75 deletions

View File

@@ -19,12 +19,13 @@ from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry
from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole
from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.models.wallets import YEAR_RANGE, Wallet, make_valid_date
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, current_expo, get_cookie, git_string, sanitize_name, write_and_commit
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, add_commit, current_expo, get_cookie, git_add, \
git_commit, git_string, sanitize_name, write_and_commit
from troggle.core.views.auth import login_required_if_public
from troggle.core.views.caves import get_cave_leniently, getCave
from troggle.core.views.scans import caveifywallet, oldwallet
from troggle.core.views.uploads import FilesForm
from troggle.parsers.scans import contentsjson
from troggle.parsers.scans import CONTENTSJSON
"""Main wallet editing form, which includes scan file upload into the wallet
"""
@@ -504,60 +505,19 @@ def walletedit(request, path=None):
return w
def commit_json(waldata):
# CHANGE THIS to use git_commit() from troggle.utils
destfolder = contents_path.parent
dr_add = subprocess.run([git, "add", contentsjson], cwd=destfolder, capture_output=True, text=True)
if dr_add.returncode != 0:
msgdata = (
"Ask a nerd to fix this.\n--"
+ dr_add.stderr
+ "\n--"
+ dr_add.stdout
+ "\n--return code: "
+ str(dr_add.returncode)
)
message = (
f"CANNOT git on server for this file {contentsjson}. Edits saved but not added to git.\n\n" + msgdata
)
print(message)
return render(request, "errors/generic.html", {"message": message})
print(f"commit_json \n..{editor=} \n..{contents_path=}")
if "cave" in waldata:
label = str(waldata["cave"]).replace("[","").replace("]","")
else:
if socket.gethostname() != "expo":
comment = f"on dev machine '{socket.gethostname()}' "
if "name" in waldata:
label = waldata["name"]
else:
comment = ""
if "cave" in waldata:
label = waldata["cave"]
else:
if "name" in waldata:
label = waldata["name"]
else:
label = ""
dr_commit = subprocess.run(
[git, "commit", "-m", f"JSON update wallet {wallet} {label} {comment}"],
cwd=destfolder,
capture_output=True,
text=True,
)
# This produces return code = 1 if it commits OK
if dr_commit.returncode != 0:
msgdata = (
"Ask a nerd to fix this.\n\nstderr: "
+ dr_commit.stderr
+ "\n\nstdout: "
+ dr_commit.stdout
+ "\n\nreturn code: "
+ str(dr_commit.returncode)
)
message = (
f"Error code with git on server for this {contentsjson}. File is added to git, but NOT committed.\n"
+ msgdata
)
print(message)
return render(request, "errors/generic.html", {"message": message})
label = ""
message = f"JSON update wallet {wallet} {label}"
add_commit(contents_path, message, editor)
def get_logbook_trips():
return None
@@ -706,7 +666,7 @@ def walletedit(request, path=None):
wurl = f"/walletedit/{wallet}".replace("#", ":")
wallet = wallet.replace(":", "#")
dirpath = Path(settings.SCANS_ROOT, year, wallet)
contents_path = Path(settings.DRAWINGS_DATA, "walletjson") / year / wallet / contentsjson
contents_path = Path(settings.DRAWINGS_DATA, "walletjson") / year / wallet / CONTENTSJSON
fresh_wallet = False