dcicutils 8.8.4.1b4__py3-none-any.whl → 8.8.4.1b6__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
dcicutils/misc_utils.py CHANGED
@@ -1524,7 +1524,7 @@ def right_trim(list_or_tuple: Union[List[Any], Tuple[Any]],
1524
1524
  def create_dict(**kwargs) -> dict:
1525
1525
  result = {}
1526
1526
  for name in kwargs:
1527
- if kwargs[name]:
1527
+ if not (kwargs[name] is None):
1528
1528
  result[name] = kwargs[name]
1529
1529
  return result
1530
1530
 
@@ -26,6 +26,9 @@ def temporary_file(name: Optional[str] = None, suffix: Optional[str] = None,
26
26
 
27
27
 
28
28
  def remove_temporary_directory(tmp_directory_name: str) -> None:
29
+ """
30
+ Removes the given directory, recursively; but ONLY if it is (somewhere) within the system temporary directory.
31
+ """
29
32
  def is_temporary_directory(path: str) -> bool:
30
33
  try:
31
34
  tmpdir = tempfile.gettempdir()
@@ -34,3 +37,26 @@ def remove_temporary_directory(tmp_directory_name: str) -> None:
34
37
  return False
35
38
  if is_temporary_directory(tmp_directory_name): # Guard against errant deletion.
36
39
  shutil.rmtree(tmp_directory_name)
40
+
41
+
42
+ def create_temporary_file_name(suffix: Optional[str] = None) -> str:
43
+ """
44
+ Generates and returns the full path to file within the system temporary directory.
45
+ """
46
+ with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp_file:
47
+ tmp_file_name = tmp_file.name
48
+ return tmp_file_name
49
+
50
+
51
+ def remove_temporary_file(tmp_file_name: str) -> bool:
52
+ """
53
+ Removes the given file; but ONLY if it is (somewhere) within the system temporary directory.
54
+ """
55
+ try:
56
+ tmpdir = tempfile.gettempdir()
57
+ if (os.path.commonpath([tmpdir, tmp_file_name]) == tmpdir) and os.path.isfile(tmp_file_name):
58
+ os.remove(tmp_file_name)
59
+ return True
60
+ return False
61
+ except Exception:
62
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.8.4.1b4
3
+ Version: 8.8.4.1b6
4
4
  Summary: Utility package for interacting with the 4DN Data Portal and other 4DN resources
5
5
  Home-page: https://github.com/4dn-dcic/utils
6
6
  License: MIT
@@ -44,7 +44,7 @@ dcicutils/license_policies/park-lab-gpl-pipeline.jsonc,sha256=vLZkwm3Js-kjV44nug
44
44
  dcicutils/license_policies/park-lab-pipeline.jsonc,sha256=9qlY0ASy3iUMQlr3gorVcXrSfRHnVGbLhkS427UaRy4,283
45
45
  dcicutils/license_utils.py,sha256=d1cq6iwv5Ju-VjdoINi6q7CPNNL7Oz6rcJdLMY38RX0,46978
46
46
  dcicutils/log_utils.py,sha256=7pWMc6vyrorUZQf-V-M3YC6zrPgNhuV_fzm9xqTPph0,10883
47
- dcicutils/misc_utils.py,sha256=lbvH1ahdTw1DZUhkP-SN1bqZo3Qg8NNs2cCUNtaVbMs,105516
47
+ dcicutils/misc_utils.py,sha256=Nw47AZs-cSOzGp5TZWrQZftePcahz1yfw6iNwOzUt-s,105530
48
48
  dcicutils/obfuscation_utils.py,sha256=fo2jOmDRC6xWpYX49u80bVNisqRRoPskFNX3ymFAmjw,5963
49
49
  dcicutils/opensearch_utils.py,sha256=V2exmFYW8Xl2_pGFixF4I2Cc549Opwe4PhFi5twC0M8,1017
50
50
  dcicutils/portal_object_utils.py,sha256=gDXRgPsRvqCFwbC8WatsuflAxNiigOnqr0Hi93k3AgE,15422
@@ -68,13 +68,13 @@ dcicutils/structured_data.py,sha256=BQuIMv6OPySsn6YxtXE2Er-zLE2QJuCYhEQ3V0u_UXY,
68
68
  dcicutils/submitr/progress_constants.py,sha256=5bxyX77ql8qEJearfHEvsvXl7D0GuUODW0T65mbRmnE,2895
69
69
  dcicutils/submitr/ref_lookup_strategy.py,sha256=Js2cVznTmgjciLWBPLCvMiwLIHXjDn3jww-gJPjYuFw,3467
70
70
  dcicutils/task_utils.py,sha256=MF8ujmTD6-O2AC2gRGPHyGdUrVKgtr8epT5XU8WtNjk,8082
71
- dcicutils/tmpfile_utils.py,sha256=n95XF8dZVbQRSXBZTGToXXfSs3JUVRyN6c3ZZ0nhAWI,1403
71
+ dcicutils/tmpfile_utils.py,sha256=fFqchs-WhXa0HyOE3o_O7nuSVOgqfiPIbJRHQ4wBQxI,2295
72
72
  dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
73
73
  dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
74
74
  dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
75
75
  dcicutils/zip_utils.py,sha256=_Y9EmL3D2dUZhxucxHvrtmmlbZmK4FpSsHEb7rGSJLU,3265
76
- dcicutils-8.8.4.1b4.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
77
- dcicutils-8.8.4.1b4.dist-info/METADATA,sha256=cddMbLW_q0x49LbY99E3nCOHwzVpoNUk7cYmzrwSPhk,3396
78
- dcicutils-8.8.4.1b4.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
79
- dcicutils-8.8.4.1b4.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
80
- dcicutils-8.8.4.1b4.dist-info/RECORD,,
76
+ dcicutils-8.8.4.1b6.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
77
+ dcicutils-8.8.4.1b6.dist-info/METADATA,sha256=2keMsnO3Jxtn7gad94bPZLA0aX0k-LO4UOtL3r9gj08,3396
78
+ dcicutils-8.8.4.1b6.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
79
+ dcicutils-8.8.4.1b6.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
80
+ dcicutils-8.8.4.1b6.dist-info/RECORD,,