Coverage for src/pull_xfce.py: 25.76%

52 statements  

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

1#!/usr/bin/env python3 

2 

3""" 

4Name: pull_xfce.py 

5Purpose: update local Xfce repositories pulled from 

6 https://gitlab.xfce.org 

7 

8source: https://gitlab.com/kevinbowen/xfce-repocapp 

9version: 0.8.7 

10updated: 20230314 

11@author: kevin.bowen@gmail.com 

12""" 

13 

14import argparse 

15import os 

16import sys 

17from pathlib import Path 

18 

19from cappdata import component_list 

20 

21parser = argparse.ArgumentParser( 

22 description="Pull/update groups of Xfce components" 

23 " from https://gitlab.xfce.org repositories." 

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 pull/update" 

39 " from https://gitlab.xfce.org.", 

40) 

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

42args = parser.parse_args() 

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

44 print( 

45 "No component was specified. Defaulting to pulling/updating" 

46 " the 'apps' component repositories." 

47 ) 

48 args.component = "apps" 

49 

50 

51def pull_xfce(component, comp_list): 

52 """Run 'git pull' on selected components to update repositories.""" 

53 print(f"Updating the Xfce {component} group...") 

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

55 

56 def get_path(comp_group): 

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

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

59 

60 return installpath 

61 

62 repopath = get_path(component) 

63 success_count = 0 

64 

65 if Path.is_dir(repopath): 

66 os.chdir(repopath) 

67 for item in component_list(comp_list): 

68 p = Path(item) 

69 if p.is_dir(): 

70 os.chdir(item) 

71 print(f"Updating {item}...") 

72 os.system("git pull") 

73 success_count += 1 

74 print( 

75 f"\n{success_count}/{len(component_list(comp_list))} " 

76 f"'{component}' repositories updated successfully." 

77 ) 

78 print("\u2248" * 16) 

79 os.chdir("..") 

80 else: 

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

82 print( 

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

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

85 ) 

86 print("\u2248" * 16) 

87 

88 else: 

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

90 print( 

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

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

93 ) 

94 print("\u2248" * 16) 

95 

96 

97def main(component_group_name): 

98 """Build arguments to pass to pull_xfce() with a call to 

99 cappdata for component name list. 

100 command format: 

101 pull_xfce(component='apps', 

102 comp_list='apps') 

103 """ 

104 cgroup_listname = component_list(component_group_name) 

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

106 if isinstance(cgroup_listname, dict): 

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

108 pull_xfce(component=comp, comp_list=cglist) 

109 else: 

110 pull_xfce( 

111 component=component_group_name, comp_list=component_group_name 

112 ) 

113 

114 

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

116 try: 

117 component_group = args.component 

118 main(component_group) 

119 except KeyboardInterrupt: 

120 print() 

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

122 sys.exit()