Skip to content

Commit ca913f4

Browse files
authored
Merge pull request #116 from endlessm/T34559-migrate-to-16-alpha
T34559 migrate to 16 alpha
2 parents 0fcc092 + 90501bc commit ca913f4

5 files changed

Lines changed: 224 additions & 169 deletions

File tree

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pipeline {
1212
// URL for the Kolibri wheel to include.
1313
// FIXME: It would be nice to cache this somehow.
1414
// FIXME: Go back to use an official release once that happens on GitHub for 0.16.
15-
KOLIBRI_WHL_URL = 'https://github.com/endlessm/kolibri-explore-plugin/releases/download/v5.8.0/kolibri-0.16.0.dev0+git.20220928203123-py2.py3-none-any.whl'
15+
KOLIBRI_WHL_URL = 'https://github.com/learningequality/kolibri/releases/download/v0.16.0-alpha12/kolibri-0.16.0a12-py2.py3-none-any.whl'
1616

1717
// Both p4a and gradle cache outputs in the home directory.
1818
// Point it inside the workspace.

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ src/kolibri: clean
109109
sed -i 's/if name.endswith(".py"):/if name.endswith(".py") or name.endswith(".pyc"):/g' src/kolibri/dist/django/db/migrations/loader.py
110110
# Apply kolibri patches
111111
patch -d src/ -p1 < patches/0001-Add-track-progress-information-to-channelimport.patch
112+
patch -d src/ -p1 < patches/0001-Break-up-DynamicWhiteNoise-code.patch
113+
114+
src/evil_kolibri: src/kolibri
115+
mkdir -p src/evil_kolibri/utils
116+
touch src/evil_kolibri/__init__.py
117+
touch src/evil_kolibri/utils/__init__.py
118+
cp src/kolibri/utils/kolibri_whitenoise.py src/evil_kolibri/utils/kolibri_whitenoise.py
112119

113120
.PHONY: apps-bundle.zip
114121
apps-bundle.zip:
@@ -157,6 +164,7 @@ dist/version.json: needs-version
157164
DIST_DEPS = \
158165
p4a_android_distro \
159166
src/kolibri \
167+
src/evil_kolibri \
160168
src/apps-bundle \
161169
src/collections \
162170
assets/welcomeScreen \
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
From 585771ca61fd6da449cce31425c2ffab322b0dd8 Mon Sep 17 00:00:00 2001
2+
From: Dylan McCall <dylan@endlessos.org>
3+
Date: Thu, 4 May 2023 17:52:48 -0700
4+
Subject: [PATCH] Break up DynamicWhiteNoise code
5+
6+
Instead of generating everything in the initializer, we will use some
7+
more specific functions. This makes it easier to create a subclass of
8+
DynamicWhiteNoise, for example to support platforms that require special
9+
libraries for file access.
10+
---
11+
kolibri/utils/kolibri_whitenoise.py | 61 ++++++++++++++++++++++-------
12+
1 file changed, 46 insertions(+), 15 deletions(-)
13+
14+
diff --git a/kolibri/utils/kolibri_whitenoise.py b/kolibri/utils/kolibri_whitenoise.py
15+
index 828324cf17..4acf1dab21 100644
16+
--- a/kolibri/utils/kolibri_whitenoise.py
17+
+++ b/kolibri/utils/kolibri_whitenoise.py
18+
@@ -8,6 +8,7 @@ from wsgiref.headers import Headers
19+
from django.contrib.staticfiles import finders
20+
from django.core.files.storage import FileSystemStorage
21+
from django.utils._os import safe_join
22+
+from django.utils.functional import cached_property
23+
from six.moves.urllib.parse import parse_qs
24+
from six.moves.urllib.parse import urljoin
25+
from whitenoise import WhiteNoise
26+
@@ -206,33 +207,57 @@ class DynamicWhiteNoise(WhiteNoise):
27+
}
28+
kwargs.update(whitenoise_settings)
29+
super(DynamicWhiteNoise, self).__init__(application, **kwargs)
30+
- self.dynamic_finder = FileFinder(dynamic_locations or [])
31+
+ self._dynamic_locations = dynamic_locations
32+
+ self._writable_locations = writable_locations
33+
+ self._app_paths = app_paths
34+
+
35+
+ if static_prefix is not None and not static_prefix.endswith("/"):
36+
+ raise ValueError("Static prefix must end in '/'")
37+
+ self.static_prefix = static_prefix
38+
+
39+
+ @cached_property
40+
+ def app_path_check(self):
41+
+ # Generate a regex to check if a path patches one of our app paths
42+
+ return (
43+
+ re.compile("^({})".format("|".join(self._app_paths)))
44+
+ if self._app_paths
45+
+ else None
46+
+ )
47+
+
48+
+ @cached_property
49+
+ def dynamic_finder(self):
50+
+ return FileFinder(self._dynamic_locations or [])
51+
+
52+
+ @cached_property
53+
+ def dynamic_check(self):
54+
# Generate a regex to check if a path matches one of our dynamic
55+
# location prefixes
56+
- self.dynamic_check = (
57+
+ return (
58+
re.compile("^({})".format("|".join(self.dynamic_finder.prefixes)))
59+
if self.dynamic_finder.prefixes
60+
else None
61+
)
62+
- self.writable_locations = {}
63+
- if dynamic_locations:
64+
- for index in writable_locations:
65+
+
66+
+ @cached_property
67+
+ def writable_locations(self):
68+
+ result = {}
69+
+ if self._dynamic_locations:
70+
+ for index in self._writable_locations:
71+
try:
72+
prefix, root = self.dynamic_finder.locations[index]
73+
- self.writable_locations[prefix] = root
74+
+ result[prefix] = root
75+
except IndexError:
76+
pass
77+
- self.writable_check = (
78+
+ return result
79+
+
80+
+ @cached_property
81+
+ def writable_check(self):
82+
+ # Generate a regex to check if a path matches a writable location
83+
+ return (
84+
re.compile("^({})".format("|".join(self.writable_locations.keys())))
85+
if self.writable_locations
86+
else None
87+
)
88+
- self.app_path_check = (
89+
- re.compile("^({})".format("|".join(app_paths))) if app_paths else None
90+
- )
91+
- if static_prefix is not None and not static_prefix.endswith("/"):
92+
- raise ValueError("Static prefix must end in '/'")
93+
- self.static_prefix = static_prefix
94+
95+
def __call__(self, environ, start_response):
96+
path = decode_path_info(environ.get("PATH_INFO", ""))
97+
@@ -308,13 +333,16 @@ class DynamicWhiteNoise(WhiteNoise):
98+
headers["Access-Control-Allow-Origin"] = "*"
99+
if self.add_headers_function:
100+
self.add_headers_function(headers, path, url)
101+
- return EndRangeStaticFile(
102+
+ return self._create_end_range_static_file(
103+
path,
104+
headers.items(),
105+
stat_cache=stat_cache,
106+
encodings={"gzip": path + ".gz", "br": path + ".br"},
107+
)
108+
109+
+ def _create_end_range_static_file(self, path, headers, **kwargs):
110+
+ return EndRangeStaticFile(path, headers, **kwargs)
111+
+
112+
def get_streaming_static_file(self, url, remote_baseurl):
113+
"""
114+
Vendor this function from source to substitute in our
115+
@@ -334,8 +362,11 @@ class DynamicWhiteNoise(WhiteNoise):
116+
if self.add_headers_function:
117+
self.add_headers_function(headers, path, url)
118+
headers["Content-Encoding"] = ""
119+
- return StreamingStaticFile(
120+
+ return self._create_streaming_range_static_file(
121+
os.path.join(local_dir, path),
122+
headers,
123+
urljoin(remote_baseurl, url.lstrip("/")),
124+
)
125+
+
126+
+ def _create_streaming_range_static_file(self, path, headers, remote_url, **kwargs):
127+
+ return StreamingStaticFile(path, headers, remote_url, **kwargs)
128+
--
129+
2.40.1
130+

0 commit comments

Comments
 (0)