summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2008-09-28 19:37:58 +0000
committerClint Adams <clint@users.sourceforge.net>2008-09-28 19:37:58 +0000
commitbf59efddfa48dbed872daa5582136b5a723118a2 (patch)
treeff68330c1895cb0573c0f8628ff32189943bcb47
parente6dec182d0b3184476a8ac260c0e798f29611f55 (diff)
downloadzsh-bf59efddfa48dbed872daa5582136b5a723118a2.tar.gz
zsh-bf59efddfa48dbed872daa5582136b5a723118a2.tar.xz
zsh-bf59efddfa48dbed872daa5582136b5a723118a2.zip
25764: completion for Django, from Chris Lamb.
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Unix/Command/.distfiles1
-rw-r--r--Completion/Unix/Command/_django199
3 files changed, 206 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index e31d700b0..fc6debf1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-09-28  Clint Adams  <clint@zsh.org>
+
+	* 25764: Completion/Unix/Command/.distfiles,
+	Completion/Unix/Command/_django: completion for Django, from Chris
+	Lamb.
+
 2008-09-28  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* Mikael Magnusson: Src/utils.c: newline in getquery() is
diff --git a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles
index 654f8a8d8..c8d935bd5 100644
--- a/Completion/Unix/Command/.distfiles
+++ b/Completion/Unix/Command/.distfiles
@@ -42,6 +42,7 @@ _dhclient
 _dict
 _diff
 _diffstat
+_django
 _dmidecode
 _du
 _dvi
