[pypy-svn] buildbot default: move getpaths to the irc module, more irc code to follow
RonnyPfannschmidt
commits-noreply at bitbucket.org
Wed Apr 20 15:53:23 CEST 2011
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch:
Changeset: r459:bff6117f3431
Date: 2011-04-19 08:20 +0200
http://bitbucket.org/pypy/buildbot/changeset/bff6117f3431/
Log: move getpaths to the irc module, more irc code to follow
diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -7,6 +7,8 @@
from smtplib import SMTP
from subprocess import Popen, PIPE
+from irc import getpaths
+
LOCAL_REPOS = py.path.local(__file__).dirpath('repos')
REMOTE_BASE = 'http://bitbucket.org'
@@ -54,38 +56,6 @@
"""
-def getpaths(files, listfiles=False):
-
- # Handle empty input
- if not files:
- return '', ''
- files = [f['file'] for f in files]
- if not any(files):
- return '', ''
-
- dirname = os.path.dirname
- basename = os.path.basename
-
- common_prefix = [dirname(f) for f in files]
-
- # Single file, show its full path
- if len(files) == 1:
- common_prefix = files[0]
- listfiles = False
-
- else:
- common_prefix = [path.split(os.sep) for path in common_prefix]
- common_prefix = os.sep.join(os.path.commonprefix(common_prefix))
- if common_prefix and not common_prefix.endswith('/'):
- common_prefix += '/'
-
- if listfiles:
- # XXX Maybe should return file paths relative to prefix? Or TMI?
- filenames = [basename(f) for f in files if f and basename(f)]
- filenames = ' M(%s)' % ', '.join(filenames)
- else:
- filenames = ''
- return common_prefix, filenames
seen_nodes = set()
diff --git a/bitbucket_hook/irc.py b/bitbucket_hook/irc.py
new file mode 100644
--- /dev/null
+++ b/bitbucket_hook/irc.py
@@ -0,0 +1,38 @@
+'''
+utilities for interacting with the irc bot (via cli)
+'''
+
+import os
+
+def getpaths(files, listfiles=False):
+
+ # Handle empty input
+ if not files:
+ return '', ''
+ files = [f['file'] for f in files]
+ if not any(files):
+ return '', ''
+
+ dirname = os.path.dirname
+ basename = os.path.basename
+
+ common_prefix = [dirname(f) for f in files]
+
+ # Single file, show its full path
+ if len(files) == 1:
+ common_prefix = files[0]
+ listfiles = False
+
+ else:
+ common_prefix = [path.split(os.sep) for path in common_prefix]
+ common_prefix = os.sep.join(os.path.commonprefix(common_prefix))
+ if common_prefix and not common_prefix.endswith('/'):
+ common_prefix += '/'
+
+ if listfiles:
+ # XXX Maybe should return file paths relative to prefix? Or TMI?
+ filenames = [basename(f) for f in files if f and basename(f)]
+ filenames = ' M(%s)' % ', '.join(filenames)
+ else:
+ filenames = ''
+ return common_prefix, filenames
diff --git a/bitbucket_hook/test/test_hook.py b/bitbucket_hook/test/test_hook.py
--- a/bitbucket_hook/test/test_hook.py
+++ b/bitbucket_hook/test/test_hook.py
@@ -52,95 +52,6 @@
handler.handle_diff_email()
assert handler.sent_commits == ['first', 'second']
-def test_getpaths():
- d = dict
-
- barefile = [d(file='file')]
- distinct = [d(file='path1/file1'), d(file='path2/file2'),
- d(file='path3/file')]
- shared = [d(file='path/file1'), d(file='path/file2'),
- d(file='path/file')]
-
- deepfile = [d(file='a/long/path/to/deepfile.py')]
- slashesfile = [d(file='/slashesfile/')]
- slashleft = [d(file='/slashleft')]
- slashright = [d(file='slashright/')]
-
-
- nocommon = distinct + [d(file='path4/file')]
- nocommonplusroot = distinct + barefile
-
- common = [d(file='some/path/to/file'), d(file='some/path/to/deeper/file'),
- d(file='some/path/to/anotherfile'), d(file='some/path/to/afile')]
- commonplusroot = shared + barefile
-
- empty = d(file='')
- nocommonplusempty = distinct + [empty]
- commonplusempty = shared + [empty]
- nocommonplusslash = distinct + [d(file='path4/dir/')]
- commonplusslash = shared + [d(file='path/dir/')]
-
- pypydoubleslash = [d(file='pypy/jit/metainterp/opt/u.py'),
- d(file='pypy/jit/metainterp/test/test_c.py'),
- d(file='pypy/jit/metainterp/test/test_o.py')]
-
- pypyempty = [d(file='pypy/rlib/rdtoa.py'),
- d(file='pypy/rlib/test/test_rdtoa.py')]
-
- nothing = ('', '')
-
- # (input, expected output) for listfiles=False
- files_expected = [([], nothing),
- ([empty], nothing),
- ([empty, empty], nothing),
- (barefile, ('file', '')),
- (deepfile, ('a/long/path/to/deepfile.py', '')),
- (slashesfile, ('/slashesfile/', '')),
- (slashleft, ('/slashleft', '')),
- (slashright, ('slashright/', '')),
- (nocommon, nothing),
- (nocommonplusroot, nothing),
- (nocommonplusempty, nothing),
- (common, ('some/path/to/', '')),
- (commonplusroot, nothing),
- (commonplusempty, nothing),
- (nocommonplusslash, nothing),
- (commonplusslash, ('path/', '')),
- (pypydoubleslash, ('pypy/jit/metainterp/', '')),
- (pypyempty, ('pypy/rlib/', '')),
- ]
-
- for f, wanted in files_expected:
- assert hook.getpaths(f) == wanted
-
- # (input, expected output) for listfiles=True
- files_expected = [([], nothing),
- ([empty], nothing),
- ([empty, empty], nothing),
- (barefile, ('file', '')),
- (deepfile, ('a/long/path/to/deepfile.py', '')),
- (slashesfile, ('/slashesfile/', '')),
- (slashleft, ('/slashleft', '')),
- (slashright, ('slashright/', '')),
- (nocommon, ('', ' M(file1, file2, file, file)')),
- (nocommonplusroot, ('', ' M(file1, file2, file, file)')),
- (nocommonplusempty, ('',' M(file1, file2, file)')),
- (common, ('some/path/to/',
- ' M(file, file, anotherfile, afile)')),
- (commonplusroot, ('', ' M(file1, file2, file, file)')),
- (commonplusempty, ('',' M(file1, file2, file)')),
- (nocommonplusslash, ('',' M(file1, file2, file)')),
- (commonplusslash, ('path/',' M(file1, file2, file)')),
- (pypydoubleslash, ('pypy/jit/metainterp/',
- ' M(u.py, test_c.py, test_o.py)')),
- (pypyempty, ('pypy/rlib/',
- ' M(rdtoa.py, test_rdtoa.py)')),
- ]
-
- for f, wanted in files_expected:
- assert hook.getpaths(f, listfiles=True) == wanted
-
-
LONG_MESSAGE = u'This is a test with a long message: ' + 'x'*1000
LONG_CUT = LONG_MESSAGE[:160-29]
diff --git a/bitbucket_hook/test/test_irc.py b/bitbucket_hook/test/test_irc.py
new file mode 100644
--- /dev/null
+++ b/bitbucket_hook/test/test_irc.py
@@ -0,0 +1,90 @@
+from bitbucket_hook.irc import getpaths
+
+def fl(*paths):
+ return [{'file': x} for x in paths]
+
+def test_getpaths():
+ d = dict
+ barefile = fl('file')
+ distinct = fl('path1/file1', 'path2/file2', 'path3/file')
+ shared = fl('path/file1', 'path/file2', 'path/file')
+
+ deepfile = fl('a/long/path/to/deepfile.py')
+ slashesfile = fl('/slashesfile/')
+ slashleft = fl('/slashleft')
+ slashright = fl('slashright/')
+
+
+ nocommon = distinct + fl('path4/file')
+ nocommonplusroot = distinct + barefile
+
+ common = fl('some/path/to/file', 'some/path/to/deeper/file',
+ 'some/path/to/anotherfile', 'some/path/to/afile')
+ commonplusroot = shared + barefile
+
+ empty = d(file='')
+ nocommonplusempty = distinct + [empty]
+ commonplusempty = shared + [empty]
+ nocommonplusslash = distinct + fl('path4/dir/')
+ commonplusslash = shared + fl('path/dir/')
+
+ pypydoubleslash = fl('pypy/jit/metainterp/opt/u.py',
+ 'pypy/jit/metainterp/test/test_c.py',
+ 'pypy/jit/metainterp/test/test_o.py')
+
+ pypyempty = fl('pypy/rlib/rdtoa.py', 'pypy/rlib/test/test_rdtoa.py'
+
+ nothing = ('', '')
+
+ # (input, expected output) for listfiles=False
+ files_expected = [([], nothing),
+ ([empty], nothing),
+ ([empty, empty], nothing),
+ (barefile, ('file', '')),
+ (deepfile, ('a/long/path/to/deepfile.py', '')),
+ (slashesfile, ('/slashesfile/', '')),
+ (slashleft, ('/slashleft', '')),
+ (slashright, ('slashright/', '')),
+ (nocommon, nothing),
+ (nocommonplusroot, nothing),
+ (nocommonplusempty, nothing),
+ (common, ('some/path/to/', '')),
+ (commonplusroot, nothing),
+ (commonplusempty, nothing),
+ (nocommonplusslash, nothing),
+ (commonplusslash, ('path/', '')),
+ (pypydoubleslash, ('pypy/jit/metainterp/', '')),
+ (pypyempty, ('pypy/rlib/', '')),
+ ]
+
+ for f, wanted in files_expected:
+ assert getpaths(f) == wanted
+
+ # (input, expected output) for listfiles=True
+ files_expected = [([], nothing),
+ ([empty], nothing),
+ ([empty, empty], nothing),
+ (barefile, ('file', '')),
+ (deepfile, ('a/long/path/to/deepfile.py', '')),
+ (slashesfile, ('/slashesfile/', '')),
+ (slashleft, ('/slashleft', '')),
+ (slashright, ('slashright/', '')),
+ (nocommon, ('', ' M(file1, file2, file, file)')),
+ (nocommonplusroot, ('', ' M(file1, file2, file, file)')),
+ (nocommonplusempty, ('',' M(file1, file2, file)')),
+ (common, ('some/path/to/',
+ ' M(file, file, anotherfile, afile)')),
+ (commonplusroot, ('', ' M(file1, file2, file, file)')),
+ (commonplusempty, ('',' M(file1, file2, file)')),
+ (nocommonplusslash, ('',' M(file1, file2, file)')),
+ (commonplusslash, ('path/',' M(file1, file2, file)')),
+ (pypydoubleslash, ('pypy/jit/metainterp/',
+ ' M(u.py, test_c.py, test_o.py)')),
+ (pypyempty, ('pypy/rlib/',
+ ' M(rdtoa.py, test_rdtoa.py)')),
+ ]
+
+ for f, wanted in files_expected:
+ assert getpaths(f, listfiles=True) == wanted
+
+
More information about the Pypy-commit
mailing list