changeset 0:89e0c87f09ca

initial (STUB) commit
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Dec 2012 16:41:39 -0800
parents
children 240f98f19ee3
files README.txt bzgit.py setup.py tests/doctest.txt tests/test.py
diffstat 5 files changed, 182 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt	Tue Dec 11 16:41:39 2012 -0800
@@ -0,0 +1,11 @@
+bzgit
+===========
+
+github <-> bugzilla.m.o bridge
+
+----
+
+Jeff Hammel
+
+http://k0s.org/mozilla/hg/bzgit
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bzgit.py	Tue Dec 11 16:41:39 2012 -0800
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+"""
+bzgit
+github <-> bugzilla.m.o bridge
+"""
+
+import bzconsole
+import optparse
+import sys
+import urlparse
+from pygithub3 import Github
+
+def path_segments(path):
+    """return path segments"""
+    segments = path.strip('/').split('/')
+    if segments == ['']:
+        return []
+    return segments
+
+def add_options(parser):
+    """add bzgit options to an OptionParser instance"""
+
+
+def main(args=sys.argv[1:]):
+
+    # parse command line arguments
+    usage = '%prog [options] ...'
+    class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
+        """description formatter"""
+        def format_description(self, description):
+            if description:
+                return description.strip() + '\n'
+            else:
+                return ''
+    parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
+    add_options(parser)
+    options, args = parser.parse_args(args)
+    if not args:
+        parser.print_usage()
+        parser.exit()
+
+    # parse resource
+    assert len(args) == 1 # for now
+    resource = args[0]
+    scheme, hostspec, path, query, anchor = urlparse.urlsplit(resource)
+    segments = path_segments(path)
+    assert len(segments) > 2 # for now
+    github_user = segments[0]
+    github_project = segments[1]
+
+    assert len(segments) == 4 # for now
+    assert segments[2] == 'pull'
+    pull_request = int(segments[3])
+
+    # connect to gh
+    gh = Github() # TODO: auth
+    pull = gh.pull_requests.get(44, github_user, github_project)
+
+    # ...and move all the things
+    bz = bzconsole
+
+if __name__ == '__main__':
+    main()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Tue Dec 11 16:41:39 2012 -0800
@@ -0,0 +1,35 @@
+import os
+from setuptools import setup
+
+try:
+    here = os.path.dirname(os.path.abspath(__file__))
+    description = file(os.path.join(here, 'README.txt')).read()
+except IOError:
+    description = None
+
+version = '0.0'
+
+deps = ['pygithub3', 'bzconsole']
+
+setup(name='bzgit',
+      version=version,
+      description="github <-> bugzilla.m.o bridge",
+      long_description=description,
+      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      keywords='mozilla',
+      author='Jeff Hammel',
+      author_email='jhammel@mozilla.com',
+      url='http://k0s.org/mozilla/hg/bzgit',
+      license='',
+      py_modules=['bzgit'],
+      packages=[],
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=deps,
+      entry_points="""
+      # -*- Entry points: -*-
+      [console_scripts]
+      bzgit = bzgit:main
+      """,
+      )
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/doctest.txt	Tue Dec 11 16:41:39 2012 -0800
@@ -0,0 +1,11 @@
+Test bzgit
+================
+
+The obligatory imports:
+
+    >>> import bzgit
+
+Run some tests.  This test will fail, please fix it:
+
+    >>> assert True == False
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test.py	Tue Dec 11 16:41:39 2012 -0800
@@ -0,0 +1,60 @@
+#!/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)
+    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()
+