easyvvuq.encoders.directory_builder
1import os 2 3__copyright__ = """ 4 5 Copyright 2018 Robin A. Richardson, David W. Wright 6 7 This file is part of EasyVVUQ 8 9 EasyVVUQ is free software: you can redistribute it and/or modify 10 it under the terms of the Lesser GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 EasyVVUQ is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 Lesser GNU General Public License for more details. 18 19 You should have received a copy of the Lesser GNU General Public License 20 along with this program. If not, see <https://www.gnu.org/licenses/>. 21 22""" 23__license__ = "LGPL" 24 25 26class DirectoryBuilder: 27 """DirectoryBuilder builds the specified directory structure for a Run. 28 29 The dir structure is specified by the 'tree' parameter. This should be a dict of dicts, 30 for example: 31 32 tree = {'a' : {'b' : {'c' : None, 'd' : None}}, 'e' : {'f' : None}} 33 34 35 Parameters 36 ---------- 37 tree : dict of dicts 38 The desired directory structure 39 """ 40 41 def __init__(self, tree): 42 self.tree = tree 43 44 def encode(self, params={}, target_dir=''): 45 """Builds the directory structure specified in self.tree into the `target_dir` directory 46 47 Parameters 48 ---------- 49 params : dict 50 Parameter information in dictionary. 51 target_dir : str 52 Path to directory where application input will be written. 53 """ 54 55 if not target_dir: 56 raise RuntimeError('No target directory specified to encoder') 57 58 self.create_dir_tree(self.tree, target_dir) 59 60 def create_dir_tree(self, dirtree, root): 61 # A beautiful Vytas creation 62 if dirtree is not None: 63 for directory in dirtree.keys(): 64 os.mkdir(os.path.join(root, directory)) 65 self.create_dir_tree(dirtree[directory], os.path.join(root, directory)) 66 67 def get_restart_dict(self): 68 return {"tree": self.tree} 69 70 def element_version(self): 71 return "0.1"
class
DirectoryBuilder:
27class DirectoryBuilder: 28 """DirectoryBuilder builds the specified directory structure for a Run. 29 30 The dir structure is specified by the 'tree' parameter. This should be a dict of dicts, 31 for example: 32 33 tree = {'a' : {'b' : {'c' : None, 'd' : None}}, 'e' : {'f' : None}} 34 35 36 Parameters 37 ---------- 38 tree : dict of dicts 39 The desired directory structure 40 """ 41 42 def __init__(self, tree): 43 self.tree = tree 44 45 def encode(self, params={}, target_dir=''): 46 """Builds the directory structure specified in self.tree into the `target_dir` directory 47 48 Parameters 49 ---------- 50 params : dict 51 Parameter information in dictionary. 52 target_dir : str 53 Path to directory where application input will be written. 54 """ 55 56 if not target_dir: 57 raise RuntimeError('No target directory specified to encoder') 58 59 self.create_dir_tree(self.tree, target_dir) 60 61 def create_dir_tree(self, dirtree, root): 62 # A beautiful Vytas creation 63 if dirtree is not None: 64 for directory in dirtree.keys(): 65 os.mkdir(os.path.join(root, directory)) 66 self.create_dir_tree(dirtree[directory], os.path.join(root, directory)) 67 68 def get_restart_dict(self): 69 return {"tree": self.tree} 70 71 def element_version(self): 72 return "0.1"
DirectoryBuilder builds the specified directory structure for a Run.
The dir structure is specified by the 'tree' parameter. This should be a dict of dicts, for example:
tree = {'a' : {'b' : {'c' : None, 'd' : None}}, 'e' : {'f' : None}}
Parameters
- tree (dict of dicts): The desired directory structure
def
encode(self, params={}, target_dir=''):
45 def encode(self, params={}, target_dir=''): 46 """Builds the directory structure specified in self.tree into the `target_dir` directory 47 48 Parameters 49 ---------- 50 params : dict 51 Parameter information in dictionary. 52 target_dir : str 53 Path to directory where application input will be written. 54 """ 55 56 if not target_dir: 57 raise RuntimeError('No target directory specified to encoder') 58 59 self.create_dir_tree(self.tree, target_dir)
Builds the directory structure specified in self.tree into the target_dir directory
Parameters
- params (dict): Parameter information in dictionary.
- target_dir (str): Path to directory where application input will be written.