Merge branch 'master' of git://gitorious.org/mediagoblin/mediagoblin

This commit is contained in:
Aditi 2013-08-04 22:01:21 +05:30
commit a857954148
8 changed files with 152 additions and 41 deletions

View File

@ -2,7 +2,7 @@
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXOPTS = -W
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build

View File

@ -1,2 +1 @@
.. _raven-setup: Set up the raven plugin
.. include:: ../../../mediagoblin/plugins/raven/README.rst

View File

@ -1,6 +1,6 @@
.. MediaGoblin Documentation
Written in 2011, 2012 by MediaGoblin contributors
Written in 2011, 2012, 2013 by MediaGoblin contributors
To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to
@ -77,7 +77,7 @@ Configure PostgreSQL
If you don't want/need postgres, skip this section.
These are the packages needed for Debian Wheezy (testing)::
These are the packages needed for Debian Wheezy (stable)::
sudo apt-get install postgresql postgresql-client python-psycopg2
@ -121,25 +121,62 @@ where the first ``mediagoblin`` is the database owner and the second
Drop Privileges for MediaGoblin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As MediaGoblin does not require special permissions or elevated
access, you should run MediaGoblin under an existing non-root user or
preferably create a dedicated user for the purpose of running
MediaGoblin. Consult your distribution's documentation on how to
create "system account" or dedicated service user. Ensure that it is
not possible to log in to your system with as this user.
MediaGoblin does not require special permissions or elevated
access to run. As such, the prefered way to run MediaGoblin is to
create a dedicated, unpriviledged system user for sole the purpose of running
MediaGoblin. Running MediaGoblin processes under an unpriviledged system user
helps to keep it more secure.
The following command (entered as root or with sudo) will create a
system account with a username of ``mediagoblin``. You may choose a different
username if you wish.::
adduser --system mediagoblin
No password will be assigned to this account, and you will not be able
to log in as this user. To switch to this account, enter either::
sudo su - mediagoblin (if you have sudo permissions)
or::
su - mediagoblin (if you have to use root permissions)
You may get a warning similar to this when entering these commands::
warning: cannot change directory to /home/mediagoblin: No such file or directory
You can disregard this warning. To return to your regular user account after
using the system account, just enter ``exit``.
.. note::
Unless otherwise noted, the remainder of this document assumes that all
operations are performed using this unpriviledged account.
.. _create-mediagoblin-directory:
Create a MediaGoblin Directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You should create a working directory for MediaGoblin. This document
assumes your local git repository will be located at
``/srv/mediagoblin.example.org/mediagoblin/`` for this documentation.
Substitute your prefer ed local deployment path as needed.
``/srv/mediagoblin.example.org/mediagoblin/``.
Substitute your prefered local deployment path as needed.
This document assumes that all operations are performed as this
user. To drop privileges to this user, run the following command::
Setting up the working directory requires that we first create the directory
with elevated priviledges, and then assign ownership of the directory
to the unpriviledged system account.
su - [mediagoblin]
To do this, enter either of the following commands, changing the defaults
to suit your particular requirements::
sudo mkdir -p /srv/mediagoblin.example.org && sudo chown -hR mediagoblin:mediagoblin /srv/mediagobin.example.org
or (as the root user)::
mkdir -p /srv/mediagoblin.example.org && chown -hR mediagoblin:mediagoblin /srv/mediagobin.example.org
Where, "``[mediagoblin]``" is the username of the system user that will
run MediaGoblin.
Install MediaGoblin and Virtualenv
----------------------------------
@ -151,11 +188,14 @@ Install MediaGoblin and Virtualenv
branch of the git repository. Eventually production deployments will
want to transition to running from more consistent releases.
Issue the following commands, to create and change the working
directory. Modify these commands to reflect your own environment::
We will now clone the MediaGoblin source code repository and setup and
configure the necessary services. Modify these commands to
suit your own environment. As a reminder, you should enter these
commands using your unpriviledged system account.
mkdir -p /srv/mediagoblin.example.org/
cd /srv/mediagoblin.example.org/
Change to the MediaGoblin directory that you just created::
cd /srv/mediagoblin.example.org
Clone the MediaGoblin repository and set up the git submodules::
@ -163,7 +203,7 @@ Clone the MediaGoblin repository and set up the git submodules::
cd mediagoblin
git submodule init && git submodule update
And set up the in-package virtualenv::
Set up the in-package virtualenv::
(virtualenv --system-site-packages . || virtualenv .) && ./bin/python setup.py develop
@ -388,4 +428,5 @@ Security Considerations
for session security. Make sure not to leak its contents anywhere.
If the contents gets leaked nevertheless, delete your file
and restart the server, so that it creates a new secret key.
All previous sessions will be invalifated then.
All previous sessions will be invalidated.

