Merge remote branch 'remotes/gandaro/324-bad-media-types'
[mediagoblin.git] / docs / hackinghowto.rst
CommitLineData
5a40e1ec
WKG
1.. _hacking-howto:
2
00fdc7bd
WKG
3===============
4 Hacking HOWTO
5===============
6
5a40e1ec
WKG
7So you want to hack on GNU MediaGoblin?
8=======================================
56d507b6 9
9d952fdc 10First thing to do is check out the `Web site
9610848c 11<http://mediagoblin.org/join/>`_ where we list all the project
9d952fdc 12infrastructure including:
56d507b6 13
56d507b6 14* the IRC channel
9610848c
WKG
15* the mailing list
16* the issue tracker
56d507b6
WKG
17
18Additionally, we have information on how to get involved, who to talk
19to, what needs to be worked on, and other things besides!
20
9610848c
WKG
21Second thing to do is take a look at :ref:`codebase-chapter` where
22we've started documenting how GNU MediaGoblin is built and how to add
23new things.
24
4564da22
WKG
25Third you'll need to :ref:`get the requirements
26<get-requirements-section>`.
56d507b6 27
2aa3bb11
WKG
28Fourth, you'll need to build a development environment. We use buildout,
29but if you want to use virtualenv, there's a set of mediocre not-very-supported
30steps in the `wiki <https://gitorious.org/mediagoblin/pages/Home>`_.
4564da22
WKG
31
32
33.. _get-requirements-section:
56d507b6 34
c66d0f5c 35Getting requirements
4564da22 36====================
56d507b6 37
c66d0f5c
WKG
38First, you need to have the following installed before you can build
39an environment for hacking on GNU MediaGoblin:
56d507b6 40
c66d0f5c 41* Python 2.6 or 2.7 - http://www.python.org/
56d507b6 42
c66d0f5c 43 You'll need Python as well as the dev files for building modules.
56d507b6 44
c66d0f5c
WKG
45* python-lxml - http://lxml.de/
46* git - http://git-scm.com/
47* MongoDB - http://www.mongodb.org/
48
49If you're running Debian GNU/Linux or a Debian-derived distribution
50such as Mint or Ubuntu, running the following should install these
51requirements::
52
5740a0d6
WKG
53 sudo apt-get install mongodb git-core python python-dev \
54 python-lxml
c66d0f5c 55
4564da22 56.. YouCanHelp::
52be418a 57
4564da22
WKG
58 If you have instructions for other GNU/Linux distributions to set
59 up requirements, let us know!
52be418a 60
52be418a 61
7a5ddb45
CAW
62.. _hacking-with-buildout:
63
2aa3bb11 64
7a5ddb45
CAW
65How to set up and maintain an environment for hacking with buildout
66===================================================================
67
7a5ddb45
CAW
68**Requirements**
69
70No additional requirements.
71
72
73**Create a development environment**
74
75After installing the requirements, follow these steps:
76
771. Clone the repository::
78
79 git clone http://git.gitorious.org/mediagoblin/mediagoblin.git
80
812. Bootstrap and run buildout::
82
83 cd mediagoblin
84 python bootstrap.py && ./bin/buildout
85
86
87That's it! Using this method, buildout should create a ``user_dev``
88directory, in which certain things will be stored (media, beaker
89session stuff, etc). You can change this, but for development
90purposes this default should be fine.
91
92
93**Updating for dependency changes**
94
95While hacking on GNU MediaGoblin over time, you'll eventually have to
96update your development environment because the dependencies have
97changed. To do that, run::
98
f4cfb4e9 99 ./bin/buildout && ./bin/gmg migrate
7a5ddb45
CAW
100
101
102**Updating for code changes**
103
104You don't need to do anything---code changes are automatically
105available.
106
107
108**Deleting your buildout**
109
110At some point, you may want to delete your buildout. Perhaps it's to
111start over. Perhaps it's to test building development environments
112with buildout.
113
114To do this, do::
115
116 rm -rf bin develop-eggs eggs mediagoblin.egg-info parts user_dev
117
4564da22 118
11e5b197
CAW
119Running the server
120==================
121
2aa3bb11 122Run::
11e5b197
CAW
123
124 ./bin/paster serve mediagoblin.ini --reload
125
126
1c424df5
CAW
127Running celeryd
128===============
129
130You need to do this if you want your media to process and actually
131show up. It's probably a good idea in development to have the web
132server (above) running in one terminal and celeryd in another window.
133
2aa3bb11 134Run::
1c424df5
CAW
135
136 CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_celery ./bin/celeryd
137
138
693b674c
CAW
139Too much work? Don't want to run an http server and celeryd at the
140same time? For development purposes there's a shortcut::
141
142 CELERY_ALWAYS_EAGER=true ./bin/paster serve mediagoblin.ini --reload
143
144This way the web server will block on processing items until they are
145done, but you don't need to run celery separately (which is probably
c0bf3c80
CAW
146good enough for development purposes, but something you almost
147certainly shouldn't do in production).
693b674c
CAW
148
149
11e5b197
CAW
150Running the test suite
151======================
152
2aa3bb11 153Run::
11e5b197 154
7eac4285 155 CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests
11e5b197
CAW
156
157
3e4a2f2b
CAW
158Running a shell
159===============
160
161If you want a shell with your database pre-setup and an instantiated
2aa3bb11 162application ready and at your fingertips....
3e4a2f2b 163
2aa3bb11 164Run::
3e4a2f2b
CAW
165
166 ./bin/gmg shell
167
3e4a2f2b 168
4564da22
WKG
169Troubleshooting
170===============
5740a0d6 171
4564da22
WKG
172pymongo.errors.AutoReconnect: could not find master/primary
173-----------------------------------------------------------
9d952fdc 174
4564da22 175If you see this::
9d952fdc 176
4564da22 177 pymongo.errors.AutoReconnect: could not find master/primary
9d952fdc 178
4564da22 179then make sure mongodb is installed and running.
5740a0d6 180
2aa3bb11
WKG
181If it's installed, check the mongodb log. On my machine, that's
182``/var/log/mongodb/mongodb.log``. If you see something like::
2704f7a6
WKG
183
184 old lock file: /var/lib/mongodb/mongod.lock. probably means...
185
186Then delete the lock file and relaunch mongodb.
187
5740a0d6 188
4564da22
WKG
189Wiping your user data
190=====================
191
192.. Note::
193
194 Unless you're doing development and working on and testing creating
195 a new instance, you will probably never have to do this. Will
196 plans to do this work and thus he documented it.
9610848c
WKG
197
198.. YouCanHelp::
199
1b734c4d
CAW
200 If you're familiar with MongoDB, we'd love to get a `script that
201 removes all the GNU MediaGoblin data from an existing instance
202 <http://bugs.foocorp.net/issues/296>`_. Let us know!
5740a0d6
WKG
203
204
9610848c
WKG
205Quickstart for Django programmers
206=================================
5740a0d6 207
9610848c
WKG
208We're not using Django, but the codebase is very Django-like in its
209structure.
5740a0d6 210
9610848c
WKG
211* ``routing.py`` is like ``urls.py`` in Django
212* ``models.py`` has mongokit ORM definitions
213* ``views.py`` is where the views go
5740a0d6 214
9610848c
WKG
215We're using MongoDB. Basically, instead of a relational database with
216tables, you have a big JSON structure which acts a lot like a Python
217dict.
5740a0d6
WKG
218
219
9610848c 220.. YouCanHelp::
5a40e1ec 221
9610848c
WKG
222 If there are other things that you think would help orient someone
223 new to GNU MediaGoblin but coming from Django, let us know!
5a40e1ec
WKG
224
225
226Bite-sized bugs to start with
227=============================
228
9610848c
WKG
229**May 3rd, 2011**: We don't have a list of bite-sized bugs, yet, but
230this is important to us. If you're interested in things to work on,
231let us know on `the mailing list <http://mediagoblin.org/join/>`_ or
232on the `IRC channel <http://mediagoblin.org/join/>`_.
9d952fdc
WKG
233
234
235Tips for people new to coding
236=============================
237
845c3ae2
WKG
238Learning Python
239---------------
9d952fdc
WKG
240
241GNU MediaGoblin is written using a programming language called `Python
242<http://python.org/>`_.
243
244There are two different incompatible iterations of Python which I'll
245refer to as Python 2 and Python 3. GNU MediaGoblin is written in
246Python 2 and requires Python 2.6 or 2.7. At some point, we might
247switch to Python 3, but that's a future thing.
248
249You can learn how to code in Python 2 from several excellent books
250that are freely available on the Internet:
251
252* `Learn Python the Hard Way <http://learnpythonthehardway.org/>`_
253* `Dive Into Pyton <http://diveintopython.org/>`_
254* `Python for Software Design <http://www.greenteapress.com/thinkpython/>`_
255* `A Byte of Python <http://www.swaroopch.com/notes/Python>`_
256
257These are all excellent texts.
258
9610848c
WKG
259.. YouCanHelp::
260
261 If you know of other good quality Python tutorials and Python
262 tutorial videos, let us know!
9d952fdc
WKG
263
264
845c3ae2
WKG
265Learning Libraries GNU MediaGoblin uses
266---------------------------------------
9d952fdc
WKG
267
268GNU MediaGoblin uses a variety of libraries in order to do what it
3dca2776 269does. These libraries are listed in the :ref:`codebase-chapter`
9d952fdc
WKG
270along with links to the project Web sites and documentation for the
271libraries.
272
273There are a variety of Python-related conferences every year that have
274sessions covering many aspects of these libraries. You can find them
275at `Python Miro Community <http://python.mirocommunity.org>`_ [0]_.
276
277.. [0] This is a shameless plug. Will Kahn-Greene runs Python Miro
278 Community.
279
280If you have questions or need help, find us on the mailing list and on
281IRC.
845c3ae2
WKG
282
283
284.. _hacking-howto-git:
285
286Learning git
287------------
288
289git is an interesting and very powerful tool. Like all powerful
290tools, it has a learning curve.
291
292If you're new to git, we highly recommend the following resources for
293getting the hang of it:
294
295* `Learn Git <http://learn.github.com/p/intro.html>`_ --- the GitHub
296 intro to git
297* `Pro Git <http://progit.org/book/>`_ --- fantastic book
298* `Git casts <http://gitcasts.com/>`_ --- screencast covering git
299 usage
300* `Git Reference <http://gitref.org/>`_ --- Git reference that makes
301 it easier to get the hang of git if you're coming from other version
302 control systems
303
2aa3bb11
WKG
304There's also a git mission at `OpenHatch <http://openhatch.org/>`_.
305
845c3ae2
WKG
306
307Learning other utilities
308------------------------
309
310The `OpenHatch <http://openhatch.org/>`_ site has a series of
311`training missions <http://openhatch.org/missions/>`_ which are
312designed to help you learn how to use these tools.
313
2aa3bb11
WKG
314If you're new to tar, diff, patch and git, we highly recommend you sign
315up with OpenHatch and do the missions.