From: Mike Bayer Date: Thu, 22 Apr 2010 22:46:42 +0000 (-0400) Subject: work in progress X-Git-Tag: rel_0_1_0~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0a2b731324a17c576fd6bb9eb08aaf738c4ad9b;p=thirdparty%2Fsqlalchemy%2Falembic.git work in progress --- diff --git a/alembic/command.py b/alembic/command.py index 9cf27e03..e8fa4d37 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -1,4 +1,23 @@ -def main(options, command): +from alembic.script import Script + +def main(options, file_config, command): raise NotImplementedError("yeah yeah nothing here yet") +def init(options, file_config): + """Initialize a new scripts directory.""" + + script = Script(options, file_config) + script.init() + +def upgrade(options, file_config): + """Upgrade to the latest version.""" + + script = Script(options, file_config) + +def revert(options, file_config): + """Revert to a specific previous version.""" + + script = Script(options, file_config) + + diff --git a/alembic/ddl/__init__.py b/alembic/ddl/__init__.py new file mode 100644 index 00000000..232d538b --- /dev/null +++ b/alembic/ddl/__init__.py @@ -0,0 +1 @@ +import base, postgresql \ No newline at end of file diff --git a/alembic/ddl/base.py b/alembic/ddl/base.py new file mode 100644 index 00000000..e69de29b diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py new file mode 100644 index 00000000..e69de29b diff --git a/alembic/options.py b/alembic/options.py new file mode 100644 index 00000000..0b1a388c --- /dev/null +++ b/alembic/options.py @@ -0,0 +1,18 @@ + + +class Options(object): + def __init__(self, options): + self.options = options + self.file_config = ConfigParser.ConfigParser() + # TODO: cfg file can come from options + self.file_config.read(['alembic.cfg']) + + def get_main_option(self, name, default=None): + if getattr(self.options, name): + return getattr(self.options, name) + elif self.file_config.get('alembic', name): + return self.file_config.get('alembic', name) + else: + return default + + \ No newline at end of file diff --git a/alembic/script.py b/alembic/script.py new file mode 100644 index 00000000..4a534ea4 --- /dev/null +++ b/alembic/script.py @@ -0,0 +1,27 @@ +import os + +class Script(object): + def __init__(self, dir): + self.dir = dir + + @classmethod + def from_options(cls, options, file_config): + if options.dir: + d = options.dir + elif file_config.get('alembic', 'dir'): + d = file_config.get('alembic', 'dir') + else: + d = os.path.join(os.path.curdir, "alembic_scripts") + return Script(d) + + + def init(self): + if not os.access(self.dir, os.F_OK): + os.makedirs(self.dir) + f = open(os.path.join(self.dir, "env.py"), 'w') + f.write( + "def startup(options, file_config):" + " pass # TOOD" + ) + f.close() + diff --git a/scripts/alembic b/scripts/alembic index 10ab018f..cc905a0b 100644 --- a/scripts/alembic +++ b/scripts/alembic @@ -1,26 +1,22 @@ #!/usr/bin/env python import alembic +import sys +from optparse import OptionParser def main(argv=None): - from os.path import isfile - from sys import stdin - - if argv is None: - import sys - argv = sys.argv - - from optparse import OptionParser parser = OptionParser("usage: %prog [options] ") + parser.add_option("-d", "--dir", type="string", action="store", help="Location of script directory.") opts, args = parser.parse_args(argv[1:]) if len(args) < 1: parser.error("no command specified") # Will exit command = args[0] - alembic.main(options, command) + + alembic.main(options, file_config, command) if __name__ == "__main__": - main() + main(sys.argv) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..5e3e76d9 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,6 @@ +[egg_info] +tag_build = dev + + +[alembic] +