Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
The Gitlab server is succesfully updated to version 17.10.3
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
8aadeaaf
Commit
8aadeaaf
authored
11 months ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
add function to install dtu license
parent
2c9563f4
No related branches found
No related tags found
1 merge request
!262
add function to install dtu license
Pipeline
#56926
passed
11 months ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/utils/installer.py
+92
-1
92 additions, 1 deletion
wetb/utils/installer.py
wetb/utils/tests/test_installer.py
+67
-2
67 additions, 2 deletions
wetb/utils/tests/test_installer.py
with
159 additions
and
3 deletions
wetb/utils/installer.py
+
92
−
1
View file @
8aadeaaf
...
...
@@ -2,12 +2,17 @@ import glob
import
io
import
json
import
os
import
stat
import
pathlib
import
platform
import
shutil
import
zipfile
import
sys
from
pathlib
import
Path
from
platform
import
architecture
from
urllib.request
import
Request
,
urlopen
def
chmod_x
(
exe_path
:
str
):
"""
Utility function to change the file mode of a file to allow execution
...
...
@@ -112,3 +117,89 @@ def install_wind_tool(
print
(
f
"
{
tool
}
version
{
version
}
succesfully installed in
{
destination
}
"
)
return
def
install_hawc2_dtu_license
():
"""
Function to install the DTU HAWC2 license. In order to install the license, you must be logged in to the DTU network.
"""
if
sys
.
platform
.
lower
()
==
'
win32
'
:
ping_param
=
"
-n 1
"
f
=
Path
(
os
.
getenv
(
'
APPDATA
'
))
/
'
DTU Wind Energy/hawc2/license.cfg
'
else
:
ping_param
=
"
-c 1
"
f
=
Path
(
'
~/.config/hawc2/license.cfg
'
)
if
not
f
.
exists
():
f
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
if
b
'
LICENSE SERVER RUNNING
'
in
urlopen
(
"
http://license-internal.windenergy.dtu.dk:34523
"
).
read
():
f
.
write_text
(
"
[licensing]
\n
host = http://license-internal.windenergy.dtu.dk
\n
port = 34523
"
)
else
:
raise
ConnectionError
(
f
"
Could not connect to the DTU license server. You must be connected to the DTU network to use this function.
"
)
def
install_keygen_license
(
software
:
str
,
cfg_file
:
str
,
force
:
bool
=
False
):
"""
Install license file for HAWC2, HAWCStab2 or Ellipsys on your machine
Parameters
----------
software : str
Must be one of HAWC2, HAWCStab2 or Ellipsys. The argument is case insensitive.
cfg_file : str
Path to the license file to install
force : bool, optional
Switch to force the installation, overwriting any existing , by default False
Returns
-------
NoneType
None
Raises
------
ValueError
A ValueError is raised if the name of the software argument is not supported.
"""
SUPPORTED_SOFTWARES
=
[
"
hawc2
"
,
"
hawcstab2
"
,
"
ellipsys
"
]
if
software
.
lower
()
not
in
SUPPORTED_SOFTWARES
:
raise
ValueError
(
f
"'
software
'
must be one of
{
SUPPORTED_SOFTWARES
}
"
)
USER_PLATFORM
=
platform
.
uname
().
system
if
USER_PLATFORM
==
"
Windows
"
:
APPDATA
=
f
"
{
os
.
environ
[
'
APPDATA
'
]
}
"
else
:
APPDATA
=
"
None
"
def
local_license_dir
(
platform
,
software
):
return
{
"
Windows
"
:
os
.
path
.
join
(
APPDATA
,
"
DTU Wind Energy
"
,
f
"
{
software
}
"
,
),
"
Linux
"
:
os
.
path
.
join
(
f
"
{
pathlib
.
Path
.
home
()
}
"
,
"
.config
"
,
f
"
{
software
}
"
),
"
Darwin
"
:
os
.
path
.
join
(
f
"
{
pathlib
.
Path
.
home
()
}
"
,
"
Library
"
,
"
Application Support
"
),
}[
platform
]
def
local_license_file
(
software
):
return
{
"
hawc2
"
:
"
license.cfg
"
,
"
hawcstab2
"
:
"
license.cfg
"
,
"
pywasp
"
:
""
,
"
ellipsys
"
:
"
license.cfg
"
,
}[
software
.
lower
()]
license_path
=
local_license_dir
(
USER_PLATFORM
,
software
)
lic_name
=
local_license_file
(
software
)
os
.
makedirs
(
license_path
,
exist_ok
=
True
)
if
os
.
path
.
exists
(
os
.
path
.
join
(
license_path
,
lic_name
))
and
os
.
path
.
isfile
(
os
.
path
.
join
(
license_path
,
lic_name
))
and
(
not
force
):
print
(
f
"
License already installed for
{
software
}
, use
'
force=True
'
to overwrite installation
"
)
else
:
shutil
.
copy
(
f
"
{
cfg_file
}
"
,
f
"
{
os
.
path
.
join
(
license_path
,
lic_name
)
}
"
)
This diff is collapsed.
Click to expand it.
wetb/utils/tests/test_installer.py
+
67
−
2
View file @
8aadeaaf
import
platform
import
pathlib
import
os
import
pytest
from
wetb.utils.installer
import
install_wind_tool
from
wetb.utils.installer
import
install_wind_tool
,
install_hawc2_dtu_license
,
install_keygen_license
import
shutil
DESTINATION
=
"
/tmp/hawc2
"
USER_PLATFORM
=
platform
.
uname
().
system
if
USER_PLATFORM
==
"
Windows
"
:
APPDATA
=
f
"
{
os
.
environ
[
'
APPDATA
'
]
}
"
else
:
APPDATA
=
"
None
"
TEST_LICENSE_FILE
=
"
/tmp/license.cfg
"
with
open
(
TEST_LICENSE_FILE
,
"
w
"
)
as
file
:
file
.
writelines
([
"
\n
[licensing]
"
,
"
\n
host: www.fakehost.com
"
,
"
\n
port=360
"
])
def
local_license_dir
(
platform
,
software
):
return
{
"
Windows
"
:
os
.
path
.
join
(
APPDATA
,
"
DTU Wind Energy
"
,
f
"
{
software
}
"
,
),
"
Linux
"
:
os
.
path
.
join
(
f
"
{
pathlib
.
Path
.
home
()
}
"
,
"
.config
"
,
f
"
{
software
}
"
),
"
Darwin
"
:
os
.
path
.
join
(
f
"
{
pathlib
.
Path
.
home
()
}
"
,
"
Library
"
,
"
Application Support
"
),
}[
platform
]
def
local_license_file
(
software
):
return
{
"
hawc2
"
:
"
license.cfg
"
,
"
hawcstab2
"
:
"
license.cfg
"
,
"
pywasp
"
:
""
,
"
ellipsys
"
:
"
license.cfg
"
,
}[
software
.
lower
()]
def
test_installer_zip
():
# Install a program distributed as a zip file
try
:
...
...
@@ -40,4 +79,30 @@ def test_version_not_available():
except
:
raise
finally
:
shutil
.
rmtree
(
DESTINATION
)
\ No newline at end of file
shutil
.
rmtree
(
DESTINATION
)
def
test_install_hawc2_dtu_license
():
license_path
=
local_license_dir
(
USER_PLATFORM
,
"
HAWC2
"
)
try
:
install_hawc2_dtu_license
()
except
:
raise
finally
:
shutil
.
rmtree
(
license_path
,
ignore_errors
=
True
)
TEST_LICENSE_FILE
=
"
/tmp/license.cfg
"
with
open
(
TEST_LICENSE_FILE
,
"
w
"
)
as
file
:
file
.
writelines
([
"
\n
[licensing]
"
,
"
\n
host: www.fakehost.com
"
,
"
\n
port=360
"
])
@pytest.mark.parametrize
(
"
software,license
"
,
[(
"
HAWC2
"
,
TEST_LICENSE_FILE
),(
"
HAWCStab2
"
,
TEST_LICENSE_FILE
),(
"
ellipSYS
"
,
TEST_LICENSE_FILE
)])
def
test_install_keygen_license
(
software
,
license
):
license_path
=
local_license_dir
(
USER_PLATFORM
,
software
)
try
:
install_keygen_license
(
software
=
software
,
cfg_file
=
license
)
except
Exception
as
exc
:
raise
exc
finally
:
shutil
.
rmtree
(
license_path
,
ignore_errors
=
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment