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/factory/factory.pmk CHANGED
@@ -6442,6 +6442,9 @@ RelCrit REAL,2
6442
6442
  END_DATA
6443
6443
  END_MASK
6444
6444
 
6445
+ //---------------------------------------------------------------------
6446
+ // Horizonte Rolante
6447
+ //---------------------------------------------------------------------
6445
6448
  DEFINE_MASK CSVDATA OPTGEN_dathzn
6446
6449
 
6447
6450
  DEFINE_HEADER
@@ -6472,7 +6475,22 @@ SensitivityGroup STRING,3
6472
6475
  Active INTEGER,4
6473
6476
  Serie INTEGER,5
6474
6477
  END_DATA
6478
+ END_MASK
6479
+
6480
+ //---------------------------------------------------------------------
6481
+ // Chronological GAP
6482
+ //---------------------------------------------------------------------
6483
+ DEFINE_MASK CSVDATA OPTGEN_dattgyear
6484
+
6485
+ DEFINE_HEADER
6486
+ !year,GAP(%),TimeLimit(s)
6487
+ END_HEADER
6475
6488
 
6489
+ DEFINE_DATA
6490
+ InitialYear INTEGER,1
6491
+ GAP REAL,2
6492
+ TimeLimit INTEGER,3
6493
+ END_DATA
6476
6494
  END_MASK
6477
6495
  //---------------------------------------------------------------------
6478
6496
  //---------------------------------------------------------------------
@@ -7643,7 +7661,7 @@ END_MASK
7643
7661
  DEFINE_MASK ROWDATA SDDP_v10.2_chidro
7644
7662
 
7645
7663
  DEFINE_HEADER
7646
- !NUM ...Nombre... .PV. .VAA .TAA #Uni Tipo ....Pot .FPMed. .QMin.. .QMax.. .VMin.. .VMax.. .VInic. Min.V+T ..VNC.. ..ICP.. ...IH.. ..FP1.. ..Vol1. ..FP2.. ..Vol2. ..FP3.. ..Vol3. ..FP4.. ..Vol4. ..FP5.. ..Vol5. .Area1. ..Vol1. .Area2. ..Vol2. .Area3. ..Vol3. .Area4. ..Vol4. .Area5. ..Vol5. .Filt1. ..Vol1. .Filt2. ..Vol2. .Filt3. ..Vol3. .Filt4. ..Vol4. .Filt5. ..Vol5. .Cota1. .Vol1.. .Cota2. .Vol2.. .Cota3. .Vol3.. .Cota4. .Vol4.. .Cota5. .Vol5.. .Ev1 .Ev2 .Ev3 .Ev4 .Ev5 .Ev6 .Ev7 .Ev8 .Ev9 Ev10 Ev11 Ev12 tini tfil .faa tare .varea. tfil .vfiltr F.Reg.. pVar .ICV C.Vert. sfal Cos.O&M Irxh RendT&G .EA. Niv.Jus I JuAr I .TurIn1 .TotIn1 .TurIn2 .TotIn2 .TurIn3 .TotIn3 .TurIn4 .TotIn4 .TurIn5 .TotIn5 H V .CFuga1 ..Def1. .CFuga2 ..Def2. .CFuga3 ..Def3. .CFuga4 ..Def4. .CFuga5 ..Def5. E PHidTur PHidVer sv st OpMd IrrR IfTp ForFill ForDraw ForPenT ForPen.
7664
+ !NUM ...Nombre... .PV. .VAA .TAA #Uni Tipo ....Pot .FPMed. .QMin.. .QMax.. .VMin.. .VMax.. .VInic. Min.V+T ..VNC.. ..ICP.. ...IH.. ..FP1.. ..Vol1. ..FP2.. ..Vol2. ..FP3.. ..Vol3. ..FP4.. ..Vol4. ..FP5.. ..Vol5. .Area1. ..Vol1. .Area2. ..Vol2. .Area3. ..Vol3. .Area4. ..Vol4. .Area5. ..Vol5. .Filt1. ..Vol1. .Filt2. ..Vol2. .Filt3. ..Vol3. .Filt4. ..Vol4. .Filt5. ..Vol5. .Cota1. .Vol1.. .Cota2. .Vol2.. .Cota3. .Vol3.. .Cota4. .Vol4.. .Cota5. .Vol5.. .Ev1 .Ev2 .Ev3 .Ev4 .Ev5 .Ev6 .Ev7 .Ev8 .Ev9 Ev10 Ev11 Ev12 tini tfil .faa tare .varea. tfil .vfiltr F.Reg.. pVar .ICV C.Vert. sfal Cos.O&M Irxh RendT&G .EA. Niv.Jus I JuAr I .TurIn1 .TotIn1 .TurIn2 .TotIn2 .TurIn3 .TotIn3 .TurIn4 .TotIn4 .TurIn5 .TotIn5 H V .CFuga1 ..Def1. .CFuga2 ..Def2. .CFuga3 ..Def3. .CFuga4 ..Def4. .CFuga5 ..Def5. E PHidTur PHidVer sv st OpMd IrrR IfTp ForFill ForDraw ForPenT ForPen. .MinGen
7647
7665
  END_HEADER