diff --git a/Completion/Unix/Command/_django b/Completion/Unix/Command/_django
new file mode 100644
index 000000000..82d5910f3
--- /dev/null
+++ b/Completion/Unix/Command/_django
@@ -0,0 +1,199 @@
+#compdef django-admin.py django-admin manage.py
+
+local ret=1 state
+
+if [ "$service" = "manage.py" ] && [ ! -x ./manage.py ]; then
+  return 0
+fi
+
+declare -ga common_args
+common_args=(
+  '--help[display help information]'
+  '--version[display version information]'
+  '--pythonpath=[directory to add to the Python path]:directory:_directories'
+  '--settings=[Python path to settings module]:settings'
+  '--traceback[print traceback on exception]'
+)
+
+_directories () {
+  _wanted directories expl directory _path_files -/ "$@" -
+}
+
+typeset -A opt_args
+_arguments \
+  $common_args \
+  ':subcommand:->subcommand' \
+  '*::options:->options' && ret=0
+
+case $state in
+  subcommand)
+    subcommands=(
+      "cleanup:remove old data from the database"
+      "compilemessages:compile .po files to .mo for use with gettext"
+      "createcachetable:creates table for SQL cache backend"
+      "createsuperuser:create a superuser"
+      "dbshell:run command-line client for the current database"
+      "diffsettings:display differences between the current settings and Django defaults"
+      "dumpdata:output contents of database as a fixture"
+      "flush:execute 'sqlflush' on the current database"
+      "inspectdb:output Django model module for tables in database"
+      "loaddata:install the named fixture(s) in the database"
+      "makemessages:pull out all strings marked for translation"
+      "reset:executes 'sqlreset' for the given app(s)"
+      "runfcgi:run this project as a fastcgi"
+      "runserver:start a lightweight web server for development"
+      "shell:run a Python interactive interpreter. Tries to use IPython, if it's available"
+      "sql:print the CREATE TABLE statements for the given app(s)"
+      "sqlall:print the CREATE TABLE, CREATE INDEX and custom statements for the given app(s)"
+      "sqlclear:print the DROP TABLE statements for the given app(s)"
+      "sqlcustom:print the custom table-modifying SQL statements for the given app(s)"
+      "sqlflush:print the SQL statements required to return all tables to installation state"
+      "sqlindexes:print the CREATE INDEX statements for the given app(s)"
+      "sqlreset:print the DROP TABLE and CREATE TABLE statements for the given app(s)"
+      "sqlsequencereset:print the SQL statements for resetting sequences for the given app(s)"
+      "startapp:create Django app directory in this project's directory"
+      "syncdb:create database tables for apps in INSTALLED_APPS where required"
+      "test:run the test suite for the specified app, or the entire site"
+      "testserver:run a development server with data from the given fixture(s)"
+      "validate:validate all installed modules"
+    )
+    
+    _describe -t subcommands 'django admin subcommand' subcommands && ret=0
+    ;;
+
+  options)
+    declare -a args
+    args=(
+      $common_args
+    )
+
+    declare -a verbosity
+    verbosity=(
+      '--verbosity=:verbosity:(0 1 2):[verbosity level; 0=minimal, 1=normal, 2=all]'
+    )
+
+    declare -a locale
+    locale=(
+      {-l,--locale=}'[locale to process (default: all)]:locale'
+    )
+
+    declare -a noinput
+    noinput=(
+      '--noinput[do not prompt for any input]'
+    )
+
+    port_opts={,0.0.0.0\\:,127.0.0.1\\:}800{0,1}
+
+    _appname () {
+      local settings=""
+      if [ -e settings.py ]; then
+          settings="settings.py"
+      elif [ -n "${DJANGO_SETTINGS_MODULE}" ]; then
+          settings="${DJANGO_SETTINGS_MODULE}"
+      else
+        return 0
+      fi 
+     
+      _wanted appname expl appname compadd - $(command \
+        sed -n "/INSTALLED_APPS\s*=\s*(/,/)/p" ${settings} | \
+        sed -n "s/^\s*'\(.*\.\)*\(.*\)'.*$/\2 /pg")
+    }
+
+    case $words[1] in
+      compilemessages)
+        args+=$locale
+        ;;
+
+      createcachetable)
+        args+=':tablename:'
+        ;;
+
+      createsuperuser)
+        args+=(
+          $noinput
+          '--username[username for the superuser]:username'
+          '--email[email address for the superuser]:email'
+        )
+        ;;
+
+      dumpdata)
+        args+=(
+          '--format=:format:(xml python json yaml):[serialization format for the fixtures]'
+          '--indent=[indent level to use when pretty-printing]:indent'
+          {-e,--exclude=}'[app to exclude]:exclude:_appname'
+        )
+        ;;
+
+      flush)
+        args+=$verbosity
+        ;;
+
+      loaddata)
+        args+=(
+          $verbosity
+          '*:fixture:'
+        )
+        ;;
+
+      makemessages)
+        args+=(
+          $locale
+          $verbosity
+          {-d,--domain=}'[domain of the message files (default: "django")]:domain'
+          {-a,--all}'[re-examine all code and templates]'
+          {-e,--extensions=}'[file extension(s) to examine (default: ".html")]:extension'
+        )
+        ;;
+
+      runserver)
+        args+=(
+          '--noreload[do not use auto-reloader]'
+      	  '--adminmedia=[directory from which to serve admin media]:directory:_directories'
+          ':port:('$port_opts')'
+        )
+        ;;
+
+      shell)
+        args+='--plain[use plain Python, not IPython]'
+        ;;
+
+      reset|sql*)
+        args+='*:appname:_appname'
+        ;;
+
+      startapp)
+        args+=':new_appname:'
+        ;;
+
+      syncdb)
+        args+=(
+          $verbosity
+          $noinput
+        )
+        ;;
+
+      "test")
+        args+=(
+          $verbosity
+          $noinput
+         '*:appname:_appname'
+        )
+        ;;
+
+      testserver)
+        args+=(
+          $verbosity
+          '--addrport=:addrport:('$port_opts'):[port number or ipaddr:port to run server on]'
+          '*:fixture:'
+        )
+        ;;
+
+      validate|runfcgi)
+        ;;
+    esac
+
+    _arguments $args && ret=0
+    ;;
+esac
+
+return ret