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 d932bba commit d110054
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Change Log
- Added extract_file_from_zip to zip_utils.
- Added http_utils with download function.
- Added get_app_specific_directory, get_os_name, and get_cpu_architecture_name to misc_utils.
- Added normalize_file_path and are_files_equal to file_utils.
- Added normalize_file_path, are_files_equal, and create_random_file to file_utils.
- Added create_temporary_file_name and remove_temporary_file tmpfile_utils.
- Minor fix to misc_utils.create_dict (do not create property only if its value is None).

Expand Down
16 changes: 16 additions & 0 deletions dcicutils/file_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import glob
import os
import pathlib
import random
import string
from typing import List, Optional, Union
from dcicutils.tmpfile_utils import create_temporary_file_name


def search_for_file(file: str,
Expand Down Expand Up @@ -96,3 +99,16 @@ def are_files_equal(filea: str, fileb: str) -> bool:
return True
except Exception:
return False


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:
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)))
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.1b8" # TODO: To become 8.8.5
version = "8.8.4.1b9" # TODO: To become 8.8.5
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down

0 comments on commit d110054

Please sign in to comment.