-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)
+
+
--- /dev/null
+import base, postgresql
\ No newline at end of file
--- /dev/null
+
+
+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
--- /dev/null
+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()
+
#!/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] <command>")
+ 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)
--- /dev/null
+[egg_info]
+tag_build = dev
+
+
+[alembic]
+