MCPcopy Create free account
hub / github.com/WebODM/WebODM / dev_tools

Function dev_tools

app/views/dev.py:35–80  ·  view source on GitHub ↗
(request, action)

Source from the content-addressed store, hash-verified

33
34@user_passes_test(lambda u: u.is_superuser)
35def dev_tools(request, action):
36 if not settings.DEV:
37 raise Http404()
38
39 if request.method == 'POST':
40 if action == "reloadTranslation":
41 try:
42 args = json.loads(request.body).get('args')
43
44 fd, tmpzipPath = tempfile.mkstemp(suffix=".zip")
45 os.close(fd)
46
47 logger.info("Downloading %s" % args[0])
48 download_file(args[0], tmpzipPath)
49
50 tmpPath = tempfile.mkdtemp()
51
52 logger.info("Extracting... %s" % tmpzipPath)
53 with zipfile.ZipFile(tmpzipPath, 'r') as zip:
54 zip.extractall(path=tmpPath)
55 os.unlink(tmpzipPath)
56
57 locale_paths = glob.glob(os.path.join(tmpPath, "**", "locale"), recursive=True)
58 if len(locale_paths) == 0:
59 raise Exception(_("Cannot find locale/ folder in .zip archive"))
60
61 webodm_locale_dir = os.path.join(settings.BASE_DIR, "locale")
62
63 for locale_path in locale_paths:
64 logger.info("Found locale at %s" % locale_path)
65 logger.info("Moving %s to %s..." % (locale_path, webodm_locale_dir))
66 copymerge(locale_path, webodm_locale_dir)
67
68 logger.info("Running python manage.py translate extract && python manage.py translate build --safe")
69 subprocess.call(['bash', '-c', 'python manage.py translate extract && %s python manage.py translate build --safe'], cwd=settings.BASE_DIR)
70
71 return JsonResponse({'message': _("Translation files reloaded!"), 'reload': True})
72 except Exception as e:
73 return JsonResponse({'error': str(e)})
74 else:
75 return JsonResponse({'error': _("Invalid action")})
76 else:
77 return render(request, 'app/dev_tools.html', {
78 'title': _('Developer Tools'),
79 'current_locale': get_language()
80 })
81

Callers

nothing calls this directly

Calls 6

copymergeFunction · 0.85
download_fileFunction · 0.70
_Function · 0.50
JsonResponseFunction · 0.50
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected