Permalink
Browse files

Python 2.6 compatability.

  • Loading branch information...
1 parent 83ab12b commit c91c35b445c9d37cd8c36a01d3239027c7b989ab @chrisrossi chrisrossi committed Sep 13, 2012
Showing with 45 additions and 24 deletions.
  1. +29 −8 acidfs/__init__.py
  2. +14 −14 acidfs/tests.py
  3. +2 −2 setup.py
View
@@ -71,7 +71,7 @@ def __init__(self, repo, head='HEAD', create=True, bare=False):
else:
wdpath = repo
dbpath = os.path.join(repo, '.git')
- subprocess.check_output(args)
+ _check_output(args)
else:
raise ValueError('No database found in %s' % dbpath)
@@ -384,7 +384,7 @@ def __init__(self, wd, db, head):
if os.path.exists(self.headref):
# Existing head, get head revision
- self.prev_commit = subprocess.check_output(
+ self.prev_commit = _check_output(
['git', 'rev-list', '--max-count=1', head], cwd=db).strip()
self.tree = _TreeNode.read(db, self.prev_commit)
else:
@@ -396,7 +396,7 @@ def set_base(self, ref):
if self.tree.dirty:
raise ConflictError(
"Cannot set base when changes already made in transaction.")
- self.prev_commit = subprocess.check_output(
+ self.prev_commit = _check_output(
['git', 'rev-list', '--max-count=1', ref], cwd=self.db).strip()
self.tree = _TreeNode.read(self.db, self.prev_commit)
@@ -455,9 +455,9 @@ def tpc_vote(self, tx):
return
# Find the merge base
- current = subprocess.check_output(
+ current = _check_output(
['git', 'rev-list', '--max-count=1', 'HEAD'], cwd=self.db).strip()
- merge_base = subprocess.check_output(
+ merge_base = _check_output(
['git', 'merge-base', current, commit_oid], cwd=self.db).strip()
# If the merge base is the current commit, it means there have been no
@@ -490,7 +490,7 @@ def tpc_finish(self, tx):
else:
args.append('--soft')
cwd = self.db
- subprocess.check_output(args, cwd=cwd)
+ _check_output(args, cwd=cwd)
else:
# If not updating current head, just write the commit to the ref
@@ -548,8 +548,7 @@ def mkcommit(self, tx, tree_oid, parents, message=None):
for parent in parents:
args.append('-p')
args.append(parent)
- return subprocess.check_output(
- args, cwd=self.db, env=gitenv).strip()
+ return _check_output(args, cwd=self.db, env=gitenv).strip()
def merge(self, base_oid, current, tree_oid):
@@ -1002,3 +1001,25 @@ def _DirectoryNotEmpty(path):
_MERGE_REMOVED_IN_REMOTE = object()
_MERGE_CHANGED_IN_BOTH = object()
_MERGE_ADDED_IN_BOTH = object()
+
+
+try:
+ # Python >= 2.7
+ _check_output = subprocess.check_output
+except AttributeError: # pragma NO COVER
+ def _check_output(*popenargs, **kwargs):
+ """
+ Stolen straight from Python 2.7.
+ """
+ if 'stdout' in kwargs:
+ raise ValueError('stdout argument not allowed, it will be overridden.')
+ process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
+ output, unused_err = process.communicate()
+ retcode = process.poll()
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ raise subprocess.CalledProcessError(retcode, cmd, output=output)
+ return output
+
View
@@ -1,7 +1,7 @@
try: #pragma no cover
import unittest2 as unittest
unittest # stfu pyflakes
-except ImportError:
+except ImportError: # pragma NO COVER
import unittest
import contextlib
@@ -12,6 +12,8 @@
import tempfile
import transaction
+from acidfs import _check_output
+
class FunctionalTests(unittest.TestCase):
@@ -196,7 +198,7 @@ def test_commit_metadata(self):
fs.open('foo', 'w').write('Howdy!')
transaction.commit()
- output = subprocess.check_output(['git', 'log'], cwd=self.tmp)
+ output = _check_output(['git', 'log'], cwd=self.tmp)
self.assertIn('Author: Fred Flintstone <fred@bed.rock>', output)
self.assertIn('A test commit.', output)
@@ -209,7 +211,7 @@ def test_commit_metadata_extended_info_for_user(self):
fs.open('foo', 'w').write('Howdy!')
transaction.commit()
- output = subprocess.check_output(['git', 'log'], cwd=self.tmp)
+ output = _check_output(['git', 'log'], cwd=self.tmp)
self.assertIn('Author: Fred Flintstone <fred@bed.rock>', output)
self.assertIn('A test commit.', output)
@@ -444,9 +446,8 @@ def test_conflict_error_on_first_commit(self):
fs = self.make_one()
fs.open('foo', 'w').write('Hello!')
open(os.path.join(self.tmp, 'foo'), 'w').write('Howdy!')
- subprocess.check_output(['git', 'add', '.'], cwd=self.tmp)
- subprocess.check_output(['git', 'commit', '-m', 'Haha! First!'],
- cwd=self.tmp)
+ _check_output(['git', 'add', '.'], cwd=self.tmp)
+ _check_output(['git', 'commit', '-m', 'Haha! First!'], cwd=self.tmp)
with self.assertRaises(ConflictError):
transaction.commit()
@@ -457,9 +458,8 @@ def test_unable_to_merge_file(self):
transaction.commit()
fs.open('foo', 'w').write('Party!')
open(os.path.join(self.tmp, 'foo'), 'w').write('Howdy!')
- subprocess.check_output(['git', 'add', '.'], cwd=self.tmp)
- subprocess.check_output(['git', 'commit', '-m', 'Haha! First!'],
- cwd=self.tmp)
+ _check_output(['git', 'add', '.'], cwd=self.tmp)
+ _check_output(['git', 'commit', '-m', 'Haha! First!'], cwd=self.tmp)
with self.assertRaises(ConflictError):
transaction.commit()
@@ -470,8 +470,8 @@ def test_merge_add_file(self):
fs.open('bar', 'w').write('Howdy!\n')
open(os.path.join(self.tmp, 'baz'), 'w').write('Ciao!\n')
- subprocess.check_output(['git', 'add', 'baz'], cwd=self.tmp)
- subprocess.check_output(['git', 'commit', '-m', 'haha'], cwd=self.tmp)
+ _check_output(['git', 'add', 'baz'], cwd=self.tmp)
+ _check_output(['git', 'commit', '-m', 'haha'], cwd=self.tmp)
transaction.commit()
self.assertTrue(fs.exists('foo'))
@@ -486,8 +486,8 @@ def test_merge_rm_file(self):
transaction.commit()
fs.rm('foo')
- subprocess.check_output(['git', 'rm', 'baz'], cwd=self.tmp)
- subprocess.check_output(['git', 'commit', '-m', 'gotcha'], cwd=self.tmp)
+ _check_output(['git', 'rm', 'baz'], cwd=self.tmp)
+ _check_output(['git', 'commit', '-m', 'gotcha'], cwd=self.tmp)
transaction.commit()
self.assertFalse(fs.exists('foo'))
@@ -636,7 +636,7 @@ def test_branch_and_then_merge(self):
self.assertFalse(fs2.exists('beez'))
# Expecting two parents for commit since it's a merge
- commit = subprocess.check_output(
+ commit = _check_output(
['git', 'cat-file', '-p', 'HEAD^{commit}'],
cwd=self.tmp).split('\n')
self.assertTrue(commit[1].startswith('parent'))
View
@@ -11,9 +11,9 @@
tests_require = requires + ['mock']
if sys.version < '2.7':
- tests_require += 'unittest2'
+ tests_require += ['unittest2']
-testing_extras = tests_require + ['nose', 'coverage']
+testing_extras = tests_require + ['nose', 'coverage', 'tox']
doc_extras = ['Sphinx']
here = os.path.abspath(os.path.dirname(__file__))

0 comments on commit c91c35b

Please sign in to comment.