Coverage for src/install_xfce.py: 23.94%

55 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-12-30 22:19 -0800

1#!/usr/bin/env python3 

2 

3import argparse 

4import os 

5import sys 

6from pathlib import Path 

7 

8from cappdata import component_list, query_yes_no 

9 

10parser = argparse.ArgumentParser( 

11 description="Install groups of Xfce components" 

12 " either locally or system-wide." 

13) 

14parser.add_argument( 

15 "-c", 

16 "--component", 

17 action="store", 

18 choices=[ 

19 "apps", 

20 "bindings", 

21 "xfce", 

22 "panel-plugins", 

23 "thunar-plugins", 

24 "www", 

25 "all_components", 

26 ], 

27 help="specify an Xfce component group to install" 

28 " either locally or system-wide.", 

29) 

30parser.add_argument("--version", action="version", version="%(prog)s 0.8.7") 

31args = parser.parse_args() 

32if args.component is None: 32 ↛ 40line 32 didn't jump to line 40 because the condition on line 32 was always true

33 print( 

34 "No component was specified. Default to installation of" 

35 " the 'apps' components...." 

36 ) 

37 args.component = "apps" 

38 

39 

40def install_xfce(component, comp_list): 

41 """Run 'make install' or 'sudo make install' on selected components.""" 

42 print(f"Installing the Xfce {component} group...") 

43 os.chdir(Path(__file__).parent.resolve()) 

44 

45 def get_path(comp_group): 

46 # grandparent directory (../../) relative to script. 

47 installpath = Path.cwd().parent.parent.joinpath(comp_group) 

48 

49 return installpath 

50 

51 repopath = get_path(component) 

52 

53 if Path.is_dir(repopath): 

54 os.chdir(repopath) 

55 for item in component_list(comp_list): 

56 p = Path(item) 

57 if p.is_dir(): 

58 os.chdir(item) 

59 confirm = query_yes_no( 

60 f"Do you want to install '{item}' to the system? " 

61 f"Answer 'No' to install locally. " 

62 ) 

63 if confirm == "yes": 

64 print(f"Installing {item} to the system...") 

65 os.system("sudo make install") 

66 print("\u2248" * 16) 

67 os.chdir("..") 

68 else: 

69 print(f"Installing {item} locally...") 

70 os.system("make install") 

71 print("\u2248" * 16) 

72 os.chdir("..") 

73 else: 

74 print("\nNothing to do...\n") 

75 print( 

76 f"The '{item}' repository does not exist.\n\n" 

77 "Perhaps you need to clone it first.\n" 

78 ) 

79 print("\u2248" * 16) 

80 

81 else: 

82 print("Nothing to do...\n") 

83 print( 

84 f"The '{component}' repositories do not exist.\n\n" 

85 "Perhaps you need to clone the directory first.\n" 

86 ) 

87 print("\u2248" * 16) 

88 

89 

90def main(component_group_name): 

91 """Build arguments to pass to install_xfce() with a call to 

92 cappdata for component name list. 

93 command format: 

94 install_xfce(component='apps', 

95 comp_list='apps') 

96 """ 

97 cgroup_listname = component_list(component_group_name) 

98 # All cgroup_listnames will return a string, except 'all' 

99 if isinstance(cgroup_listname, dict): 

100 for comp, cglist in cgroup_listname.items(): 

101 install_xfce(component=comp, comp_list=cglist) 

102 else: 

103 install_xfce( 

104 component=component_group_name, comp_list=component_group_name 

105 ) 

106 

107 

108if __name__ == "__main__": 108 ↛ 109line 108 didn't jump to line 109 because the condition on line 108 was never true

109 try: 

110 component_group = args.component 

111 main(component_group) 

112 except KeyboardInterrupt: 

113 print() 

114 print("Stopped xfce-repocapp. Exiting...") 

115 sys.exit()