Coverage for src/purge_xfce.py: 24.00%
59 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-12-30 22:19 -0800
« prev ^ index » next coverage.py v7.6.10, created at 2024-12-30 22:19 -0800
1#!/usr/bin/env python3
3"""
4Name: purge_xfce.py
5Purpose: delete the local Xfce repositories originally pulled from
6 https://gitlab.xfce.org
8source: https://gitlab.com/kevinbowen/xfce-repocapp
9version: 0.8.7
10updated: 20220114
11@author: kevin.bowen@gmail.com
12"""
14import argparse
15import os
16import shutil
17import sys
18from pathlib import Path
20from cappdata import component_list, query_yes_no
22parser = argparse.ArgumentParser(
23 description="Purge(Delete) groups of local Xfce component directories."
24)
25parser.add_argument(
26 "-c",
27 "--component",
28 action="store",
29 choices=[
30 "apps",
31 "bindings",
32 "xfce",
33 "panel-plugins",
34 "thunar-plugins",
35 "www",
36 "all_components",
37 ],
38 help="Specify an Xfce component group to delete.",
39)
40parser.add_argument("--version", action="version", version="%(prog)s 0.8.7")
41args = parser.parse_args()
42if args.component is None: 42 ↛ 50line 42 didn't jump to line 50 because the condition on line 42 was always true
43 print(
44 "No component was specified.\nPlease specify a component group'"
45 " to delete with the '-c' option."
46 )
47 args.component = "apps"
50def purge_xfce(component, comp_list):
51 """Delete files and directories of selected components."""
52 print(f"Purging the Xfce {component} group...")
53 os.chdir(Path(__file__).parent.resolve())
55 def get_path(comp_group):
56 # grandparent directory (../../) relative to script.
57 installpath = Path.cwd().parent.parent.joinpath(comp_group)
59 return installpath
61 repopath = get_path(component)
62 success_count = 0
64 confirm = query_yes_no(
65 f"Are you sure you want to remove the "
66 f"Xfce '{component}' repositories? "
67 )
69 if confirm == "yes":
70 if Path.is_dir(repopath):
71 os.chdir(repopath)
72 for item in component_list(comp_list):
73 p = Path(item)
74 if p.is_dir():
75 try:
76 shutil.rmtree(item)
77 success_count += 1
78 print(f"\nThe '{item}' directory has been deleted.\n")
79 print(
80 f"{success_count}"
81 f"/{len(component_list(comp_list))} "
82 f"'{component}' repositories deleted "
83 f"successfully."
84 )
85 print("\u2248" * 16)
86 except FileNotFoundError:
87 print(
88 f"The directory '{item}' does not exist. "
89 f"Skipping..."
90 )
91 print("\u2248" * 16)
92 os.chdir("..")
93 shutil.rmtree(component)
94 print(f"\nThe directory '{component}' has been deleted.\n")
95 print("\u2248" * 16)
96 else:
97 print("Nothing to do...\n")
98 print(
99 f"The '{component}' repositories do not exist.\n\n"
100 "Perhaps you need to clone the directory first.\n"
101 )
102 print("\u2248" * 16)
104 else:
105 print("No repositories have been deleted. Have a nice day.")
108def main(component_group_name):
109 """Build arguments to pass to purge_xfce() with a call to
110 cappdata for component name list.
111 command format:
112 pull_xfce(component='apps',
113 comp_list='apps')
114 """
115 cgroup_listname = component_list(component_group_name)
116 # All cgroup_listnames will return a string, except 'all'
117 if isinstance(cgroup_listname, dict):
118 for comp, cglist in cgroup_listname.items():
119 purge_xfce(component=comp, comp_list=cglist)
120 else:
121 purge_xfce(
122 component=component_group_name, comp_list=component_group_name
123 )
126if __name__ == "__main__": 126 ↛ 127line 126 didn't jump to line 127 because the condition on line 126 was never true
127 try:
128 component_group = args.component
129 main(component_group)
130 except KeyboardInterrupt:
131 print()
132 print("Stopped xfce-repocapp. Exiting...")
133 sys.exit()