Skip to content

Commit

Permalink
cleanup and add open-manual
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriceSalvaire committed Jan 26, 2024
1 parent b44c378 commit d7062e5
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions tasks/ngspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

####################################################################################################

import PySpice.Spice.NgSpice as NgSpice
from PySpice.Spice import NgSpice

####################################################################################################

Expand All @@ -39,6 +39,7 @@
RELEASE_URL = BASE_URL + '/ng-spice-rework'
RELEASE_NOTE_URL = RELEASE_URL + '/{}/ReleaseNotes.txt/download'
MANUAL_URL = RELEASE_URL + '/{0}/ngspice-{0}-manual.pdf/download'
CURRENT_MANUAL_URL = 'https://ngspice.sourceforge.io/docs/ngspice-manual.pdf'
# LATEST_URL = BASE_URL + '/latest/download' # zip
TAR_URL = RELEASE_URL + '/{0}/ngspice-{0}.tar.gz'
# OSX_URL = RELEASE_URL + '/{0}/ngspice-{0}.pkg'
Expand All @@ -51,8 +52,8 @@
def get_last_version(ctx):
from bs4 import BeautifulSoup
import requests
response = requests.get(RELEASE_URL)
assert(response.status_code == requests.codes.ok)
response = requests.get(RELEASE_URL, timeout=10)
assert response.status_code == requests.codes.ok
soup = BeautifulSoup(response.text, 'html.parser')
divs = soup.find_all('tr', attrs={'class': 'folder'})
for div in divs:
Expand All @@ -63,7 +64,7 @@ def get_last_version(ctx):
if not hasattr(ctx, 'ngspice_last_version'):
ctx.ngspice_last_version = version
date = div.find('td', attrs={'headers': 'files_date_h'}).get_text()
print('version {} on {}'.format(version, date))
print(f'version {version} on {date}')
except:
# raise NameError('Bad version {}'.format(version))
pass
Expand All @@ -74,29 +75,28 @@ def get_last_version(ctx):
def get_last_release_note(ctx):
import requests
url = RELEASE_NOTE_URL.format(ctx.ngspice_last_version)
print('Get {} ...'.format(url))
response = requests.get(url, allow_redirects=True)
assert(response.status_code == requests.codes.ok)
print(f'Get {url} ...')
response = requests.get(url, allow_redirects=True, timeout=10)
assert response.status_code == requests.codes.ok
print(response.text)

####################################################################################################

def donwload_file(url, dst_path):
import requests
print('Get {} ... -> {}'.format(url, dst_path))
response = requests.get(url, allow_redirects=True)
assert(response.status_code == requests.codes.ok)
print(f'Get {url} ... -> {dst_path}')
response = requests.get(url, allow_redirects=True, timeout=10)
assert response.status_code == requests.codes.ok
with open(dst_path, mode='wb') as fh:
fh.write(response.content)

####################################################################################################

def init(ctx):

if hasattr(ctx, 'ctx.ngspice_base_path'):
return

ctx.ngspice_base_path = PYSPICE_SOURCE_PATH.joinpath('ngspice-{}'.format(ctx.ngspice_last_version))
ctx.ngspice_base_path = PYSPICE_SOURCE_PATH.joinpath(f'ngspice-{ctx.ngspice_last_version}')

ctx.ngspice_source_path = Path(str(ctx.ngspice_base_path) + '-src')
print('ngspice source path', ctx.ngspice_source_path)
Expand All @@ -117,7 +117,7 @@ def remove_directories(ctx):
ctx.ngspice_build_path,
ctx.install_path,
):
rc = input('remove {} ? [n]/y '.format(path))
rc = input(f'remove {path} ? [n]/y ')
if rc == 'y':
shutil.rmtree(path, ignore_errors=True)

Expand All @@ -130,12 +130,12 @@ def get_source(ctx, extract=True):
return
# remove_directories(ctx)
url = TAR_URL.format(ctx.ngspice_last_version)
dst_path = 'ngspice-{}.tar.gz'.format(ctx.ngspice_last_version)
dst_path = f'ngspice-{ctx.ngspice_last_version}.tar.gz'
donwload_file(url, dst_path)
if extract:
import tarfile
tar_file = tarfile.open(dst_path)
tar_file.extractall()
with tarfile.open(dst_path) as tar_file:
tar_file.extractall()
ctx.ngspice_base_path.rename(ctx.ngspice_source_path)

####################################################################################################
Expand All @@ -146,12 +146,12 @@ def configure(ctx):
configure_path = ctx.ngspice_source_path.joinpath('configure')
command = [
str(configure_path),
'--prefix={}'.format(ctx.install_path),
'--with-ngshared',
'--enable-xspice',
'--enable-cider',
'--enable-openmp',
'--disable-debug',
f'--prefix={ctx.install_path}',
'--with-ngshared',
'--enable-xspice',
'--enable-cider',
'--enable-openmp',
'--disable-debug',
]
if not ctx.ngspice_build_path.exists():
os.mkdir(ctx.ngspice_build_path)
Expand Down Expand Up @@ -195,9 +195,13 @@ def install(ctx):
@task(get_last_version)
def get_manual(ctx):
url = MANUAL_URL.format(ctx.ngspice_last_version)
dst_path = 'ngspice-manual-{}.pdf'.format(ctx.ngspice_last_version)
dst_path = f'ngspice-manual-{ctx.ngspice_last_version}.pdf'
donwload_file(url, dst_path)

@task()
def open_manual(ctx):
ctx.run(f'xdg-open {CURRENT_MANUAL_URL}')

####################################################################################################

# @task(get_last_version)
Expand All @@ -211,7 +215,7 @@ def get_manual(ctx):
@task(get_last_version)
def get_windows(ctx):
url = WINDOWS_URL.format(ctx.ngspice_last_version)
dst_path = 'ngspice-{}_64.zip'.format(ctx.ngspice_last_version)
dst_path = f'ngspice-{ctx.ngspice_last_version}_64.zip'
donwload_file(url, dst_path)

####################################################################################################
Expand All @@ -221,7 +225,7 @@ def get_windows_dll(ctx):
# version = ctx.ngspice_last_version
version = NgSpice.NGSPICE_SUPPORTED_VERSION
url = WINDOWS_DLL_URL.format(version)
dst_path = 'ngspice-{}_dll_64.zip'.format(version)
dst_path = f'ngspice-{version}_dll_64.zip'
donwload_file(url, dst_path)

####################################################################################################
Expand Down

0 comments on commit d7062e5

Please sign in to comment.