Coverage for src/install_xfce.py: 23.94%
55 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: install._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
16from pathlib import Path
18from cappdata import component_list, query_yes_no
20parser = argparse.ArgumentParser(
21 description="Install groups of Xfce components either locally or system-wide."
22)
23parser.add_argument(
24 "-c",
25 "--component",
26 action="store",
27 choices=[
28 "apps",
29 "bindings",
30 "xfce",
31 "panel-plugins",
32 "thunar-plugins",
33 "www",
34 "all_components",
35 ],
36 help="specify an Xfce component group to install either locally or system-wide.",
37)
38parser.add_argument("--version", action="version", version="%(prog)s 0.8.7")
39args = parser.parse_args()
40if args.component is None: 40 ↛ 48line 40 didn't jump to line 48 because the condition on line 40 was always true
41 print(
42 "No component was specified. Default to installation of"
43 " the 'apps' components...."
44 )
45 args.component = "apps"
48def install_xfce(component, comp_list):
49 """Run 'make install' or 'sudo make install' on selected components."""
50 print(f"Installing the Xfce {component} group...")
51 os.chdir(Path(__file__).parent.resolve())
53 def get_path(comp_group):
54 # grandparent directory (../../) relative to script.
55 installpath = Path.cwd().parent.parent.joinpath(comp_group)
57 return installpath
59 repopath = get_path(component)
61 if Path.is_dir(repopath):
62 os.chdir(repopath)
63 for item in component_list(comp_list):
64 p = Path(item)
65 if p.is_dir():
66 os.chdir(item)
67 confirm = query_yes_no(
68 f"Do you want to install '{item}' to the system? "
69 f"Answer 'No' to install locally. "
70 )
71 if confirm == "yes":
72 print(f"Installing {item} to the system...")
73 # ruff: ignore[start-process-with-a-shell]
74 os.system("sudo make install") # ruff: ignore[start-process-with-partial-path]
75 print("\u2248" * 16)
76 os.chdir("..")
77 else:
78 print(f"Installing {item} locally...")
79 # ruff: ignore[start-process-with-a-shell]
80 os.system("make install") # ruff: ignore[start-process-with-partial-path]
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 install_xfce() with a call to
102 cappdata for component name list.
103 command format:
104 install_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 install_xfce(component=comp, comp_list=cglist)
112 else:
113 install_xfce(component=component_group_name, comp_list=component_group_name)
116if __name__ == "__main__": 116 ↛ 117line 116 didn't jump to line 117 because the condition on line 116 was never true
117 try:
118 component_group = args.component
119 main(component_group)
120 except KeyboardInterrupt:
121 print()
122 print("Stopped xfrepos. Exiting...")
123 sys.exit()