Skip to content

Commit 84f58ef

Browse files
author
Paulo Barros
committed
Use format() instead of % string operator
1 parent fffc858 commit 84f58ef

File tree

23 files changed

+98
-97
lines changed

23 files changed

+98
-97
lines changed

gitfs/cache/commits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ def __gt__(self, commit):
7070
return self.timestamp > commit.timestamp
7171

7272
def __repr__(self):
73-
return "%s-%s" % (self.time, self.hex[:10])
73+
return "{}-{}".format(self.time, self.hex[:10])

gitfs/cache/gitignore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def update(self):
4747
pattern = re.compile("path(\s*)=(\s*)(\w*)")
4848
results = re.findall(pattern, content)
4949
for result in results:
50-
self.items.append("/%s/*" % result[2])
51-
self.items.append("/%s" % result[2])
52-
self.items.append("%s" % result[2])
50+
self.items.append("/{}/*".format(result[2]))
51+
self.items.append("/{}".format(result[2]))
52+
self.items.append("{}".format(result[2]))
5353

5454
self.cache = {}
5555
self.items += self.hard_ignore

gitfs/merges/accept_mine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class AcceptMine(Merger):
2323
def _create_remote_copy(self, branch_name, upstream, new_branch):
24-
reference = "%s/%s" % (upstream, branch_name)
24+
reference = "{}/{}".format(upstream, branch_name)
2525
remote = self.repository.lookup_branch(reference,
2626
pygit2.GIT_BRANCH_REMOTE)
2727
remote_commit = remote.get_object()

gitfs/repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def ahead(self, upstream, branch):
6464
return ahead
6565

6666
def diverge(self, upstream, branch):
67-
reference = "%s/%s" % (upstream, branch)
67+
reference = "{}/{}".format(upstream, branch)
6868
remote_branch = self.lookup_branch(reference, GIT_BRANCH_REMOTE)
6969
local_branch = self.lookup_branch(branch, GIT_BRANCH_LOCAL)
7070

gitfs/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, remote_url, repo_path, mount_path, credentials,
5353

5454
self.routes = []
5555

56-
log.info('Cloning into %s' % self.repo_path)
56+
log.info('Cloning into {}'.format(self.repo_path))
5757

5858
self.repo = Repository.clone(self.remote_url, self.repo_path,
5959
self.branch, credentials)

gitfs/utils/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_commiter_user(self, args):
162162
return args.user
163163

164164
def get_commiter_email(self, args):
165-
return "%s@%s" % (args.user, socket.gethostname())
165+
return "{}@{}".format(args.user, socket.gethostname())
166166

167167
def get_repo_path(self, args):
168168
return tempfile.mkdtemp(dir="/var/lib/gitfs")

gitfs/utils/decorators/while_not.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def __call__(self, f):
3030
@wraps(f)
3131
def decorated(obj, *args, **kwargs):
3232
if not self.event:
33-
raise ValueError("Except that %s to not be None %s" %
34-
obj.__class__.__name__)
33+
raise ValueError("Except that %s to not be "
34+
"None {}".format(obj.__class__.__name__))
3535
if not isinstance(self.event, Event):
36-
raise TypeError("%s should be of type threading.Event" %
37-
self.event)
36+
raise TypeError("{} should be of type threading."
37+
"Event".format(self.event))
3838

3939
while self.event.is_set():
4040
time.sleep(self.wait)

gitfs/utils/strptime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, format):
6060
spec = SPEC[spec]
6161
pattern.append(spec)
6262
except KeyError:
63-
raise ValueError("unknown specificer: %s" % spec)
63+
raise ValueError("unknown specificer:{}".format(spec))
6464

6565
self.pattern = re.compile(r"(?i)" + "".join(pattern))
6666

gitfs/views/current.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def rename(self, old, new):
4040
new = re.sub(self.regex, '', new)
4141
result = super(CurrentView, self).rename(old, new)
4242

