-
Notifications
You must be signed in to change notification settings - Fork 3
/
manage
executable file
·85 lines (79 loc) · 3.47 KB
/
manage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
# vim: ts=8 sw=4 sts=4 et ai:
export DJANGO_SETTINGS_MODULE="${DJANGO_SETTINGS_MODULE:-pstore.settings}"
projectpath="$(cd "$(dirname "$0")" >/dev/null && pwd)"
# Set python path according project path and optionally django path
pythonpath="$projectpath"
[ -n "$PYTHONPATH" ] && pythonpath="$pythonpath:$PYTHONPATH"
export PYTHONPATH="$pythonpath"
# Do show deprecation warnings
export PYTHONWARNINGS="d"
# Source manage.cfg if it exists
# E.g. for:
# test -z "$VIRTUAL_ENV" && . /srv/pstore/.venv/pstore-py3.10/bin/activate
test -f "$projectpath/manage.cfg" && . "$projectpath/manage.cfg"
# The django-admin app wants a non-option as first argument
arg1="$1"; [ $# -gt 0 ] && shift; [ -z "$arg1" ] && arg1=help
# Find a working django-admin app
django_admin=`which "django-admin"`
[ -z "$django_admin" ] && echo "Missing django-admin! Using virtualenv and forgot to workon? requirements.txt not installed yet?" >&2 && exit 1
django_admin="python -tt $django_admin"
# Try regular ./manage extensions
case "$arg1" in
dbdump)
shell="$django_admin shell --plain" # plain instead of ipython
setup='from django.conf import settings as s; g = lambda x: s.DATABASES["default"][x]' # django>=1.2
engine="`echo $setup'; print "$$$%s" % g("ENGINE")' | $shell 2>/dev/null | sed -e '/\\$\\$\\$/!d;s/^.*\\$\\$\\$\\(.*\\)/\1/'`"
case $engine in
django.db.backends.mysql|mysql)
opts="`echo $setup'; print "$$$-u%s -p%s %s%s"%(g("USER"),g("PASSWORD"),("","-h%s "%g("HOST"))[g("HOST")!=""],g("NAME"))' \
| $shell 2>/dev/null | sed -e '/\\$\\$\\$/!d;s/^.*\\$\\$\\$//'`"
mysqldump $opts --skip-extended-insert "$@" | sed -e '{
/^-- MySQL dump [0-9]\+/d
/^-- \(Dump completed\|Host:\|Server version\)/d
/^\/\*!40/d
/^\/\*!50013/d
/^SET \(@saved_cs\|character_set\)_client[[:blank:]]/d
s/ AUTO_INCREMENT=[0-9]*//g
s/ AUTO_INCREMENT/ auto_increment/
s/ CHARACTER SET / character set /
s/ COLLATE / collate /
s/ DEFAULT\(.*\),/ default\1,/
s/ PRIMARY KEY (/ PRIMARY KEY (/
}'
;;
postgresql_psycopg2)
opts="`echo $setup'; print "$$$user=%s password=%s dbname=%s%s"%(g("USER"),g("PASSWORD"),g("NAME"),(""," host=%s"%g("HOST"))[g("HOST")!=""])' \
| $shell 2>/dev/null | sed -e '/\\$\\$\\$/!d;s/^.*\\$\\$\\$//'`"
if [ "$*" = "--help" ]; then pg_dump --help
else pg_dump "$opts" "$@"; fi
;;
esac
;;
flushall)
printf 'Flushing all data to example setup! Continue [y/n]? '
read x; [ "$x" = y ] || exit 1
$django_admin migrate --noinput &&
yes "`printf 'yes\nno'`" | $django_admin flush >/dev/null 2>&1 &&
$django_admin loaddata example_data
echo 'Imported example_data!'
;;
test)
GNUPGHOME=$projectpath/tests.gnupghome
export GNUPGHOME
mkdir -p "$GNUPGHOME" && chmod 0700 "$GNUPGHOME"
echo 'INFO: example GPG user passwords are: <username> + "2"'
gpg --import docs/examples/[aijw]*.pub # not harm
gpg --import docs/examples/[aijw]*.key # not harm
if $django_admin "$arg1" "$@"; then
# Remove Harm [email protected] secret GPG key for testing purposes
gpg --batch --delete-secret-keys AB933A9DF55AA0313450C524DD070DB4AF37FBFF
# Run tests and bail early on failure
FAILFAST=1 ./docs/integrationtest.sh
fi
;;
*)
# Run the regular commands
exec $django_admin "$arg1" "$@"
;;
esac