Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endlesskey: Import only specified content in collections #141

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions config/personality/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ apps_add =
com.endlessnetwork.drawingtutorials
com.endlessnetwork.htmltutorials
com.endlessnetwork.sciencesnacks

[endlesskey]
collections =
artist
athlete
curious
explorer
extras
inventor
scientist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to also include extras or this won't work offline. The explore plugin will try to import all the thumbnails from nodes in the extras pack at runtime. See https://github.com/endlessm/kolibri-explore-plugin/blob/master/kolibri_explore_plugin/collectionviews.py#L43. I think it's fine to import whatever nodes are specified in it.

Copy link
Contributor Author

@dylanmccall dylanmccall Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that's a good one. I pushed a change just now (4583308) getting it to download all thumbnails for all the included channels.

Alas, adding the extras collection is a bit problematic, since that manifest file includes a bunch of content as well. But it probably shouldn't? I proposed endlessm/endless-key-collections#37 just now to address that, and then I can add it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The collections change was merged, released, and included in an org.endlessos.Key flathub release. So, I think this should be good now.

41 changes: 32 additions & 9 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,35 @@ if [ -n "${EIB_KOLIBRI_CENTRAL_CONTENT_BASE_URL}" ]; then
export KOLIBRI_CENTRAL_CONTENT_BASE_URL
fi

for channel in $channels; do
# Import all channel metadata and thumbnails for all channels
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 \
--node_ids="" --all-thumbnails \
network "${channel}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this should only be in the not full channels branch below. The full channels branch is obviously already going to import all the thumbnails. Not a big deal, though.

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
Loading