43-
message = "Rename %s to %s" % (old, new)
43+
message = "Rename {} to {}".format(old, new)
4444
self._stage(**{
4545
'remove': os.path.split(old)[1],
4646
'add': new,
@@ -55,7 +55,7 @@ def rename(self, old, new):
5555
def symlink(self, name, target):
5656
result = os.symlink(target, self.repo._full_path(name))
5757

58-
message = "Create symlink to %s for %s" % (target, name)
58+
message = "Create symlink to {} for {}".format(target, name)
5959
self._stage(add=name, message=message)
6060

6161
log.debug("CurrentView: Created symlink to %s from %s", name, target)
@@ -69,7 +69,7 @@ def link(self, name, target):
6969

7070
result = super(CurrentView, self).link(target, name)
7171

72-
message = "Create link to %s for %s" % (target, name)
72+
message = "Create link to {} for {}".format(target, name)
7373
self._stage(add=name, message=message)
7474

7575
log.debug("CurrentView: Created link to %s from %s", name, target)
@@ -106,7 +106,7 @@ def write(self, path, buf, offset, fh):
106106

107107
result = super(CurrentView, self).write(path, buf, offset, fh)
108108
self.dirty[fh] = {
109-
'message': 'Update %s' % path,
109+
'message': 'Update {}'.format(path),
110110
}
111111

112112
log.debug("CurrentView: Wrote %s to %s", len(buf), path)
@@ -117,7 +117,7 @@ def write(self, path, buf, offset, fh):
117117
def mkdir(self, path, mode):
118118
result = super(CurrentView, self).mkdir(path, mode)
119119

120-
keep_path = "%s/.keep" % path
120+
keep_path = "{}/.keep".format(path)
121121
full_path = self.repo._full_path(keep_path)
122122
if not os.path.exists(keep_path):
123123
global writers
@@ -128,7 +128,7 @@ def mkdir(self, path, mode):
128128
super(CurrentView, self).chmod(keep_path, 0o644)
129129

130130
self.dirty[fh] = {
131-
'message': "Create the %s directory" % path,
131+
'message': "Create the {} directory".format(path),
132132
}
133133

134134
self.release(keep_path, fh)
@@ -142,7 +142,7 @@ def create(self, path, mode, fi=None):
142142
super(CurrentView, self).chmod(path, mode)
143143

144144
self.dirty[fh] = {
145-
'message': "Created %s" % path,
145+
'message': "Created {}".format(path),
146146
}
147147

148148
log.debug("CurrentView: Created %s", path)
@@ -163,7 +163,7 @@ def chmod(self, path, mode):
163163
if os.path.isdir(self.repo._full_path(path)):
164164
return result
165165

166-
message = 'Chmod to %s on %s' % (str_mode, path)
166+
message = 'Chmod to {} on {}'.format(str_mode, path)
167167
self._stage(add=path, message=message)
168168

169169
log.debug("CurrentView: Change %s mode to %s", path,
@@ -179,7 +179,7 @@ def fsync(self, path, fdatasync, fh):
179179

180180
result = super(CurrentView, self).fsync(path, fdatasync, fh)
181181

182-
message = 'Fsync %s' % path
182+
message = 'Fsync {}'.format(path)
183183
self._stage(add=path, message=message)
184184

185185
log.debug("CurrentView: Fsync %s", path)
@@ -227,7 +227,7 @@ def release(self, path, fh):
227227
@write_operation
228228
@not_in("ignore", check=["path"])
229229
def rmdir(self, path):
230-
message = 'Delete the %s directory' % path
230+
message = 'Delete the {} directory'.format(path)
231231

232232
# Unlink all the files
233233
full_path = self.repo._full_path(path)
@@ -239,7 +239,7 @@ def rmdir(self, path):
239239
self._stage(remove=os.path.join(path, _file), message=message)
240240

241241
# Delete the actual directory
242-
result = super(CurrentView, self).rmdir("%s/" % path)
242+
result = super(CurrentView, self).rmdir("{}/".format(path))
243243
log.debug("CurrentView: %s", message)
244244

245245
return result
@@ -249,7 +249,7 @@ def rmdir(self, path):
249249
def unlink(self, path):
250250
result = super(CurrentView, self).unlink(path)
251251

252-
message = 'Deleted %s' % path
252+
message = 'Deleted {}'.format(path)
253253
self._stage(remove=path, message=message)
254254

255255
log.debug("CurrentView: Deleted %s", path)
@@ -265,7 +265,8 @@ def _stage(self, message, add=None, remove=None):
265265
paths = self._get_files_from_path(add)
266266
if paths:
267267
for path in paths:
268-
path = path.replace("%s/" % add, "%s/" % remove)
268+
path = path.replace("{}/".format(add),
269+
"{}/".format(remove))
269270
self.repo.index.remove(path)
270271
else:
271272
self.repo.index.remove(remove)
@@ -295,8 +296,8 @@ def _get_files_from_path(self, path):
295296
if os.path.isdir(full_path):
296297
for (dirpath, dirs, files) in os.walk(full_path):
297298
for filename in files:
298-
paths.append("%s/%s" % (dirpath.replace(workdir, ''),
299-
filename))
299+
paths.append("{}/{}".format(
300+
dirpath.replace(workdir, ''), filename))
300301
return paths
301302

302303
def _sanitize(self, path):

gitfs/worker/fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def work(self):
2828
if idle.is_set():
2929
timeout = self.idle_timeout
3030

31-
log.debug("Wait for %s" % timeout)
31+
log.debug("Wait for {}".format(timeout))
3232
fetch.wait(timeout)
3333

3434
if shutting_down.is_set():

gitfs/worker/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def commit(self, jobs):
170170
updates = updates | set(job['params']['add'])
171171
updates = updates | set(job['params']['remove'])
172172

173-
message = "Update %s items" % len(updates)
173+
message = "Update {} items".format(len(updates))
174174

175175
old_head = self.repository.head.target
176176
new_commit = self.repository.commit(message, self.author,

tests/cache/test_commits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def test_cache(self):
4747
cache['2014-09-20'] = Commit(1, 1, "1111111111")
4848
assert sorted(cache.keys()) == ['2014-09-19', '2014-09-20']
4949
asserted_time = datetime.fromtimestamp(mocked_commit.commit_time)
50-
asserted_time = "%s-%s-%s" % (asserted_time.hour, asserted_time.minute,
51-
asserted_time.second)
50+
asserted_time = "{}-{}-{}".format(asserted_time.hour, asserted_time.minute,
51+
asserted_time.second)
5252
assert repr(cache['2014-09-19']) == '[%s-1111111111]' % asserted_time
5353
del cache['2014-09-20']
5454
for commit_date in cache:

tests/integrations/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
5555

5656
class BaseTest(object):
5757
def setup(self):
58-
self.mount_path = "%s" % os.environ["MOUNT_PATH"]
58+
self.mount_path = "{}".format(os.environ["MOUNT_PATH"])
5959

6060
self.repo_name = os.environ["REPO_NAME"]
6161
self.repo_path = os.environ["REPO_PATH"]

tests/integrations/commit/test_read.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
class TestReadCommitView(BaseTest):
2525
def test_listdirs(self):
2626
commits = self.get_commits_by_date()
27-
files = os.listdir("%s/history/%s/%s" % (self.mount_path, self.today,
28-
commits[-1]))
27+
files = os.listdir("{}/history/{}/{}".format(
28+
self.mount_path, self.today, commits[-1]))
2929

3030
real_files = os.listdir(self.repo_path)
3131
real_files.remove(".git")
3232
assert set(files) == set(real_files)
3333

3434
def test_stats(self):
3535
commit = self.get_commits_by_date()[0]
36-
directory = "%s/history/%s/%s" % (self.mount_path, self.today, commit)
37-
filename = "%s/testing" % directory
36+
directory = "{}/history/{}/{}".format(self.mount_path, self.today, commit)
37+
filename = "{}/testing".format(directory)
3838

3939
stats = os.stat(filename)
4040

@@ -47,7 +47,7 @@ def test_stats(self):
4747
for name, value in iteritems(attrs):
4848
assert getattr(stats, name) == value
4949

50-
st_time = "%s %s" % (self.today, "-".join(commit.split("-")[:-1]))
50+
st_time = "{} {}".format(self.today, "-".join(commit.split("-")[:-1]))
5151

5252
format = "%Y-%m-%d %H-%M-%S"
5353
ctime = datetime.fromtimestamp(stats.st_ctime).strftime(format)

tests/integrations/commit/test_write.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ class TestWriteCommitView(ReadOnlyFSTest):
2020
def setup(self):
2121
super(TestWriteCommitView, self).setup()
2222
date = self.get_commit_dates()
23-
self.path = "%s/history/%s/%s" % (self.mount_path, date[0],
24-
self.get_commits_by_date()[0])
23+
self.path = "{}/history/{}/{}".format(self.mount_path, date[0],
24+
self.get_commits_by_date()[0])

tests/integrations/current/test_read.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def test_listdirs(self):
2626
assert dirs == set(['testing', 'me'])
2727

2828
def test_read_from_a_file(self):
29-
with open("%s/testing" % self.current_path) as f:
29+
with open("{}/testing".format(self.current_path)) as f:
3030
content = f.read()
3131
assert content == "just testing around here\n"
3232

3333
def test_get_correct_stats(self):
34-
filename = "%s/testing" % self.current_path
34+
filename = "{}/testing".format(self.current_path)
3535
stats = os.stat(filename)
3636

37-
filename = "%s/testing" % self.repo_path
37+
filename = "{}/testing".format(self.repo_path)
3838
real_stats = os.stat(filename)
3939

4040
attrs = {

0 commit comments

Comments
 (0)