Coverage for src/purge_xfce.py: 24.00%

59 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-02 08:58 -0700

1#!/usr/bin/env python 

2 

3""" 

4Name: purge_xfce.py 

5Purpose: Delete local Xfce repositories installed by clone_xfce.py from 

6 https://gitlab.xfce.org 

7 

8source: https://gitlab.com/kevinbowen/xfrepos 

9version: 0.8.7 

10updated: 20260827 

11@author: kevin.bowen@gmail.com 

12""" 

13 

14import argparse 

15import os 

16import shutil 

17import sys 

18from pathlib import Path 

19 

20from cappdata import component_list, query_yes_no 

21 

22parser = argparse.ArgumentParser( 

23 description="Purge(Delete) groups of local Xfce component directories." 

24) 

25parser.add_argument( 

26 "-c", 

27 "--component", 

28 action="store", 

29 choices=[ 

30 "apps", 

31 "bindings", 

32 "xfce", 

33 "panel-plugins", 

34 "thunar-plugins", 

35 "www", 

36 "all_components", 

37 ], 

38 help="Specify an Xfce component group to delete.", 

39) 

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

41args = parser.parse_args() 

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

43 print( 

44 "No component was specified.\nPlease specify a component group'" 

45 " to delete with the '-c' option." 

46 ) 

47 args.component = "apps" 

48 

49 

50def purge_xfce(component, comp_list): 

51 """Delete files and directories of selected components.""" 

52 print(f"Purging the Xfce {component} group...") 

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

54 

55 def get_path(comp_group): 

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

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

58 

59 return installpath 

60 

61 repopath = get_path(component) 

62 success_count = 0 

63 

64 confirm = query_yes_no( 

65 f"Are you sure you want to remove the Xfce '{component}' repositories? " 

66 ) 

67 

68 if confirm == "yes": 

69 if Path.is_dir(repopath): 

70 os.chdir(repopath) 

71 for item in component_list(comp_list): 

72 p = Path(item) 

73 if p.is_dir(): 

74 try: 

75 shutil.rmtree(item) 

76 success_count += 1 

77 print(f"\nThe '{item}' directory has been deleted.\n") 

78 print( 

79 f"{success_count}" 

80 f"/{len(component_list(comp_list))} " 

81 f"'{component}' repositories deleted " 

82 f"successfully." 

83 ) 

84 print("\u2248" * 16) 

85 except FileNotFoundError: 

86 print(f"The directory '{item}' does not exist. Skipping...") 

87 print("\u2248" * 16) 

88 os.chdir("..") 

89 shutil.rmtree(component) 

90 print(f"\nThe directory '{component}' has been deleted.\n") 

91 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) 

99 

100 else: 

101 print("No repositories have been deleted. Have a nice day.") 

102 

103 

104def main(component_group_name): 

105 """Build arguments to pass to purge_xfce() with a call to 

106 cappdata for component name list. 

107 command format: 

108 pull_xfce(component='apps', 

109 comp_list='apps') 

110 """ 

111 cgroup_listname = component_list(component_group_name) 

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

113 if isinstance(cgroup_listname, dict): 

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

115 purge_xfce(component=comp, comp_list=cglist) 

116 else: 

117 purge_xfce(component=component_group_name, comp_list=component_group_name) 

118 

119 

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

121 try: 

122 component_group = args.component 

123 main(component_group) 

124 except KeyboardInterrupt: 

125 print() 

126 print("Stopped xfrepos. Exiting...") 

127 sys.exit()