View File

@ -108,8 +108,8 @@ please note the following:
.. code-block:: ini
[plugins]
[[mediagoblin.plugins.geolocation]]
[plugins]
[[mediagoblin.plugins.geolocation]]
If you have your own theme, you may need to make some adjustments to
it as some theme related things may have changed in this release. If

View File

@ -29,7 +29,7 @@ class MigrationManager(object):
to the latest migrations, etc.
"""
def __init__(self, name, models, migration_registry, session,
def __init__(self, name, models, foundations, migration_registry, session,
printer=simple_printer):
"""
Args:
@ -40,6 +40,7 @@ class MigrationManager(object):
"""
self.name = unicode(name)
self.models = models
self.foundations = foundations
self.session = session
self.migration_registry = migration_registry
self._sorted_migrations = None
@ -140,6 +141,18 @@ class MigrationManager(object):
self.session.bind,
tables=[model.__table__ for model in self.models])
def populate_table_foundations(self):
"""
Create the table foundations (default rows) as layed out in FOUNDATIONS
in mediagoblin.db.models
"""
for Model, rows in self.foundations.items():
self.printer(u' + Laying foundations for %s table\n' %
(Model.__name__))
for parameters in rows:
new_row = Model(**parameters)
self.session.add(new_row)
def create_new_migration_record(self):
"""
Create a new migration record for this migration set
@ -202,9 +215,9 @@ class MigrationManager(object):
self.init_tables()
# auto-set at latest migration number
self.create_new_migration_record()
self.create_new_migration_record()
self.printer(u"done.\n")
self.populate_table_foundations()
self.set_current_migration()
return u'inited'

View File

@ -585,6 +585,21 @@ MODELS = [
Notification, CommentNotification, ProcessingNotification,
CommentSubscription]
"""
Foundations are the default rows that are created immediately after the tables
are initialized. Each entry to this dictionary should be in the format of:
ModelConstructorObject:List of Dictionaries
(Each Dictionary represents a row on the Table to be created, containing each
of the columns' names as a key string, and each of the columns' values as a
value)
ex. [NOTE THIS IS NOT BASED OFF OF OUR USER TABLE]
user_foundations = [{'name':u'Joanna', 'age':24},
{'name':u'Andrea', 'age':41}]
FOUNDATIONS = {User:user_foundations}
"""
FOUNDATIONS = {}
######################################################
# Special, migrations-tracking table

View File

