Skip to content

Commit

Permalink
endlesskey: Import only specified content in collections
Browse files Browse the repository at this point in the history
The previous behaviour, of importing all content from all channels in
the collections, is preserved by setting include_full_channels to true.

https://phabricator.endlessm.com/T35103
  • Loading branch information
dylanmccall committed Dec 13, 2023
1 parent 6dbfbfd commit 486a37f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
5 changes: 5 additions & 0 deletions config/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ kolibri_pkgspec = https://github.com/learningequality/kolibri/releases/download/
# (ex. artist, explorer, spanish etc).
collections =

# By default, only the content specified in each collection will be included.
# Set this to true to include all content from all channels in the requested
# collections.
include_full_channels = false

[ostree]
# Repository setup. By default the remote, remote repo and OS name are
# all named eos.
Expand Down
43 changes: 30 additions & 13 deletions hooks/image/53-ek-content-preload
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ if [[ ! "${EIB_FLATPAK_REMOTE_FLATHUB_APPS}" =~ .*"org.endlessos.Key".* ]]; then
exit 0
fi

# Get the list of channels to preload.
selected_collection_files=()

channels_file="${EIB_TMPDIR}"/ek-channels
rm -f "${channels_file}"
touch "${channels_file}"
collections="${OSTREE_VAR}"/lib/flatpak/app/org.endlessos.Key/current/active/files/share/endless-key/collections/*.json
for collection in ${collections}; do
all_collection_files="${OSTREE_VAR}"/lib/flatpak/app/org.endlessos.Key/current/active/files/share/endless-key/collections/*.json
for collection_file in ${all_collection_files}; do
# Check if the file basename stripped off of -0001.json is part of the list
# of collections to be installed.
bn=$(basename ${collection})
bn=$(basename ${collection_file})
if [[ "${EIB_ENDLESSKEY_COLLECTIONS}" =~ .*"${bn%-????.json}".* ]] ; then
jq -r '.channels[].id' "${collection}" >> "${channels_file}"
selected_collection_files+=("${collection_file}")
jq -r '.channels[].id' "${collection_file}" >> "${channels_file}"
fi
done

channels=$(sort -u "${channels_file}")
if [ -z "${channels}" ]; then
all_channels=$(sort -u "${channels_file}")
if [ -z "${all_channels}" ]; then
echo "No Kolibri channels to preload"
exit 0
fi

# Seed the needed channels on the content server.
"${EIB_HELPERSDIR}"/seed-kolibri-channels ${channels}
"${EIB_HELPERSDIR}"/seed-kolibri-channels ${all_channels}

venv_dir="${EIB_TMPDIR}/kolibri-content-venv"
python3 -m venv ${venv_dir}
Expand All @@ -48,14 +50,29 @@ if [ -n "${EIB_KOLIBRI_CENTRAL_CONTENT_BASE_URL}" ]; then
export KOLIBRI_CENTRAL_CONTENT_BASE_URL
fi

for channel in $channels; do
for channel in $all_channels; do
kolibri manage --skip-update importchannel network "${channel}"
EIB_RETRY_ATTEMPTS=2 EIB_RETRY_INTERVAL=30 eib_retry \
kolibri manage --skip-update \
importcontent --include-unrenderable-content --fail-on-error \
network "${channel}"
done

if [ "${EIB_ENDLESSKEY_INCLUDE_FULL_CHANNELS}" == true ]; then
for channel in $all_channels; do
EIB_RETRY_ATTEMPTS=2 EIB_RETRY_INTERVAL=30 eib_retry \
kolibri manage --skip-update \
importcontent --include-unrenderable-content --fail-on-error \
network "${channel}"
done
else
for collection_file in "${selected_collection_files[@]}"; do
collection_channels=$(jq -r '.channels[].id' "${collection_file}")
for channel in $collection_channels; do
EIB_RETRY_ATTEMPTS=2 EIB_RETRY_INTERVAL=30 eib_retry \
kolibri manage --skip-update \
importcontent --include-unrenderable-content --fail-on-error \
--manifest="${collection_file}" network "${channel}"
done
done
fi

# Empty the user database, and ensure that each instance of this image has a
# unique Facility ID.
# <https://kolibri.readthedocs.io/en/latest/install/provision.html#prepare-the-kolibri-folder-for-copying>
Expand Down

0 comments on commit 486a37f

Please sign in to comment.