Skip to content

Commit eefbc02

Browse files
Adds useful script to run a query against each chapter site
I was tired of having questions like "how many chapters have X object in their database" and having no easy way to answer them. This script is janky but should hopefully work; maybe some day we will have an actual build system that can do this reasonably. Note that while the script lives in the codebase of one site, it is designed to run on all sites, I just don't have a better place to keep it.
1 parent 8b6839d commit eefbc02

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

esp/useful_scripts/run_queries.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Run a query against each chapter site on the LU server.
4+
# usage e.g. $0 "print Program.objects.count()"
5+
# $0 "$(cat script.py)"
6+
7+
set -e
8+
9+
this_dir=${0%/*}
10+
base_dir=/lu/sites
11+
12+
cd $base_dir || exit 1
13+
sites=$(ls -d */ | tr -d '/')
14+
echo "$@"
15+
for i in $sites ; do
16+
if [ -f $i/esp/manage.py ] ; then
17+
echo -n "$i: "
18+
python $this_dir/single_query.py "$base_dir/$i" "$@"
19+
fi
20+
done

esp/useful_scripts/single_query.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python2
2+
3+
# Run a query against a site in a given directory.
4+
# usage e.g. $0 /lu/sites/smith "print Program.objects.count()"
5+
# $0 /lu/sites/smith "$(cat script.py)"
6+
# Intended primarily to be used by run_queries.sh.
7+
8+
import sys
9+
sys.path.insert(0, sys.argv[1]+'/esp/useful_scripts')
10+
11+
try:
12+
from script_setup import *
13+
except:
14+
print "ERROR: no script_setup.py"
15+
sys.exit(1)
16+
17+
try:
18+
exec sys.argv[2]
19+
except:
20+
print "ERROR: code failed to run"
21+
raise

0 commit comments

Comments
 (0)