@ -32,14 +32,15 @@ def dbupdate_parse_setup(subparser):
class DatabaseData(object):
def __init__(self, name, models, migrations):
def __init__(self, name, models, foundations, migrations):
self.name = name
self.models = models
self.foundations = foundations
self.migrations = migrations
def make_migration_manager(self, session):
return MigrationManager(
self.name, self.models, self.migrations, session)
self.name, self.models, self.foundations, self.migrations, session)
def gather_database_data(plugins):
@ -54,10 +55,11 @@ def gather_database_data(plugins):
# Add main first
from mediagoblin.db.models import MODELS as MAIN_MODELS
from mediagoblin.db.migrations import MIGRATIONS as MAIN_MIGRATIONS
from mediagoblin.db.models import FOUNDATIONS as MAIN_FOUNDATIONS
managed_dbdata.append(
DatabaseData(
u'__main__', MAIN_MODELS, MAIN_MIGRATIONS))
u'__main__', MAIN_MODELS, MAIN_FOUNDATIONS, MAIN_MIGRATIONS))
for plugin in plugins:
try:
@ -83,13 +85,26 @@ forgotten to add it? ({1})'.format(plugin, exc))
migrations = {}
except AttributeError as exc:
_log.debug('Cloud not find MIGRATIONS in {0}.migrations, have you \
_log.debug('Could not find MIGRATIONS in {0}.migrations, have you \
forgotten to add it? ({1})'.format(plugin, exc))
migrations = {}
try:
foundations = import_component('{0}.models:FOUNDATIONS'.format(plugin))
except ImportError as exc:
_log.debug('No foundations found for {0}: {1}'.format(
plugin,
exc))
foundations = {}
except AttributeError as exc:
_log.debug('Could not find FOUNDATIONS in {0}.models, have you \
forgotten to add it? ({1})'.format(plugin, exc))
foundations = {}
if models:
managed_dbdata.append(
DatabaseData(plugin, models, migrations))
DatabaseData(plugin, models, foundations, migrations))
return managed_dbdata
@ -111,7 +126,7 @@ def run_dbupdate(app_config, global_config):
def run_all_migrations(db, app_config, global_config):
"""
Initializes or migrates a database that already has a
Initializes or migrates a database that already has a
connection setup and also initializes or migrates all
extensions based on the config files.

View File

@ -58,6 +58,10 @@ class Level1(Base1):
SET1_MODELS = [Creature1, Level1]
FOUNDATIONS = {Creature1:[{'name':u'goblin','num_legs':2,'is_demon':False},
{'name':u'cerberus','num_legs':4,'is_demon':True}]
}
SET1_MIGRATIONS = {}
#######################################################
@ -542,7 +546,6 @@ def _insert_migration3_objects(session):
session.commit()
def create_test_engine():
from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:', echo=False)
@ -572,7 +575,7 @@ def test_set1_to_set3():
printer = CollectingPrinter()
migration_manager = MigrationManager(
u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(),
u'__main__', SET1_MODELS, FOUNDATIONS, SET1_MIGRATIONS, Session(),
printer)
# Check latest migration and database current migration
@ -585,11 +588,13 @@ def test_set1_to_set3():
assert result == u'inited'
# Check output
assert printer.combined_string == (
"-> Initializing main mediagoblin tables... done.\n")
"-> Initializing main mediagoblin tables... done.\n" + \
" + Laying foundations for Creature1 table\n" )
# Check version in database
assert migration_manager.latest_migration == 0
assert migration_manager.database_current_migration == 0
# Install the initial set
# -----------------------
@ -597,8 +602,8 @@ def test_set1_to_set3():
# Try to "re-migrate" with same manager settings... nothing should happen
migration_manager = MigrationManager(
u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(),
printer)
u'__main__', SET1_MODELS, FOUNDATIONS, SET1_MIGRATIONS,
Session(), printer)
assert migration_manager.init_or_migrate() == None
# Check version in database
@ -639,6 +644,20 @@ def test_set1_to_set3():
# Now check to see if stuff seems to be in there.
session = Session()
# Check the creation of the foundation rows on the creature table
creature = session.query(Creature1).filter_by(
name=u'goblin').one()
assert creature.num_legs == 2
assert creature.is_demon == False
creature = session.query(Creature1).filter_by(
name=u'cerberus').one()
assert creature.num_legs == 4
assert creature.is_demon == True
# Check the creation of the inserted rows on the creature and levels tables
creature = session.query(Creature1).filter_by(
name=u'centipede').one()
assert creature.num_legs == 100
@ -679,7 +698,7 @@ def test_set1_to_set3():
# isn't said to be updated yet
printer = CollectingPrinter()
migration_manager = MigrationManager(
u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
u'__main__', SET3_MODELS, FOUNDATIONS, SET3_MIGRATIONS, Session(),
printer)
assert migration_manager.latest_migration == 8
@ -706,7 +725,7 @@ def test_set1_to_set3():
# Make sure version matches expected
migration_manager = MigrationManager(
u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
u'__main__', SET3_MODELS, FOUNDATIONS, SET3_MIGRATIONS, Session(),
printer)
assert migration_manager.latest_migration == 8
assert migration_manager.database_current_migration == 8
@ -772,6 +791,15 @@ def test_set1_to_set3():
# Now check to see if stuff seems to be in there.
session = Session()
# Start with making sure that the foundations did not run again
assert session.query(Creature3).filter_by(
name=u'goblin').count() == 1
assert session.query(Creature3).filter_by(
name=u'cerberus').count() == 1
# Then make sure the models have been migrated correctly
creature = session.query(Creature3).filter_by(
name=u'centipede').one()
assert creature.num_limbs == 100.0