Coverage for src/clean_xfce.py: 29.58%
57 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: clean_xfce.py
5Purpose: Clean local Xfce repository directories
7source: https://gitlab.com/kevinbowen/xfce-repocapp
8version: 0.8.7
9updated: 20230314
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 os.system("make -s clean")
75 success_count += 1
76 print(f"\nExiting {item} directory...\n")
77 print(
78 f"{success_count}/{len(component_list(comp_list))} "
79 f"'{component}' repositories cleaned."
80 )
81 print("\u2248" * 16)
82 os.chdir("..")
83 else:
84 print("\nNothing to do...\n")
85 print(
86 f"The '{item}' repository does not exist.\n\n"
87 "Perhaps you need to clone it first.\n"
88 )
89 print("\u2248" * 16)
91 else:
92 print("Nothing to do...\n")
93 print(
94 f"The '{component}' repositories do not exist.\n\n"
95 "Perhaps you need to clone the directory first.\n"
96 )
97 print("\u2248" * 16)
100def main(component_group_name):
101 """Build arguments to pass to clean_xfce() with a call to
102 cappdata for component name list.
103 command format:
104 clean_xfce(component='apps',
105 comp_list='apps')
106 """
107 cgroup_listname = component_list(component_group_name)
108 # All cgroup_listnames will return a string, except 'all'
109 if isinstance(cgroup_listname, dict):
110 for comp, cglist in cgroup_listname.items():
111 clean_xfce(component=comp, comp_list=cglist)
112 else:
113 clean_xfce(
114 component=component_group_name, comp_list=component_group_name
115 )
118if __name__ == "__main__": 118 ↛ 119line 118 didn't jump to line 119 because the condition on line 118 was never true
119 try:
120 component_group = args.component
121 main(component_group)
122 except KeyboardInterrupt:
123 print()
124 print("Stopped xfce-repocapp. Exiting...")
125 sys.exit()