10
10
class ArtifactExporter :
11
11
def __init__ (self , config : Dict [str , Any ]):
12
12
self .config = config
13
- # Ensure absolute path and proper directory structure
14
13
self .config ["output_dir" ] = os .path .abspath (config .get ("output_dir" , "release" ))
14
+
15
+ # Ensure directory exists with write permissions
15
16
os .makedirs (os .path .join (self .config ["output_dir" ], "latest" ), exist_ok = True )
17
+ os .chmod (os .path .join (self .config ["output_dir" ], "latest" ), 0o777 )
16
18
17
19
def export_training_artifacts (
18
20
self , training_results : Dict [str , Any ]
@@ -24,6 +26,7 @@ def export_training_artifacts(
24
26
# Clear existing contents
25
27
shutil .rmtree (release_dir , ignore_errors = True )
26
28
os .makedirs (release_dir , exist_ok = True )
29
+ os .chmod (release_dir , 0o777 )
27
30
28
31
exported_files = {}
29
32
artifacts = training_results ["artifacts" ]
@@ -42,6 +45,7 @@ def export_training_artifacts(
42
45
if src and os .path .exists (src ):
43
46
dest = os .path .join (release_dir , filename )
44
47
shutil .copy2 (src , dest )
48
+ os .chmod (dest , 0o666 ) # Ensure writable
45
49
exported_files [filename .split ("." )[0 ]] = dest
46
50
elif filename == "metrics.json" :
47
51
# Create default metrics if missing
@@ -71,8 +75,10 @@ def _create_default_metrics(
71
75
"warning" : "Metrics not properly saved during training" ,
72
76
},
73
77
)
74
- with open (os .path .join (release_dir , "metrics.json" ), "w" ) as f :
78
+ metrics_path = os .path .join (release_dir , "metrics.json" )
79
+ with open (metrics_path , "w" ) as f :
75
80
json .dump (default_metrics , f , indent = 2 )
81
+ os .chmod (metrics_path , 0o666 )
76
82
77
83
def _create_feature_structure (
78
84
self , release_dir : str , training_results : Dict [str , Any ]
@@ -82,14 +88,18 @@ def _create_feature_structure(
82
88
"required_features" : len (training_results .get ("selected_features" , [])),
83
89
"version" : datetime .now ().strftime ("%Y%m%d_%H%M%S" ),
84
90
}
85
- with open (os .path .join (release_dir , "feature_structure.json" ), "w" ) as f :
91
+ features_path = os .path .join (release_dir , "feature_structure.json" )
92
+ with open (features_path , "w" ) as f :
86
93
json .dump (feature_structure , f , indent = 2 )
94
+ os .chmod (features_path , 0o666 )
87
95
88
96
def _create_package_info (self , release_dir : str , files : Dict [str , str ]):
89
97
package_info = {
90
98
"created_at" : datetime .now ().isoformat (),
91
99
"contents" : {k : os .path .basename (v ) for k , v in files .items ()},
92
100
"notes" : "Automatically generated by spyware-detector-training pipeline" ,
93
101
}
94
- with open (os .path .join (release_dir , "package_info.json" ), "w" ) as f :
102
+ info_path = os .path .join (release_dir , "package_info.json" )
103
+ with open (info_path , "w" ) as f :
95
104
json .dump (package_info , f , indent = 2 )
105
+ os .chmod (info_path , 0o666 )
0 commit comments