Skip to content

Commit d7062e5

Browse files
cleanup and add open-manual
1 parent b44c378 commit d7062e5

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

tasks/ngspice.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
####################################################################################################
3131

32-
import PySpice.Spice.NgSpice as NgSpice
32+
from PySpice.Spice import NgSpice
3333

3434
####################################################################################################
3535

@@ -39,6 +39,7 @@
3939
RELEASE_URL = BASE_URL + '/ng-spice-rework'
4040
RELEASE_NOTE_URL = RELEASE_URL + '/{}/ReleaseNotes.txt/download'
4141
MANUAL_URL = RELEASE_URL + '/{0}/ngspice-{0}-manual.pdf/download'
42+
CURRENT_MANUAL_URL = 'https://ngspice.sourceforge.io/docs/ngspice-manual.pdf'
4243
# LATEST_URL = BASE_URL + '/latest/download' # zip
4344
TAR_URL = RELEASE_URL + '/{0}/ngspice-{0}.tar.gz'
4445
# OSX_URL = RELEASE_URL + '/{0}/ngspice-{0}.pkg'
@@ -51,8 +52,8 @@
5152
def get_last_version(ctx):
5253
from bs4 import BeautifulSoup
5354
import requests
54-
response = requests.get(RELEASE_URL)
55-
assert(response.status_code == requests.codes.ok)
55+
response = requests.get(RELEASE_URL, timeout=10)
56+
assert response.status_code == requests.codes.ok
5657
soup = BeautifulSoup(response.text, 'html.parser')
5758
divs = soup.find_all('tr', attrs={'class': 'folder'})
5859
for div in divs:
@@ -63,7 +64,7 @@ def get_last_version(ctx):
6364
if not hasattr(ctx, 'ngspice_last_version'):
6465
ctx.ngspice_last_version = version
6566
date = div.find('td', attrs={'headers': 'files_date_h'}).get_text()
66-
print('version {} on {}'.format(version, date))
67+
print(f'version {version} on {date}')
6768
except:
6869
# raise NameError('Bad version {}'.format(version))
6970
pass
@@ -74,29 +75,28 @@ def get_last_version(ctx):
7475
def get_last_release_note(ctx):
7576
import requests
7677
url = RELEASE_NOTE_URL.format(ctx.ngspice_last_version)
77-
print('Get {} ...'.format(url))
78-
response = requests.get(url, allow_redirects=True)
79-
assert(response.status_code == requests.codes.ok)
78+
print(f'Get {url} ...')
79+
response = requests.get(url, allow_redirects=True, timeout=10)
80+
assert response.status_code == requests.codes.ok
8081
print(response.text)
8182

8283
####################################################################################################
8384

8485
def donwload_file(url, dst_path):
8586
import requests
86-
print('Get {} ... -> {}'.format(url, dst_path))
87-
response = requests.get(url, allow_redirects=True)
88-
assert(response.status_code == requests.codes.ok)
87+
print(f'Get {url} ... -> {dst_path}')
88+
response = requests.get(url, allow_redirects=True, timeout=10)
89+
assert response.status_code == requests.codes.ok
8990
with open(dst_path, mode='wb') as fh:
9091
fh.write(response.content)
9192

9293
####################################################################################################
9394

9495
def init(ctx):
95-
9696
if hasattr(ctx, 'ctx.ngspice_base_path'):
9797
return
9898

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

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

@@ -130,12 +130,12 @@ def get_source(ctx, extract=True):
130130
return
131131
# remove_directories(ctx)
132132
url = TAR_URL.format(ctx.ngspice_last_version)
133-
dst_path = 'ngspice-{}.tar.gz'.format(ctx.ngspice_last_version)
133+
dst_path = f'ngspice-{ctx.ngspice_last_version}.tar.gz'
134134
donwload_file(url, dst_path)
135135
if extract:
136136
import tarfile
137-
tar_file = tarfile.open(dst_path)
138-
tar_file.extractall()
137+
with tarfile.open(dst_path) as tar_file:
138+
tar_file.extractall()
139139
ctx.ngspice_base_path.rename(ctx.ngspice_source_path)
140140

141141
####################################################################################################
@@ -146,12 +146,12 @@ def configure(ctx):
146146
configure_path = ctx.ngspice_source_path.joinpath('configure')
147147
command = [
148148
str(configure_path),
149-
'--prefix={}'.format(ctx.install_path),
150-
'--with-ngshared',
151-
'--enable-xspice',
152-
'--enable-cider',
153-
'--enable-openmp',
154-
'--disable-debug',
149+
f'--prefix={ctx.install_path}',
150+
'--with-ngshared',
151+
'--enable-xspice',
152+
'--enable-cider',
153+
'--enable-openmp',
154+
'--disable-debug',
155155
]
156156
if not ctx.ngspice_build_path.exists():
157157
os.mkdir(ctx.ngspice_build_path)
@@ -195,9 +195,13 @@ def install(ctx):
195195
@task(get_last_version)
196196
def get_manual(ctx):
197197
url = MANUAL_URL.format(ctx.ngspice_last_version)
198-
dst_path = 'ngspice-manual-{}.pdf'.format(ctx.ngspice_last_version)
198+
dst_path = f'ngspice-manual-{ctx.ngspice_last_version}.pdf'
199199
donwload_file(url, dst_path)
200200

201+
@task()
202+
def open_manual(ctx):
203+
ctx.run(f'xdg-open {CURRENT_MANUAL_URL}')
204+
201205
####################################################################################################
202206

203207
# @task(get_last_version)
@@ -211,7 +215,7 @@ def get_manual(ctx):
211215
@task(get_last_version)
212216
def get_windows(ctx):
213217
url = WINDOWS_URL.format(ctx.ngspice_last_version)
214-
dst_path = 'ngspice-{}_64.zip'.format(ctx.ngspice_last_version)
218+
dst_path = f'ngspice-{ctx.ngspice_last_version}_64.zip'
215219
donwload_file(url, dst_path)
216220

217221
####################################################################################################
@@ -221,7 +225,7 @@ def get_windows_dll(ctx):
221225
# version = ctx.ngspice_last_version
222226
version = NgSpice.NGSPICE_SUPPORTED_VERSION
223227
url = WINDOWS_DLL_URL.format(version)
224-
dst_path = 'ngspice-{}_dll_64.zip'.format(version)
228+
dst_path = f'ngspice-{version}_dll_64.zip'
225229
donwload_file(url, dst_path)
226230

227231
####################################################################################################

0 commit comments

Comments
 (0)