django.plugin.zsh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #compdef manage.py
  2. typeset -ga nul_args
  3. nul_args=(
  4. '--settings=-[the Python path to a settings module.]:file:_files'
  5. '--pythonpath=-[a directory to add to the Python path.]::directory:_directories'
  6. '--traceback[print traceback on exception.]'
  7. "--version[show program's version number and exit.]"
  8. {-h,--help}'[show this help message and exit.]'
  9. )
  10. _managepy-adminindex(){
  11. _arguments -s : \
  12. $nul_args \
  13. '*::directory:_directories' && ret=0
  14. }
  15. _managepy-createcachetable(){
  16. _arguments -s : \
  17. $nul_args && ret=0
  18. }
  19. _managepy-dbshell(){
  20. _arguments -s : \
  21. $nul_args && ret=0
  22. }
  23. _managepy-diffsettings(){
  24. _arguments -s : \
  25. $nul_args && ret=0
  26. }
  27. _managepy-dumpdata(){
  28. _arguments -s : \
  29. '--format=-[specifies the output serialization format for fixtures.]:format:(json yaml xml)' \
  30. '--indent=-[specifies the indent level to use when pretty-printing output.]:' \
  31. $nul_args \
  32. '*::appname:_applist' && ret=0
  33. }
  34. _managepy-flush(){
  35. _arguments -s : \
  36. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  37. '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
  38. $nul_args && ret=0
  39. }
  40. _managepy-help(){
  41. _arguments -s : \
  42. '*:command:_managepy_cmds' \
  43. $nul_args && ret=0
  44. }
  45. _managepy_cmds(){
  46. local line
  47. local -a cmd
  48. _call_program help-command ./manage.py help \
  49. |& sed -n '/^ /s/[(), ]/ /gp' \
  50. | while read -A line; do cmd=($line $cmd) done
  51. _describe -t managepy-command 'manage.py command' cmd
  52. }
  53. _managepy-inspectdb(){
  54. _arguments -s : \
  55. $nul_args && ret=0
  56. }
  57. _managepy-loaddata(){
  58. _arguments -s : \
  59. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  60. '*::file:_files' \
  61. $nul_args && ret=0
  62. }
  63. _managepy-reset(){
  64. _arguments -s : \
  65. '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
  66. '*::appname:_applist' \
  67. $nul_args && ret=0
  68. }
  69. _managepy-runfcgi(){
  70. local state
  71. local fcgi_opts
  72. fcgi_opts=(
  73. 'protocol[fcgi, scgi, ajp, ... (default fcgi)]:protocol:(fcgi scgi ajp)'
  74. 'host[hostname to listen on..]:'
  75. 'port[port to listen on.]:'
  76. 'socket[UNIX socket to listen on.]::file:_files'
  77. 'method[prefork or threaded (default prefork)]:method:(prefork threaded)'
  78. 'maxrequests[number of requests a child handles before it is killed and a new child is forked (0 = no limit).]:'
  79. 'maxspare[max number of spare processes / threads.]:'
  80. 'minspare[min number of spare processes / threads.]:'
  81. 'maxchildren[hard limit number of processes / threads.]:'
  82. 'daemonize[whether to detach from terminal.]:boolean:(False True)'
  83. 'pidfile[write the spawned process-id to this file.]:file:_files'
  84. 'workdir[change to this directory when daemonizing.]:directory:_files'
  85. 'outlog[write stdout to this file.]:file:_files'
  86. 'errlog[write stderr to this file.]:file:_files'
  87. )
  88. _arguments -s : \
  89. $nul_args \
  90. '*: :_values "FCGI Setting" $fcgi_opts' && ret=0
  91. }
  92. _managepy-runserver(){
  93. _arguments -s : \
  94. '--noreload[tells Django to NOT use the auto-reloader.]' \
  95. '--adminmedia[specifies the directory from which to serve admin media.]:directory:_files' \
  96. $nul_args && ret=0
  97. }
  98. _managepy-shell(){
  99. _arguments -s : \
  100. '--plain[tells Django to use plain Python, not IPython.]' \
  101. $nul_args && ret=0
  102. }
  103. _managepy-sql(){}
  104. _managepy-sqlall(){}
  105. _managepy-sqlclear(){}
  106. _managepy-sqlcustom(){}
  107. _managepy-sqlflush(){}
  108. _managepy-sqlindexes(){}
  109. _managepy-sqlinitialdata(){}
  110. _managepy-sqlreset(){}
  111. _managepy-sqlsequencereset(){}
  112. _managepy-startapp(){}
  113. _managepy-syncdb() {
  114. _arguments -s : \
  115. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  116. '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
  117. $nul_args && ret=0
  118. }
  119. _managepy-test() {
  120. _arguments -s : \
  121. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  122. '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
  123. '*::appname:_applist' \
  124. $nul_args && ret=0
  125. }
  126. _managepy-testserver() {
  127. _arguments -s : \
  128. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  129. '--addrport=-[port number or ipaddr:port to run the server on.]' \
  130. '*::fixture:_files' \
  131. $nul_args && ret=0
  132. }
  133. _managepy-validate() {
  134. _arguments -s : \
  135. $nul_args && ret=0
  136. }
  137. _managepy-commands() {
  138. local -a commands
  139. commands=(
  140. 'adminindex:prints the admin-index template snippet for the given app name(s).'
  141. 'createcachetable:creates the table needed to use the SQL cache backend.'
  142. 'dbshell:runs the command-line client for the current DATABASE_ENGINE.'
  143. "diffsettings:displays differences between the current settings.py and Django's default settings."
  144. 'dumpdata:Output the contents of the database as a fixture of the given format.'
  145. 'flush:Executes ``sqlflush`` on the current database.'
  146. 'help:manage.py help.'
  147. 'inspectdb:Introspects the database tables in the given database and outputs a Django model module.'
  148. 'loaddata:Installs the named fixture(s) in the database.'
  149. 'reset:Executes ``sqlreset`` for the given app(s) in the current database.'
  150. 'runfcgi:Run this project as a fastcgi (or some other protocol supported by flup) application,'
  151. 'runserver:Starts a lightweight Web server for development.'
  152. 'shell:Runs a Python interactive interpreter.'
  153. 'sql:Prints the CREATE TABLE SQL statements for the given app name(s).'
  154. 'sqlall:Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).'
  155. 'sqlclear:Prints the DROP TABLE SQL statements for the given app name(s).'
  156. 'sqlcustom:Prints the custom table modifying SQL statements for the given app name(s).'
  157. 'sqlflush:Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed.'
  158. 'sqlindexes:Prints the CREATE INDEX SQL statements for the given model module name(s).'
  159. "sqlinitialdata:RENAMED: see 'sqlcustom'"
  160. 'sqlreset:Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).'
  161. 'sqlsequencereset:Prints the SQL statements for resetting sequences for the given app name(s).'
  162. "startapp:Creates a Django app directory structure for the given app name in this project's directory."
  163. "syncdb:Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
  164. 'test:Runs the test suite for the specified applications, or the entire site if no apps are specified.'
  165. 'testserver:Runs a development server with data from the given fixture(s).'
  166. 'validate:Validates all installed models.'
  167. )
  168. _describe -t commands 'manage.py command' commands && ret=0
  169. }
  170. _applist() {
  171. local line
  172. local -a apps
  173. _call_program help-command "python -c \"import os.path as op, re, django.conf, sys;\\
  174. bn=op.basename(op.abspath(op.curdir));[sys\\
  175. .stdout.write(str(re.sub(r'^%s\.(.*?)$' %
  176. bn, r'\1', i)) + '\n') for i in django.conf.settings.\\
  177. INSTALLED_APPS if re.match(r'^%s' % bn, i)]\"" \
  178. | while read -A line; do apps=($line $apps) done
  179. _values 'Application' $apps && ret=0
  180. }
  181. _managepy() {
  182. local curcontext=$curcontext ret=1
  183. if ((CURRENT == 2)); then
  184. _managepy-commands
  185. else
  186. shift words
  187. (( CURRENT -- ))
  188. curcontext="${curcontext%:*:*}:managepy-$words[1]:"
  189. _call_function ret _managepy-$words[1]
  190. fi
  191. }
  192. compdef _managepy manage.py
  193. compdef _managepy django
  194. compdef _managepy django-manage