]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
work in progress
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 22 Apr 2010 22:46:42 +0000 (18:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 22 Apr 2010 22:46:42 +0000 (18:46 -0400)
alembic/command.py
alembic/ddl/__init__.py [new file with mode: 0644]
alembic/ddl/base.py [new file with mode: 0644]
alembic/ddl/postgresql.py [new file with mode: 0644]
alembic/options.py [new file with mode: 0644]
alembic/script.py [new file with mode: 0644]
scripts/alembic
setup.cfg [new file with mode: 0644]

index 9cf27e03a42fe87207a68f39c3ccb19e8398b220..e8fa4d3768278e4c4d5d66194b22f01d66084b44 100644 (file)
@@ -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 (file)
index 0000000..232d538
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/alembic/options.py b/alembic/options.py
new file mode 100644 (file)
index 0000000..0b1a388
--- /dev/null
@@ -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 (file)
index 0000000..4a534ea
--- /dev/null
@@ -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()
+        
index 10ab018f476579569f2d802f0c2b6768e4f88136..cc905a0b6efdbda88390011e80e950ad4223844c 100644 (file)
@@ -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] <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)
 
diff --git a/setup.cfg b/setup.cfg
new file mode 100644 (file)
index 0000000..5e3e76d
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,6 @@
+[egg_info]
+tag_build = dev
+
+
+[alembic]
+