7648
7666
 
7649
7667
  DEFINE_MACRO
@@ -7717,8 +7735,9 @@ IrrigationDchr INTEGER 820 823 AUTOSET(model.
7717
7735
  InfiltType INTEGER 825 828 AUTOSET(model.parm("InfiltType"))
7718
7736
  ForebayFillUp REAL 830 836 AUTOSET(model.parm("ForebayFillUp"))
7719
7737
  ForebayDrawDown REAL 838 844 AUTOSET(model.parm("ForebayDrawDown"))
7720
- ForebayPenType INTEGER 846 849 AUTOSET(model.parm("ForebayPenType"))
7721
- ForebayPen REAL 851 857 AUTOSET(model.parm("ForebayPen"))
7738
+ ForebayPenType INTEGER 846 852 AUTOSET(model.parm("ForebayPenType"))
7739
+ ForebayPen REAL 854 860 AUTOSET(model.parm("ForebayPen"))
7740
+ MinGen REAL 862 868 AUTOSET
7722
7741
 
7723
7742
  END_DATA
7724
7743
 
@@ -9829,7 +9848,7 @@ DEFINE_BLOCK
9829
9848
  BLOCK_IDENT Num
9830
9849
 
9831
9850
  DEFINE_HEADER
9832
- !NUM ...Nombre... .PV. .VAA .TAA #Uni Tipo ....Pot .FPMed. .QMin.. .QMax.. .VMin.. .VMax.. .VInic. Min.V+T ..VNC.. ..ICP.. ...IH.. ..FP1.. ..Vol1. ..FP2.. ..Vol2. ..FP3.. ..Vol3. ..FP4.. ..Vol4. ..FP5.. ..Vol5. .Area1. ..Vol1. .Area2. ..Vol2. .Area3. ..Vol3. .Area4. ..Vol4. .Area5. ..Vol5. .Filt1. ..Vol1. .Filt2. ..Vol2. .Filt3. ..Vol3. .Filt4. ..Vol4. .Filt5. ..Vol5. .Cota1. .Vol1.. .Cota2. .Vol2.. .Cota3. .Vol3.. .Cota4. .Vol4.. .Cota5. .Vol5.. .Ev1 .Ev2 .Ev3 .Ev4 .Ev5 .Ev6 .Ev7 .Ev8 .Ev9 Ev10 Ev11 Ev12 tini tfil .faa tare .varea. tfil .vfiltr F.Reg.. pVar .ICV C.Vert. sfal Cos.O&M Irxh RendT&G .EA. Niv.Jus I JuAr I .TurIn1 .TotIn1 .TurIn2 .TotIn2 .TurIn3 .TotIn3 .TurIn4 .TotIn4 .TurIn5 .TotIn5 H V .CFuga1 ..Def1. .CFuga2 ..Def2. .CFuga3 ..Def3. .CFuga4 ..Def4. .CFuga5 ..Def5. E
9851
+ !NUM ...Nombre... .PV. .VAA .TAA #Uni Tipo ....Pot .FPMed. .QMin.. .QMax.. .VMin.. .VMax.. .VInic. Min.V+T ..VNC.. ..ICP.. ...IH.. ..FP1.. ..Vol1. ..FP2.. ..Vol2. ..FP3.. ..Vol3. ..FP4.. ..Vol4. ..FP5.. ..Vol5. .Area1. ..Vol1. .Area2. ..Vol2. .Area3. ..Vol3. .Area4. ..Vol4. .Area5. ..Vol5. .Filt1. ..Vol1. .Filt2. ..Vol2. .Filt3. ..Vol3. .Filt4. ..Vol4. .Filt5. ..Vol5. .Cota1. .Vol1.. .Cota2. .Vol2.. .Cota3. .Vol3.. .Cota4. .Vol4.. .Cota5. .Vol5.. .Ev1 .Ev2 .Ev3 .Ev4 .Ev5 .Ev6 .Ev7 .Ev8 .Ev9 Ev10 Ev11 Ev12 tini tfil .faa tare .varea. tfil .vfiltr F.Reg.. pVar .ICV C.Vert. sfal Cos.O&M Irxh RendT&G .EA. Niv.Jus I JuAr I .TurIn1 .TotIn1 .TurIn2 .TotIn2 .TurIn3 .TotIn3 .TurIn4 .TotIn4 .TurIn5 .TotIn5 H V .CFuga1 ..Def1. .CFuga2 ..Def2. .CFuga3 ..Def3. .CFuga4 ..Def4. .CFuga5 ..Def5. E .MinGen
9833
9852
  END_HEADER
9834
9853
 
9835
9854
  DEFINE_MACRO
@@ -9858,6 +9877,7 @@ TotIn($(P)) REAL 619+(16*$(P)),626+(16*$(P)) AUTOSET
9858
9877
  OxT_Tail($(P)) REAL 695+(16*$(P)) 701+(16*$(P)) AUTOSET
9859
9878
  OxT_Outflow($(P)) REAL 703+(16*$(P)) 709+(16*$(P)) AUTOSET
9860
9879
  Eaflu INTEGER 791 791 AUTOSET
9880
+ MinGen REAL 793 799 AUTOSET
9861
9881
  END_DATA
9862
9882
 
9863
9883
  END_BLOCK
@@ -11122,6 +11142,98 @@ END_BLOCK
11122
11142
 
11123
11143
  END_MASK
11124
11144
 
11145
+ //---------------------------------------------------------------------
11146
+ //---------------------------------------------------------------------
11147
+ DEFINE_MASK MIXROWDATA SDDP_v10.2_mntbme
11148
+
11149
+ TOTAL_BLOCK 2
11150
+
11151
+ //-------------------------------------------------------------
11152
+ //-- PRIMEIRO BLOCO -> Identificacao da Usina ---
11153
+ //-------------------------------------------------------------
11154
+ DEFINE_BLOCK
11155
+ BLOCK_IDENT ****
11156
+ BLOCK_LENGTH 1
11157
+ NEXT_BLOCK 2
11158
+
11159
+ DEFINE_DATA
11160
+ IdentBloco STRING 1,12 ****_Planta:
11161
+ Num INTEGER 14,17
11162
+ Nome STRING 19,30
11163
+ IdentPenal STRING 32,37 Penal:
11164
+ MinTurbiningPenalty REAL 42,50 AUTOSET(model.parm("MinTurbiningPenalty"))
11165
+ END_DATA
11166
+
11167
+ END_BLOCK
11168
+ //-------------------------------------------------------------
11169
+ //-- SEGUNDO BLOCO -> Dados ---
11170
+ //-------------------------------------------------------------
11171
+ DEFINE_BLOCK
11172
+ BLOCK_IDENT Year
11173
+
11174
+ DEFINE_HEADER
11175
+ A~no ......1 ......2 ......3 ......4 ......5 ......6 ......7 ......8 ......9 .....10 .....11 .....12
11176
+ END_HEADER
11177
+
11178
+ DEFINE_MACRO
11179
+ VAR N 1,12
11180
+ END_MACRO
11181
+
11182
+ DEFINE_DATA
11183
+ Ano INTEGER 1,4
11184
+ Dado$(N) REAL 5+8*($(N)-1),12+8*($(N)-1)
11185
+ END_DATA
11186
+
11187
+ END_BLOCK
11188
+
11189
+ END_MASK
11190
+
11191
+ //---------------------------------------------------------------------
11192
+ //---------------------------------------------------------------------
11193
+ DEFINE_MASK MIXROWDATA SDDP_v10.2_mntbse
11194
+
11195
+ TOTAL_BLOCK 2
11196
+
11197
+ //-------------------------------------------------------------
11198
+ //-- PRIMEIRO BLOCO -> Identificacao da Usina ---
11199
+ //-------------------------------------------------------------
11200
+ DEFINE_BLOCK
11201
+ BLOCK_IDENT ****
11202
+ BLOCK_LENGTH 1
11203
+ NEXT_BLOCK 2
11204
+
11205
+ DEFINE_DATA
11206
+ IdentBloco STRING 1,12 ****_Planta:
11207
+ Num INTEGER 14,17
11208
+ Nome STRING 19,30
11209
+ IdentPenal STRING 32,37 Penal:
11210
+ MinTurbiningPenalty REAL 42,50 AUTOSET(model.parm("MinTurbiningPenalty"))
11211
+ END_DATA
11212
+
11213
+ END_BLOCK
11214
+ //-------------------------------------------------------------
11215
+ //-- SEGUNDO BLOCO -> Dados ---
11216
+ //-------------------------------------------------------------
11217
+ DEFINE_BLOCK
11218
+ BLOCK_IDENT Year
11219
+
11220
+ DEFINE_HEADER
11221
+ A~no ......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
11222
+ END_HEADER
11223
+
11224
+ DEFINE_MACRO
11225
+ VAR N 1,52
11226
+ END_MACRO
11227
+
11228
+ DEFINE_DATA
11229
+ Ano INTEGER 1,4
11230
+ Dado$(N) REAL 5+8*($(N)-1),12+8*($(N)-1)
11231
+ END_DATA
11232
+
11233
+ END_BLOCK
11234
+
11235
+ END_MASK
11236
+
11125
11237
  //---------------------------------------------------------------------
11126
11238
  //---------------------------------------------------------------------
11127
11239
  DEFINE_MASK MIXROWDATA SDDP_v10.2_mxtbme
@@ -11669,7 +11781,7 @@ MaxReactivePower REAL,21 AUTOSET
11669
11781
  ReactivePowerFactor REAL,22 AUTOSET
11670
11782
  GenDev REAL,23 AUTOSET
11671
11783
  MaxDev REAL,24 AUTOSET
11672
- DevOpt REAL,25 AUTOSET(model.parm("DevOpt"))
11784
+ DevOpt INTEGER,25 AUTOSET(model.parm("DevOpt"))
11673
11785
 
11674
11786
  END_DATA
11675
11787
 
@@ -13839,7 +13951,7 @@ MaxReactivePower REAL,15 AUTOSET
13839
13951
  ReactivePowerFactor REAL,16 AUTOSET
13840
13952
  GenDev REAL,17 AUTOSET
13841
13953
  MaxDev REAL,18 AUTOSET
13842
- DevOpt INTEGER,19 AUTOSET
13954
+ DevOpt INTEGER,19 AUTOSET(model.parm("DevOpt"))
13843
13955
  END_DATA
13844
13956
  END_MASK
13845
13957
  //---------------------------------------------------------------------
@@ -13855,7 +13967,7 @@ Code INTEGER,2
13855
13967
  Name STRING,3
13856
13968
  Bus INTEGER,4
13857
13969
  Existing INTEGER,5 AUTOSET
13858
- NumberOfUnits INTEGER,6 AUTOSET
13970
+ Unidades INTEGER,6 AUTOSET
13859
13971
  PotInst REAL,7 AUTOSET
13860
13972
  SM REAL,8 AUTOSET
13861
13973
  Efficiency REAL,9 AUTOSET
@@ -13869,7 +13981,6 @@ MaxDev REAL,16 AUTOSET
13869
13981
  END_DATA
13870
13982
  END_MASK
13871
13983
 
13872
-
13873
13984
  //---------------------------------------------------------------------
13874
13985
  //---------------------------------------------------------------------
13875
13986
  DEFINE_MASK CSVDATA SDDP_polca
@@ -13888,7 +13999,6 @@ A4 REAL, 7
13888
13999
  END_DATA
13889
14000
  END_MASK
13890
14001
 
13891
-
13892
14002
  //---------------------------------------------------------------------
13893
14003
  //---------------------------------------------------------------------
13894
14004
  DEFINE_MASK CSVDATA SDDP_hidtrb
@@ -13915,7 +14025,7 @@ HydroFrom STRING, 3
13915
14025
  HydroTo STRING, 4
13916
14026
  FlowMin REAL, 5 AUTOSET(model.parm("FlowMin"))
13917
14027
  FlowMax REAL, 6 AUTOSET(model.parm("FlowMax"))
13918
- TravelTime INTEGER, 7 AUTOSET(model.parm("TravelTime"))
14028
+ TravelTime REAL, 7 AUTOSET(model.parm("TravelTime"))
13919
14029
  Currency STRING, 8 AUTOSET(model.parm("Currency"))
13920
14030
  Disabled INTEGER, 9 AUTOSET(model.parm("Disabled"))
13921
14031
  END_DATA
@@ -14368,11 +14478,14 @@ name STRING,2
14368
14478
  unit STRING,3 AUTOSET(model.parm("unit"))
14369
14479
  resol INTEGER,4 AUTOSET(model.parm("resol"))
14370
14480
  type INTEGER,5 AUTOSET(model.parm("type"))
14371
- cost REAL,6 AUTOSET(model.parm("cost"))
14481
+ type INTEGER,6 AUTOSET(model.parm("UseCostAndBounds"))
14482
+ cost REAL,7 AUTOSET(model.parm("cost"))
14483
+ cost REAL,8 AUTOSET(model.parm("UpperBound"))
14484
+ cost REAL,9 AUTOSET(model.parm("LowerBound"))
14372
14485
  END_DATA
14373
14486
  DEFINE_HEADER
14374
14487
  $version=1
14375
- !code,name,unit,resol,type,cost
14488
+ !code,name,unit,resol,type,UseCostAndBounds,cost,UpperBound,LowerBound
14376
14489
  END_HEADER
14377
14490
  END_MASK
14378
14491
  //---------------------------------------------------------------------
@@ -15058,7 +15171,7 @@ DEFINE_MASK CSVDATA SDDP_dflowcontroller
15058
15171
 
15059
15172
  DEFINE_HEADER
15060
15173
  $version=1
15061
- !Code,Name,CircuitCode,ControlType,DeviceType,Location,Existing,Decommissioned,Xmin,Xmax,Rating,EmergencyRating,OutageProbability
15174
+ !Code,Name,CircuitCode,ControlType,DeviceType,Location,Existing,Decommissioned,Xmin,Xmax,Rating,EmergencyRating,MaxPower,OutageProbability
15062
15175
  END_HEADER
15063
15176
 
15064
15177
  DEFINE_DATA
@@ -15074,7 +15187,8 @@ Xmin REAL 9 AUTOSET
15074
15187
  Xmax REAL 10 AUTOSET
15075
15188
  Rn REAL 11 AUTOSET
15076
15189
  Re REAL 12 AUTOSET
15077
- Prob REAL 13 AUTOSET
15190
+ MaxPower REAL 13 AUTOSET
15191
+ Prob REAL 14 AUTOSET
15078
15192
  END_DATA
15079
15193
 
15080
15194
  END_MASK
@@ -15083,7 +15197,7 @@ DEFINE_MASK CSVDATA SDDP_mflowcontroller
15083
15197
 
15084
15198
  DEFINE_HEADER
15085
15199
  $version=1
15086
- !Day,Month,Year,Code,Name,CircuitCode,Existing,Decommissioned,Xmin,Xmax,Rating,EmergencyRating,OutageProbability
15200
+ !Day,Month,Year,Code,Name,CircuitCode,Existing,Decommissioned,Xmin,Xmax,Rating,EmergencyRating,MaxPower,OutageProbability
15087
15201
  END_HEADER
15088
15202
 
15089
15203
  DEFINE_DATA
@@ -15099,7 +15213,8 @@ Xmin REAL 9 AUTOSET
15099
15213
  Xmax REAL 10 AUTOSET
15100
15214
  Rn REAL 11 AUTOSET
15101
15215
  Re REAL 12 AUTOSET
15102
- Prob REAL 13 AUTOSET
15216
+ MaxPower REAL 13 AUTOSET
15217
+ Prob REAL 14 AUTOSET
15103
15218
  END_DATA
15104
15219
 
15105
15220
  END_MASK
@@ -15752,9 +15867,9 @@ END_DATA
15752
15867
  END_MASK
15753
15868
  //---------------------------------------------------------------------
15754
15869
  //---------------------------------------------------------------------
15755
- DEFINE_MASK CSVDATA SDDP_areatransf
15870
+ DEFINE_MASK CSVDATA SDDP_areamintransf
15756
15871
  DEFINE_AUTOMATIC_INFO
15757
- FILENAME areatransf.dat
15872
+ FILENAME areamintransf.dat
15758
15873
  VERSION 1
15759
15874
  CONTEXT_READ sddpac
15760
15875
  CONTEXT_WRITE sddpac
@@ -15764,15 +15879,38 @@ ATTRIBUTE_ID code
15764
15879
  END_AUTOMATIC_INFO
15765
15880
 
15766
15881
  DEFINE_DATA
15767
- code REFERENCE 1
15768
- DateTransfer DATE 2 YYYY/MM/DD AUTOSET
15769
- block INTEGER 3
15770
- MaxImport REAL 4
15771
- MaxExport REAL 5
15882
+ code REFERENCE 1
15883
+ DateMinTransfer DATE 2 YYYY/MM/DD AUTOSET
15884
+ block INTEGER 3
15885
+ MinTransfer REAL 4
15886
+ END_DATA
15887
+ DEFINE_HEADER
15888
+ $version=1
15889
+ !code,Date,block,MinTransfer
15890
+ END_HEADER
15891
+ END_MASK
15892
+ //---------------------------------------------------------------------
15893
+ //---------------------------------------------------------------------
15894
+ DEFINE_MASK CSVDATA SDDP_areamaxtransf
15895
+ DEFINE_AUTOMATIC_INFO
15896
+ FILENAME areamaxtransf.dat
15897
+ VERSION 1
15898
+ CONTEXT_READ sddpac
15899
+ CONTEXT_WRITE sddpac
15900
+ CLASSNAME PSRArea
15901
+ MODEL MODL:SDDP_Area
15902
+ ATTRIBUTE_ID code
15903
+ END_AUTOMATIC_INFO
15904
+
15905
+ DEFINE_DATA
15906
+ code REFERENCE 1
15907
+ DateMaxTransfer DATE 2 YYYY/MM/DD AUTOSET
15908
+ block INTEGER 3
15909
+ MaxTransfer REAL 4
15772
15910
  END_DATA
15773
15911
  DEFINE_HEADER
15774
15912
  $version=1
15775
- !code,Date,block,MinImport,MaxExport
15913
+ !code,Date,block,MaxTransfer
15776
15914
  END_HEADER
15777
15915
  END_MASK
15778
15916
  //---------------------------------------------------------------------
psr/factory/factorylib.py CHANGED
@@ -12,10 +12,13 @@ import psr.psrfcommon
12
12
  lib = None
13
13
 
14
14
  if sys.platform == "win32":
15
+ def get_lib_path() -> str:
16
+ return os.path.join(os.path.dirname(__file__), "factory.dll")
15
17
  def load_lib():
16
- lib_path = os.path.join(os.path.dirname(__file__), "factory.dll")
17
- return ctypes.cdll.LoadLibrary(lib_path)
18
+ return ctypes.cdll.LoadLibrary(get_lib_path())
18
19
  else:
20
+ def get_lib_path() -> str:
21
+ return os.path.join(os.path.dirname(__file__), "libfactory.so")
19
22
  def load_lib():
20
23
  with psr.psrfcommon.change_cwd(os.path.dirname(__file__)):
21
24
  lib_path = "./libfactory.so"
Binary file
@@ -0,0 +1,6 @@
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 .psrfcommon import *
6
+
@@ -0,0 +1,54 @@
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 os
6
+ import pathlib
7
+ import subprocess
8
+ import sys
9
+ from contextlib import contextmanager
10
+ from typing import Union, List
11
+
12
+
13
+ @contextmanager
14
+ def change_cwd(new_dir: Union[str, pathlib.Path]):
15
+ last_dir = os.getcwd()
16
+ os.chdir(new_dir)
17
+ try:
18
+ yield
19
+ finally:
20
+ os.chdir(last_dir)
21
+
22
+
23
+ def exec_cmd(cmd: Union[str, List[str]], **kwargs) -> int:
24
+ dry_run = kwargs.get("dry_run", False)
25
+ print_progress = kwargs.get("show_progress", False)
26
+
27
+ if print_progress or dry_run:
28
+ sys.stdout.flush()
29
+
30
+ if dry_run:
31
+ if isinstance(cmd, list):
32
+ print(" ".join(cmd))
33
+ else:
34
+ print(cmd)
35
+ return_code = 0
36
+ else:
37
+ try:
38
+ return_code = subprocess.call(cmd, shell=True)
39
+ if return_code > 0:
40
+ raise RuntimeError(f"Execution error, code {return_code}")
41
+ else:
42
+ if print_progress:
43
+ print("Execution success", return_code)
44
+ except OSError as e:
45
+ msg = f"Execution failed: {e}"
46
+ if print_progress:
47
+ print(msg, file=sys.stderr)
48
+ raise RuntimeError(msg)
49
+
50
+ if print_progress or dry_run:
51
+ sys.stdout.flush()
52
+ return return_code
53
+
54
+
@@ -0,0 +1,118 @@
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 errno
6
+ import io
7
+ import os
8
+ from random import Random
9
+
10
+
11
+ class _RandomNameSequence:
12
+ """An instance of _RandomNameSequence generates an endless
13
+ sequence of unpredictable strings which can safely be incorporated
14
+ into file names. Each string is eight characters long. Multiple
15
+ threads can safely use the same instance at the same time.
16
+
17
+ _RandomNameSequence is an iterator."""
18
+
19
+ # Method extracted from tempfile Python's module.
20
+
21
+ characters = "abcdefghijklmnopqrstuvwxyz0123456789_"
22
+
23
+ @property
24
+ def rng(self):
25
+ cur_pid = os.getpid()
26
+ if cur_pid != getattr(self, "_rng_pid", None):
27
+ self._rng = Random() # nosec
28
+ self._rng_pid = cur_pid
29
+ return self._rng
30
+
31
+ def __iter__(self):
32
+ return self
33
+
34
+ def __next__(self):
35
+ c = self.characters
36
+ choose = self.rng.choice
37
+ letters = [choose(c) for dummy in range(8)]
38
+ return "".join(letters)
39
+
40
+
41
+ def _get_tempfile_name(base_path: str, prefix: str):
42
+ """Calculate the default directory to use for temporary files.
43
+ This routine should be called exactly once.
44
+
45
+ We determine whether a candidate temp dir is usable by
46
+ trying to create and write to a file in that directory. If this
47
+ is successful, the test file is deleted. To prevent denial of
48
+ service, the name of the test file must be randomized."""
49
+ # Method extracted from tempfile Python's module.
50
+
51
+ _text_openflags = os.O_RDWR | os.O_CREAT | os.O_EXCL
52
+ if hasattr(os, "O_NOFOLLOW"):
53
+ _text_openflags |= os.O_NOFOLLOW
54
+
55
+ _bin_openflags = _text_openflags
56
+ if hasattr(os, "O_BINARY"):
57
+ _bin_openflags |= os.O_BINARY
58
+
59
+ namer = _RandomNameSequence()
60
+
61
+ if base_path != os.curdir:
62
+ base_path = os.path.abspath(base_path)
63
+ # Try only a few names per directory.
64
+ for seq in range(100):
65
+ name = next(namer)
66
+ filename = os.path.join(base_path, prefix + name)
67
+ try:
68
+ fd = os.open(filename, _bin_openflags, 0o600)
69
+ try:
70
+ try:
71
+ with io.open(fd, "wb", closefd=False) as fp:
72
+ fp.write(b"blat")
73
+ finally:
74
+ os.close(fd)
75
+ finally:
76
+ os.unlink(filename)
77
+ return filename
78
+ except FileExistsError:
79
+ pass
80
+ except PermissionError:
81
+ # This exception is thrown when a directory with the chosen name
82
+ # already exists on windows.
83
+ if (
84
+ os.name == "nt"
85
+ and os.path.isdir(base_path)
86
+ and os.access(base_path, os.W_OK)
87
+ ):
88
+ continue
89
+ break # no point trying more names in this directory
90
+ except OSError:
91
+ break # no point trying more names in this directory
92
+ raise FileNotFoundError(
93
+ errno.ENOENT, "No usable temporary file found in " % base_path
94
+ )
95
+
96
+
97
+ class CreateTempFile:
98
+ def __init__(
99
+ self,
100
+ base_path: str,
101
+ prefix: str,
102
+ file_content: str,
103
+ extension: str = ".dat",
104
+ delete_tempfile: bool = True,
105
+ ):
106
+ self.delete_tempfile = delete_tempfile
107
+ # get temp file name
108
+ self.temp_file_name = _get_tempfile_name(base_path, prefix) + extension
109
+ self.temp_content = file_content
110
+
111
+ def __enter__(self):
112
+ with open(self.temp_file_name, "w", encoding="utf-8-sig") as tempfile:
113
+ tempfile.write(self.temp_content)
114
+ return tempfile
115
+
116
+ def __exit__(self, exc_type, exc_val, exc_tb):
117
+ if self.delete_tempfile:
118
+ os.remove(self.temp_file_name)
psr/runner/__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 .runner import *
7
+