Commit f982ccbb authored by Guido Günther's avatar Guido Günther

Use cls consistently

So far we used a mixture of klass and cls to denote the class variable.

Git-Dch: Ignore
parent 6f75d7c4
......@@ -366,7 +366,7 @@ class GbpOptionParser(OptionParser):
list_opts = ['filter', 'component']
@classmethod
def get_config_files(klass, no_local=False):
def get_config_files(cls, no_local=False):
"""
Get list of config files from the I{GBP_CONF_FILES} environment
variable.
......@@ -394,7 +394,7 @@ class GbpOptionParser(OptionParser):
>>> if conf_backup is not None: os.environ['GBP_CONF_FILES'] = conf_backup
"""
envvar = os.environ.get('GBP_CONF_FILES')
files = envvar.split(':') if envvar else [f for (f, _) in klass.def_config_files]
files = envvar.split(':') if envvar else [f for (f, _) in cls.def_config_files]
files = [os.path.expanduser(fname) for fname in files]
if no_local:
files = [fname for fname in files if fname.startswith('/')]
......
......@@ -49,7 +49,7 @@ class ChangeLogSection(object):
return self._version
@classmethod
def parse(klass, section):
def parse(cls, section):
"""
Parse one changelog section
......@@ -61,7 +61,7 @@ class ChangeLogSection(object):
header = section.split('\n')[0]
package = header.split()[0]
version = header.split()[1][1:-1]
return klass(package, version)
return cls(package, version)
class ChangeLog(object):
......
......@@ -74,7 +74,7 @@ class DebianSourceFormat(object):
return "%s (%s)" % (self._version, self._type)
@classmethod
def parse_file(klass, filename):
def parse_file(cls, filename):
"""
Parse debian/source/format file
......@@ -95,10 +95,10 @@ class DebianSourceFormat(object):
>>> os.unlink(t.name)
"""
with open(filename) as f:
return klass(f.read())
return cls(f.read())
@classmethod
def from_content(klass, version, type, format_file=None):
def from_content(cls, version, type, format_file=None):
"""
Write a format file from I{type} and I{format} at
I{format_file}
......@@ -108,10 +108,10 @@ class DebianSourceFormat(object):
@param format_file: the format file to create with
the above parameters
"""
format_file = format_file or klass.format_file
with open(klass.format_file, 'w') as f:
format_file = format_file or cls.format_file
with open(cls.format_file, 'w') as f:
f.write("%s (%s)" % (version, type))
return klass.parse_file(klass.format_file)
return cls.parse_file(cls.format_file)
if __name__ == "__main__":
......
......@@ -1865,7 +1865,7 @@ class GitRepository(object):
#{ Repository Creation
@classmethod
def create(klass, path, description=None, bare=False):
def create(cls, path, description=None, bare=False):
"""
Create a repository at path
......@@ -1886,12 +1886,12 @@ class GitRepository(object):
if not os.path.exists(abspath):
os.makedirs(abspath)
try:
stdout, stderr, ret = klass.__git_inout(command='init',
args=args.args,
input=None,
extra_env=None,
cwd=abspath,
capture_stderr=True)
stdout, stderr, ret = cls.__git_inout(command='init',
args=args.args,
input=None,
extra_env=None,
cwd=abspath,
capture_stderr=True)
except Exception as excobj:
raise GitRepositoryError("Error running git init: %s" % excobj)
if ret:
......@@ -1901,14 +1901,14 @@ class GitRepository(object):
with open(os.path.join(abspath, git_dir, "description"), 'w') as f:
description += '\n' if description[-1] != '\n' else ''
f.write(description)
return klass(abspath)
return cls(abspath)
except OSError as err:
raise GitRepositoryError("Cannot create Git repository at '%s': %s"
% (abspath, err[1]))
return None
@classmethod
def clone(klass, path, remote, depth=0, recursive=False, mirror=False,
def clone(cls, path, remote, depth=0, recursive=False, mirror=False,
bare=False, auto_name=True, reference=None):
"""
Clone a git repository at I{remote} to I{path}.
......@@ -1952,12 +1952,12 @@ class GitRepository(object):
os.makedirs(abspath)
try:
stdout, stderr, ret = klass.__git_inout(command='clone',
args=args.args,
input=None,
extra_env=None,
cwd=abspath,
capture_stderr=True)
stdout, stderr, ret = cls.__git_inout(command='clone',
args=args.args,
input=None,
extra_env=None,
cwd=abspath,
capture_stderr=True)
except Exception as excobj:
raise GitRepositoryError("Error running git clone: %s" % excobj)
if ret:
......@@ -1973,7 +1973,7 @@ class GitRepository(object):
name = "%s.git" % name
elif name.endswith('.git'):
name = name[:-4]
return klass(os.path.join(abspath, name))
return cls(os.path.join(abspath, name))
except OSError as err:
raise GitRepositoryError("Cannot clone Git repository "
"'%s' to '%s': %s"
......
......@@ -167,7 +167,7 @@ class PatchSeries(list):
level_re = re.compile('-p(?P<level>[0-9]+)')
@classmethod
def read_series_file(klass, seriesfile):
def read_series_file(cls, seriesfile):
"""Read a series file into L{Patch} objects"""
patch_dir = os.path.dirname(seriesfile)
......@@ -179,12 +179,12 @@ class PatchSeries(list):
except Exception as err:
raise GbpError("Cannot open series file: %s" % err)
queue = klass._read_series(s, patch_dir)
queue = cls._read_series(s, patch_dir)
s.close()
return queue
@classmethod
def _read_series(klass, series, patch_dir):
def _read_series(cls, series, patch_dir):
"""
Read patch series
......@@ -211,7 +211,7 @@ class PatchSeries(list):
continue
except IndexError:
continue # ignore empty lines
queue.append(klass._parse_line(line, patch_dir))
queue.append(cls._parse_line(line, patch_dir))
return queue
@staticmethod
......@@ -230,7 +230,7 @@ class PatchSeries(list):
return topic
@classmethod
def _strip_comment(klass, line):
def _strip_comment(cls, line):
"""
Strip a comment from a series file line
......@@ -241,10 +241,10 @@ class PatchSeries(list):
>>> PatchSeries._strip_comment("leave/level/intact -p1 # comment # text")
'leave/level/intact -p1'
"""
return re.sub(klass.comment_re, '', line)
return re.sub(cls.comment_re, '', line)
@classmethod
def _split_strip(klass, line):
def _split_strip(cls, line):
"""
Separate the -p<num> option from the patch name
......@@ -260,7 +260,7 @@ class PatchSeries(list):
split = line.rsplit(None, 1)
if len(split) > 1:
m = klass.level_re.match(split[1])
m = cls.level_re.match(split[1])
if m:
patch = split[0]
strip = int(m.group('level'))
......@@ -268,7 +268,7 @@ class PatchSeries(list):
return (patch, strip)
@classmethod
def _parse_line(klass, line, patch_dir):
def _parse_line(cls, line, patch_dir):
"""
Parse a single line from a series file
......@@ -277,7 +277,7 @@ class PatchSeries(list):
>>> PatchSeries._parse_line("a/b", '.')
<gbp.patch_series.Patch path='./a/b' topic='a' >
"""
line = klass._strip_comment(line.rstrip())
topic = klass._get_topic(line)
(patch, split) = klass._split_strip(line)
line = cls._strip_comment(line.rstrip())
topic = cls._get_topic(line)
(patch, split) = cls._split_strip(line)
return Patch(os.path.join(patch_dir, patch), topic, split)
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