Skip to content

Commit b5bd2e2

Browse files
committed
Merge pull request #1692 from learning-unlimited/run-queries
Adds useful script to run a query against each chapter site
2 parents 1e48b32 + eefbc02 commit b5bd2e2

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)