Unify string formatting
Use one way of string formatting: replace old `%` style with new `str.format`. Resolve #855.
This commit is contained in:
parent
f984a918b9
commit
4c2d273f07
17 changed files with 67 additions and 65 deletions
|
|
@ -34,17 +34,17 @@ class IllegalObjectIdError(cdist.Error):
|
|||
self.message = message or 'Illegal object id'
|
||||
|
||||
def __str__(self):
|
||||
return '%s: %s' % (self.message, self.object_id)
|
||||
return '{}: {}'.format(self.message, self.object_id)
|
||||
|
||||
|
||||
class MissingObjectIdError(cdist.Error):
|
||||
def __init__(self, type_name):
|
||||
self.type_name = type_name
|
||||
self.message = ("Type %s requires object id (is not a "
|
||||
"singleton type)") % self.type_name
|
||||
self.message = ("Type {} requires object id (is not a "
|
||||
"singleton type)").format(self.type_name)
|
||||
|
||||
def __str__(self):
|
||||
return '%s' % (self.message)
|
||||
return '{}'.format(self.message)
|
||||
|
||||
|
||||
class CdistObject:
|
||||
|
|
@ -142,7 +142,7 @@ class CdistObject:
|
|||
if self.object_marker in self.object_id.split(os.sep):
|
||||
raise IllegalObjectIdError(
|
||||
self.object_id, ('object_id may not contain '
|
||||
'\'%s\'') % self.object_marker)
|
||||
'\'{}\'').format(self.object_marker))
|
||||
if '//' in self.object_id:
|
||||
raise IllegalObjectIdError(
|
||||
self.object_id, 'object_id may not contain //')
|
||||
|
|
@ -189,7 +189,7 @@ class CdistObject:
|
|||
object_id=object_id)
|
||||
|
||||
def __repr__(self):
|
||||
return '<CdistObject %s>' % self.name
|
||||
return '<CdistObject {}>'.format(self.name)
|
||||
|
||||
def __eq__(self, other):
|
||||
"""define equality as 'name is the same'"""
|
||||
|
|
@ -277,7 +277,7 @@ class CdistObject:
|
|||
os.makedirs(path, exist_ok=allow_overwrite)
|
||||
except EnvironmentError as error:
|
||||
raise cdist.Error(('Error creating directories for cdist object: '
|
||||
'%s: %s') % (self, error))
|
||||
'{}: {}').format(self, error))
|
||||
|
||||
def requirements_unfinished(self, requirements):
|
||||
"""Return state whether requirements are satisfied"""
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class InvalidTypeError(cdist.Error):
|
|||
self.source_path = os.path.realpath(self.type_absolute_path)
|
||||
|
||||
def __str__(self):
|
||||
return "Invalid type '%s' at '%s' defined at '%s'" % (
|
||||
return "Invalid type '{}' at '{}' defined at '{}'".format(
|
||||
self.type_path, self.type_absolute_path, self.source_path)
|
||||
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ class CdistType:
|
|||
return cls._instances[name]
|
||||
|
||||
def __repr__(self):
|
||||
return '<CdistType %s>' % self.name
|
||||
return '<CdistType {}>'.format(self.name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and self.name == other.name
|
||||
|
|
|
|||
|
|
@ -122,8 +122,8 @@ class Code:
|
|||
|
||||
def _run_gencode(self, cdist_object, which):
|
||||
cdist_type = cdist_object.cdist_type
|
||||
script = os.path.join(self.local.type_path,
|
||||
getattr(cdist_type, 'gencode_%s_path' % which))
|
||||
gencode_attr = getattr(cdist_type, 'gencode_{}_path'.format(which))
|
||||
script = os.path.join(self.local.type_path, gencode_attr)
|
||||
if os.path.isfile(script):
|
||||
env = os.environ.copy()
|
||||
env.update(self.env)
|
||||
|
|
@ -167,8 +167,8 @@ class Code:
|
|||
|
||||
def _run_code(self, cdist_object, which, env=None):
|
||||
which_exec = getattr(self, which)
|
||||
script = os.path.join(which_exec.object_path,
|
||||
getattr(cdist_object, 'code_%s_path' % which))
|
||||
code_attr = getattr(cdist_object, 'code_{}_path'.format(which))
|
||||
script = os.path.join(which_exec.object_path, code_attr)
|
||||
if which_exec.save_output_streams:
|
||||
stderr_path = os.path.join(cdist_object.stderr_path,
|
||||
'code-' + which)
|
||||
|
|
|
|||
|
|
@ -160,8 +160,8 @@ class Explorer:
|
|||
self.remote.transfer(self.local.global_explorer_path,
|
||||
self.remote.global_explorer_path,
|
||||
self.jobs)
|
||||
self.remote.run(["chmod", "0700",
|
||||
"%s/*" % (self.remote.global_explorer_path)])
|
||||
self.remote.run(["chmod", "0700", "{}/*".format(
|
||||
self.remote.global_explorer_path)])
|
||||
|
||||
def run_global_explorer(self, explorer):
|
||||
"""Run the given global explorer and return it's output."""
|
||||
|
|
@ -242,7 +242,7 @@ class Explorer:
|
|||
destination = os.path.join(self.remote.type_path,
|
||||
cdist_type.explorer_path)
|
||||
self.remote.transfer(source, destination)
|
||||
self.remote.run(["chmod", "0700", "%s/*" % (destination)])
|
||||
self.remote.run(["chmod", "0700", "{}/*".format(destination)])
|
||||
self._type_explorers_transferred.append(cdist_type.name)
|
||||
|
||||
def transfer_object_parameters(self, cdist_object):
|
||||
|
|
|
|||
|
|
@ -80,13 +80,12 @@ class NoInitialManifestError(cdist.Error):
|
|||
|
||||
if user_supplied:
|
||||
if os.path.islink(manifest_path):
|
||||
self.message = "%s: %s -> %s" % (
|
||||
msg_header, manifest_path,
|
||||
os.path.realpath(manifest_path))
|
||||
self.message = "{}: {} -> {}".format(
|
||||
msg_header, manifest_path, os.path.realpath(manifest_path))
|
||||
else:
|
||||
self.message = "%s: %s" % (msg_header, manifest_path)
|
||||
self.message = "{}: {}".format(msg_header, manifest_path)
|
||||
else:
|
||||
self.message = "%s" % (msg_header)
|
||||
self.message = "{}".format(msg_header)
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.message)
|
||||
|
|
@ -107,7 +106,7 @@ class Manifest:
|
|||
self._open_logger()
|
||||
|
||||
self.env = {
|
||||
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
||||
'PATH': "{}:{}".format(self.local.bin_path, os.environ['PATH']),
|
||||
# for use in type emulator
|
||||
'__cdist_type_base_path': self.local.type_path,
|
||||
'__global': self.local.base_path,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue