codebase.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. .. MediaGoblin Documentation
  2. Written in 2011, 2012 by MediaGoblin contributors
  3. To the extent possible under law, the author(s) have dedicated all
  4. copyright and related and neighboring rights to this software to
  5. the public domain worldwide. This software is distributed without
  6. any warranty.
  7. You should have received a copy of the CC0 Public Domain
  8. Dedication along with this software. If not, see
  9. <http://creativecommons.org/publicdomain/zero/1.0/>.
  10. .. _codebase-chapter:
  11. ========================
  12. Codebase Documentation
  13. ========================
  14. .. contents:: Sections
  15. :local:
  16. This chapter covers the libraries that GNU MediaGoblin uses as well as
  17. various recipes for getting things done.
  18. .. Note::
  19. This chapter is in flux. Clearly there are things here that aren't
  20. documented. If there's something you have questions about, please
  21. ask!
  22. See `the join page on the website <http://mediagoblin.org/join/>`_
  23. for where we hang out.
  24. For more information on how to get started hacking on GNU MediaGoblin,
  25. see `the wiki <http://wiki.mediagoblin.org/>`_, and specifically, go
  26. through the
  27. `Hacking HOWTO <http://wiki.mediagoblin.org/HackingHowto>`_
  28. which explains generally how to get going with running an instance for
  29. development.
  30. What's where
  31. ============
  32. After you've run checked out mediagoblin and followed the virtualenv
  33. instantiation instructions, you're faced with the following directory
  34. tree::
  35. mediagoblin/
  36. |- mediagoblin/ # source code
  37. | |- db/ # database setup
  38. | |- tools/ # various utilities
  39. | |- init/ # "initialization" tools (arguably should be in tools/)
  40. | |- tests/ # unit tests
  41. | |- templates/ # templates for this application
  42. | |- media_types/ # code for processing, displaying different media
  43. | |- storage/ # different storage backends
  44. | |- gmg_commands/ # command line tools (./bin/gmg)
  45. | |- themes/ # pre-bundled themes
  46. | |
  47. | | # ... some submodules here as well for different sections
  48. | | # of the application... here's just a few
  49. | |- auth/ # authentication (login/registration) code
  50. | |- user_dev/ # user pages (under /u/), including media pages
  51. | \- submit/ # submitting media for processing
  52. |
  53. |- docs/ # documentation
  54. |- devtools/ # some scripts for developer convenience
  55. |
  56. |- user_dev/ # local instance sessions, media, etc
  57. |
  58. | # the below directories are installed into your virtualenv checkout
  59. |
  60. |- bin/ # scripts
  61. |- develop-eggs/
  62. |- lib/ # python libraries installed into your virtualenv
  63. |- include/
  64. |- mediagoblin.egg-info/
  65. \- parts/
  66. As you can see, all the code for GNU MediaGoblin is in the
  67. ``mediagoblin`` directory.
  68. Here are some interesting files and what they do:
  69. :routing.py: maps url paths to views
  70. :views.py: views handle http requests
  71. :forms.py: wtforms stuff for this submodule
  72. You'll notice that there are several sub-directories: tests,
  73. templates, auth, submit, ...
  74. ``tests`` holds the unit test code.
  75. ``templates`` holds all the templates for the output.
  76. ``auth`` and ``submit`` are modules that enacpsulate authentication
  77. and media item submission. If you look in these directories, you'll
  78. see they have their own ``routing.py``, ``view.py``, and forms.py in
  79. addition to some other code.
  80. You'll also notice that mediagoblin/db/ contains quite a few things,
  81. including the following:
  82. :models.py: This is where the database is set up
  83. :mixin.py: Certain functions appended to models from here
  84. :migrations.py: When creating a new migration (a change to the
  85. database structure), we put it here
  86. Software Stack
  87. ==============
  88. * Project infrastructure
  89. * `Python <http://python.org/>`_: the language we're using to write
  90. this
  91. * `Py.Test <http://pytest.org/>`_:
  92. for unit tests
  93. * `virtualenv <http://www.virtualenv.org/>`_: for setting up an
  94. isolated environment to keep mediagoblin and related packages
  95. (potentially not required if MediaGoblin is packaged for your
  96. distro)
  97. * Data storage
  98. * `SQLAlchemy <http://sqlalchemy.org/>`_: SQL ORM and database
  99. interaction library for Python. Currently we support sqlite and
  100. postgress as backends.
  101. * Web application
  102. * `Paste Deploy <http://pythonpaste.org/deploy/>`_ and
  103. `Paste Script <http://pythonpaste.org/script/>`_: we'll use this for
  104. configuring and launching the application
  105. * `werkzeug <http://werkzeug.pocoo.org/>`_: nice abstraction layer
  106. from HTTP requests, responses and WSGI bits
  107. * `itsdangerous <http://pythonhosted.org/itsdangerous/>`_:
  108. for handling sessions
  109. * `Jinja2 <http://jinja.pocoo.org/docs/>`_: the templating engine
  110. * `WTForms <http://wtforms.simplecodes.com/>`_: for handling,
  111. validation, and abstraction from HTML forms
  112. * `Celery <http://celeryproject.org/>`_: for task queuing (resizing
  113. images, encoding video, ...)
  114. * `Babel <http://babel.edgewall.org>`_: Used to extract and compile
  115. translations.
  116. * `Markdown (for python) <http://pypi.python.org/pypi/Markdown>`_:
  117. implementation of `Markdown <http://daringfireball.net/projects/markdown/>`_
  118. text-to-html tool to make it easy for people to write richtext
  119. comments, descriptions, and etc.
  120. * `lxml <http://lxml.de/>`_: nice xml and html processing for
  121. python.
  122. * Media processing libraries
  123. * `Python Imaging Library <http://www.pythonware.com/products/pil/>`_:
  124. used to resize and otherwise convert images for display.
  125. * `GStreamer <http://gstreamer.freedesktop.org/>`_: (Optional, for
  126. video hosting sites only) Used to transcode video, and in the
  127. future, probably audio too.
  128. * `chardet <http://pypi.python.org/pypi/chardet>`_: (Optional, for
  129. ascii art hosting sites only) Used to make ascii art thumbnails.
  130. * Front end
  131. * `JQuery <http://jquery.com/>`_: for groovy JavaScript things