cannect 1.0.2__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cannect/utils/tools.py CHANGED
@@ -1,8 +1,9 @@
1
+ from cannect.config import env
1
2
  from pathlib import Path
2
- from typing import AnyStr, Callable, Iterable, List, Union
3
+ from typing import Callable, Iterable, List, Union
3
4
  from xml.etree.ElementTree import Element, ElementTree
4
5
  from xml.dom import minidom
5
- import os, zipfile, shutil, io, re
6
+ import os, zipfile, shutil, io, re, stat
6
7
 
7
8
 
8
9
  def unzip(src: Union[str, Path], to: Union[str, Path] = "") -> bool:
@@ -38,7 +39,12 @@ def zip(path:Union[str, Path]):
38
39
  return
39
40
 
40
41
  def copy_to(file:Union[str, Path], dst:Union[str, Path]) -> str:
41
- shutil.copy(file, dst)
42
+ if os.path.isfile(str(file)):
43
+ os.chmod(dst, stat.S_IWRITE)
44
+ os.chmod(file, stat.S_IWRITE)
45
+ shutil.copy(file, dst)
46
+ else:
47
+ shutil.copytree(file, dst, dirs_exist_ok=True)
42
48
  # if '.' in os.path.basename(file):
43
49
  # shutil.copy(file, dst)
44
50
  # else:
@@ -85,6 +91,8 @@ def clear(path: str, leave_path: bool = True):
85
91
  print(f"Error occurs while clearing directory: {e}")
86
92
 
87
93
  def path_abbreviate(path: Union[str, Path]) -> str:
94
+ if str(path).startswith(str(env.DOWNLOADS)):
95
+ return path
88
96
  sep = os.path.sep
89
97
  split = str(path).split(sep)
90
98
  return f"{sep.join(split[:2])}{sep} ... {sep}{sep.join(split[-3:])}"