Use pathclass.Path.open.
This commit is contained in:
parent
c6d7450028
commit
342062dd99
3 changed files with 14 additions and 11 deletions
|
@ -86,7 +86,7 @@ def load_file(filepath, defaults):
|
|||
needs_rewrite = False
|
||||
|
||||
if user_config_exists:
|
||||
with open(path.absolute_path, 'r', encoding='utf-8') as handle:
|
||||
with path.open('r', encoding='utf-8') as handle:
|
||||
user_config = json.load(handle)
|
||||
(config, needs_rewrite) = layer_json(config, user_config)
|
||||
else:
|
||||
|
|
|
@ -36,11 +36,13 @@ def equal_file(filename1, filename2, *args, **kwargs):
|
|||
'''
|
||||
Given two files, return True if they have the same quickid hash.
|
||||
'''
|
||||
filename1 = pathclass.Path(filename1).absolute_path
|
||||
filename2 = pathclass.Path(filename2).absolute_path
|
||||
if os.path.getsize(filename1) != os.path.getsize(filename2):
|
||||
file1 = pathclass.Path(filename1)
|
||||
file2 = pathclass.Path(filename2)
|
||||
file1.assert_is_file()
|
||||
file2.assert_is_file()
|
||||
if file1.size != file2.size:
|
||||
return False
|
||||
with open(filename1, 'rb') as handle1, open(filename2, 'rb') as handle2:
|
||||
with file1.open('rb') as handle1, file2.open('rb') as handle2:
|
||||
return equal_handle(handle1, handle2, *args, **kwargs)
|
||||
|
||||
def matches_handle(handle, other_id):
|
||||
|
@ -65,8 +67,8 @@ def matches_file(filename, other_id):
|
|||
Given a file and a quickid hash, return True if the file matches
|
||||
that hash.
|
||||
'''
|
||||
filename = pathclass.Path(filename).absolute_path
|
||||
with open(filename, 'rb') as handle:
|
||||
file = pathclass.Path(filename)
|
||||
with file.open('rb') as handle:
|
||||
return matches_handle(handle, other_id)
|
||||
|
||||
def quickid_handle(handle, hashtype='md5', chunk_size=CHUNK_SIZE):
|
||||
|
@ -96,8 +98,9 @@ def quickid_file(filename, *args, **kwargs):
|
|||
'''
|
||||
Return the quickid hash for this file.
|
||||
'''
|
||||
filename = pathclass.Path(filename).absolute_path
|
||||
with open(filename, 'rb') as handle:
|
||||
file = pathclass.Path(filename)
|
||||
file.assert_is_file()
|
||||
with file.open('rb') as handle:
|
||||
return quickid_handle(handle, *args, **kwargs)
|
||||
|
||||
def main(argv):
|
||||
|
|
|
@ -438,7 +438,7 @@ def copy_file(
|
|||
|
||||
def handlehelper(path, mode):
|
||||
try:
|
||||
handle = open(path.absolute_path, mode)
|
||||
handle = path.open(mode)
|
||||
return handle
|
||||
except PermissionError as exception:
|
||||
if callback_permission_denied is not None:
|
||||
|
@ -548,7 +548,7 @@ def hash_file(
|
|||
checked_bytes = 0
|
||||
file_size = os.path.getsize(path.absolute_path)
|
||||
|
||||
handle = open(path.absolute_path, 'rb')
|
||||
handle = path.open('rb')
|
||||
with handle:
|
||||
while True:
|
||||
chunk = handle.read(chunk_size)
|
||||
|
|
Loading…
Reference in a new issue