Changeset - 45ee73bdfa03
kallithea/bin/kallithea_config.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 

	
 
# -*- coding: utf-8 -*-
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""
 
kallithea.bin.kallithea_config
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
configuration generator for Kallithea
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Jun 18, 2013
 
:author: marcink
kallithea/bin/rebranddb.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 

	
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""
 
Script for rebranding of database to and from what Kallithea expects
 

	
 
Works on databases from v1.7.2 to v2.2.5
 
"""
 

	
 
import sys
 
from sqlalchemy import *
 
import sqlalchemy.orm
 
import sqlalchemy.ext.declarative
 
import migrate.changeset # a part of sqlalchemy-migrate which is available on pypi
kallithea/config/post_receive_tmpl.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
import os
 
import sys
 

	
 
try:
 
    import kallithea
 
    KALLITHEA_HOOK_VER = '_TMPL_'
 
    os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
 
    from kallithea.lib.hooks import handle_git_post_receive as _handler
 
except ImportError:
 
    if os.environ.get('RC_DEBUG_GIT_HOOK'):
 
        import traceback
 
        print traceback.format_exc()
 
    kallithea = None
 

	
 

	
 
def main():
 
    if kallithea is None:
 
        # exit with success if we cannot import kallithea !!
 
        # this allows simply push to this repo even without
 
        # kallithea
 
        sys.exit(0)
 

	
 
    repo_path = os.path.abspath('.')
 
    push_data = sys.stdin.readlines()
kallithea/config/pre_receive_tmpl.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
import os
 
import sys
 

	
 
try:
 
    import kallithea
 
    KALLITHEA_HOOK_VER = '_TMPL_'
 
    os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
 
    from kallithea.lib.hooks import handle_git_pre_receive as _handler
 
except ImportError:
 
    if os.environ.get('RC_DEBUG_GIT_HOOK'):
 
        import traceback
 
        print traceback.format_exc()
 
    kallithea = None
 

	
 

	
 
def main():
 
    if kallithea is None:
 
        # exit with success if we cannot import kallithea !!
 
        # this allows simply push to this repo even without
 
        # kallithea
 
        sys.exit(0)
 

	
 
    repo_path = os.path.abspath('.')
 
    push_data = sys.stdin.readlines()
kallithea/lib/dbmigrate/migrate/versioning/config.py
Show inline comments
 
#!/usr/bin/python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
from sqlalchemy.util import OrderedDict
 

	
 

	
 
__all__ = ['databases', 'operations']
 

	
 
databases = ('sqlite', 'postgres', 'mysql', 'oracle', 'mssql', 'firebird')
 

	
 
# Map operation names to function names
 
operations = OrderedDict()
 
operations['upgrade'] = 'upgrade'
 
operations['downgrade'] = 'downgrade'
kallithea/lib/dbmigrate/migrate/versioning/script/__init__.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
from kallithea.lib.dbmigrate.migrate.versioning.script.base import BaseScript
 
from kallithea.lib.dbmigrate.migrate.versioning.script.py import PythonScript
 
from kallithea.lib.dbmigrate.migrate.versioning.script.sql import SqlScript
kallithea/lib/dbmigrate/migrate/versioning/script/base.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
import logging
 

	
 
from kallithea.lib.dbmigrate.migrate import exceptions
 
from kallithea.lib.dbmigrate.migrate.versioning.config import operations
 
from kallithea.lib.dbmigrate.migrate.versioning import pathed
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
class BaseScript(pathed.Pathed):
 
    """Base class for other types of scripts.
 
    All scripts have the following properties:
 

	
 
    source (script.source())
 
      The source code of the script
 
    version (script.version())
 
      The version number of the script
 
    operations (script.operations())
 
      The operations defined by the script: upgrade(), downgrade() or both.
 
      Returns a tuple of operations.
 
      Can also check for an operation with ex. script.operation(Script.ops.up)
 
    """ # TODO: sphinxfy this and implement it correctly
 

	
kallithea/lib/dbmigrate/migrate/versioning/script/py.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
import shutil
 
import warnings
 
import logging
 
import inspect
 
from StringIO import StringIO
 

	
 
from kallithea.lib.dbmigrate import migrate
 
from kallithea.lib.dbmigrate.migrate.versioning import genmodel, schemadiff
 
from kallithea.lib.dbmigrate.migrate.versioning.config import operations
 
from kallithea.lib.dbmigrate.migrate.versioning.template import Template
 
from kallithea.lib.dbmigrate.migrate.versioning.script import base
 
from kallithea.lib.dbmigrate.migrate.versioning.util import import_path, load_model, with_engine
 
from kallithea.lib.dbmigrate.migrate.exceptions import MigrateDeprecationWarning, InvalidScriptError, ScriptError
 

	
 
log = logging.getLogger(__name__)
 
__all__ = ['PythonScript']
 

	
 

	
 
class PythonScript(base.BaseScript):
 
    """Base for Python scripts"""
 

	
 
    @classmethod
kallithea/lib/dbmigrate/migrate/versioning/script/sql.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
import logging
 
import shutil
 

	
 
from kallithea.lib.dbmigrate.migrate.versioning.script import base
 
from kallithea.lib.dbmigrate.migrate.versioning.template import Template
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
class SqlScript(base.BaseScript):
 
    """A file containing plain SQL statements."""
 

	
 
    @classmethod
 
    def create(cls, path, **opts):
 
        """Create an empty migration script at specified path
 

	
 
        :returns: :class:`SqlScript instance <migrate.versioning.script.sql.SqlScript>`"""
 
        cls.require_notfound(path)
 

	
 
        src = Template(opts.pop('templates_path', None)).get_sql_script(theme=opts.pop('templates_theme', None))
 
        shutil.copy(src, path)
 
        return cls(path)
 

	
kallithea/lib/dbmigrate/migrate/versioning/shell.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
"""The migrate command-line tool."""
 

	
 
import sys
 
import inspect
 
import logging
 
from optparse import OptionParser, BadOptionError
 

	
 
from kallithea.lib.dbmigrate.migrate import exceptions
 
from kallithea.lib.dbmigrate.migrate.versioning import api
 
from kallithea.lib.dbmigrate.migrate.versioning.config import *
 
from kallithea.lib.dbmigrate.migrate.versioning.util import asbool
 

	
 

	
 
alias = dict(
 
    s=api.script,
 
    vc=api.version_control,
 
    dbv=api.db_version,
 
    v=api.version,
 
)
 

	
 
def alias_setup():
 
    global alias
kallithea/lib/dbmigrate/migrate/versioning/template.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
import os
 
import shutil
 
import sys
 

	
 
from pkg_resources import resource_filename
 

	
 
from kallithea.lib.dbmigrate.migrate.versioning.config import *
 
from kallithea.lib.dbmigrate.migrate.versioning import pathed
 

	
 

	
 
class Collection(pathed.Pathed):
 
    """A collection of templates of a specific type"""
 
    _mask = None
 

	
 
    def get_path(self, file):
 
        return os.path.join(self.path, str(file))
 

	
 

	
 
class RepositoryCollection(Collection):
 
    _mask = '%s'
 

	
 
class ScriptCollection(Collection):
kallithea/lib/dbmigrate/migrate/versioning/templates/manage.py_tmpl
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
from migrate.versioning.shell import main
 

	
 
if __name__ == '__main__':
 
    main(%(defaults)s)
kallithea/lib/dbmigrate/migrate/versioning/templates/manage/default.py_tmpl
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
from migrate.versioning.shell import main
 

	
 
{{py:
 
_vars = locals().copy()
 
del _vars['__template_name__']
 
_vars.pop('repository_name', None)
 
defaults = ", ".join(["%s='%s'" % var for var in _vars.iteritems()])
 
}}
 

	
 
if __name__ == '__main__':
 
    main({{ defaults }})
kallithea/lib/dbmigrate/migrate/versioning/templates/manage/pylons.py_tmpl
Show inline comments
 
#!/usr/bin/python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
import sys
 

	
 
from sqlalchemy import engine_from_config
 
from paste.deploy.loadwsgi import ConfigLoader
 

	
 
from migrate.versioning.shell import main
 
from {{ locals().pop('repository_name') }}.model import migrations
 

	
 

	
 
if '-c' in sys.argv:
 
    pos = sys.argv.index('-c')
 
    conf_path = sys.argv[pos + 1]
 
    del sys.argv[pos:pos + 2]
 
else:
 
    conf_path = 'development.ini'
 

	
 
{{py:
 
_vars = locals().copy()
 
del _vars['__template_name__']
 
defaults = ", ".join(["%s='%s'" % var for var in _vars.iteritems()])
 
}}
 

	
 
conf_dict = ConfigLoader(conf_path).parser._sections['app:main']
kallithea/lib/dbmigrate/migrate/versioning/util/__init__.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 
""".. currentmodule:: migrate.versioning.util"""
 

	
 
import warnings
 
import logging
 
from decorator import decorator
 
from pkg_resources import EntryPoint
 

	
 
from sqlalchemy import create_engine
 
from sqlalchemy.engine import Engine
 
from sqlalchemy.pool import StaticPool
 

	
 
from kallithea.lib.dbmigrate.migrate import exceptions
 
from kallithea.lib.dbmigrate.migrate.versioning.util.keyedinstance import KeyedInstance
 
from kallithea.lib.dbmigrate.migrate.versioning.util.importpath import import_path
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
def load_model(dotted_name):
 
    """Import module and use module-level variable".
 

	
 
    :param dotted_name: path to model in form of string: ``some.python.module:Class``
 

	
