changeset 0:c8c2d98afc98

initial commit (stub)
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 18 Mar 2012 20:37:19 -0700
parents
children 1981f44ca250
files INSTALL.py README.txt lockedfile/__init__.py lockedfile/main.py lockedfile/template.py lockedfile/web.py setup.py tests/doctest.txt tests/test.py tests/unit.py
diffstat 10 files changed, 327 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/INSTALL.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+"""
+installation script for lockedfile
+locked file implementation
+"""
+
+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/lockedfile'
+DEST='lockedfile' # 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)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,22 @@
+lockedfile
+===========
+
+locked file implementation
+
+
+Goal
+----
+
+Often it becomes necessary to write to a file from multiple streams.
+
+API
+---
+
+
+
+----
+
+Jeff Hammel
+
+http://k0s.org/hg/lockedfile
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lockedfile/__init__.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,6 @@
+class LockedFile(file):
+    """locked file implementation"""
+
+    def locked(self):
+        """is the file locked?"""
+        raise NotImplementedError
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lockedfile/main.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+"""
+locked file implementation
+"""
+
+import sys
+import optparse
+
+def main(args=sys.argv[:]):
+
+    # parse command line options
+    usage = '%prog [options]'
+    class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
+        """description formatter for console script entry point"""
+        def format_description(self, description):
+            if description:
+                return description + '\n'
+            else:
+                return ''
+    parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
+    options, args = parser.parse_args(args)
+
+if __name__ == '__main__':
+  main()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lockedfile/template.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+"""
+lockedfile template for makeitso
+"""
+
+import sys
+from cli import MakeItSoCLI
+from optparse import OptionParser
+from template import MakeItSoTemplate
+
+class lockedfileTemplate(MakeItSoTemplate):
+  """
+  lockedfile template
+  """
+  name = 'lockedfile'
+  templates = ['template']
+  look = True
+
+class TemplateCLI(MakeItSoCLI):
+  """
+  CLI driver for the lockedfile template
+  """
+
+def main(args=sys.argv[:]):
+  cli = TemplateCLI()
+  cli(*args)
+  
+if __name__ == '__main__':
+  main()  
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lockedfile/web.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+"""
+web handler for lockedfile
+"""
+
+from webob import Request, Response, exc
+
+class Handler(object):
+
+    def __init__(self, **kw):
+        pass
+
+    def __call__(self, environ, start_response):
+        request = Request(environ)
+        response = Response(content_type='text/plain',
+                            body="lockedfile")
+        return response(environ, start_response)
+
+if __name__ == '__main__':
+    from wsgiref import simple_server
+    app = Handler()
+    server = simple_server.make_server(host='0.0.0.0', port=8080, app=app)
+    server.serve_forever()
+          
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,45 @@
+"""
+setup packaging script for lockedfile
+"""
+
+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]
+      lockedfile = lockedfile.main:main
+      lockedfile-template = lockedfile.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 = file(os.path.join(here, 'README.txt')).read()
+except IOError:
+    description = ''
+
+
+setup(name='lockedfile',
+      version=version,
+      description="locked file implementation",
+      long_description=description,
+      classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      author='Jeff Hammel',
+      author_email='jhammel@mozilla.com',
+      url='http://k0s.org/hg/lockedfile',
+      license='',
+      packages=['lockedfile'],
+      include_package_data=True,
+      zip_safe=False,
+      **kw
+      )
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/doctest.txt	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,21 @@
+Test lockedfile
+================
+
+The obligatory imports::
+
+    >>> import lockedfile
+    >>> import tempfile
+
+Make a locked file::
+
+    >>> filename = tempfile.mktemp()
+    >>> f = lockedfile.LockedFile(filename, 'w')
+
+The file is initially unlocked::
+
+    >>> f.locked()
+    False
+
+Merge example::
+
+    >>> NotImplementedError # TODO
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+"""
+doctest runner
+"""
+
+import doctest
+import os
+import sys
+from optparse import OptionParser
+
+
+def run_tests(raise_on_error=False, report_first=False):
+
+    # add results here
+    results = {}
+
+    # doctest arguments
+    directory = os.path.dirname(os.path.abspath(__file__))
+    extraglobs = {'here': directory}
+    doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error)
+    doctest_args['optionsflags'] = doctest.ELLIPSIS
+    if report_first:
+        doctest_args['optionflags'] |= doctest.REPORT_ONLY_FIRST_FAILURE
+
+    # gather tests
+    tests =  [test for test in os.listdir(directory)
+              if test.endswith('.txt')]
+
+    # run the tests
+    for test in tests:
+        try:
+            results[test] = doctest.testfile(test, **doctest_args)
+        except doctest.DocTestFailure, failure:
+            raise
+        except doctest.UnexpectedException, failure:
+            raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
+
+    return results
+
+def main(args=sys.argv[1:]):
+
+    # parse command line args
+    parser = OptionParser(description=__doc__)
+    parser.add_option('--raise', dest='raise_on_error',
+                      default=False, action='store_true',
+                      help="raise on first error")
+    parser.add_option('--report-first', dest='report_first',
+                      default=False, action='store_true',
+                      help="report the first error only (all tests will still run)")
+    options, args = parser.parse_args(args)
+
+    # run the tests
+    results = run_tests(**options.__dict__)
+    if sum([i.failed for i in results.values()]):
+        sys.exit(1) # error
+                
+
+if __name__ == '__main__':
+    main()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/unit.py	Sun Mar 18 20:37:19 2012 -0700
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+"""
+unit tests
+"""
+
+import os
+import sys
+import unittest
+
+# globals
+here = os.path.dirname(os.path.abspath(__file__))
+
+class lockedfileUnitTest(unittest.TestCase):
+
+    def test_lockedfile(self):
+        pass
+
+if __name__ == '__main__':
+    unittest.main()
+