1
1
from hkpilot .utils .cmake import CMake
2
+ from hkpilot .utils import fancylogger
2
3
4
+ import sys , os
5
+
6
+ logger = fancylogger .getLogger (__name__ )
3
7
4
8
class HKToolApp (CMake ):
5
9
6
10
def __init__ (self , path ):
7
11
super ().__init__ (path )
8
12
self ._package_name = "hk-ToolApp"
13
+
14
+ def configure (self ):
15
+ # We override the configure step to add the symlink to the compiled_tools repository
16
+ logger .info ("Adding linkage to compiled tools directory" )
17
+ compiledtools_dirname = os .getenv ("HK_COMPILEDTOOLS_DIR" )
18
+ inactivetools_dirname = os .path .join (self ._path , "UserTools" , "InactiveTools" )
19
+ activetools_dirname = os .path .join (self ._path , "UserTools" )
20
+
21
+
22
+ # Find all the inactive tools
23
+ list_inactive_tools = []
24
+ for name in os .listdir (inactivetools_dirname ):
25
+ if os .path .isdir (os .path .join (inactivetools_dirname , name )) or os .path .islink (os .path .join (inactivetools_dirname , name )):
26
+ list_inactive_tools .append (name )
27
+ logger .debug (f"List of inactive tools: { list_inactive_tools } " )
28
+
29
+ # Find all the active tools
30
+ list_active_tools = []
31
+ for name in os .listdir (activetools_dirname ):
32
+ if name in ["Factory" , "InactiveTools" , "template" ]:
33
+ continue
34
+ if os .path .isdir (os .path .join (activetools_dirname , name )) or os .path .islink (os .path .join (activetools_dirname , name )):
35
+ list_active_tools .append (name )
36
+ logger .debug (f"List of active tools: { list_active_tools } " )
37
+
38
+ for name in os .listdir (compiledtools_dirname ):
39
+ full = os .path .join (compiledtools_dirname , name )
40
+ # only looking for symlink to which we will create another link
41
+ if not os .path .islink (full ):
42
+ continue
43
+ # checking the tool is not already active or exists as inactive
44
+ if name in list_inactive_tools :
45
+ logger .debug (f"Tool { name } is already linked as inactive tool" )
46
+ continue
47
+ if name in list_active_tools :
48
+ logger .debug (f"Tool { name } is already linked as active tool" )
49
+ continue
50
+
51
+ symlink = os .path .join (inactivetools_dirname , name )
52
+ logger .info (f"Adding link of tool { name } -> { symlink } " )
53
+ os .symlink (full , symlink )
54
+ logger .info ("Done with linkage" )
55
+
56
+ return super ().configure ()
57
+
0 commit comments