kallithea/lib/dbmigrate/migrate/versioning/util/keyedinstance.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
class KeyedInstance(object):
 
    """A class whose instances have a unique identifier of some sort
 
    No two instances with the same unique ID should exist - if we try to create
 
    a second instance, the first should be returned.
 
    """
 

	
 
    _instances = dict()
 

	
 
    def __new__(cls, *p, **k):
 
        instances = cls._instances
 
        clskey = str(cls)
 
        if clskey not in instances:
 
            instances[clskey] = dict()
 
        instances = instances[clskey]
 

	
 
        key = cls._key(*p, **k)
 
        if key not in instances:
 
            instances[key] = super(KeyedInstance, cls).__new__(cls)
 
        return instances[key]
 

	
 
    @classmethod
 
    def _key(cls, *p, **k):
kallithea/lib/dbmigrate/migrate/versioning/version.py
Show inline comments
 
#!/usr/bin/env python
 
#!/usr/bin/env python2
 
# -*- coding: utf-8 -*-
 

	
 
import os
 
import re
 
import shutil
 
import logging
 

	
 
from kallithea.lib.dbmigrate.migrate import exceptions
 
from kallithea.lib.dbmigrate.migrate.versioning import pathed, script
 
from datetime import datetime
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 
class VerNum(object):
 
    """A version number that behaves like a string and int at the same time"""
 

	
 
    _instances = dict()
 

	
 
    def __new__(cls, value):
 
        val = str(value)
 
        if val not in cls._instances:
 
            cls._instances[val] = super(VerNum, cls).__new__(cls)
 
        ret = cls._instances[val]
0 comments (0 inline, 0 general)