changeset 0:a05c70cc24be

initial commit
author Jeff Hammel <k0scist@gmail.com>
date Fri, 31 Mar 2017 18:21:15 -0700
parents
children 1cfdb859f9d2
files README.txt setup.py sqlex/__init__.py sqlex/main.py tests/test_sqlex.py tests/testall.py
diffstat 6 files changed, 178 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt	Fri Mar 31 18:21:15 2017 -0700
@@ -0,0 +1,11 @@
+sqlex
+===========
+
+sql(ite) explorer/exporter
+
+----
+
+Jeff Hammel
+
+http://k0s.org/hg/sqlex
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Fri Mar 31 18:21:15 2017 -0700
@@ -0,0 +1,44 @@
+"""
+setup packaging script for sqlex
+"""
+
+import os
+
+version = "0.0"
+dependencies = []
+
+# allow use of setuptools/distribute or distutils
+kw = {}
+try:
+    from setuptools import setup
+    kw['entry_points'] = """
+      [console_scripts]
+      sqlex = sqlex.main:main
+"""
+    kw['install_requires'] = dependencies
+except ImportError:
+    from distutils.core import setup
+    kw['requires'] = dependencies
+
+try:
+    here = os.path.dirname(os.path.abspath(__file__))
+    description = open(os.path.join(here, 'README.txt')).read()
+except IOError:
+    description = ''
+
+
+setup(name='sqlex',
+      version=version,
+      description="sql(ite) explorer/exporter",
+      long_description=description,
+      classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      author='Jeff Hammel',
+      author_email='k0scist@gmail.com',
+      url='http://k0s.org/hg/sqlex',
+      license='',
+      packages=['sqlex'],
+      include_package_data=True,
+      tests_require=['tox'],
+      zip_safe=False,
+      **kw
+      )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sqlex/__init__.py	Fri Mar 31 18:21:15 2017 -0700
@@ -0,0 +1,2 @@
+#
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sqlex/main.py	Fri Mar 31 18:21:15 2017 -0700
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+sql(ite) explorer/exporter
+"""
+
+# imports
+import argparse
+import os
+import sys
+
+def ensure_dir(directory):
+    """ensure a directory exists"""
+    if os.path.exists(directory):
+        if not os.path.isdir(directory):
+            raise OSError("Not a directory: '{}'".format(directory))
+        return directory
+    os.makedirs(directory)
+    return directory
+
+
+class SQLExParser(argparse.ArgumentParser):
+    """CLI option parser"""
+
+    def __init__(self, **kwargs):
+        kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
+        kwargs.setdefault('description', __doc__)
+        argparse.ArgumentParser.__init__(self, **kwargs)
+        self.add_argument('db', help="sqlite `.db` file")
+        self.options = None
+
+    def parse_args(self, *args, **kw):
+        options = argparse.ArgumentParser.parse_args(self, *args, **kw)
+        self.validate(options)
+        self.options = options
+        return options
+
+    def validate(self, options):
+        """validate options"""
+
+def main(args=sys.argv[1:]):
+    """CLI"""
+
+    # parse command line options
+    parser = SQLExParser()
+    options = parser.parse_args(args)
+
+if __name__ == '__main__':
+    main()
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_sqlex.py	Fri Mar 31 18:21:15 2017 -0700
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+unit tests for sqlex
+"""
+
+import os
+import sys
+import tempfile
+import unittest
+
+# globals
+here = os.path.dirname(os.path.abspath(__file__))
+
+class sqlexUnitTest(unittest.TestCase):
+
+    def test_sqlex(self):
+        tf = tempfile.mktemp()
+        try:
+            # pass
+            pass
+        finally:
+            if os.path.exists(tf):
+                os.remove(tf)
+
+if __name__ == '__main__':
+    unittest.main()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/testall.py	Fri Mar 31 18:21:15 2017 -0700
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+"""
+run all unit tests
+"""
+
+import os
+import sys
+import unittest
+
+here = os.path.dirname(os.path.abspath(__file__))
+
+def main(args=sys.argv[1:]):
+
+    results = unittest.TestResult()
+    suite = unittest.TestLoader().discover(here, 'test_*.py')
+    suite.run(results)
+    n_errors = len(results.errors)
+    n_failures = len(results.failures)
+    print ("Run {} tests ({} failures; {} errors)".format(results.testsRun,
+                                                          n_failures,
+                                                          n_errors))
+    if results.wasSuccessful():
+        print ("Success")
+        sys.exit(0)
+    else:
+        # print failures and errors
+        for label, item in (('FAIL', results.failures),
+                            ('ERROR', results.errors)):
+            if item:
+                print ("\n{}::\n".format(label))
+                for index, (i, message) in enumerate(item):
+                    print ('{})  {}:'.format(index, str(i)))
+                    print (message)
+        sys.exit(1)
+
+if __name__ == '__main__':
+    main()
+
+