Coverage for src/repocapp.py: 0.00%
74 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: repocapp.py
5Purpose: Clones Xfce repositories pulled from
6 https://gitlab.xfce.org/
8source: https://gitlab.com/kevinbowen/xfce-repocapp
9version: 0.8.7
10updated: 20230314
11@author: kevin.bowen@gmail.com
12"""
14import os
15import subprocess # noqa: S404
16import sys
17from pathlib import Path
19from cappdata import press_any_key
21menus = {
22 "clone": [
23 "apps",
24 "bindings",
25 "xfce",
26 "panel-plugins",
27 "thunar-plugins",
28 "www",
29 "all",
30 ],
31 "build": [
32 "apps",
33 "bindings",
34 "xfce",
35 "panel-plugins",
36 "thunar-plugins",
37 "all",
38 ],
39 "install": [
40 "apps",
41 "bindings",
42 "xfce",
43 "panel-plugins",
44 "thunar-plugins",
45 "all",
46 ],
47 "clean": [
48 "apps",
49 "bindings",
50 "xfce",
51 "panel-plugins",
52 "thunar-plugins",
53 "all",
54 ],
55 "pull": [
56 "apps",
57 "bindings",
58 "xfce",
59 "panel-plugins",
60 "thunar-plugins",
61 "www",
62 "all",
63 ],
64 "purge": [
65 "apps",
66 "bindings",
67 "xfce",
68 "panel-plugins",
69 "thunar-plugins",
70 "www",
71 "all",
72 ],
73 "quit": "quit",
74}
76path = Path(__file__).parent.resolve()
77os.chdir(path)
80def main_menu():
81 """Display selection of available actions to take with repositories."""
82 os.system("/usr/bin/clear") # noqa: S605
83 main_banner = "\u2248: xfce-repocapp: local Xfce repository maintenance :\u2248"
84 border = "\u2248" * len(main_banner)
85 print(f"{border}\n{main_banner}\n{border}")
86 main_list = list(menus.keys())
87 selection = range(1, len(main_list) + 1)
88 for select, m_list in zip(selection, main_list, strict=False):
89 print(f"{select}. {m_list.title()}")
90 print(f"{border}")
91 question = f"Please enter your choice[1-{len(menus)}]: "
92 try:
93 choice = int(input(question))
94 if choice not in selection:
95 print("Invalid input. Try again.")
96 main_menu()
97 else:
98 if choice == selection[-1]:
99 print("Goodbye!")
100 sys.exit()
101 else:
102 action = main_list[choice - 1]
103 sub_menus(action)
104 except (ValueError, EOFError):
105 print("Invalid input. Try again.")
106 main_menu()
109def sub_menus(action):
110 """Display actions to take upon a specific repository."""
111 os.system("/usr/bin/clear") # noqa: S605
112 banner = f"\u2248: xfce-repocapp: {action} local Xfce repositories :\u2248"
113 border = "\u2248" * len(banner)
114 print(f"{border}\n{banner}\n{border}")
115 selection = list(range(1, len(menus[action]) + 1))
116 for select, component in zip(selection, menus[action], strict=False):
117 print(f"{select}. {action.title()} {component}")
118 # Add numbers to selection list for menu options not in action list.
119 selection.append(selection[-1] + 1)
120 selection.append(selection[-1] + 1)
121 print(f"{selection[-2]}. Return to Main Menu")
122 print(f"{selection[-1]}. Quit")
123 print(f"{border}")
124 question = f"Please enter your choice[1-{len(selection)}]: "
125 try:
126 answer = int(input(question))
127 if answer not in selection:
128 sub_menus(action)
129 else:
130 if answer == selection[-1]:
131 print("Goodbye!")
132 sys.exit()
133 elif answer == selection[-2]:
134 main_menu()
135 else:
136 component_list = list(menus[action])
137 if component_list[answer - 1] == "all":
138 component = "all_components"
139 else:
140 component = component_list[answer - 1]
141 script = action + "_xfce.py"
142 command = f"{path}/{script} -c {component}"
143 subprocess.run([command], shell=True) # noqa: S602
144 press_any_key()
145 main_menu()
146 except (ValueError, EOFError):
147 print("Invalid input. Try again.")
148 sub_menus(action)
151if __name__ == "__main__":
152 try:
153 main_menu()
154 except KeyboardInterrupt:
155 print()
156 print("Stopped xfce-repocapp. Exiting...")
157 sys.exit()