Coverage for src/shephex/executor/slurm/slurm_profile.py: 27%
41 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-06-20 14:13 +0200
« prev ^ index » next coverage.py v7.6.1, created at 2025-06-20 14:13 +0200
1import json
2from pathlib import Path
5class SlurmProfileManager:
7 def __init__(self) -> None:
8 self.settings_directory = Path.home() / '.shephex/'
9 self.settings_directory.mkdir(exist_ok=True)
10 self.settings_path = self.settings_directory / 'slurm_profile_manager.json'
12 self.settings = self.load_settings()
13 self.profile_directory = Path(self.settings['profile_directory'])
14 self.profile_directory.mkdir(exist_ok=True)
16 def load_settings(self) -> dict:
17 if self.settings_path.exists():
18 with open(self.settings_path) as f:
19 settings = json.load(f)
20 else:
21 settings = {"profile_directory": str(Path.home() / '.shephex/slurm_profiles/')}
22 with open(self.settings_path, 'w') as f:
23 json.dump(settings, f, indent=4)
25 return settings
27 def set_profile_directory(self, path: Path) -> None:
28 self.settings['profile_directory'] = str(path)
29 with open(self.settings_path, 'w') as f:
30 json.dump(self.settings, f, indent=4)
32 def get_profile_directory(self) -> Path:
33 return self.profile_directory
35 def get_all_profiles(self) -> list[Path]:
36 return list(self.profile_directory.glob('*.json'))
38 def get_profile_path(self, name: str) -> Path:
39 if not name.endswith('.json'):
40 name = name + '.json'
42 path = self.profile_directory / name
43 if not path.exists():
44 raise FileNotFoundError(f'Profile {name} not found in {self.profile_directory}')
46 return path
48 def get_profile(self, name: str) -> dict:
49 path = self.get_profile_path(name)
50 with open(path) as f:
51 return json.load(f)
55if __name__ == '__main__':
57 spm = SlurmProfileManager()
59 z = spm.get_all_profiles()
61 spm.get_profile('kage')