Coverage for src/clean_xfce.py: 29.58%
57 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-02 08:58 -0700
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-02 08:58 -0700
1#!/usr/bin/env python
3"""
4Name: clean_xfce.py
5Purpose: Clean local Xfce repository directories
7source: https://gitlab.com/kevinbowen/xfrepos
8version: 0.8.7
9updated: 20260827
10@author: kevin.bowen@gmail.com
11"""
13import argparse
14import os
15import sys
16import time
17from pathlib import Path
19from cappdata import component_list
21parser = argparse.ArgumentParser(
22 description="Clean groups of Xfce local component directories."
23)
24parser.add_argument(
25 "-c",
26 "--component",
27 action="store",
28 choices=[
29 "apps",
30 "bindings",
31 "xfce",
32 "panel-plugins",
33 "thunar-plugins",
34 "www",
35 "all_components",
36 ],
37 help="Specify an Xfce component group directory to clean.",
38)
39parser.add_argument("--version", action="version", version="%(prog)s 0.8.7")
40args = parser.parse_args()
41if args.component is None: 41 ↛ 48line 41 didn't jump to line 48 because the condition on line 41 was always true
42 print(
43 "No component was specified. Default to cleaning"
44 " the 'apps' component directories...."
45 )
46 args.component = "apps"
48line_rule = "\u2248" * 16
49path = Path(__file__).parent.resolve()
50os.chdir(path)
53def clean_xfce(component, comp_list):
54 """Run make clean on component directories."""
55 print(f"Cleaning the Xfce {component} group...")
57 def get_path(comp_group):
58 # grandparent directory (../../) relative to script.
59 installpath = Path.cwd().parent.parent.joinpath(comp_group)
61 return installpath
63 repopath = get_path(component)
64 success_count = 0
66 if Path.is_dir(repopath):
67 os.chdir(repopath)
68 for item in component_list(comp_list):
69 p = Path(item)
70 if p.is_dir():
71 os.chdir(item)
72 print(f"\nCleaning {item} directory...\n")
73 time.sleep(1.5)
74 # ruff: ignore[start-process-with-a-shell]
75 os.system("make -s clean") # ruff: ignore[start-process-with-partial-path]
76 success_count += 1
77 print(f"\nExiting {item} directory...\n")
78 print(
79 f"{success_count}/{len(component_list(comp_list))} "
80 f"'{component}' repositories cleaned."
81 )
82 print("\u2248" * 16)
83 os.chdir("..")
84 else:
85 print("\nNothing to do...\n")
86 print(
87 f"The '{item}' repository does not exist.\n\n"
88 "Perhaps you need to clone it first.\n"
89 )
90 print("\u2248" * 16)
92 else:
93 print("Nothing to do...\n")
94 print(
95 f"The '{component}' repositories do not exist.\n\n"
96 "Perhaps you need to clone the directory first.\n"
97 )
98 print("\u2248" * 16)
101def main(component_group_name):
102 """Build arguments to pass to clean_xfce() with a call to
103 cappdata for component name list.
104 command format:
105 clean_xfce(component='apps',
106 comp_list='apps')
107 """
108 cgroup_listname = component_list(component_group_name)
109 # All cgroup_listnames will return a string, except 'all'
110 if isinstance(cgroup_listname, dict):
111 for comp, cglist in cgroup_listname.items():
112 clean_xfce(component=comp, comp_list=cglist)
113 else:
114 clean_xfce(component=component_group_name, comp_list=component_group_name)
117if __name__ == "__main__": 117 ↛ 118line 117 didn't jump to line 118 because the condition on line 117 was never true
118 try:
119 component_group = args.component
120 main(component_group)
121 except KeyboardInterrupt:
122 print()
123 print("Stopped xfrepos. Exiting...")
124 sys.exit()