Commit 32c52b7f authored by Guido Günther's avatar Guido Günther

Make pylint happy

parent 94bfcca3
# vim: set fileencoding=utf-8 : # vim: set fileencoding=utf-8 :
# #
# (C) 2011 Guido Guenther <agx@sigxcpu.org> # (C) 2011,2015 Guido Guenther <agx@sigxcpu.org>
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
...@@ -22,6 +22,7 @@ import subprocess ...@@ -22,6 +22,7 @@ import subprocess
import tempfile import tempfile
from gbp.errors import GbpError from gbp.errors import GbpError
class Patch(object): class Patch(object):
""" """
A patch in a L{PatchSeries} A patch in a L{PatchSeries}
...@@ -49,7 +50,7 @@ class Patch(object): ...@@ -49,7 +50,7 @@ class Patch(object):
repr = "<gbp.patch_series.Patch path='%s' " % self.path repr = "<gbp.patch_series.Patch path='%s' " % self.path
if self.topic: if self.topic:
repr += "topic='%s' " % self.topic repr += "topic='%s' " % self.topic
if self.strip != None: if self.strip is not None:
repr += "strip=%d " % self.strip repr += "strip=%d " % self.strip
repr += ">" repr += ">"
return repr return repr
...@@ -72,7 +73,7 @@ class Patch(object): ...@@ -72,7 +73,7 @@ class Patch(object):
header = rfc_header[:-1].lower() header = rfc_header[:-1].lower()
self.info[header] = value.strip() self.info[header] = value.strip()
try: try:
self.long_desc = "".join([ line for line in body ]) self.long_desc = "".join([line for line in body])
body.close() body.close()
except IOError as msg: except IOError as msg:
raise GbpError("Failed to read patch header of '%s': %s" % raise GbpError("Failed to read patch header of '%s': %s" %
...@@ -112,7 +113,7 @@ class Patch(object): ...@@ -112,7 +113,7 @@ class Patch(object):
if ext in self.patch_exts: if ext in self.patch_exts:
subject = base subject = base
except ValueError: except ValueError:
pass # No ext so keep subject as is pass # No ext so keep subject as is
return subject.lstrip('0123456789-') or subject return subject.lstrip('0123456789-') or subject
def _get_info_field(self, key, get_val=None): def _get_info_field(self, key, get_val=None):
...@@ -127,7 +128,7 @@ class Patch(object): ...@@ -127,7 +128,7 @@ class Patch(object):
@param get_val: alternate value if key is not in info dict @param get_val: alternate value if key is not in info dict
@type get_val: C{str} @type get_val: C{str}
""" """
if self.info == None: if self.info is None:
self._read_info() self._read_info()
if key in self.info: if key in self.info:
...@@ -135,7 +136,6 @@ class Patch(object): ...@@ -135,7 +136,6 @@ class Patch(object):
else: else:
return get_val() if get_val else None return get_val() if get_val else None
@property @property
def subject(self): def subject(self):
""" """
...@@ -205,10 +205,10 @@ class PatchSeries(list): ...@@ -205,10 +205,10 @@ class PatchSeries(list):
queue = PatchSeries() queue = PatchSeries()
for line in series: for line in series:
try: try:
if line[0] in [ '\n', '#' ]: if line[0] in ['\n', '#']:
continue continue
except IndexError: except IndexError:
continue # ignore empty lines continue # ignore empty lines
queue.append(klass._parse_line(line, patch_dir)) queue.append(klass._parse_line(line, patch_dir))
return queue return queue
...@@ -223,7 +223,7 @@ class PatchSeries(list): ...@@ -223,7 +223,7 @@ class PatchSeries(list):
>>> PatchSeries._get_topic("/asdf") >>> PatchSeries._get_topic("/asdf")
""" """
topic = os.path.dirname(line) topic = os.path.dirname(line)
if topic in [ '', '/' ]: if topic in ['', '/']:
topic = None topic = None
return topic return topic
...@@ -265,5 +265,3 @@ class PatchSeries(list): ...@@ -265,5 +265,3 @@ class PatchSeries(list):
topic = klass._get_topic(line) topic = klass._get_topic(line)
(patch, split) = klass._split_strip(line) (patch, split) = klass._split_strip(line)
return Patch(os.path.join(patch_dir, patch), topic, split) return Patch(os.path.join(patch_dir, patch), topic, split)
...@@ -89,7 +89,7 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds, filter_cmds=None): ...@@ -89,7 +89,7 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds, filter_cmds=None):
""" """
body = [] body = []
cmd_re = re.compile(r'^%s:\s*(?P<cmd>[a-z-]+)(\s+(?P<args>\S.*))?' % cmd_re = re.compile(r'^%s:\s*(?P<cmd>[a-z-]+)(\s+(?P<args>\S.*))?' %
cmd_tag, flags=re.I) cmd_tag, flags=re.I)
commands = {} commands = {}
for line in info['body'].splitlines(): for line in info['body'].splitlines():
match = re.match(cmd_re, line) match = re.match(cmd_re, line)
...@@ -105,14 +105,12 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds, filter_cmds=None): ...@@ -105,14 +105,12 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds, filter_cmds=None):
commands[cmd] = match.group('args') commands[cmd] = match.group('args')
else: else:
gbp.log.warn("Ignoring unknown gbp-command '%s' in commit %s" gbp.log.warn("Ignoring unknown gbp-command '%s' in commit %s"
% (line, info['id'])) % (line, info['id']))
if filter_cmds is None or cmd not in filter_cmds: if filter_cmds is None or cmd not in filter_cmds:
body.append(line) body.append(line)
else: else:
body.append(line) body.append(line)
msg = '\n'.join(body) msg = '\n'.join(body)
# Add trailing newline if the originial body hat one
#msg += '\n' if info['body'] and info['body'][-1] == '\n' else ''
return (commands, msg) return (commands, msg)
...@@ -193,7 +191,7 @@ def format_patch(outdir, repo, commit_info, series, numbered=True, ...@@ -193,7 +191,7 @@ def format_patch(outdir, repo, commit_info, series, numbered=True,
# Make sure that we don't overwrite existing patches in the series # Make sure that we don't overwrite existing patches in the series
if filepath in series: if filepath in series:
presuffix = '-%d' % len(series) presuffix = '-%d' % len(series)
base = base[:base_maxlen-len(presuffix)] + presuffix base = base[:base_maxlen - len(presuffix)] + presuffix
filename = (num_prefix if numbered else '') + base + suffix filename = (num_prefix if numbered else '') + base + suffix
filepath = os.path.join(outdir, filename) filepath = os.path.join(outdir, filename)
...@@ -220,7 +218,7 @@ def format_diff(outdir, filename, repo, start, end, path_exclude_regex=None): ...@@ -220,7 +218,7 @@ def format_diff(outdir, filename, repo, start, end, path_exclude_regex=None):
info['subject'] = "Raw diff %s..%s" % (start, end) info['subject'] = "Raw diff %s..%s" % (start, end)
info['body'] = ("Raw diff between %s '%s' and\n%s '%s'\n" % info['body'] = ("Raw diff between %s '%s' and\n%s '%s'\n" %
(repo.get_obj_type(start), start, (repo.get_obj_type(start), start,
repo.get_obj_type(end), end)) repo.get_obj_type(end), end))
if not filename: if not filename:
filename = '%s-to-%s.diff' % (start, end) filename = '%s-to-%s.diff' % (start, end)
filename = os.path.join(outdir, filename) filename = os.path.join(outdir, filename)
...@@ -281,7 +279,7 @@ def apply_and_commit_patch(repo, patch, fallback_author, topic=None): ...@@ -281,7 +279,7 @@ def apply_and_commit_patch(repo, patch, fallback_author, topic=None):
"""apply a single patch 'patch', add topic 'topic' and commit it""" """apply a single patch 'patch', add topic 'topic' and commit it"""
author = {'name': patch.author, author = {'name': patch.author,
'email': patch.email, 'email': patch.email,
'date': patch.date } 'date': patch.date}
patch_fn = os.path.basename(patch.path) patch_fn = os.path.basename(patch.path)
if not (author['name'] and author['email']): if not (author['name'] and author['email']):
......
...@@ -26,6 +26,7 @@ from gbp.scripts.pq import generate_patches, export_patches ...@@ -26,6 +26,7 @@ from gbp.scripts.pq import generate_patches, export_patches
import gbp.scripts.common.pq as pq import gbp.scripts.common.pq as pq
import gbp.patch_series import gbp.patch_series
class TestApplyAndCommit(testutils.DebianGitTestRepo): class TestApplyAndCommit(testutils.DebianGitTestRepo):
"""Test L{gbp.pq}'s apply_and_commit""" """Test L{gbp.pq}'s apply_and_commit"""
...@@ -40,7 +41,6 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo): ...@@ -40,7 +41,6 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
pq.apply_and_commit_patch(self.repo, patch, None) pq.apply_and_commit_patch(self.repo, patch, None)
self.assertIn('foo', self.repo.list_files()) self.assertIn('foo', self.repo.list_files())
def test_topic(self): def test_topic(self):
"""Test if setting a topic works""" """Test if setting a topic works"""
patch = gbp.patch_series.Patch(_patch_path('foo.patch')) patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
...@@ -57,7 +57,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo): ...@@ -57,7 +57,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
""" """
def _check_log(msg): def _check_log(msg):
self.assertEqual(msg, "Patch 'foo.patch' has no authorship " self.assertEqual(msg, "Patch 'foo.patch' has no authorship "
"information, using 'Guido Günther <gg@godiug.net>'") "information, using 'Guido Günther <gg@godiug.net>'")
patch = gbp.patch_series.Patch(_patch_path('foo.patch')) patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
...@@ -79,6 +79,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo): ...@@ -79,6 +79,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
self.assertEqual(info['author'].email, 'gg@godiug.net') self.assertEqual(info['author'].email, 'gg@godiug.net')
self.assertIn('foo', self.repo.list_files()) self.assertIn('foo', self.repo.list_files())
class TestApplySinglePatch(testutils.DebianGitTestRepo): class TestApplySinglePatch(testutils.DebianGitTestRepo):
"""Test L{gbp.pq}'s apply_single_patch""" """Test L{gbp.pq}'s apply_single_patch"""
...@@ -94,6 +95,7 @@ class TestApplySinglePatch(testutils.DebianGitTestRepo): ...@@ -94,6 +95,7 @@ class TestApplySinglePatch(testutils.DebianGitTestRepo):
pq.apply_single_patch(self.repo, 'master', patch, None) pq.apply_single_patch(self.repo, 'master', patch, None)
self.assertIn('foo', self.repo.list_files()) self.assertIn('foo', self.repo.list_files())
class TestWritePatch(testutils.DebianGitTestRepo): class TestWritePatch(testutils.DebianGitTestRepo):
"""Test L{gbp.pq}'s write_patch """ """Test L{gbp.pq}'s write_patch """
...@@ -107,7 +109,8 @@ class TestWritePatch(testutils.DebianGitTestRepo): ...@@ -107,7 +109,8 @@ class TestWritePatch(testutils.DebianGitTestRepo):
def test_generate_patches(self): def test_generate_patches(self):
"""Test generation of patches""" """Test generation of patches"""
class opts: patch_numbers = False class opts:
patch_numbers = False
# Add test file with topic: # Add test file with topic:
msg = ("added foo\n\n" msg = ("added foo\n\n"
...@@ -121,7 +124,7 @@ class TestWritePatch(testutils.DebianGitTestRepo): ...@@ -121,7 +124,7 @@ class TestWritePatch(testutils.DebianGitTestRepo):
expected = os.path.join(str(d), 'gbptest', 'added-foo.patch') expected = os.path.join(str(d), 'gbptest', 'added-foo.patch')
self.assertEqual(os.path.basename(patchfile), self.assertEqual(os.path.basename(patchfile),
'added-foo.patch') 'added-foo.patch')
self.assertTrue(os.path.exists(expected)) self.assertTrue(os.path.exists(expected))
logging.debug(open(expected).read()) logging.debug(open(expected).read())
...@@ -134,6 +137,7 @@ class TestWritePatch(testutils.DebianGitTestRepo): ...@@ -134,6 +137,7 @@ class TestWritePatch(testutils.DebianGitTestRepo):
# Branches must be identical afterwards # Branches must be identical afterwards
self.assertEqual('', diff) self.assertEqual('', diff)
class TestExport(testutils.DebianGitTestRepo): class TestExport(testutils.DebianGitTestRepo):
class Options(object): class Options(object):
drop = True drop = True
...@@ -158,15 +162,15 @@ class TestExport(testutils.DebianGitTestRepo): ...@@ -158,15 +162,15 @@ class TestExport(testutils.DebianGitTestRepo):
class TestParseGbpCommand(unittest.TestCase): class TestParseGbpCommand(unittest.TestCase):
def test_empty_body(self): def test_empty_body(self):
"""Test command filtering with an empty body""" """Test command filtering with an empty body"""
info = { 'body': '' } info = {'body': ''}
(cmds, body) = pq.parse_gbp_commands(info, ['tag'], ['cmd1'], ['cmd2']) (cmds, body) = pq.parse_gbp_commands(info, ['tag'], ['cmd1'], ['cmd2'])
self.assertEquals(cmds, {}) self.assertEquals(cmds, {})
self.assertEquals(body, '') self.assertEquals(body, '')
def test_noarg_cmd(self): def test_noarg_cmd(self):
orig_body = '\n'.join(["Foo", orig_body = '\n'.join(["Foo",
"tag: cmd1"]) "tag: cmd1"])
info = { 'body': orig_body } info = {'body': orig_body}
(cmds, body) = pq.parse_gbp_commands(info, 'tag', ['cmd'], ['argcmd']) (cmds, body) = pq.parse_gbp_commands(info, 'tag', ['cmd'], ['argcmd'])
self.assertEquals(cmds, {'cmd': None}) self.assertEquals(cmds, {'cmd': None})
self.assertEquals(body, orig_body) self.assertEquals(body, orig_body)
...@@ -174,7 +178,7 @@ class TestParseGbpCommand(unittest.TestCase): ...@@ -174,7 +178,7 @@ class TestParseGbpCommand(unittest.TestCase):
def test_filter_cmd(self): def test_filter_cmd(self):
orig_body = '\n'.join(["Foo", orig_body = '\n'.join(["Foo",
"tag: cmd1"]) "tag: cmd1"])
info = { 'body': orig_body } info = {'body': orig_body}
(cmds, body) = pq.parse_gbp_commands(info, 'tag', ['cmd'], ['argcmd'], ['cmd']) (cmds, body) = pq.parse_gbp_commands(info, 'tag', ['cmd'], ['argcmd'], ['cmd'])
self.assertEquals(cmds, {'cmd': None}) self.assertEquals(cmds, {'cmd': None})
self.assertEquals(body, 'Foo') self.assertEquals(body, 'Foo')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment