django.plugin.zsh 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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-syncdb() {
  126. _arguments -s : \
  127. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  128. '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
  129. $nul_args && ret=0
  130. }
  131. _managepy-test() {
  132. _arguments -s : \
  133. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  134. '--noinput[tells Django to NOT prompt the user for input of any kind.]' \
  135. '*::appname:_applist' \
  136. $nul_args && ret=0
  137. }
  138. _managepy-testserver() {
  139. _arguments -s : \
  140. '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \
  141. '--addrport=-[port number or ipaddr:port to run the server on.]' \
  142. '*::fixture:_files' \
  143. $nul_args && ret=0
  144. }
  145. _managepy-validate() {
  146. _arguments -s : \
  147. $nul_args && ret=0
  148. }
  149. _managepy-commands() {
  150. local -a commands
  151. commands=(
  152. 'adminindex:prints the admin-index template snippet for the given app name(s).'
  153. 'createcachetable:creates the table needed to use the SQL cache backend.'
  154. 'collectstatic:Collect static files in a single location.'
  155. 'dbshell:runs the command-line client for the current DATABASE_ENGINE.'
  156. "diffsettings:displays differences between the current settings.py and Django's default settings."
  157. 'dumpdata:Output the contents of the database as a fixture of the given format.'
  158. 'flush:Executes ``sqlflush`` on the current database.'
  159. 'help:manage.py help.'
  160. 'inspectdb:Introspects the database tables in the given database and outputs a Django model module.'
  161. 'loaddata:Installs the named fixture(s) in the database.'
  162. 'reset:Executes ``sqlreset`` for the given app(s) in the current database.'
  163. 'runfcgi:Run this project as a fastcgi (or some other protocol supported by flup) application,'
  164. 'runserver:Starts a lightweight Web server for development.'
  165. 'shell:Runs a Python interactive interpreter.'
  166. 'sql:Prints the CREATE TABLE SQL statements for the given app name(s).'
  167. 'sqlall:Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).'
  168. 'sqlclear:Prints the DROP TABLE SQL statements for the given app name(s).'
  169. 'sqlcustom:Prints the custom table modifying SQL statements for the given app name(s).'
  170. '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.'
  171. 'sqlindexes:Prints the CREATE INDEX SQL statements for the given model module name(s).'
  172. "sqlinitialdata:RENAMED: see 'sqlcustom'"
  173. 'sqlreset:Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).'
  174. 'sqlsequencereset:Prints the SQL statements for resetting sequences for the given app name(s).'
  175. "startapp:Creates a Django app directory structure for the given app name in this project's directory."
  176. "syncdb:Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
  177. 'test:Runs the test suite for the specified applications, or the entire site if no apps are specified.'
  178. 'testserver:Runs a development server with data from the given fixture(s).'
  179. 'validate:Validates all installed models.'
  180. )
  181. _describe -t commands 'manage.py command' commands && ret=0
  182. }
  183. _applist() {
  184. local line
  185. local -a apps
  186. _call_program help-command "python -c \"import os.path as op, re, django.conf, sys;\\
  187. bn=op.basename(op.abspath(op.curdir));[sys\\
  188. .stdout.write(str(re.sub(r'^%s\.(.*?)$' %
  189. bn, r'\1', i)) + '\n') for i in django.conf.settings.\\
  190. INSTALLED_APPS if re.match(r'^%s' % bn, i)]\"" \
  191. | while read -A line; do apps=($line $apps) done
  192. _values 'Application' $apps && ret=0
  193. }
  194. _managepy() {
  195. local curcontext=$curcontext ret=1
  196. if ((CURRENT == 2)); then
  197. _managepy-commands
  198. else
  199. shift words
  200. (( CURRENT -- ))
  201. curcontext="${curcontext%:*:*}:managepy-$words[1]:"
  202. _call_function ret _managepy-$words[1]
  203. fi
  204. }
  205. compdef _managepy manage.py
  206. compdef _managepy django
  207. compdef _managepy django-admin.py
  208. compdef _managepy django-manage