@@ -12,7 +12,6 @@ class MirrorConfigError(RuntimeError):
1212 """Exception class for errors thrown by mirror configuration problems."""
1313
1414
15-
1615def configuration_from_file (system_config_root : pathlib .Path , cmdline_cache : Optional [str ] = None ):
1716 """Configure mirrors from both the system 'mirror.yaml' file and the command line."""
1817
@@ -62,7 +61,7 @@ def configuration_from_file(system_config_root: pathlib.Path, cmdline_cache: Opt
6261 if not path .is_absolute ():
6362 raise FileNotFoundError (f"The mirror path '{ path } ' is not absolute" )
6463 if not path .is_dir ():
65- raise FileNotFoundError (f"The mirror path '{ path } ' does not exist " )
64+ raise FileNotFoundError (f"The mirror path '{ path } ' is not a directory " )
6665
6766 mirror ["url" ] = path
6867
@@ -82,11 +81,12 @@ def configuration_from_file(system_config_root: pathlib.Path, cmdline_cache: Opt
8281 return mirrors
8382
8483
85- def setup (mirrors , config_path ):
84+ def yaml_setup (mirrors , config_path ):
85+ """Generate the mirrors.yaml for spack"""
86+
8687 dst = config_path / "mirrors.yaml"
88+
8789 self ._logger .debug (f"generate the spack mirrors.yaml: { dst } " )
88- with dst .open ("w" ) as fid :
89- fid .write ()
9090 yaml = {"mirrors" : {}}
9191
9292 for m in mirrors :
@@ -98,13 +98,22 @@ def setup(mirrors, config_path):
9898 "push" : {"url" : url },
9999 }
100100
101- return yaml .dump (yaml , default_flow_style = False )
101+ with dst .open ("w" ) as file :
102+ yaml .dump (yaml , default_flow_style = False )
103+
104+ # return dst
105+
102106
103- #called from builder
104107def key_setup (mirrors : List [Dict ], system_config_path : pathlib .Path , key_store : pathlib .Path ):
108+ """Validate mirror keys, relocate to key_store, and update mirror config with new key paths"""
109+
105110 for mirror in mirrors :
106111 if mirror ["key" ]:
107112 key = mirror ["key" ]
113+
114+ # key will be saved under key_store/mirror_name.gpg
115+ dst = (key_store / f"'{ mirror ["name" ]} '.gpg" ).resolve ()
116+
108117 # if path, check if abs path, if not, append sys config path in front and check again
109118 path = pathlib .Path (os .path .expandvars (key ))
110119 if path .exists ():
@@ -115,20 +124,23 @@ def key_setup(mirrors: List[Dict], system_config_path: pathlib.Path, key_store:
115124 raise FileNotFoundError (
116125 f"The key path '{ path } ' is not a file. "
117126 f"Check the key listed in mirrors.yaml in system config." )
127+
118128 file_type = magic .from_file (path )
129+
119130 if not file_type .startswith ("OpenPGP Public Key" ):
120131 raise MirrorConfigError (
121- f"'{ key } ' is not a valid GPG key. "
132+ f"'{ path } ' is not a valid GPG key. "
122133 f"Check the key listed in mirrors.yaml in system config." )
123- # copy file to key store
124- with file open :
125- data = key .read
126- dest = mkdir (new_key_file )
127- dest .write (data )
128- # mirror["key"] = new_path
134+
135+ # copy key to new destination in key store
136+ with open (path , 'r' ) as reader , open (dst , 'w' ) as writer :
137+ data = reader .read ()
138+ writer .write (data )
129139
130140 else :
131141 # if PGP key, convert to binary, ???, convert back
132- # if key, save to file, change to path
142+ with open (dst , "w" ) as file :
143+ file .write (key )
133144
134-
145+ # update mirror with new path
146+ mirror ["key" ] = dst
0 commit comments