Coverage for src/build_xfce.py: 30.43%

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 

6import time 

7from pathlib import Path 

8 

9from cappdata import component_list 

10 

11parser = argparse.ArgumentParser( 

12 description="Build groups of Xfce components locally." 

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 build locally.", 

28) 

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

30args = parser.parse_args() 

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

32 print( 

33 "No component was specified. Default to building" 

34 " the 'apps' components locally...." 

35 ) 

36 args.component = "apps" 

37 

38line_rule = "\u2248" * 16 

39path = Path(__file__).parent.resolve() 

40os.chdir(path) 

41 

42 

43def build_xfce(component, comp_list): 

44 """Run autogen.sh and make on selected components.""" 

45 print(f"Building the Xfce {component} group...") 

46 

47 def get_path(comp_group): 

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

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

50 

51 return installpath 

52 

53 repopath = get_path(component) 

54 os.environ["PKG_CONFIG_PATH"] = "/usr/lib/pkgconfig:/usr" 

55 

56 if Path.is_dir(repopath): 

57 os.chdir(repopath) 

58 for item in component_list(comp_list): 

59 p = Path(item) 

60 if p.is_dir(): 

61 os.chdir(item) 

62 print(f"\nRunning autogen.sh for {item} ...\n") 

63 os.system("./autogen.sh --prefix=/usr") 

64 print(f"\nRunning make for {item} ...\n") 

65 time.sleep(1.5) 

66 os.system("make") 

67 os.chdir("..") 

68 else: 

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

70 print( 

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

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

73 ) 

74 print(line_rule) 

75 

76 else: 

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

78 print( 

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

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

81 ) 

82 print(line_rule) 

83 

84 

85def main(component_group_name): 

86 """Build arguments to pass to build_xfce() with a call to 

87 cappdata for component name list. 

88 command format: 

89 build_xfce(component='apps', 

90 comp_list='apps') 

91 """ 

92 cgroup_listname = component_list(component_group_name) 

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

94 if isinstance(cgroup_listname, dict): 

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

96 build_xfce(component=comp, comp_list=cglist) 

97 else: 

98 build_xfce( 

99 component=component_group_name, comp_list=component_group_name 

100 ) 

101 

102 

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

104 try: 

105 component_group = args.component 

106 main(component_group) 

107 except KeyboardInterrupt: 

108 print() 

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

110 sys.exit()