Skip to content

Commit

Permalink
If 3rd party files are missing, download them on first web use
Browse files Browse the repository at this point in the history
  • Loading branch information
TinoDidriksen committed Mar 14, 2022
1 parent a326484 commit d16fd80
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
15 changes: 15 additions & 0 deletions apertium-regtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import threading
import time
import urllib.parse
import urllib.request
import shutil
import xml.etree.ElementTree
import zlib

Expand All @@ -31,6 +33,18 @@ class InputFileIsEmpty(Exception):
class ErrorInPipeline(Exception):
pass

def ensure_javascript(spath):
if not os.path.exists(spath + '/bootstrap.css') or not os.path.exists(spath + '/bootstrap.js') or not os.path.exists(spath + '/jquery.js') or not os.path.exists(spath + '/diff.js'):
print('Downloading Bootstrap, jQuery, and jsDiff from the jsDelivr CDN')
with urllib.request.urlopen('https://cdn.jsdelivr.net/npm/bootstrap@5.1/dist/css/bootstrap.min.css') as response, open(spath + '/bootstrap.css', 'wb') as out_file:
shutil.copyfileobj(response, out_file)
with urllib.request.urlopen('https://cdn.jsdelivr.net/npm/bootstrap@5.1/dist/js/bootstrap.min.js') as response, open(spath + '/bootstrap.js', 'wb') as out_file:
shutil.copyfileobj(response, out_file)
with urllib.request.urlopen('https://cdn.jsdelivr.net/npm/jquery@3.6/dist/jquery.min.js') as response, open(spath + '/jquery.js', 'wb') as out_file:
shutil.copyfileobj(response, out_file)
with urllib.request.urlopen('https://cdn.jsdelivr.net/npm/diff@4.0/dist/diff.min.js') as response, open(spath + '/diff.js', 'wb') as out_file:
shutil.copyfileobj(response, out_file)

def load_input(fname):
try:
with open(fname, 'r') as fin:
Expand Down Expand Up @@ -744,6 +758,7 @@ class BigQueueServer(socketserver.ThreadingTCPServer):

def start_server(port, page_size=25):
d = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/')
ensure_javascript(d)
handle = partial(CallbackRequestHandler, directory=d, page_size=page_size)
print('Starting server')
print('Open http://localhost:%d in your browser' % port)
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ(2.52)

AC_INIT([Apertium Regtest], [0.9.0], [awesomeevildudes@gmail.com], [apertium-regtest], [https://wiki.apertium.org/wiki/Regtest])
AC_INIT([Apertium Regtest], [0.9.1], [awesomeevildudes@gmail.com], [apertium-regtest], [https://wiki.apertium.org/wiki/Regtest])
AM_INIT_AUTOMAKE([foreign])
AC_OUTPUT([Makefile apertium-regtest.pc])
6 changes: 3 additions & 3 deletions static/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

| Library | Link | Version Used Here |
| ------- | ---- | ----------------- |
| Bootstrap | https://getbootstrap.com | 5.0.2 |
| jQuery | https://jquery.com | 3.6.0 |
| jsdiff | https://github.com/kpdecker/jsdiff | 4.0.1 |
| Bootstrap | https://getbootstrap.com | 5.1.x |
| jQuery | https://jquery.com | 3.6.x |
| jsdiff | https://github.com/kpdecker/jsdiff | 4.0.x |
4 changes: 2 additions & 2 deletions static/bootstrap.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions static/bootstrap.js

Large diffs are not rendered by default.

0 comments on commit d16fd80

Please sign in to comment.