Zine

open source content publishing system


Changeset 1327:132fbdaa8899


Ignore:
Timestamp:
01/10/10 15:58:34 (2 years ago)
Author:
Georg Brandl <georg@…>
Branch:
default
Parents:
1280:e7db1dd838ba (diff), 1326:4b0d1121e32c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with zine-migrations

Files:
1 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • external-plugins/eric_the_fish/__init__.py

    r1319 r1327  
    88    registration system. 
    99 
    10     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     10    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    1111    :license: BSD, see LICENSE for more details. 
    1212""" 
  • external-plugins/eric_the_fish/__init__.py

    r1279 r1327  
    4545from zine.privileges import BLOG_ADMIN 
    4646 
    47 # the last thing is importing the FORTUNES list from the fortunes.py file 
    48 # from the same folder. It's just a long list with quotes. 
    49 from zine.plugins.eric_the_fish.fortunes import FORTUNES 
     47# import Zine's database related stuff 
     48from zine.database import db 
     49 
     50# the last thing is importing the Fortunes database mapped object. 
     51from zine.plugins.eric_the_fish.database import Fortune 
    5052 
    5153# because we have an admin panel page we need to store the templates 
     
    8991    for link_id, url, title, children in navigation_bar: 
    9092        if link_id == 'options': 
    91             children.insert(-3, ('eric_the_fish', url_for('eric_the_fish/config'), 
     93            children.insert(-3, ('eric_the_fish', 
     94                                 url_for('eric_the_fish/config'), 
    9295                                 _('Eric The Fish'))) 
    9396 
     
    116119 
    117120def get_fortune(req): 
    118     """The servicepoint function. Just return one fortune from the list.""" 
    119     return {'fortune': choice(FORTUNES)} 
     121    """The servicepoint function. Just return one fortune from the database.""" 
     122    fortune_ids = db.session.query(Fortune.id).all() 
     123    return {'fortune': db.session.query(Fortune).get(choice(fortune_ids)).text} 
    120124 
    121125 
    122126def setup(app, plugin): 
    123     """This function is called by Zine in the application initialization 
     127    """This function is called by Zine in the application initialisation 
    124128    phase. Here we connect to the events and register our template paths, 
    125129    url rules, views etc. 
    126130    """ 
     131 
     132    # we need to register eric's database upgrades repository; 
     133    # Basically it should be a folder which itself has another child folder 
     134    # named "versions" where the upgrade script(s) should reside. 
     135    # In "Eric the fish" case we pass the plugin's folder which has that child 
     136    # folder called "versions" 
     137    app.register_upgrade_repository(plugin, dirname(__file__)) 
    127138 
    128139    # we want our fish to appear in the admin panel, so hook into the 
  • external-plugins/eric_the_fish/database.py

    r1316 r1327  
    66    Database tables and objects for the "Annoying fish for the admin panel". 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
  • scripts/_install-posix.py

    r1323 r1327  
    66    This script is invoked by the makefile to install Zine on a POSIX system. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
  • scripts/_install-posix.py

    r1279 r1327  
    1818 
    1919 
    20 PACKAGES = '_dynamic _ext importers utils views websetup docs'.split() 
     20PACKAGES = '_dynamic _ext importers upgrades utils views websetup docs'.split() 
    2121SCRIPTS = 'create-apache-config server shell'.split() 
    2222DESTDIR = os.environ.get('DESTDIR') 
  • scripts/_make-setup-virtualenv.py

    r1324 r1327  
    66    Execute this file to regenerate the `setup-virtualenv` script. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
  • scripts/_make-setup-virtualenv.py

    r1279 r1327  
    2525    'SQLAlchemy==dev', 
    2626    'pytz', 
    27     'Babel>=0.9.4' 
     27    'Babel>=0.9.4', 
     28    'sqlalchemy-migrate==0.5.4' 
    2829] 
    2930 
  • scripts/manage-database

    r1314 r1327  
    77    Database maintenance script. 
    88 
    9     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     9    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    1010    :license: BSD, see LICENSE for more details. 
    1111""" 
  • zine/_core.py

    r1325 r1327  
    66    Internal core module that survives reloads. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
     
    4040    after `timeout` seconds a `RuntimeError` is raised. 
    4141    """ 
    42     global _application 
     42    global _application, _setup_failed 
    4343    _setup_failed = False 
    4444    _setup_lock.acquire() 
     
    8484def _unload_zine(): 
    8585    """Unload all zine libraries.""" 
    86     global _application 
     86    global _application, _setup_failed 
    8787    import sys 
    8888 
     
    111111                    for key, value in module.__dict__.iteritems(): 
    112112                        setattr(module, key, None) 
     113                    # clear references 
    113114                    value = None 
    114115                except: 
  • zine/_core.py

    r1279 r1327  
    2727    instance folder. 
    2828    """ 
     29 
     30class InstanceUpgradeRequired(RuntimeError): 
     31    """Zine requires a database upgrade""" 
     32 
     33class MissingDependency(RuntimeError): 
     34    """Zine requires an external library which is not installed.""" 
    2935 
    3036 
     
    6066        try: 
    6167            app.__init__(instance_folder) 
     68            app.upgrade_required 
     69        except InstanceUpgradeRequired: 
     70            from zine.upgrades.webapp import WebUpgrades 
     71            _application = app = WebUpgrades(app) 
    6272        except: 
    6373            # if an exception happened, tear down the application 
     
    92102                    if key not in preserve and not key.startswith('__'): 
    93103                        module.__dict__.pop(key, None) 
    94             elif name.startswith('zine.') and name != 'zine._core': 
     104            elif name.startswith('zine.') and name not in ( 
     105                                'zine._core', 'zine.upgrades', 
     106                                'zine.upgrades.customisation'): 
    95107                # get rid of the module 
    96108                sys.modules.pop(name, None) 
  • zine/application.py

    r1326 r1327  
    88 
    99 
    10     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     10    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    1111    :license: BSD, see LICENSE for more details. 
    1212""" 
     
    1414from os import path, remove, makedirs, walk, environ 
    1515from time import time 
    16 from itertools import izip 
    17 from datetime import datetime, timedelta 
    18 from urlparse import urlparse, urljoin 
     16from urlparse import urlparse 
    1917from collections import deque 
    2018from inspect import getdoc 
     
    13201318            result = callback(request) 
    13211319            if result is not None: 
    1322                 return result(environ, start_response) 
     1320                return result 
    13231321 
    13241322        # normal request dispatching 
     
    14941492from zine import i18n 
    14951493from zine.utils import log 
     1494from zine.utils.net import NetException 
    14961495from zine.utils.http import make_external_url 
  • zine/application.py

    r1279 r1327  
    636636                            self.__class__.__name__) 
    637637        self.instance_folder = path.abspath(instance_folder) 
     638        self.upgrade_lockfile = path.join(instance_folder, 
     639                                          '.upgrade_in_progress') 
    638640 
    639641        # create the event manager, this is the first thing we have to 
     
    832834            self.list_parsers() 
    833835 
     836        # Register Zine's upgrade repository 
     837        from zine.upgrades import REPOSITORY_PATH 
     838        self.register_upgrade_repository('Zine', REPOSITORY_PATH) 
     839        # Allow plugins to register their upgrade's repositories 
     840        emit_event('register-upgrade-repository') 
     841 
    834842        self.initialized = True 
    835843 
    836844        #! called after the application and all plugins are initialized 
    837845        emit_event('application-setup-done') 
     846 
     847    def register_upgrade_repository(self, repo_id, repo_path): 
     848        """This function is responsible for adding upgrade repositories to the 
     849        database. 
     850        """ 
     851        from zine.models import SchemaVersion 
     852        from zine.pluginsystem import Plugin 
     853        from zine.upgrades.customisation import Repository 
     854        if isinstance(repo_id, Plugin): 
     855            repo_id = repo_id.metadata.get('name') 
     856        repo_path = path.abspath(repo_path) 
     857        try: 
     858            sv = SchemaVersion.query.filter_by(repository_id=repo_id).first() 
     859            if not sv: 
     860                db.session.add(SchemaVersion(Repository(repo_path, repo_id))) 
     861                db.session.commit() 
     862        except (SQLAlchemyError, AttributeError): 
     863            # The schema_versions table does not yet exist. Let's create it 
     864            db.session.rollback() 
     865            from zine.database import metadata, schema_versions 
     866            metadata.bind = self.database_engine 
     867            if not schema_versions.exists(): 
     868                schema_versions.create(self.database_engine) 
     869            db.session.add(SchemaVersion(Repository(repo_path, repo_id))) 
     870            db.session.commit() 
     871 
     872 
     873    @property 
     874    def upgrade_required(self): 
     875        from zine.models import SchemaVersion 
     876        from zine.upgrades.customisation import Repository 
     877 
     878        for sv in SchemaVersion.query.all(): 
     879            repository = Repository(sv.repository_path, sv.repository_id) 
     880            try: 
     881                self.repository_has_upgrade(repository, sv) 
     882            except _core.InstanceUpgradeRequired: 
     883                # Set Zine in maintenance mode 
     884                cfg = self.cfg.edit() 
     885                cfg['maintenance_mode'] = True 
     886                cfg.commit() 
     887                raise _core.InstanceUpgradeRequired() 
     888 
     889        # We got here, let's check for a bad upgrade lockfile left behind 
     890        if path.isfile(self.upgrade_lockfile): 
     891            remove(self.upgrade_lockfile) 
     892 
     893    def repository_has_upgrade(self, repository, schema_version): 
     894        try: 
     895            if schema_version.version < repository.latest: 
     896                raise _core.InstanceUpgradeRequired() 
     897        except (SQLAlchemyError, AttributeError): 
     898            self.log.error('WE EVEN GOT HERE??? schema_versions table does not ' 
     899                           'yet exist at this stage?') 
     900            # The schema_versions table does not yet exist. Let's create it 
     901            db.session.rollback() 
     902            from zine.database import metadata, schema_versions 
     903            metadata.bind = self.database_engine 
     904            if not schema_versions.exists(): 
     905                schema_versions.create(self.database_engine) 
     906            db.session.add(SchemaVersion(Repository(repo_path))) 
     907            db.session.commit() 
     908            raise _core.InstanceUpgradeRequired() 
    838909 
    839910    @property 
     
    12111282        from zine.notifications import send_notification_template, ZINE_ERROR 
    12121283        request_buffer = StringIO() 
    1213         pprint(request.__dict__, request_buffer) 
    12141284        request_buffer.seek(0) 
    12151285        send_notification_template( 
  • zine/database.py

    r1314 r1327  
    1111 
    1212 
    13     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     13    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    1414    :license: BSD, see LICENSE for more details. 
    1515""" 
     
    1818import sys 
    1919import time 
    20 import urlparse 
    2120from os import path 
    22 from datetime import datetime, timedelta 
    2321from types import ModuleType 
    2422from copy import deepcopy 
     
    3028from sqlalchemy.exc import ArgumentError 
    3129from sqlalchemy.ext.declarative import declarative_base 
    32 from sqlalchemy.util import to_list 
    3330from sqlalchemy.engine.url import make_url, URL 
    34 from sqlalchemy.types import MutableType, TypeDecorator 
     31from sqlalchemy.types import TypeDecorator 
    3532from sqlalchemy.ext.associationproxy import association_proxy 
    3633 
     
    159156        if value is None: 
    160157            return 
    161         from zine.utils.zeml import dump_parser_data, RootElement 
     158        from zine.utils.zeml import dump_parser_data 
    162159        return dump_parser_data(value) 
    163160 
  • zine/database.py

    r1279 r1327  
    248248metadata = db.MetaData() 
    249249 
     250schema_versions = db.Table('schema_versions', metadata, 
     251    db.Column('repository_id', db.String(255), primary_key=True), 
     252    db.Column('repository_path', db.Text), 
     253    db.Column('version', db.Integer) 
     254) 
    250255 
    251256users = db.Table('users', metadata, 
  • zine/models.py

    r1314 r1327  
    66    The core models and query helper functions. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
     
    2525from zine.utils.crypto import gen_pwhash, check_pwhash 
    2626from zine.utils.http import make_external_url 
    27 from zine.privileges import Privilege, _Privilege, privilege_attribute, \ 
     27from zine.privileges import _Privilege, privilege_attribute, \ 
    2828     add_admin_privilege, MODERATE_COMMENTS, ENTER_ADMIN_PANEL, BLOG_ADMIN, \ 
    2929     VIEW_DRAFTS, VIEW_PROTECTED, MODERATE_OWN_ENTRIES, MODERATE_OWN_PAGES 
     
    575575    def set_auto_slug(self): 
    576576        """Generate a slug for this post.""" 
    577         cfg = get_application().cfg 
     577        #cfg = get_application().cfg 
    578578        slug = gen_slug(self.title) 
    579579        if not slug: 
     
    10831083        if user is None: 
    10841084            user = request.user 
    1085         if user.has_privilege(MODERATE_OWN_ENTRIES | MODERATE_OWN_PAGES): 
    1086             # Comment belongs to a post the user is the author. It's visible. 
    1087             return self.post.author is user 
     1085        if self.post.author is user and \ 
     1086           user.has_privilege(MODERATE_OWN_ENTRIES | MODERATE_OWN_PAGES): 
     1087            return True 
    10881088        elif user.has_privilege(MODERATE_COMMENTS): 
    10891089            # User is able to manage comments. It's visible. 
  • zine/models.py

    r1279 r1327  
    1818     post_categories, post_tags, tags, comments, groups, group_users, \ 
    1919     privileges, user_privileges, group_privileges, texts, \ 
    20      notification_subscriptions, db 
     20     notification_subscriptions, schema_versions, db 
    2121from zine.utils import zeml 
    2222from zine.utils.text import gen_slug, gen_timestamped_slug, build_tag_uri, \ 
     
    177177    def authors(self): 
    178178        return self.filter_by(is_author=True) 
     179 
     180 
     181class SchemaVersion(object): 
     182    """Represents a database schema version.""" 
     183 
     184    query = db.query_property(db.Query) 
     185 
     186    def __init__(self, repos, version=0): 
     187        self.repository_id = repos.config.get('repository_id') 
     188        self.repository_path = repos.path 
     189        self.version = version 
    179190 
    180191 
     
    12561267 
    12571268# connect the tables. 
     1269db.mapper(SchemaVersion, schema_versions) 
    12581270db.mapper(User, users, properties={ 
    12591271    'id':               users.c.user_id, 
  • zine/upgrades/__init__.py

    r1325 r1327  
    66    database. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
  • zine/upgrades/customisation.py

    r1318 r1327  
    66    to do our job. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
  • zine/upgrades/versions/__init__.py

    r1318 r1327  
    66    to maintain the database schema changes. 
    77 
    8     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    99    :license: BSD, see LICENSE for more details. 
    1010""" 
  • zine/upgrades/webapp.py

    r1318 r1327  
    77    for upgrading Zine to the latest schema changes. 
    88 
    9     :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     9    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    1010    :license: BSD, see LICENSE for more details. 
    1111""" 
Note: See TracChangeset for help on using the changeset viewer.