Spell-check the entire documentation.
[mediagoblin.git] / docs / source / devel / storage.rst
CommitLineData
340100ee
E
1=========
2 Storage
3=========
4
340100ee
E
5The storage systems attached to your app
6----------------------------------------
7
8Dynamic content: queue_store and public_store
9~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
a2d94b0c 11Two instances of the StorageInterface come attached to your app. These
12are:
13
90e7fc67
CAW
14+ **queue_store:** When a user submits a fresh piece of media for
15 their gallery, before the Processing stage, that piece of media sits
16 here in the queue_store. (It's possible that we'll rename this to
17 "private_store" and start storing more non-publicly-stored stuff in
18 the future...). This is a StorageInterface implementation
19 instance. Visitors to your site probably cannot see it... it isn't
20 designed to be seen, anyway.
21
22+ **public_store:** After your media goes through processing it gets
23 moved to the public store. This is also a StorageInterface
9650aa39 24 implementation, and is for stuff that's intended to be seen by
90e7fc67 25 site visitors.
a2d94b0c 26
340100ee
E
27The workbench
28~~~~~~~~~~~~~
29
30In addition, there's a "workbench" used during
31processing... it's just for temporary files during
32processing, and also for making local copies of stuff that
33might be on remote storage interfaces while transitionally
34moving/converting from the queue_store to the public store.
35See the workbench module documentation for more.
36
37.. automodule:: mediagoblin.tools.workbench
38 :members:
39 :show-inheritance:
40
41
42Static assets / staticdirect
43~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
a2d94b0c 45On top of all that, there is some static media that comes bundled with your
9650aa39 46application. This stuff is kept in ``mediagoblin/static/``.
a2d94b0c 47
9650aa39 48These files are for MediaGoblin base assets. Things like the CSS files,
a2d94b0c 49logos, etc. You can mount these at whatever location is appropriate to you
50(see the direct_remote_path option in the config file) so if your users
51are keeping their static assets at http://static.mgoblin.example.org/ but
52their actual site is at http://mgoblin.example.org/, you need to be able
53to get your static files in a where-it's-mounted agnostic way. There's a
54"staticdirector" attached to the request object. It's pretty easy to use;
55just look at this bit taken from the
9650aa39 56mediagoblin/templates/mediagoblin/base.html main template::
a2d94b0c 57
58 <link rel="stylesheet" type="text/css"
59 href="Template:Request.staticdirect('/css/extlib/text.css')"/>
60
61see? Not too hard. As expected, if you configured direct_remote_path to be
62http://static.mgoblin.example.org/ you'll get back
63http://static.mgoblin.example.org/css/extlib/text.css just as you'd
64probably expect.
340100ee
E
65
66StorageInterface and implementations
67------------------------------------
68
69The guts of StorageInterface and friends
70~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71
a2d94b0c 72So, the StorageInterface!
73
74So, the public and queue stores both use StorageInterface implementations
75... but what does that mean? It's not too hard.
76
9650aa39 77Open up ``mediagoblin/storage.py``.
a2d94b0c 78
79In here you'll see a couple of things. First of all, there's the
80StorageInterface class. What you'll see is that this is just a very simple
81python class. A few of the methods actually implement things, but for the
82most part, they don't. What really matters about this class is the
83docstrings. Each expected method is documented as to how it should be
84constructed. Want to make a new StorageInterface? Simply subclass it. Want
85to know how to use the methods of your storage system? Read these docs,
86they span all implementations.
87
88There are a couple of implementations of these classes bundled in
89storage.py as well. The most simple of these is BasicFileStorage, which is
90also the default storage system used. As expected, this stores files
91locally on your machine.
92
93There's also a CloudFileStorage system. This provides a mapping to
9650aa39 94[OpenStack's Swift http://swift.openstack.org/] storage system (used by
a2d94b0c 95RackSpace Cloud files and etc).
96
97Between these two examples you should be able to get a pretty good idea of
98how to write your own storage systems, for storing data across your
9650aa39 99Beowulf cluster of radioactive monkey brains, whatever.
a2d94b0c 100
340100ee
E
101Writing code to store stuff
102~~~~~~~~~~~~~~~~~~~~~~~~~~~
a2d94b0c 103
104So what does coding for StorageInterface implementations actually look
105like? It's pretty simple, really. For one thing, the design is fairly
106inspired by [Django's file storage API
107https://docs.djangoproject.com/en/dev/ref/files/storage/]... with some
108differences.
109
110Basically, you access files on "file paths", which aren't exactly like
9650aa39
BS
111Unix file paths, but are close. If you wanted to store a file on a path
112like dir1/dir2/filename.jpg you'd actually write that file path like::
a2d94b0c 113
9650aa39 114 ['dir1', 'dir2', 'filename.jpg']
a2d94b0c 115
116This way we can be *sure* that each component is actually a component of
117the path that's expected... we do some filename cleaning on each component.
118
119Your StorageInterface should pass in and out "file like objects". In other
120words, they should provide .read() and .write() at minimum, and probably
121also .seek() and .close().