First complete version

This commit is contained in:
Eric Coissac
2025-10-16 01:07:07 +02:00
parent 57bf9934a3
commit 02b48e75fa
24 changed files with 1265 additions and 110 deletions

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env python3
import os
import re
import json
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PAGES_DIR = os.path.join(SCRIPT_DIR,"..","jupyterhub_volumes","web","pages")
def clean_label(filename):
"""Nettoie les préfixes numériques et formate un label lisible."""
name = os.path.splitext(os.path.basename(filename))[0]
name = re.sub(r'^\d+_', '', name) # Supprime "00_", "01_", etc.
name = name.replace("_", " ")
return name.capitalize()
def build_tree(directory):
"""Construit récursivement la structure de menu à partir du répertoire donné."""
entries = []
for name in sorted(os.listdir(directory)):
path = os.path.join(directory, name)
# Ignorer les répertoires cachés ou ceux finissant par 'libs'
if os.path.isdir(path):
if name.endswith("libs") or name.startswith("."):
continue
children = build_tree(path)
if children:
entries.append({
"label": clean_label(name),
"children": children
})
elif name.endswith(".html"):
entries.append({
"file": os.path.relpath(path, PAGES_DIR).replace("\\", "/"),
"label": clean_label(name)
})
return entries
def count_pages(tree):
"""Compte le nombre total de fichiers HTML dans l'arborescence."""
total = 0
for node in tree:
if "file" in node:
total += 1
if "children" in node:
total += count_pages(node["children"])
return total
if __name__ == "__main__":
tree = build_tree(PAGES_DIR)
output_path = os.path.join(PAGES_DIR, "pages.json")
with open(output_path, "w", encoding="utf-8") as out:
json.dump(tree, out, indent=2, ensure_ascii=False)
print(f"✅ Generated {output_path} with {count_pages(tree)} HTML pages.")

77
tools/install_packages.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
# Script to install R packages in the course directory (admin only)
# Usage: ./install-r-packages.sh package1 package2 package3
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VOLUME="obijupyterhub_course"
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}📦 R Package Installer (Admin)${NC}"
echo "================================"
echo ""
# Check if packages are provided
if [ $# -eq 0 ]; then
echo -e "${RED}❌ Error: No packages specified${NC}"
echo ""
echo "Usage:"
echo " ./install-r-packages.sh package1 package2 package3"
echo ""
echo "Example:"
echo " ./install-r-packages.sh reshape2 plotly knitr"
exit 1
fi
# Build package list
PACKAGES=$(IFS=,; echo "$*")
R_PACKAGES=$(echo "$PACKAGES" | sed "s/,/', '/g")
echo -e "${YELLOW}📋 Packages to install: ${R_PACKAGES}${NC}"
echo ""
# Create a temporary directory for installation
TEMP_DIR=$(mktemp -d)
echo -e "${BLUE}📁 Creating temporary directory: ${TEMP_DIR}${NC}"
# Install packages in temporary directory
echo -e "${BLUE}🔨 Installing R packages...${NC}"
docker run --rm \
--user root \
-v "${TEMP_DIR}:/temp_packages" \
jupyterhub-student:latest \
R -e "install.packages(c('${R_PACKAGES}'), lib='/temp_packages', repos='http://cran.rstudio.com/')" || {
echo -e "${RED}❌ Failed to install packages${NC}"
rm -rf "${TEMP_DIR}"
exit 1
}
# Copy to course R packages directory
echo ""
echo -e "${BLUE}💾 Copying to course/R_packages...${NC}"
docker run --rm \
-v ${VOLUME}:/target \
-v "${TEMP_DIR}:/source" \
alpine sh -c "mkdir -p /target/R_packages && cp -r /source/* /target/R_packages/"
# Clean up
rm -rf "${TEMP_DIR}"
# List installed packages
echo ""
echo -e "${GREEN}✅ Installation complete!${NC}"
echo ""
echo -e "${BLUE}📦 Installed packages in work/course/R_packages:${NC}"
docker run --rm \
-v ${VOLUME}:/course \
alpine ls -1 /course/R_packages/
echo ""
echo -e "${YELLOW} Students need to restart their R kernels to use new packages.${NC}"