From 3ac617431f41c9bb85636c68d1aef72feb3944ff Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 6 Mar 2022 01:29:45 +0000 Subject: [PATCH] Make .3d files in same dir as .svx --- core/TESTS/tests_logins.py | 4 ++-- core/fixtures/test_upload_file.pdf | 5 +++++ core/models/caves.py | 14 +++++++++--- core/views/statistics.py | 2 -- parsers/survex.py | 36 ++++++++++++++++++++++-------- templates/menu.html | 3 +-- urls.py | 1 - 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 core/fixtures/test_upload_file.pdf diff --git a/core/TESTS/tests_logins.py b/core/TESTS/tests_logins.py index b09b7b6..e07907f 100644 --- a/core/TESTS/tests_logins.py +++ b/core/TESTS/tests_logins.py @@ -108,7 +108,7 @@ class PostTests(TestCase): def test_dwg_upload_txt(self): - '''Expect .txt file to be refused upload + '''Expect .pdf file to be refused upload Need to login first. ''' c = self.client @@ -118,7 +118,7 @@ class PostTests(TestCase): self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE') logged_in = c.login(username=u.username, password='secretword') - with open('core/fixtures/test_upload_file.txt','r') as testf: + with open('core/fixtures/test_upload_file.pdf','r') as testf: response = self.client.post('/dwgupload/uploads', data={'name': 'test_upload_file.txt', 'uploadfiles': testf }) content = response.content.decode() self.assertEqual(response.status_code, 200) diff --git a/core/fixtures/test_upload_file.pdf b/core/fixtures/test_upload_file.pdf new file mode 100644 index 0000000..9d955a5 --- /dev/null +++ b/core/fixtures/test_upload_file.pdf @@ -0,0 +1,5 @@ +This file is uploaded by the integration test suite as part of the tests. + +It, and any other with similar names, e.g test_upload_GPev9qN.txt can be safely deleted, +EXCEPT for the original copy which lives in troggle/core/fixtures/ + diff --git a/core/models/caves.py b/core/models/caves.py index 0a4cc3e..41a1b47 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -3,7 +3,8 @@ import os import datetime import re import json -from subprocess import call +import subprocess + from collections import defaultdict from pathlib import Path @@ -56,8 +57,15 @@ def writetrogglefile(filepath, filecontent): f.write(filecontent) #os.chmod(filepath, 0o664) # set file permissions to rw-rw-r-- # should replace .call with .run and capture_output=True - call([git, "add", filename], cwd=cwd) - call([git, "commit", "-m", f'Troggle online: cave or entrance edit -{filename}'], cwd=cwd) + sp = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, check=True, text=True) + if sp.returncode != 0: + print(f'git ADD {cwd}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) + + sp = subprocess.run([git, "commit", "-m", f'Troggle online: cave or entrance edit -{filename}'], cwd=cwd, capture_output=True, check=True, text=True) + if sp.returncode != 0: + print(f'git COMMIT {cwd}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) + # not catching and re-raising any exceptions yet, inc. the stderr etc.,. We should do that. + class Area(TroggleModel): diff --git a/core/views/statistics.py b/core/views/statistics.py index 054c3a4..950b147 100644 --- a/core/views/statistics.py +++ b/core/views/statistics.py @@ -53,7 +53,6 @@ def pathsreport(request): "SURVEYS" : str( settings.SURVEYS), "SURVEYS_URL" : str( settings.SURVEYS_URL), "SURVEXPORT" : str( settings.SURVEXPORT), - "THREEDCACHEDIR" : str( settings.THREEDCACHEDIR), "DRAWINGS_DATA" : str( settings.DRAWINGS_DATA), "URL_ROOT" : str( settings.URL_ROOT) } @@ -91,7 +90,6 @@ def pathsreport(request): "SURVEYS" : type(settings.SURVEYS), "SURVEYS_URL" : type(settings.SURVEYS_URL), "SURVEXPORT" : type(settings.SURVEXPORT), - "THREEDCACHEDIR" : type(settings.THREEDCACHEDIR), "DRAWINGS_DATA" : type(settings.DRAWINGS_DATA), "URL_ROOT" : type(settings.URL_ROOT) } diff --git a/parsers/survex.py b/parsers/survex.py index 70649da..fc234d0 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -1205,9 +1205,13 @@ class LoadingSurvex(): # see design docum in troggle/templates/cave.html # and views/caves.py rendercave() ''' - print(" - Regenerating stale (or chaos-monkeyed) cavern .log and .3d for '{}'\n at '{}'\n days svx old: {:.1f} cav:{:.1f} log old: {:.1f}".format(fullpath, logpath, (svx_t - log_t)/(24*3600), (cav_t - log_t)/(24*3600), (now - log_t)/(24*3600))) - #print(f' - cav_t: {cav_t/(24*3600)} - log_t: {log_t/(24*3600)} - svx_t: {svx_t/(24*3600)} - now: {now}') - subprocess.call([settings.CAVERN, "--log", "--output={}".format(settings.THREEDCACHEDIR), "{}.svx".format(fullpath)]) + print(f" - Regenerating stale (or chaos-monkeyed) cavern .log and .3d for '{fullpath}'\n at '{logpath}'\n") + print(f"days svx old: {(svx_t - log_t)/(24*3600):.1f} cav:{(cav_t - log_t)/(24*3600):.1f} log old: { (now - log_t)/(24*3600):.1f}") + + outputdir = Path(str(f'{fullpath}.svx')).parent + sp = subprocess.run([settings.CAVERN, "--log", f'--output={outputdir}', f'{fullpath}.svx']) + if sp.returncode != 0: + print(f'fullpath: {fullpath}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) self.caverncount += 1 # should also collect all the .err files too and create a DataIssue for each one which @@ -1215,7 +1219,8 @@ class LoadingSurvex(): # - has Error greater than 5% anywhere, or some other more serious error svxpath = fullpath + ".svx" - logpath = Path(settings.THREEDCACHEDIR) / str(Path(fullpath).name + ".log") + logpath = fullpath + ".log" + outputdir = Path(svxpath).parent if not os.path.isfile(logpath): runcavern() @@ -1412,15 +1417,28 @@ def LoadPositions(): svx_t = 0 d3d_t = 0 def runcavern3d(): + outputdir = Path(str(f'{topdata}.svx')).parent + # print(" - Regenerating stale cavern .log and .3d for '{}'\n days old: {:.1f} {:.1f} {:.1f}". # format(topdata, (svx_t - d3d_t)/(24*3600), (cav_t - d3d_t)/(24*3600), (now - d3d_t)/(24*3600))) - subprocess.call([settings.CAVERN, "--log", "--output={}".format(topdata), "{}.svx".format(topdata)]) - - # print(" - Regenerating {} {}.3d in {}".format(settings.SURVEXPORT, topdata, settings.SURVEX_DATA)) - subprocess.call([settings.SURVEXPORT, '--pos', '{}.3d'.format(topdata)], cwd = settings.SURVEX_DATA) + # subprocess.call([settings.CAVERN, "--log", f"--output={topdata}", f"{topdata}.svx"]) + try: + sp = subprocess.run([settings.CAVERN, "--log", f"--output={outputdir}", f"{topdata}.svx"], + capture_output=True, check=True, text=True) + if sp.returncode != 0: + print(f'topdata: {topdata}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) + + # print(" - Regenerating {} {}.3d in {}".format(settings.SURVEXPORT, topdata, settings.SURVEX_DATA)) + sp = subprocess.run([settings.SURVEXPORT, '--pos', f'{topdata}.3d'], cwd = settings.SURVEX_DATA, + capture_output=True, check=True, text=True) + if sp.returncode != 0: + print(f'topdata: {topdata}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) + except: + print(f'topdata: {topdata}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) + topdata = os.fspath(Path(settings.SURVEX_DATA) / settings.SURVEX_TOPNAME) - print((' - Generating a list of Pos from %s.svx and then loading...' % (topdata))) + print(' - Generating a list of Pos from %s.svx and then loading...' % (topdata)) found = 0 skip = {} diff --git a/templates/menu.html b/templates/menu.html index 502a31b..c22b38d 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -11,8 +11,7 @@
  • -{% if editable %}
  • Edit this page
  • -{% else %}This page not editable{% endif %} +{% if editable %}
  • Edit this page
  • {% endif %} {% if cave_editable %}
  • Edit this cave
  • {% endif %} {% endif %} diff --git a/urls.py b/urls.py index 77f9c8d..0ee12a2 100644 --- a/urls.py +++ b/urls.py @@ -181,7 +181,6 @@ trogglepatterns = [ re_path(r'^site_media/(?P.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # MEDIA_ROOT: CSS and JS re_path(r'^static/(?P.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # STATIC only used by admin pages path('javascript/', mediapage, {'doc_root': settings.JSLIB_ROOT}, name="mediapage"), # JSLIB_URL - re_path(r'^expowebcache/3d/(?P.*)$', mediapage, {'doc_root': settings.THREEDCACHEDIR}, name="mediapage"), re_path(r'^/loser/(?P.*)$', mediapage, {'doc_root': settings.SURVEX_DATA}, name="mediapage"), # Oddly not working !? re_path(r'^map/map.html', map, name="map"), # Redirects to OpenStreetMap JavaScript