django.plugin.zsh 8.8 KB

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