# HG changeset patch # User Jeff Hammel # Date 1495504211 25200 # Node ID 7a4a073ee13ed0deb611090a2768d021ded3287a initial commit diff -r 000000000000 -r 7a4a073ee13e INSTALL.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL.py Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +""" +installation script for Lemuriformes +ReSTful API consumer in python +""" + +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/Lemuriformes' +DEST='Lemuriformes' # 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 7a4a073ee13e README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,11 @@ +Lemuriformes +=========== + +ReSTful API consumer in python + +---- + +Jeff Hammel + +http://k0s.org/hg/Lemuriformes + diff -r 000000000000 -r 7a4a073ee13e lemuriformes/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemuriformes/__init__.py Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,2 @@ +# + diff -r 000000000000 -r 7a4a073ee13e lemuriformes/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemuriformes/main.py Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +ReSTful API consumer in python +""" + +# imports +import argparse +import os +import subprocess +import sys +import time + +# python requirements +# (key, value) = (module, PyPI name) +requirements = () +for module, package in requirements: + try: + globals()[module] = __import__(module) + except ImportError: + # install requirement and try again + subprocess.check_call(['pip', 'install', package]) + args = [sys.executable] + sys.argv + os.execl(sys.executable, *args) + +# module globals +__all__ = ['main', 'Parser'] +here = os.path.dirname(os.path.realpath(__file__)) + +try: + # python 2 + string = (str, unicode) +except NameError: + # python 3 + string = (str, ) + + +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 Parser(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('--monitor', dest='monitor', + type=float, metavar='SLEEP', + help="run in monitor mode") + 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 = Parser() + options = parser.parse_args(args) + + try: + while True: + if options.monitor: + time.sleep(options.monitor) + else: + break + except KeyboardInterrupt: + pass + + +if __name__ == '__main__': + main() + + diff -r 000000000000 -r 7a4a073ee13e setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,46 @@ +""" +setup packaging script for Lemuriformes +""" + +import os + +version = "0.0" +dependencies = ['MakeItSo', 'webob'] + +# allow use of setuptools/distribute or distutils +kw = {} +try: + from setuptools import setup + kw['entry_points'] = """ + [console_scripts] + Lemuriformes = lemuriformes.main:main + lemuriformes-template = lemuriformes.template: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='Lemuriformes', + version=version, + description="ReSTful API consumer in python", + 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/Lemuriformes', + license='', + packages=['lemuriformes'], + include_package_data=True, + tests_require=['tox'], + zip_safe=False, + **kw + ) + diff -r 000000000000 -r 7a4a073ee13e tests/test_lemuriformes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_lemuriformes.py Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +unit tests for lemuriformes +""" + +import os +import sys +import tempfile +import unittest + +# globals +here = os.path.dirname(os.path.abspath(__file__)) + +class lemuriformesUnitTest(unittest.TestCase): + + def test_lemuriformes(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 7a4a073ee13e tests/testall.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testall.py Mon May 22 18:50:11 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() + + diff -r 000000000000 -r 7a4a073ee13e tox.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tox.ini Mon May 22 18:50:11 2017 -0700 @@ -0,0 +1,6 @@ +# https://tox.readthedocs.io/en/latest/ +[tox] +envlist=py27 +[testenv] +commands=python setup.py test +