some more PEP8 love all over the files
This commit is contained in:
parent
5aaaa05fcc
commit
d5c7fedbd4
@ -14,11 +14,13 @@
|
||||
|
||||
import sys
|
||||
import inspect
|
||||
from sqlalchemy import create_engine
|
||||
from migrate.versioning import exceptions, repository, schema, version
|
||||
import script as script_ #command name conflict
|
||||
|
||||
__all__=[
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
from migrate.versioning import (exceptions, repository, schema, version,
|
||||
script as script_) # command name conflict
|
||||
|
||||
__all__ = [
|
||||
'help',
|
||||
'create',
|
||||
'script',
|
||||
@ -73,7 +75,7 @@ def create(repository, name, **opts):
|
||||
databases.
|
||||
"""
|
||||
try:
|
||||
rep=cls_repository.create(repository, name, **opts)
|
||||
rep = cls_repository.create(repository, name, **opts)
|
||||
except exceptions.PathFoundError, e:
|
||||
raise exceptions.KnownError("The path %s already exists" % e.args[0])
|
||||
|
||||
@ -93,7 +95,7 @@ def script(description, repository=None, **opts):
|
||||
repos = cls_repository(repository)
|
||||
repos.create_script(description, **opts)
|
||||
except exceptions.PathFoundError, e:
|
||||
raise exceptions.KnownError("The path %s already exists"%e.args[0])
|
||||
raise exceptions.KnownError("The path %s already exists" % e.args[0])
|
||||
|
||||
|
||||
def script_sql(database, repository=None, **opts):
|
||||
@ -113,7 +115,7 @@ def script_sql(database, repository=None, **opts):
|
||||
repos = cls_repository(repository)
|
||||
repos.create_script_sql(database, **opts)
|
||||
except exceptions.PathFoundError, e:
|
||||
raise exceptions.KnownError("The path %s already exists"%e.args[0])
|
||||
raise exceptions.KnownError("The path %s already exists" % e.args[0])
|
||||
|
||||
|
||||
def test(repository, url=None, **opts):
|
||||
@ -124,8 +126,8 @@ def test(repository, url=None, **opts):
|
||||
bad state. You should therefore better run the test on a copy of
|
||||
your database.
|
||||
"""
|
||||
engine=create_engine(url)
|
||||
repos=cls_repository(repository)
|
||||
engine = create_engine(url)
|
||||
repos = cls_repository(repository)
|
||||
script = repos.version(None).script()
|
||||
# Upgrade
|
||||
print "Upgrading...",
|
||||
@ -151,7 +153,7 @@ def version(repository, **opts):
|
||||
|
||||
Display the latest version available in a repository.
|
||||
"""
|
||||
repos=cls_repository(repository)
|
||||
repos = cls_repository(repository)
|
||||
return repos.latest
|
||||
|
||||
|
||||
@ -164,12 +166,12 @@ def source(version, dest=None, repository=None, **opts):
|
||||
"""
|
||||
if repository is None:
|
||||
raise exceptions.UsageError("A repository must be specified")
|
||||
repos=cls_repository(repository)
|
||||
ret=repos.version(version).script().source()
|
||||
repos = cls_repository(repository)
|
||||
ret = repos.version(version).script().source()
|
||||
if dest is not None:
|
||||
dest=open(dest, 'w')
|
||||
dest = open(dest, 'w')
|
||||
dest.write(ret)
|
||||
ret=None
|
||||
ret = None
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -2,9 +2,10 @@
|
||||
Configuration parser module.
|
||||
"""
|
||||
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from migrate.versioning.base import *
|
||||
from migrate.versioning import pathed
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
|
||||
class Parser(ConfigParser):
|
||||
|
@ -56,11 +56,12 @@ class LogSqlError(Error):
|
||||
self.entry = entry
|
||||
|
||||
def __str__(self):
|
||||
ret = "SQL error in statement: \n%s\n"%(str(self.entry))
|
||||
ret += "Traceback from change script:\n"
|
||||
ret += ''.join(traceback.format_list(self.entry.traceback))
|
||||
ret += str(self.sqlerror)
|
||||
return ret
|
||||
"""SQL error in statement:
|
||||
%s
|
||||
Traceback from change script:
|
||||
%s%s""" % (self.entry,
|
||||
''.join(traceback.format_list(self.entry.traceback)),
|
||||
self.sqlerror)
|
||||
|
||||
|
||||
class PathError(Error):
|
||||
|
@ -7,6 +7,7 @@
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
import migrate
|
||||
import sqlalchemy
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
"""
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -2,11 +2,12 @@
|
||||
A path/directory class.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from migrate.versioning.base import *
|
||||
from migrate.versioning.util import KeyedInstance
|
||||
from migrate.versioning import exceptions
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
class Pathed(KeyedInstance):
|
||||
@ -16,21 +17,21 @@ class Pathed(KeyedInstance):
|
||||
Only one instance of this class may exist for a particular file;
|
||||
__new__ will return an existing instance if possible
|
||||
"""
|
||||
parent=None
|
||||
parent = None
|
||||
|
||||
@classmethod
|
||||
def _key(cls, path):
|
||||
return str(path)
|
||||
|
||||
def __init__(self, path):
|
||||
self.path=path
|
||||
self.path = path
|
||||
if self.__class__.parent is not None:
|
||||
self._init_parent(path)
|
||||
|
||||
def _init_parent(self, path):
|
||||
"""Try to initialize this object's parent, if it has one"""
|
||||
parent_path=self.__class__._parent_path(path)
|
||||
self.parent=self.__class__.parent(parent_path)
|
||||
parent_path = self.__class__._parent_path(path)
|
||||
self.parent = self.__class__.parent(parent_path)
|
||||
log.info("Getting parent %r:%r" % (self.__class__.parent, parent_path))
|
||||
self.parent._init_child(path, self)
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
"""
|
||||
SQLAlchemy migrate repository management.
|
||||
"""
|
||||
from pkg_resources import resource_string, resource_filename
|
||||
import os
|
||||
import shutil
|
||||
import string
|
||||
from migrate.versioning.base import *
|
||||
from migrate.versioning.template import template
|
||||
from pkg_resources import resource_string, resource_filename
|
||||
|
||||
from migrate.versioning import exceptions, script, version, pathed, cfgparse
|
||||
from migrate.versioning.template import template
|
||||
from migrate.versioning.base import *
|
||||
|
||||
|
||||
class Changeset(dict):
|
||||
@ -61,9 +62,9 @@ class Changeset(dict):
|
||||
class Repository(pathed.Pathed):
|
||||
"""A project's change script repository"""
|
||||
# Configuration file, inside repository
|
||||
_config='migrate.cfg'
|
||||
_config = 'migrate.cfg'
|
||||
# Version information, inside repository
|
||||
_versions='versions'
|
||||
_versions = 'versions'
|
||||
|
||||
def __init__(self, path):
|
||||
log.info('Loading repository %s...' % path)
|
||||
@ -177,7 +178,7 @@ def manage(file, **opts):
|
||||
"""Create a project management script"""
|
||||
pkg, rsrc = template.manage(as_pkg=True)
|
||||
tmpl = resource_string(pkg, rsrc)
|
||||
vars = ",".join(["%s='%s'"%vars for vars in opts.iteritems()])
|
||||
vars = ",".join(["%s='%s'" % vars for vars in opts.iteritems()])
|
||||
result = tmpl%dict(defaults=vars)
|
||||
|
||||
fd = open(file, 'w')
|
||||
|
@ -1,21 +1,22 @@
|
||||
"""
|
||||
Database schema version management.
|
||||
"""
|
||||
from sqlalchemy import Table, Column, MetaData, String, Text, Integer, \
|
||||
create_engine
|
||||
from sqlalchemy import (Table, Column, MetaData, String, Text, Integer,
|
||||
create_engine)
|
||||
from sqlalchemy.sql import and_
|
||||
from sqlalchemy import exceptions as sa_exceptions
|
||||
|
||||
from migrate.versioning import exceptions, genmodel, schemadiff
|
||||
from migrate.versioning.repository import Repository
|
||||
from migrate.versioning.util import loadModel
|
||||
from migrate.versioning.version import VerNum
|
||||
from migrate.versioning import exceptions, genmodel, schemadiff
|
||||
|
||||
|
||||
class ControlledSchema(object):
|
||||
"""A database under version control"""
|
||||
|
||||
def __init__(self, engine, repository):
|
||||
if type(repository) is str:
|
||||
if isinstance(repository, str):
|
||||
repository=Repository(repository)
|
||||
self.engine = engine
|
||||
self.repository = repository
|
||||
@ -76,7 +77,7 @@ class ControlledSchema(object):
|
||||
:return: valid version number
|
||||
"""
|
||||
if version is None:
|
||||
version=0
|
||||
version = 0
|
||||
try:
|
||||
version = VerNum(version) # raises valueerror
|
||||
if version < 0 or version > repository.latest:
|
||||
|
@ -14,6 +14,7 @@ alias = dict(
|
||||
dbv=api.db_version,
|
||||
v=api.version,
|
||||
)
|
||||
|
||||
def alias_setup():
|
||||
global alias
|
||||
for key,val in alias.iteritems():
|
||||
@ -25,6 +26,7 @@ class PassiveOptionParser(OptionParser):
|
||||
|
||||
def _process_args(self, largs, rargs, values):
|
||||
"""little hack to support all --some_option=value parameters"""
|
||||
|
||||
while rargs:
|
||||
arg = rargs[0]
|
||||
if arg == "--":
|
||||
@ -50,6 +52,7 @@ class PassiveOptionParser(OptionParser):
|
||||
|
||||
def main(argv=None, **kwargs):
|
||||
"""kwargs are default options that can be overriden with passing --some_option to cmdline"""
|
||||
|
||||
argv = argv or list(sys.argv[1:])
|
||||
commands = list(api.__all__)
|
||||
commands.sort()
|
||||
|
Loading…
x
Reference in New Issue
Block a user