Skip to content

Issue #227: Fix code quality issues #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gitfs/cache/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def __gt__(self, commit):
return self.timestamp > commit.timestamp

def __repr__(self):
return "%s-%s" % (self.time, self.hex[:10])
return "{}-{}".format(self.time, self.hex[:10])
6 changes: 3 additions & 3 deletions gitfs/cache/gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def update(self):
pattern = re.compile("path(\s*)=(\s*)(\w*)")
results = re.findall(pattern, content)
for result in results:
self.items.append("/%s/*" % result[2])
self.items.append("/%s" % result[2])
self.items.append("%s" % result[2])
self.items.append("/{}/*".format(result[2]))
self.items.append("/{}".format(result[2]))
self.items.append("{}".format(result[2]))

self.cache = {}
self.items += self.hard_ignore
Expand Down
2 changes: 1 addition & 1 deletion gitfs/merges/accept_mine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class AcceptMine(Merger):
def _create_remote_copy(self, branch_name, upstream, new_branch):
reference = "%s/%s" % (upstream, branch_name)
reference = "{}/{}".format(upstream, branch_name)
remote = self.repository.lookup_branch(reference,
pygit2.GIT_BRANCH_REMOTE)
remote_commit = remote.get_object()
Expand Down
2 changes: 1 addition & 1 deletion gitfs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def ahead(self, upstream, branch):
return ahead

def diverge(self, upstream, branch):
reference = "%s/%s" % (upstream, branch)
reference = "{}/{}".format(upstream, branch)
remote_branch = self.lookup_branch(reference, GIT_BRANCH_REMOTE)
local_branch = self.lookup_branch(branch, GIT_BRANCH_LOCAL)

Expand Down
2 changes: 1 addition & 1 deletion gitfs/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, remote_url, repo_path, mount_path, credentials,

self.routes = []

log.info('Cloning into %s' % self.repo_path)
log.info('Cloning into {}'.format(self.repo_path))

self.repo = Repository.clone(self.remote_url, self.repo_path,
self.branch, credentials)
Expand Down
2 changes: 1 addition & 1 deletion gitfs/utils/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_commiter_user(self, args):
return args.user

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

def get_repo_path(self, args):
return tempfile.mkdtemp(dir="/var/lib/gitfs")
Expand Down
8 changes: 4 additions & 4 deletions gitfs/utils/decorators/while_not.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def __call__(self, f):
@wraps(f)
def decorated(obj, *args, **kwargs):
if not self.event:
raise ValueError("Except that %s to not be None %s" %
obj.__class__.__name__)
raise ValueError("Except that %s to not be "
"None {}".format(obj.__class__.__name__))
if not isinstance(self.event, Event):
raise TypeError("%s should be of type threading.Event" %
self.event)
raise TypeError("{} should be of type threading."
"Event".format(self.event))

while self.event.is_set():
time.sleep(self.wait)
Expand Down
2 changes: 1 addition & 1 deletion gitfs/utils/strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, format):
spec = SPEC[spec]
pattern.append(spec)
except KeyError:
raise ValueError("unknown specificer: %s" % spec)
raise ValueError("unknown specificer:{}".format(spec))

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

Expand Down
31 changes: 16 additions & 15 deletions gitfs/views/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rename(self, old, new):
new = re.sub(self.regex, '', new)
result = super(CurrentView, self).rename(old, new)

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

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

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

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

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

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

result = super(CurrentView, self).write(path, buf, offset, fh)
self.dirty[fh] = {
'message': 'Update %s' % path,
'message': 'Update {}'.format(path),
}

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

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

self.dirty[fh] = {
'message': "Create the %s directory" % path,
'message': "Create the {} directory".format(path),
}

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

self.dirty[fh] = {
'message': "Created %s" % path,
'message': "Created {}".format(path),
}

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

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

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

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

message = 'Fsync %s' % path
message = 'Fsync {}'.format(path)
self._stage(add=path, message=message)

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

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

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

return result
Expand All @@ -249,7 +249,7 @@ def rmdir(self, path):
def unlink(self, path):
result = super(CurrentView, self).unlink(path)

message = 'Deleted %s' % path
message = 'Deleted {}'.format(path)
self._stage(remove=path, message=message)

