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