migrate.versioning.repository PEP-8 clean, added to api.rst
This commit is contained in:
parent
5289c4df3b
commit
2a8860478c
@ -111,3 +111,10 @@ Module :mod:`pathed <migrate.versioning.pathed>`
|
||||
.. automodule:: migrate.versioning.pathed
|
||||
:members:
|
||||
:synopsis: File/Directory handling class
|
||||
|
||||
Module :mod:`repository <migrate.versioning.repository>`
|
||||
--------------------------------------------------------
|
||||
|
||||
.. automodule:: migrate.versioning.repository
|
||||
:members:
|
||||
:synopsis: SQLAlchemy migrate repository management
|
||||
|
@ -1,5 +1,9 @@
|
||||
"""
|
||||
SQLAlchemy migrate repository management.
|
||||
"""
|
||||
from pkg_resources import resource_string, resource_filename
|
||||
import os,shutil
|
||||
import os
|
||||
import shutil
|
||||
import string
|
||||
from migrate.versioning.base import *
|
||||
from migrate.versioning.template import template
|
||||
@ -7,13 +11,19 @@ from migrate.versioning import exceptions,script,version,pathed,cfgparse
|
||||
|
||||
|
||||
class Changeset(dict):
|
||||
"""A collection of changes to be applied to a database
|
||||
Changesets are bound to a repository and manage a set of logsql scripts from
|
||||
that repository.
|
||||
Behaves like a dict, for the most part. Keys are ordered based on start/end.
|
||||
"""A collection of changes to be applied to a database.
|
||||
|
||||
Changesets are bound to a repository and manage a set of logsql
|
||||
scripts from that repository.
|
||||
|
||||
Behaves like a dict, for the most part. Keys are ordered based on
|
||||
start/end.
|
||||
"""
|
||||
|
||||
def __init__(self, start, *changes, **k):
|
||||
"""Give a start version; step must be explicitly stated"""
|
||||
"""
|
||||
Give a start version; step must be explicitly stated.
|
||||
"""
|
||||
self.step = k.pop('step', 1)
|
||||
self.start = version.VerNum(start)
|
||||
self.end = self.start
|
||||
@ -24,13 +34,17 @@ class Changeset(dict):
|
||||
return iter(self.items())
|
||||
|
||||
def keys(self):
|
||||
"""In a series of upgrades x -> y, keys are version x. Sorted."""
|
||||
"""
|
||||
In a series of upgrades x -> y, keys are version x. Sorted.
|
||||
"""
|
||||
ret = super(Changeset, self).keys()
|
||||
# Reverse order if downgrading
|
||||
ret.sort(reverse=(self.step < 1))
|
||||
return ret
|
||||
|
||||
def values(self):
|
||||
return [self[k] for k in self.keys()]
|
||||
|
||||
def items(self):
|
||||
return zip(self.keys(), self.values())
|
||||
|
||||
@ -56,14 +70,17 @@ class Repository(pathed.Pathed):
|
||||
self.verify(path)
|
||||
super(Repository, self).__init__(path)
|
||||
self.config=cfgparse.Config(os.path.join(self.path, self._config))
|
||||
self.versions=version.Collection(os.path.join(self.path,self._versions))
|
||||
self.versions=version.Collection(os.path.join(self.path,
|
||||
self._versions))
|
||||
log.info('Repository %s loaded successfully' % path)
|
||||
log.debug('Config: %r' % self.config.to_dict())
|
||||
|
||||
@classmethod
|
||||
def verify(cls, path):
|
||||
"""Ensure the target path is a valid repository
|
||||
Throws InvalidRepositoryError if not
|
||||
"""
|
||||
Ensure the target path is a valid repository.
|
||||
|
||||
:raises: :exc:`InvalidRepositoryError` if not valid
|
||||
"""
|
||||
# Ensure the existance of required files
|
||||
try:
|
||||
@ -75,13 +92,14 @@ class Repository(pathed.Pathed):
|
||||
|
||||
@classmethod
|
||||
def prepare_config(cls, pkg, rsrc, name, **opts):
|
||||
"""Prepare a project configuration file for a new project"""
|
||||
"""
|
||||
Prepare a project configuration file for a new project.
|
||||
"""
|
||||
# Prepare opts
|
||||
defaults=dict(
|
||||
version_table='migrate_version',
|
||||
repository_id=name,
|
||||
required_dbs=[],
|
||||
)
|
||||
required_dbs=[], )
|
||||
for key, val in defaults.iteritems():
|
||||
if (key not in opts) or (opts[key] is None):
|
||||
opts[key]=val
|
||||
@ -120,7 +138,8 @@ class Repository(pathed.Pathed):
|
||||
self.versions.createNewSQLVersion(database, **k)
|
||||
|
||||
latest=property(lambda self: self.versions.latest)
|
||||
version_table=property(lambda self: self.config.get('db_settings','version_table'))
|
||||
version_table=property(lambda self: self.config.get('db_settings',
|
||||
'version_table'))
|
||||
id=property(lambda self: self.config.get('db_settings', 'repository_id'))
|
||||
|
||||
def version(self, *p, **k):
|
||||
@ -132,7 +151,8 @@ class Repository(pathed.Pathed):
|
||||
version.Collection.clear()
|
||||
|
||||
def changeset(self, database, start, end=None):
|
||||
"""Create a changeset to migrate this dbms from ver. start to end/latest
|
||||
"""
|
||||
Create a changeset to migrate this dbms from ver. start to end/latest.
|
||||
"""
|
||||
start = version.VerNum(start)
|
||||
if end is None:
|
||||
@ -148,7 +168,6 @@ class Repository(pathed.Pathed):
|
||||
range_mod = 0
|
||||
op = 'downgrade'
|
||||
versions = range(start+range_mod, end+range_mod, step)
|
||||
#changes = [self.version(v).script(database,op).log for v in versions]
|
||||
changes = [self.version(v).script(database, op) for v in versions]
|
||||
ret = Changeset(start, step=step, *changes)
|
||||
return ret
|
||||
|
Loading…
x
Reference in New Issue
Block a user