[Python-modules-commits] [gerritlib] 04/06: Import gerritlib_0.8.0.orig.tar.gz
Filip Pytloun
fpytloun-guest at moszumanska.debian.org
Mon Dec 11 21:46:44 UTC 2017
This is an automated email from the git hooks/post-receive script.
fpytloun-guest pushed a commit to branch master
in repository gerritlib.
commit a5309c26f2878d9d9c0a6c001c14d71750b2c4a6
Author: Filip Pytloun <filip at pytloun.cz>
Date: Mon Dec 11 22:21:23 2017 +0100
Import gerritlib_0.8.0.orig.tar.gz
---
.testr.conf | 5 +++-
gerritlib/gerrit.py | 54 +++++++++++++++++++++++++++++++++-
{tests => gerritlib/tests}/__init__.py | 0
gerritlib/tests/base.py | 5 ++++
gerritlib/tests/test_gerritlib.py | 28 ++++++++++++++++++
requirements.txt | 4 +--
test-requirements.txt | 3 +-
tox.ini | 7 ++---
8 files changed, 96 insertions(+), 10 deletions(-)
diff --git a/.testr.conf b/.testr.conf
index 5433c07..6d83b3c 100644
--- a/.testr.conf
+++ b/.testr.conf
@@ -1,4 +1,7 @@
[DEFAULT]
-test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} ${PYTHON:-python} -m subunit.run discover -t ./ tests $LISTOPT $IDOPTION
+test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
+ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
+ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
+ ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
diff --git a/gerritlib/gerrit.py b/gerritlib/gerrit.py
index b994314..5730aac 100644
--- a/gerritlib/gerrit.py
+++ b/gerritlib/gerrit.py
@@ -211,6 +211,36 @@ class Gerrit(object):
out, err = self._ssh(cmd)
return err
+ def listMembers(self, group, recursive=False):
+ cmd = 'gerrit ls-members'
+ if recursive:
+ cmd = '%s --recursive' % cmd
+ cmd = '%s "%s"' % (cmd, group)
+ out, err = self._ssh(cmd)
+ ret = []
+ rows = out.split('\n')
+ if len(rows) > 1:
+ keys = rows[0].split('\t')
+ for row in rows[1:]:
+ ret.append(dict(zip(keys, row.split('\t'))))
+ return ret
+
+ def _setMember(self, verb, group, member):
+ cmd = 'gerrit set-members'
+ if verb == 'add':
+ cmd = '%s --add "%s"' % (cmd, member)
+ elif verb == 'remove':
+ cmd = '%s --remove "%s"' % (cmd, member)
+ cmd = '%s "%s"' % (cmd, group)
+ out, err = self._ssh(cmd)
+ return err
+
+ def addMember(self, group, member):
+ self._setMember('add', group, member)
+
+ def removeMember(self, group, member):
+ self._setMember('remove', group, member)
+
def createProject(self, project, require_change_id=True, empty_repo=False,
description=None):
cmd = 'gerrit create-project'
@@ -221,7 +251,16 @@ class Gerrit(object):
if description:
cmd = "%s --description \"%s\"" % \
(cmd, description.replace('"', r'\"'))
- cmd = '%s --name %s' % (cmd, project)
+ version = None
+ try:
+ version = self.parseGerritVersion(self.getVersion())
+ except Exception:
+ # If no version then we know version is old and should use --name
+ pass
+ if not version or version < (2, 12):
+ cmd = '%s --name "%s"' % (cmd, project)
+ else:
+ cmd = '%s "%s"' % (cmd, project)
out, err = self._ssh(cmd)
return err
@@ -275,6 +314,19 @@ class Gerrit(object):
out = out.split(' ')[2]
return out.strip('\n')
+ def parseGerritVersion(self, version):
+ # Adapted from gertty setRemoteVersion()
+ base = version.split('-')[0]
+ parts = base.split('.')
+ major = minor = micro = 0
+ if len(parts) > 0:
+ major = int(parts[0])
+ if len(parts) > 1:
+ minor = int(parts[1])
+ if len(parts) > 2:
+ micro = int(parts[2])
+ return (major, minor, micro)
+
def replicate(self, project='--all'):
cmd = 'replication start %s' % project
if self.installed_plugins is None:
diff --git a/tests/__init__.py b/gerritlib/tests/__init__.py
similarity index 100%
rename from tests/__init__.py
rename to gerritlib/tests/__init__.py
diff --git a/gerritlib/tests/base.py b/gerritlib/tests/base.py
new file mode 100644
index 0000000..c44ed80
--- /dev/null
+++ b/gerritlib/tests/base.py
@@ -0,0 +1,5 @@
+import testtools
+
+
+class TestCase(testtools.TestCase):
+ "Placeholder wrapper for the testtools.TestCase class."
diff --git a/gerritlib/tests/test_gerritlib.py b/gerritlib/tests/test_gerritlib.py
new file mode 100644
index 0000000..5d978e3
--- /dev/null
+++ b/gerritlib/tests/test_gerritlib.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+test_gerritlib
+----------------------------------
+
+Tests for `gerritlib` module.
+"""
+
+from gerritlib.tests import base
+
+
+class TestGerritlib(base.TestCase):
+
+ def test_something(self):
+ pass
diff --git a/requirements.txt b/requirements.txt
index 676d32b..4656213 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-pbr>=0.8.2,<1.0
-paramiko>=1.8.0
+pbr>=0.11
+paramiko>=1.8.0,<2.0.0
six>=1.7.0
diff --git a/test-requirements.txt b/test-requirements.txt
index 2a69250..e928618 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,4 +1,5 @@
-hacking>=0.5.6,<0.8
+hacking>=0.5.6,<0.11
sphinx>=1.1.2,<1.2
python-subunit
testrepository
+testtools
diff --git a/tox.ini b/tox.ini
index 7386a0e..22c2faa 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,18 +4,15 @@ skipdist = True
envlist = pep8, py27, pypy, py33, py34
[testenv]
+commands = python setup.py test --slowest --testr-args='{posargs}'
setenv = VIRTUAL_ENV={envdir}
usedevelop = True
install_command = pip install {opts} {packages}
-deps = -r{toxinidir}/requirements.txt
- -r{toxinidir}/test-requirements.txt
+deps = -r{toxinidir}/test-requirements.txt
[testenv:pep8]
commands = flake8
-[testenv:pyflakes]
-commands = flake8
-
[testenv:docs]
commands = python setup.py build_sphinx
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/gerritlib.git
More information about the Python-modules-commits
mailing list