]> git.jsancho.org Git - datasette-connectors.git/commitdiff
Initial commit
authorJavier Sancho <jsf@jsancho.org>
Mon, 1 Oct 2018 11:42:29 +0000 (13:42 +0200)
committerJavier Sancho <jsf@jsancho.org>
Mon, 1 Oct 2018 11:42:29 +0000 (13:42 +0200)
VERSION [new file with mode: 0644]
datasette_connectors/__init__.py [new file with mode: 0644]
datasette_connectors/connectors.py [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/VERSION b/VERSION
new file mode 100644 (file)
index 0000000..2a64fae
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.25
\ No newline at end of file
diff --git a/datasette_connectors/__init__.py b/datasette_connectors/__init__.py
new file mode 100644 (file)
index 0000000..9cecd04
--- /dev/null
@@ -0,0 +1,16 @@
+import datasette
+from datasette.cli import cli
+
+
+# Monkey patching for original Datasette
+def init(self, *args, **kwargs):
+    print("Test")
+    self.original_init(*args, **kwargs)
+
+datasette.app.Datasette.original_init = datasette.app.Datasette.__init__
+datasette.app.Datasette.__init__ = init
+
+
+# Read external database connectors
+from . import connectors
+connectors.load_connectors()
diff --git a/datasette_connectors/connectors.py b/datasette_connectors/connectors.py
new file mode 100644 (file)
index 0000000..6b09abb
--- /dev/null
@@ -0,0 +1,22 @@
+import pkg_resources
+
+db_connectors = {}
+
+def load_connectors():
+    for entry_point in pkg_resources.iter_entry_points('datasette.connectors'):
+        db_connectors[entry_point.name] = entry_point.load()
+
+def inspect(path):
+    for connector in db_connectors.values():
+        try:
+            return connector.inspect(path)
+        except:
+            pass
+    else:
+        raise Exception("No database connector found for %s" % path)
+
+def connect(path, dbtype):
+    try:
+        return db_connectors[dbtype].Connection(path)
+    except:
+        raise Exception("No database connector found for %s" % path)
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..764fbf9
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,30 @@
+from setuptools import setup
+import os
+
+def get_version():
+    with open('VERSION') as fd:
+        return fd.read().strip()
+
+def get_long_description():
+    with open(os.path.join(
+        os.path.dirname(os.path.abspath(__file__)), 'README.md'
+    ), encoding='utf8') as fp:
+        return fp.read()
+
+
+setup(
+    name='datasette-connectors',
+    version=get_version(),
+    description='Datasette support to other database types',
+    long_description=get_long_description(),
+    long_description_content_type='text/markdown',
+    author='Javier Sancho',
+    url='https://github.com/pytables/datasette-connectors',
+    license='Apache License, Version 2.0',
+    packages=['datasette_connectors'],
+    install_requires=['datasette==0.25'],
+    entry_points='''
+        [console_scripts]
+        datasette=datasette_connectors:cli
+    '''
+)