Skip to content
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

Sourcery refactored master branch #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Feb 21, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from dansan February 21, 2022 07:26
Comment on lines -64 to +66
self._error_tmp = dict()
self._move_tmp = dict()
self._previous_stat = dict()
self._error_tmp = {}
self._move_tmp = {}
self._previous_stat = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncClient.__init__ refactored with the following changes:

Comment on lines -165 to +175
if not handler in inotify.adapters._LOGGER.handlers:
if handler not in inotify.adapters._LOGGER.handlers:
inotify.adapters._LOGGER.addHandler(handler)
inotify.adapters._LOGGER.setLevel(self.logger.level)
notifyier = inotify.adapters.InotifyTree(base_dir, mask=mask)
for event in notifyier.event_gen():
if event is not None:
header, type_names, watch_path, filename = event
if not any([tn in HANDLE_EVENTS for tn in type_names]):
if all(tn not in HANDLE_EVENTS for tn in type_names):
self.logger.debug("ignoring event type_names=%r", type_names)
continue
if any([re.search(regex, filename) for regex in FILE_IGNORE_REGEX]):
if any(re.search(regex, filename) for regex in FILE_IGNORE_REGEX):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncClient.watch_dir refactored with the following changes:

Comment on lines -211 to +212
if "IN_ISDIR" in action:
if "IN_CREATE" in action:
if "IN_CREATE" in action:
if "IN_ISDIR" in action:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncClient.handle_fs_event refactored with the following changes:

This removes the following comments ( why? ):

# prevent unnecessary request by detecting IN_ATTRIB following
# file was moved away, noticed by request.add_stat() above
# IN_CREATE and IN_CLOSE_WRITE without stat change
# moved in from outside of inotify-observed tree
# prevent unnecessary request in case of an empty file

Comment on lines -457 to +402
processes = list()
processes = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

if key == "data":
self._request[key] = self.encode_binary(value)
else:
self._request[key] = value
self._request[key] = self.encode_binary(value) if key == "data" else value
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ZRequest.__setitem__ refactored with the following changes:

Comment on lines -448 to +455
self.diff_tree = dict()
self.diff_tree = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncServer.sync_tree refactored with the following changes:

Comment on lines +591 to -604
elif node["st_size"] == 0:
self.logger.info("truncate %r", file_path)
with open(file_path, "w") as fp:
fp.truncate(0)
warn = self.utime(file_path, node["st_atime"], node["st_mtime"])
return dict(cmd="truncate", result="done", name=file_path, warn=warn)
elif node["st_blocks"] < MIN_BLOCK_DIFF_SIZE:
# not worth diffing on both ends and patching
self.logger.info("req full %r", file_path)
return dict(cmd="full", name=file_path)
else:
if node["st_size"] == 0:
self.logger.info("truncate %r", file_path)
with open(file_path, "w") as fp:
fp.truncate(0)
warn = self.utime(file_path, node["st_atime"], node["st_mtime"])
return dict(cmd="truncate", result="done", name=file_path, warn=warn)
elif node["st_blocks"] < MIN_BLOCK_DIFF_SIZE:
# not worth diffing on both ends and patching
self.logger.info("req full %r", file_path)
return dict(cmd="full", name=file_path)
else:
self.logger.info("req diff %r", file_path)
sig = self.get_signature(file_path)
return dict(cmd="diff", name=file_path, data=ZRequest.encode_binary(sig.read()))
self.logger.info("req diff %r", file_path)
sig = self.get_signature(file_path)
return dict(cmd="diff", name=file_path, data=ZRequest.encode_binary(sig.read()))
else:
raise RuntimeError("We should not be here.")
else:
# src_st == dst_st
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncServer.cmp_node refactored with the following changes:

This removes the following comments ( why? ):

# src_st == dst_st

Comment on lines -693 to +703
if _node["cmd"] != "ignore":
if (not all([isinstance(_node[x], int) for x in ["st_mode", "st_uid", "st_gid", "st_size"]]) or
not isinstance(_node["st_mtime"], float)):
return (False, "Bad src_tree _node {}. Item 'st_mode', 'st_uid', 'st_gid', 'st_mtime' or "
"'st_size' has wrong type.".format(_node))
if _node["cmd"] != "ignore" and (
not all(
isinstance(_node[x], int)
for x in ["st_mode", "st_uid", "st_gid", "st_size"]
)
or not isinstance(_node["st_mtime"], float)
):
return (False, "Bad src_tree _node {}. Item 'st_mode', 'st_uid', 'st_gid', 'st_mtime' or "
"'st_size' has wrong type.".format(_node))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncServer.validate_tree_structure.validate_node refactored with the following changes:

Comment on lines -773 to +779
if exc.errno == 2:
pass
else:
if exc.errno != 2:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncServer.run refactored with the following changes:

Comment on lines -804 to +809
else:
self.logger.error("Checksum mismatch after patching %r.", request.name)
return {"status": 2, "reason": "Checksum mismatch for '{}'.".format(request.name)}
self.logger.error("Checksum mismatch after patching %r.", request.name)
return {"status": 2, "reason": "Checksum mismatch for '{}'.".format(request.name)}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SyncServer.post_file_write_action refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Feb 21, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 2.85%.

Quality metrics Before After Change
Complexity 20.96 😞 15.75 🙂 -5.21 👍
Method Length 78.85 🙂 75.65 🙂 -3.20 👍
Working memory 11.56 😞 10.97 😞 -0.59 👍
Quality 52.26% 🙂 55.11% 🙂 2.85% 👍
Other metrics Before After Change
Lines 1320 1272 -48
Changed files Quality Before Quality After Quality Change
zrsync/zrsync.py 36.70% 😞 43.21% 😞 6.51% 👍
zrsync/zrsyncd.py 60.32% 🙂 60.69% 🙂 0.37% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
zrsync/zrsyncd.py SyncServer.cmp_node 69 ⛔ 597 ⛔ 21 ⛔ 4.78% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
zrsync/zrsyncd.py SyncServer.run 29 😞 369 ⛔ 22 ⛔ 14.79% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
zrsync/zrsync.py SyncClient.handle_fs_event 35 ⛔ 344 ⛔ 16 ⛔ 16.96% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
zrsync/zrsync.py SyncClient.stat_dir 25 😞 271 ⛔ 14 😞 26.51% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
zrsync/zrsyncd.py SyncServer.sync_tree 25 😞 263 ⛔ 13 😞 28.28% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants