mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Better printing for file install
- print all managed files including those defined with directories - CLI option --print now also shows files that would be removed - added --dry-run alias to --print
This commit is contained in:
@@ -217,10 +217,10 @@ class Directory:
|
|||||||
if group is not None:
|
if group is not None:
|
||||||
self.gid = grp.getgrnam(group).gr_gid
|
self.gid = grp.getgrnam(group).gr_gid
|
||||||
|
|
||||||
def copy_to(
|
def copy_to(self,
|
||||||
self,
|
|
||||||
target_directory: str,
|
target_directory: str,
|
||||||
variables: typing.Optional[dict[str, str]] = None) -> list[str]:
|
variables: typing.Optional[dict[str, str]] = None,
|
||||||
|
only_print: bool = False) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Copies the files in this directory to the target directory.
|
Copies the files in this directory to the target directory.
|
||||||
|
|
||||||
@@ -242,6 +242,8 @@ class Directory:
|
|||||||
target = os.path.normpath(
|
target = os.path.normpath(
|
||||||
os.path.join(target_directory, src_path))
|
os.path.join(target_directory, src_path))
|
||||||
created.append(target)
|
created.append(target)
|
||||||
|
|
||||||
|
if not only_print:
|
||||||
file.copy_to(target, variables)
|
file.copy_to(target, variables)
|
||||||
finally:
|
finally:
|
||||||
os.chdir(original_wd)
|
os.chdir(original_wd)
|
||||||
|
|||||||
+10
-16
@@ -32,11 +32,10 @@ def main():
|
|||||||
help="python file containing configuration")
|
help="python file containing configuration")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--print",
|
"--print",
|
||||||
|
"--dry-run",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=
|
help="print what would happen as a result of running decman")
|
||||||
"print what would happen as a result of running decman (doesn't print removed files)"
|
|
||||||
)
|
|
||||||
parser.add_argument("--debug",
|
parser.add_argument("--debug",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
@@ -263,23 +262,18 @@ class Core:
|
|||||||
|
|
||||||
def _create_and_remove_files(self):
|
def _create_and_remove_files(self):
|
||||||
l.print_summary("Installing files.")
|
l.print_summary("Installing files.")
|
||||||
l.print_list("Files to install:",
|
|
||||||
self.source.all_file_targets(),
|
all_created = self.source.create_all_files(self.only_print)
|
||||||
elements_per_line=1,
|
to_remove = self.source.files_to_remove(self.store, all_created)
|
||||||
level=l.INFO)
|
|
||||||
l.print_list("Directories to install:",
|
l.print_list("Ensured files are up to date:",
|
||||||
self.source.all_directory_targets(),
|
all_created,
|
||||||
elements_per_line=1,
|
elements_per_line=1)
|
||||||
level=l.INFO)
|
l.print_list("Removing files:", to_remove, elements_per_line=1)
|
||||||
|
|
||||||
if self.only_print:
|
if self.only_print:
|
||||||
return
|
return
|
||||||
|
|
||||||
all_created = self.source.create_all_files()
|
|
||||||
to_remove = self.source.files_to_remove(self.store, all_created)
|
|
||||||
|
|
||||||
l.print_list("Removing files:", to_remove, elements_per_line=1)
|
|
||||||
|
|
||||||
for file in to_remove:
|
for file in to_remove:
|
||||||
try:
|
try:
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ class Source:
|
|||||||
elif module.enabled and module.name not in store.enabled_modules:
|
elif module.enabled and module.name not in store.enabled_modules:
|
||||||
module.after_version_change()
|
module.after_version_change()
|
||||||
|
|
||||||
def create_all_files(self) -> list[str]:
|
def create_all_files(self, only_print: bool) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Creates all files and returns them. The files created are based on the specified files,
|
Creates all files and returns them. The files created are based on the specified files,
|
||||||
directories and modules.
|
directories and modules.
|
||||||
@@ -470,9 +470,13 @@ class Source:
|
|||||||
variables: typing.Optional[dict[str, str]] = None):
|
variables: typing.Optional[dict[str, str]] = None):
|
||||||
for target, file in files.items():
|
for target, file in files.items():
|
||||||
created_files.append(target)
|
created_files.append(target)
|
||||||
|
|
||||||
|
if only_print:
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file.copy_to(target, variables)
|
|
||||||
print_debug(f"Installing file to {target}.")
|
print_debug(f"Installing file to {target}.")
|
||||||
|
file.copy_to(target, variables)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print_error(f"{e}")
|
print_error(f"{e}")
|
||||||
raise err.UserFacingError(
|
raise err.UserFacingError(
|
||||||
@@ -483,7 +487,8 @@ class Source:
|
|||||||
for target, directory in dirs.items():
|
for target, directory in dirs.items():
|
||||||
try:
|
try:
|
||||||
print_debug(f"Installing directory to {target}.")
|
print_debug(f"Installing directory to {target}.")
|
||||||
created_files.extend(directory.copy_to(target, variables))
|
created_files.extend(
|
||||||
|
directory.copy_to(target, variables, only_print))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print_error(f"{e}")
|
print_error(f"{e}")
|
||||||
raise err.UserFacingError(
|
raise err.UserFacingError(
|
||||||
|
|||||||
Reference in New Issue
Block a user