-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcopy_to_site_packages.py
64 lines (47 loc) · 1.69 KB
/
copy_to_site_packages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pathlib
import shutil
import logging
from distutils.dir_util import copy_tree
from typing import Tuple
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s.%(msecs)03d %(levelname)s [%(filename)s]:\t%(message)s",
datefmt="%d %H:%M:%S",
)
logging.info("-" * 60)
logging.info("Copying local package to site-package dir")
logging.info("-" * 60)
package_name = "pyofw"
src_path = pathlib.Path(r"src").resolve()
src_package_path = src_path.joinpath(package_name)
# create dir in site-packages
site_packages_path = pathlib.Path(
r"D:\Development\Python\Python39-64\Lib\site-packages"
)
tgt_package_path = site_packages_path.joinpath(package_name)
def __copy_dir(source_path: pathlib.Path, destination_path: pathlib.Path) -> bool:
success = True
try:
if destination_path.exists():
shutil.rmtree(destination_path)
destination_path.mkdir(parents=True, exist_ok=True)
copy_tree(str(source_path), str(destination_path))
logging.info(f"Copied")
__get_contents_count(source_path)
__get_contents_count(destination_path)
except:
logging.exception(f"ERROR.")
return success
def __get_contents_count(path: pathlib.Path) -> Tuple[int, int]:
num_of_sub_dirs, num_of_files = 0, 0
for f in path.rglob('*'):
if f.is_dir():
num_of_sub_dirs += 1
if f.is_file():
num_of_files += 1
logging.info(
f"Directory Count = {num_of_sub_dirs}, Files Count = {num_of_files}, Path: {path}")
return (num_of_sub_dirs, num_of_files)
logging.info(f"Copying '{src_package_path}' to '{tgt_package_path}' ...")
__copy_dir(src_package_path, tgt_package_path)
logging.info("-" * 60)