# HG changeset patch # User Jeff Hammel # Date 1458066562 25200 # Node ID 4b51bcbcdb156f48bcb2489f58a2e1adedf47649 initial stub diff -r 000000000000 -r 4b51bcbcdb15 INSTALL.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL.py Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +""" +installation script for sqlitex +sqlite explorer via web +""" + +import os +import sys +import urllib2 +import subprocess +try: + from subprocess import check_call as call +except: + from subprocess import call + +REPO='http://k0s.org/hg/sqlitex' +DEST='sqlitex' # name of the virtualenv +VIRTUALENV='https://raw.github.com/pypa/virtualenv/develop/virtualenv.py' + +def which(binary, path=os.environ['PATH']): + dirs = path.split(os.pathsep) + for dir in dirs: + if os.path.isfile(os.path.join(dir, fileName)): + return os.path.join(dir, fileName) + if os.path.isfile(os.path.join(dir, fileName + ".exe")): + return os.path.join(dir, fileName + ".exe") + +def main(args=sys.argv[1:]): + + # create a virtualenv + virtualenv = which('virtualenv') or which('virtualenv.py') + if virtualenv: + call([virtualenv, DEST]) + else: + process = subproces.Popen([sys.executable, '-', DEST], stdin=subprocess.PIPE) + process.communicate(stdin=urllib2.urlopen(VIRTUALENV).read()) + + # create a src directory + src = os.path.join(DEST, 'src') + os.mkdir(src) + + # clone the repository + call(['hg', 'clone', REPO], cwd=src) + + # find the virtualenv python + python = None + for path in (('bin', 'python'), ('Scripts', 'python.exe')): + _python = os.path.join(DEST, *path) + if os.path.exists(_python) + python = _python + break + else: + raise Exception("Python binary not found in %s" % DEST) + + # find the clone + filename = REPO.rstrip('/') + filename = filename.split('/')[-1] + clone = os.path.join(src, filename) + assert os.path.exists(clone), "Clone directory not found in %s" % src + + # ensure setup.py exists + assert os.path.exists(os.path.join(clone, 'setup.py')), 'setup.py not found in %s' % clone + + # install the package in develop mode + call([python 'setup.py', 'develop'], cwd=clone) + diff -r 000000000000 -r 4b51bcbcdb15 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,11 @@ +sqlitex +=========== + +sqlite explorer via web + +---- + +Jeff Hammel + +http://k0s.org/hg/sqlitex + diff -r 000000000000 -r 4b51bcbcdb15 setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,45 @@ +""" +setup packaging script for sqlitex +""" + +import os + +version = "0.0" +dependencies = ['webob'] + +# allow use of setuptools/distribute or distutils +kw = {} +try: + from setuptools import setup + kw['entry_points'] = """ + [console_scripts] + sqlitex = sqlitex.api:main + sqlitex-web = sqlitex.web: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 = file(os.path.join(here, 'README.txt')).read() +except IOError: + description = '' + + +setup(name='sqlitex', + version=version, + description="sqlite explorer via web", + 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/sqlitex', + license='', + packages=['sqlitex'], + include_package_data=True, + zip_safe=False, + **kw + ) + diff -r 000000000000 -r 4b51bcbcdb15 sqlitex/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqlitex/__init__.py Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,2 @@ +# + diff -r 000000000000 -r 4b51bcbcdb15 sqlitex/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqlitex/api.py Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,37 @@ +""" +sqlitex API +""" + +# imports +import argparse +import csv +import os +import sqlite3 +import sys + + +class SQLitEx(object): + + def __init__(self, db_file): + self.db_file = os.path.abspath(db_file) + if not os.path.isfile(self.db_file): + raise AssertionError("Not a file: '{0}'".format(self.db_file)) + + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('db_file', + help="path to sqlite database file") + parser.add_argument('table', nargs='?', default=None, + help="table to output") + + options = parser.parse_args(args) + + # instantiate api + api = SQLitEx(options.db_file) + +if __name__ == '__main__': + main() diff -r 000000000000 -r 4b51bcbcdb15 sqlitex/web.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqlitex/web.py Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +""" +web handler for sqlitex +""" + +# imports +import argparse +import os +import sys +from webob import Request, Response, exc +from wsgiref import simple_server + +class Handler(object): + """WSGI HTTP Handler""" + + def __init__(self, db_file): + assert os.path.isfile(db_file) + + def __call__(self, environ, start_response): + request = Request(environ) + response = Response(content_type='text/plain', + body="sqlitex") + return response(environ, start_response) + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-p', '--port', dest='port', + type=int, default=8080, + help="port to serve on") + options = parser.parse_arguments(args) + + # instantiate WSGI handler + app = Handler() + + # serve it (Warning! Single threaded!) + server = simple_server.make_server(host='0.0.0.0', + port=options.port + app=app) + try: + server.serve_forever() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main() + diff -r 000000000000 -r 4b51bcbcdb15 tests/test_sqlitex.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_sqlitex.py Tue Mar 15 11:29:22 2016 -0700 @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +unit tests for sqlitex +""" + +import os +import sys +import tempfile +import unittest + +# globals +here = os.path.dirname(os.path.abspath(__file__)) + +class sqlitexUnitTest(unittest.TestCase): + + def test_sqlitex(self): + tf = tempfile.mktemp() + try: + # pass + pass + finally: + if os.path.exists(tf): + os.remove(tf) + +if __name__ == '__main__': + unittest.main() + diff -r 000000000000 -r 4b51bcbcdb15 tests/testall.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testall.py Tue Mar 15 11:29:22 2016 -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() + +