Commit 10bd8aac authored by Jenni Rinker's avatar Jenni Rinker
Browse files

Resolve "Make a function to download tower clearance directly"

parent 8d459470
run_tests:
image: dtuwindenergy/wetb
script:
- python -m pip install --upgrade pip
- pip install git+https://gitlab.windenergy.dtu.dk/hawc-reference-models/reference-utilities.git
- pip install pytest
- python -m pytest
tags:
#- CPAV_old
# shared runner with Windows. shell executor. pip doesn't really work.
- python
# python: gitlab runner with synnefo docker image. Works, just really slow.
#- ellipsys
# shared runner. debian.
......@@ -2,10 +2,6 @@
Python-script utilities for the HAWC Reference Models
## Requirements
Wind Energy Toolbox (`wetb`).
## HTC file creation
The functions in `refutils.htc_conversion` convert a "base" htc file to a
......
# -*- coding: utf-8 -*-
"""Import functions from other modules
"""
import os, subprocess
from .htc_conversion import base_to_hs2, base_to_step, base_to_turb
import subprocess
#from .hawc_wrappers import run_hawc2, run_h2s
def delete_dlls(folder):
"""Delete DLLs in a specific folder"""
[os.remove(folder + f) for f in os.listdir(folder) if f.endswith('dll')]
def clone_repo(git_url, git_branch):
"""Clone specific branch of a repo"""
subprocess.run(f'git clone -b {git_branch} --single-branch ' +
f'--depth 1 {git_url}', shell=True, check=True)
def get_repo_info():
"""Get branch and commit of repo"""
url_res = subprocess.run(['git', 'config', '--get', 'remote.origin.url'],
......
# -*- coding: utf-8 -*-
"""Download DLLs from control binary repository
"""
import os
import subprocess
import zipfile
import requests
def delete_dlls(folder):
"""Delete DLLs in a specific folder"""
[os.remove(os.path.join(folder, f)) for f in os.listdir(folder) if
f.endswith('dll')]
def clone_dll_repo(branch='master'):
"""Clone repo with binary dlls"""
git_url = 'https://gitlab.windenergy.dtu.dk/OpenLAC/control-binary/control-win32.git'
subprocess.run(f'git clone -b {branch} --single-branch ' +
f'--depth 1 {git_url}', shell=True, check=True)
def get_towerclearance_mblade(version='1.0.0', bits=[32]):
"""Get towerclearance_mblade directly from repository"""
zipname = 'artifacts.zip'
url = ('https://gitlab.windenergy.dtu.dk/OpenLAC/servosandutilities/' +
f'towerclearance-mblade/-/jobs/artifacts/v{version}/download?job=compile_dlls')
r = requests.get(url)
with open(zipname, 'wb') as f:
f.write(r.content)
with zipfile.ZipFile(zipname, 'r') as zip_ref:
zip_ref.extractall('.')
os.remove(zipname)
if 32 not in bits:
os.remove('towerclearance_mblade.dll')
if 64 not in bits:
os.remove('towerclearance_mblade_x64.dll')
# -*- coding: utf-8 -*-
"""tests for dll utils
"""
import os
import subprocess
import sys
import pytest
from refutils.dll_utils import get_towerclearance_mblade, delete_dlls, clone_dll_repo
@pytest.fixture
def clean_zips_dlls():
"""remove dlls and zips before and after test"""
[os.remove(f) for f in os.listdir('.') if
(f.endswith('.zip') or f.endswith('.dll'))]
yield # run the test
[os.remove(f) for f in os.listdir('.') if
(f.endswith('.zip') or f.endswith('.dll'))]
@pytest.mark.parametrize("bits", [(32,), (64,), (32, 64)])
def test_get_towerclearance_mblade(bits, clean_zips_dlls):
"""check download of tower clearance"""
out_files = sorted([f'towerclearance_mblade{"_x64"*(b == 64)}.dll' for b in bits])
get_towerclearance_mblade(bits=bits)
local_files = sorted([f for f in os.listdir('.') if f.endswith('.dll')])
assert out_files == local_files
def test_delete_dlls():
"""verify dlls are deleted"""
get_towerclearance_mblade(bits=[32])
delete_dlls('.')
assert 0 == len([f for f in os.listdir('.') if f.endswith('.dll')])
def test_clone_dll_repo():
if 'win' in sys.platform:
subprocess.run(f'RD /S /Q control-win32', shell=True)
clone_dll_repo()
assert 'control-win32' in os.listdir('.')
if 'win' in sys.platform:
subprocess.run(f'RD /S /Q control-win32', shell=True, check=True)
......@@ -13,6 +13,6 @@ setup(name='refutils',
license='MIT',
packages=['refutils', # top-level package
],
install_requires=[#'wetb', # wind energy toolbox (pip installation currently broken)
],
install_requires=['wetb', # wind energy toolbox (pip installation currently broken)
'requests'],
zip_safe=False)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment