Skip to content

Commit

Permalink
added are_files_equal to file_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Apr 25, 2024
1 parent d110054 commit 556f60b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions dcicutils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,26 @@ def are_files_equal(filea: str, fileb: str) -> bool:
def create_random_file(file: Optional[str] = None,
prefix: Optional[str] = None, suffix: Optional[str] = None,
nbytes: int = 1024, binary: bool = False) -> str:
if not file:
if not isinstance(nbytes, int) or nbytes < 0:
nbytes = 0
if not isinstance(file, str) or not file:
if not isinstance(prefix, str):
prefix = ""
if not isinstance(suffix, str):
suffix = ""
file = create_temporary_file_name(prefix=prefix, suffix=suffix)
with open(file, "wb" if binary is True else "w") as f:
if binary is True:
f.write(os.urandom(nbytes))
else:
f.write(''.join(random.choices(string.ascii_letters + string.digits, k=nbytes)))
nchars = 81
nlines = nbytes // nchars
nremainder = nbytes % nchars
for n in range(nlines):
f.write("".join(random.choices(string.ascii_letters + string.digits, k=nchars - 1)))
f.write("\n")
if nremainder > 1:
f.write("".join(random.choices(string.ascii_letters + string.digits, k=nremainder - 1)))
if nremainder > 0:
f.write("\n")
return file
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.4.1b9" # TODO: To become 8.8.5
version = "8.8.4.1b10" # TODO: To become 8.8.5
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 556f60b

Please sign in to comment.