kkpyutil 1.47.1__tar.gz → 1.48.0__tar.gz
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.
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/PKG-INFO +1 -1
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/kkpyutil.py +39 -14
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/pyproject.toml +1 -1
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/LICENSE +0 -0
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/README.md +0 -0
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/kkpyutil_helper/windows/kkttssave.ps1 +0 -0
- {kkpyutil-1.47.1 → kkpyutil-1.48.0}/kkpyutil_helper/windows/kkttsspeak.ps1 +0 -0
|
@@ -2079,7 +2079,7 @@ def move_file(src, dst, isdstdir=False):
|
|
|
2079
2079
|
return dst if not isdstdir else osp.join(dst, osp.basename(src))
|
|
2080
2080
|
|
|
2081
2081
|
|
|
2082
|
-
def sync_dirs(src_root, dst_root, logger=glogger):
|
|
2082
|
+
def sync_dirs(src_root, dst_root, logger=glogger, sudo=False):
|
|
2083
2083
|
"""
|
|
2084
2084
|
- assume src and dst folders are the same level of folder tree
|
|
2085
2085
|
- the result will be dst_root mirrors src_root
|
|
@@ -2088,19 +2088,44 @@ def sync_dirs(src_root, dst_root, logger=glogger):
|
|
|
2088
2088
|
if not os.path.exists(src_root):
|
|
2089
2089
|
logger.error(f"Error: Source directory {src_root} does not exist.")
|
|
2090
2090
|
return False
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2091
|
+
if not sudo:
|
|
2092
|
+
# Iterate through the items inside the source directory
|
|
2093
|
+
for item in os.listdir(src_root):
|
|
2094
|
+
src_path = os.path.join(src_root, item)
|
|
2095
|
+
dst_path = os.path.join(dst_root, item)
|
|
2096
|
+
if os.path.isdir(src_path):
|
|
2097
|
+
# copytree with dirs_exist_ok=True will overwrite existing files
|
|
2098
|
+
# and merge directories without warning.
|
|
2099
|
+
shutil.copytree(src_path, dst_path, dirs_exist_ok=True)
|
|
2100
|
+
logger.info(f"Copied directory: {item}")
|
|
2101
|
+
else:
|
|
2102
|
+
# For individual files at the root of my_src_dir
|
|
2103
|
+
shutil.copy2(src_path, dst_path)
|
|
2104
|
+
logger.info(f"Copied file: {item}")
|
|
2105
|
+
return True
|
|
2106
|
+
# on macOS, merge to system folders
|
|
2107
|
+
# Identify the original user (the one who called sudo)
|
|
2108
|
+
# Default to current effective user if SUDO_USER isn't set
|
|
2109
|
+
user = os.environ.get('SUDO_USER') or os.environ.get('USER')
|
|
2110
|
+
if not user:
|
|
2111
|
+
logger.error("Could not determine the current user.")
|
|
2112
|
+
return False
|
|
2113
|
+
try:
|
|
2114
|
+
# rsync flags:
|
|
2115
|
+
# -a: Archive mode (preserves links, etc.)
|
|
2116
|
+
# --chown: Forces the owner:group of all copied files
|
|
2117
|
+
# Note: 'staff' is the default group for users on macOS
|
|
2118
|
+
cmd = [
|
|
2119
|
+
"sudo", "rsync", "-av", "--inplace",
|
|
2120
|
+
f"--chown={user}:staff",
|
|
2121
|
+
osp.join(src_root, ""), # Trailing slash copies contents
|
|
2122
|
+
dst_root
|
|
2123
|
+
]
|
|
2124
|
+
logger.info(f"Syncing to {dst_root} and setting owner to '{user}'...")
|
|
2125
|
+
subprocess.check_call(cmd)
|
|
2126
|
+
except subprocess.CalledProcessError as e:
|
|
2127
|
+
logger.error(f"Sync failed with error code: {e.returncode}")
|
|
2128
|
+
return False
|
|
2104
2129
|
return True
|
|
2105
2130
|
|
|
2106
2131
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|