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