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