psr-factory 4.1.0b1__py3-none-win_amd64.whl → 4.1.0b3__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
psr/apps/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ # PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
2
+ # Unauthorized copying of this file, via any medium is strictly prohibited
3
+ # Proprietary and confidential
4
+
5
+ from .version import __version__
6
+ from .apps import *
7
+
psr/apps/apps.py ADDED
@@ -0,0 +1,232 @@
1
+ # PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
2
+ # Unauthorized copying of this file, via any medium is strictly prohibited
3
+ # Proprietary and confidential
4
+
5
+ import glob
6
+ import os
7
+ import pathlib
8
+ from typing import (
9
+ Dict,
10
+ List,
11
+ Optional,
12
+ Tuple,
13
+ Union
14
+ )
15
+
16
+ if os.name == "nt":
17
+ import winreg
18
+
19
+
20
+ from psr.runner import (
21
+ run_sddp,
22
+ run_sddp_check,
23
+ run_hydro_estimation,
24
+ run_sddp_cleanup,
25
+ get_sddp_version,
26
+ run_optgen,
27
+ run_optgen_check,
28
+ run_optgen_cleanup,
29
+ run_ncp,
30
+ run_graph,
31
+ run_psrcloud,
32
+ run_tsl,
33
+ )
34
+
35
+
36
+ class ModelNotFound(Exception):
37
+ pass
38
+
39
+
40
+ def _get_versions_from_base_path(base_path: Union[str, pathlib.Path], program_name: str) -> Dict[str, str]:
41
+ program_path = os.path.join(base_path, program_name)
42
+ if not os.path.exists(program_path):
43
+ return dict()
44
+ versions = dict()
45
+ for entry in os.scandir(program_path):
46
+ if entry.is_dir():
47
+ versions[entry.name] = entry.path
48
+ return versions
49
+
50
+ def get_program_versions_paths(program_name: str) -> Dict[str, str]:
51
+ if os.name == "nt":
52
+ return _get_registry_versions(program_name)
53
+ else:
54
+ return _get_versions_from_base_path("/opt/psr/", program_name)
55
+
56
+
57
+ def get_latest_version_and_path(program_name: str) -> Tuple[str, str]:
58
+ versions = get_program_versions_paths(program_name)
59
+ if not versions:
60
+ raise ModelNotFound(f"Model {program_name} not found")
61
+ # sort keys
62
+ versions_keys = dict(sorted(versions.items()))
63
+ latest = list(versions_keys.keys())[-1]
64
+ return latest, versions[latest]
65
+
66
+
67
+ def get_latest_version(program_name: str) -> "AppRunner":
68
+ program_name_lower = program_name.lower()
69
+ facade_names = {
70
+ "sddp": SDDP,
71
+ "optgen": OptGen,
72
+ "ncp": NCP,
73
+ "graph": Graph,
74
+ "psrcloud": PSRCloud,
75
+ "tsl": TSL,
76
+ }
77
+ version, path = get_latest_version_and_path(program_name)
78
+ if program_name_lower == "sddp":
79
+ return SDDP(path)
80
+
81
+ if program_name_lower == "optgen":
82
+ _, sddp_path = get_latest_version_and_path("sddp")
83
+ return OptGen(path, sddp_path, version)
84
+
85
+ if program_name_lower == "ncp":
86
+ return NCP(path, version)
87
+
88
+ if program_name_lower == "graph":
89
+ return Graph(path, version)
90
+
91
+ if program_name_lower == "psrcloud":
92
+ return PSRCloud(path, version)
93
+
94
+ if program_name_lower == "tsl" or program_name_lower == "timeserieslab":
95
+ return TSL(path, version)
96
+
97
+ raise ModelNotFound(f"Model {program_name} not found")
98
+
99
+
100
+ class AppRunner:
101
+ def __init__(self):
102
+ pass
103
+ def run(self, case_path: str, **kwargs):
104
+ pass
105
+ def version(self) -> str:
106
+ pass
107
+ def install_path(self) -> str:
108
+ pass
109
+
110
+
111
+ class SDDP(AppRunner):
112
+ def __init__(self, sddp_path: str):
113
+ super().__init__()
114
+ self._sddp_path = sddp_path
115
+
116
+ def run(self, case_path: str, **kwargs):
117
+ run_sddp(case_path, self._sddp_path, **kwargs)
118
+
119
+ def run_check(self, case_path: str, **kwargs):
120
+ run_sddp_check(case_path, self._sddp_path, **kwargs)
121
+
122
+ def run_cleanup(self, case_path: str, **kwargs):
123
+ run_sddp_cleanup(case_path, self._sddp_path, **kwargs)
124
+
125
+ def run_hydro_estimation(self, case_path: str, **kwargs):
126
+ run_hydro_estimation(case_path, self._sddp_path, **kwargs)
127
+
128
+ def version(self) -> str:
129
+ return get_sddp_version(self._sddp_path)
130
+
131
+ def install_path(self) -> str:
132
+ return self._sddp_path
133
+
134
+
135
+ class OptGen(AppRunner):
136
+ def __init__(self, optgen_path: str, sddp_path: str, version: str):
137
+ super().__init__()
138
+ self._optgen_path = optgen_path
139
+ self._sddp_path = sddp_path
140
+ self._version = version
141
+
142
+ def run(self, case_path: str, **kwargs):
143
+ run_optgen(case_path, self._optgen_path, self._sddp_path, **kwargs)
144
+
145
+ def run_check(self, case_path: str, **kwargs):
146
+ run_optgen_check(case_path, self._optgen_path, self._sddp_path, **kwargs)
147
+
148
+ def run_cleanup(self, case_path: str, **kwargs):
149
+ run_optgen_cleanup(case_path, self._optgen_path, self._sddp_path, **kwargs)
150
+
151
+ def version(self) -> str:
152
+ return self._version
153
+
154
+
155
+ class NCP(AppRunner):
156
+ def __init__(self, ncp_path: str, version: str):
157
+ super().__init__()
158
+ self._ncp_path = ncp_path
159
+ self._version = version
160
+
161
+ def run(self, case_path: str, **kwargs):
162
+ run_ncp(case_path, self._ncp_path, **kwargs)
163
+
164
+ def version(self) -> str:
165
+ return self._version
166
+
167
+ class Graph(AppRunner):
168
+ def __init__(self, graph_path: str, version: str):
169
+ super().__init__()
170
+ self._graph_path = graph_path
171
+ self._version = version
172
+
173
+ def run(self, case_path: str, **kwargs):
174
+ run_graph(case_path, self._graph_path, **kwargs)
175
+
176
+ def version(self) -> str:
177
+ return self._version
178
+
179
+ class TSL(AppRunner):
180
+ def __init__(self, tsl_path: str, version: str):
181
+ super().__init__()
182
+ self._tsl_path = tsl_path
183
+ self._version = version
184
+
185
+ def run(self, **kwargs):
186
+ run_tsl(self._tsl_path, **kwargs)
187
+
188
+ def version(self) -> str:
189
+ return self._version
190
+
191
+ class PSRCloud(AppRunner):
192
+ def __init__(self, psrcloud_path: str, version: str):
193
+ super().__init__()
194
+ self._psrcloud_path = psrcloud_path
195
+ self._version = version
196
+
197
+ def run(self, **kwargs):
198
+ run_psrcloud(self._psrcloud_path, **kwargs)
199
+
200
+ def version(self) -> str:
201
+ return self._version
202
+
203
+
204
+
205
+ if os.name == "nt":
206
+ def _get_registry_versions(program_name: str) -> Dict[str, str]:
207
+ base_key = winreg.HKEY_LOCAL_MACHINE
208
+ subkey_path = rf"SOFTWARE\PSR\{program_name}"
209
+ version_paths: Dict[str, str] = dict()
210
+ try:
211
+ with winreg.OpenKey(base_key, subkey_path) as key:
212
+ i = 0
213
+ while True:
214
+ try:
215
+ subkey_name = winreg.EnumKey(key, i)
216
+ subkey_full_path = f"{subkey_path}\\{subkey_name}"
217
+
218
+ with winreg.OpenKey(base_key, subkey_full_path) as subkey:
219
+ try:
220
+ path_value, _ = winreg.QueryValueEx(subkey, "Path")
221
+ # if subkey ends with .x, replace with blank
222
+ subkey_name = subkey_name.replace(".x", "")
223
+ version_paths[subkey_name] = path_value
224
+ except FileNotFoundError:
225
+ pass
226
+ i += 1
227
+ except OSError:
228
+ break
229
+ except FileNotFoundError:
230
+ pass
231
+ return version_paths
232
+
psr/apps/version.py ADDED
@@ -0,0 +1,5 @@
1
+ # PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
2
+ # Unauthorized copying of this file, via any medium is strictly prohibited
3
+ # Proprietary and confidential
4
+
5
+ __version__ = "0.1.0"
psr/cloud/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ # PSR Cloud. Copyright (C) PSR, Inc - All Rights Reserved
2
+ # Unauthorized copying of this file, via any medium is strictly prohibited
3
+ # Proprietary and confidential
4
+
5
+ from .cloud import *
6
+ from .data import *
7
+ from .version import __version__