log.debug("CurrentView: Deleted %s", path)
Expand All @@ -265,7 +265,8 @@ def _stage(self, message, add=None, remove=None):
paths = self._get_files_from_path(add)
if paths:
for path in paths:
path = path.replace("%s/" % add, "%s/" % remove)
path = path.replace("{}/".format(add),
"{}/".format(remove))
self.repo.index.remove(path)
else:
self.repo.index.remove(remove)
Expand Down Expand Up @@ -295,8 +296,8 @@ def _get_files_from_path(self, path):
if os.path.isdir(full_path):
for (dirpath, dirs, files) in os.walk(full_path):
for filename in files:
paths.append("%s/%s" % (dirpath.replace(workdir, ''),
filename))
paths.append("{}/{}".format(
dirpath.replace(workdir, ''), filename))
return paths

def _sanitize(self, path):
Expand Down
2 changes: 1 addition & 1 deletion gitfs/worker/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def work(self):
if idle.is_set():
timeout = self.idle_timeout

log.debug("Wait for %s" % timeout)
log.debug("Wait for {}".format(timeout))
fetch.wait(timeout)

if shutting_down.is_set():
Expand Down
2 changes: 1 addition & 1 deletion gitfs/worker/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def commit(self, jobs):
updates = updates | set(job['params']['add'])
updates = updates | set(job['params']['remove'])

message = "Update %s items" % len(updates)
message = "Update {} items".format(len(updates))

old_head = self.repository.head.target
new_commit = self.repository.commit(message, self.author,
Expand Down
4 changes: 2 additions & 2 deletions tests/cache/test_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def test_cache(self):
cache['2014-09-20'] = Commit(1, 1, "1111111111")
assert sorted(cache.keys()) == ['2014-09-19', '2014-09-20']
asserted_time = datetime.fromtimestamp(mocked_commit.commit_time)
asserted_time = "%s-%s-%s" % (asserted_time.hour, asserted_time.minute,
asserted_time.second)
asserted_time = "{}-{}-{}".format(asserted_time.hour, asserted_time.minute,
asserted_time.second)
assert repr(cache['2014-09-19']) == '[%s-1111111111]' % asserted_time
del cache['2014-09-20']
for commit_date in cache:
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from six import string_types


class Sh:
class Sh(object):
def __init__(self, cwd=None):
self.command = ""
self.cwd = cwd
Expand All @@ -42,7 +42,7 @@ def __call__(self, *args, **kwargs):
cwd=self.cwd).stdout.read().decode()


class pull:
class pull(object):
def __init__(self, sh):
self.sh = sh

Expand All @@ -55,7 +55,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

class BaseTest(object):
def setup(self):
self.mount_path = "%s" % os.environ["MOUNT_PATH"]
self.mount_path = "{}".format(os.environ["MOUNT_PATH"])

self.repo_name = os.environ["REPO_NAME"]
self.repo_path = os.environ["REPO_PATH"]
Expand Down
10 changes: 5 additions & 5 deletions tests/integrations/commit/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
class TestReadCommitView(BaseTest):
def test_listdirs(self):
commits = self.get_commits_by_date()
files = os.listdir("%s/history/%s/%s" % (self.mount_path, self.today,
commits[-1]))
files = os.listdir("{}/history/{}/{}".format(
self.mount_path, self.today, commits[-1]))

real_files = os.listdir(self.repo_path)
real_files.remove(".git")
assert set(files) == set(real_files)

def test_stats(self):
commit = self.get_commits_by_date()[0]
directory = "%s/history/%s/%s" % (self.mount_path, self.today, commit)
filename = "%s/testing" % directory
directory = "{}/history/{}/{}".format(self.mount_path, self.today, commit)
filename = "{}/testing".format(directory)

stats = os.stat(filename)

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

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

format = "%Y-%m-%d %H-%M-%S"
ctime = datetime.fromtimestamp(stats.st_ctime).strftime(format)
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/commit/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ class TestWriteCommitView(ReadOnlyFSTest):
def setup(self):
super(TestWriteCommitView, self).setup()
date = self.get_commit_dates()
self.path = "%s/history/%s/%s" % (self.mount_path, date[0],
self.get_commits_by_date()[0])
self.path = "{}/history/{}/{}".format(self.mount_path, date[0],
self.get_commits_by_date()[0])
6 changes: 3 additions & 3 deletions tests/integrations/current/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def test_listdirs(self):
assert dirs == set(['testing', 'me'])

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

def test_get_correct_stats(self):
filename = "%s/testing" % self.current_path
filename = "{}/testing".format(self.current_path)
stats = os.stat(filename)

filename = "%s/testing" % self.repo_path
filename = "{}/testing".format(self.repo_path)
real_stats = os.stat(filename)

attrs = {
Expand Down
Loading