2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

detecting empty wallets where we only have JSON and no files

This commit is contained in:
Philip Sargent 2022-08-16 20:02:28 +03:00
parent e94dc6eb6f
commit 41c68aef26
3 changed files with 29 additions and 6 deletions

View File

@ -3,6 +3,7 @@ import os
import datetime
import difflib
from pathlib import Path
import socket
from django import forms
from django.http import HttpResponseRedirect, HttpResponse, Http404
@ -165,7 +166,11 @@ class SvxForm(forms.Form):
res = fout.write("\n")
fout.close()
only_commit(fname, f"Online survex edit: {self.data['filename']}.svx")
if socket.gethostname() == "expo":
comment = f"Online survex edit: {self.data['filename']}.svx"
else:
comment = f"Online survex edit: {self.data['filename']}.svx on dev machine '{socket.gethostname()}' "
only_commit(fname, comment)
return "SAVED and committed to git"

View File

@ -1,4 +1,4 @@
import re, os
import re, os, socket
import subprocess
import json
import settings
@ -270,7 +270,10 @@ def scanupload(request, path=None):
print(message)
return render(request,'errors/generic.html', {'message': message})
else:
dr_commit = subprocess.run([git, "commit", "-m", f'JSON update for wallet {wallet}'], cwd=destfolder, capture_output=True, text=True)
if socket.gethostname() != "expo":
comment = f"on dev machine '{socket.gethostname()}' "
dr_commit = subprocess.run([git, "commit", "-m", f'JSON update for wallet {wallet} {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\n' + dr_commit.stderr + '\n\n' + dr_commit.stdout + '\n\nreturn code: ' + str(dr_commit.returncode)
@ -441,6 +444,7 @@ def scanupload(request, path=None):
chkpland = ""
svxfiles = []
checked = {}
context = {}
if waldata:
if not waldata["people"]:
waldata["people"]=["NOBODY"]

View File

@ -110,11 +110,25 @@ def load_all_scans():
CheckEmptyPeople(wallet)
wallet.save()
LoadListScansFile(wallet)
else:
# but We should load all the scans, even for nonstandard names.
print(f'\n - IGNORE {walletname} - {fpath}')
# but we also need to check if JSON exists, even if there are no uploaded scan files
contents_path = Path(settings.DRAWINGS_DATA, "walletjson")
for yeardir in contents_path.iterdir():
if yeardir.is_dir():
for walletpath in yeardir.iterdir():
if Path(walletpath, contentsjson).is_file():
walletname = walletpath.name
wallet, created = Wallet.objects.update_or_create(walletname=walletname)
if created:
print(f"\n{walletname} created: only JSON, no actual uploaded scan files.", end=' ')
CheckEmptyDate(wallet)
CheckEmptyPeople(wallet)
wallet.save()
print("", flush=True)