fix problem with wokwi files not being fetched. Add the wokwi truthtable testing that got lost in merge

This commit is contained in:
Matt Venn
2023-05-25 14:57:16 +02:00
parent 02e5cc1ae2
commit bd524505bf
3 changed files with 45 additions and 9 deletions
-5
View File
@@ -99,11 +99,6 @@ class Projects():
project.post_clone_setup() project.post_clone_setup()
logging.debug(project) logging.debug(project)
# fetch the wokwi source
if args.clone_all:
if not project.is_fill() and project.is_wokwi():
project.fetch_wokwi_files()
if args.harden: if args.harden:
if filler is False: if filler is False:
project.create_user_config() project.create_user_config()
+4 -2
View File
@@ -3,7 +3,9 @@ from urllib.parse import urlparse
import logging import logging
import requests import requests
import os import os
import zipfile, io import zipfile
import io
import errno
def unique(duplist): def unique(duplist):
@@ -21,7 +23,7 @@ def fetch_file(url, filename):
r = requests.get(url) r = requests.get(url)
if r.status_code != 200: if r.status_code != 200:
logging.warning("couldn't download {}".format(url)) logging.warning("couldn't download {}".format(url))
exit(1) raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename)
with open(filename, 'wb') as fh: with open(filename, 'wb') as fh:
logging.info("written to {}".format(filename)) logging.info("written to {}".format(filename))
+41 -2
View File
@@ -293,15 +293,54 @@ class Project():
def fetch_wokwi_files(self): def fetch_wokwi_files(self):
logging.info("fetching wokwi files") logging.info("fetching wokwi files")
src_file = self.src_files[0] src_file = self.src_files[0]
url = "https://wokwi.com/api/projects/{}/verilog".format(self.wokwi_id) url = f"https://wokwi.com/api/projects/{self.wokwi_id}/verilog"
git_utils.fetch_file(url, os.path.join(self.local_dir, "src", src_file)) git_utils.fetch_file(url, os.path.join(self.local_dir, "src", src_file))
# also fetch the wokwi diagram # also fetch the wokwi diagram
url = "https://wokwi.com/api/projects/{}/diagram.json".format(self.wokwi_id) url = f"https://wokwi.com/api/projects/{self.wokwi_id}/diagram.json"
diagram_file = "wokwi_diagram.json" diagram_file = "wokwi_diagram.json"
git_utils.fetch_file(url, os.path.join(self.local_dir, "src", diagram_file)) git_utils.fetch_file(url, os.path.join(self.local_dir, "src", diagram_file))
# attempt to download the *optional* truthtable for the project
truthtable_file = "truthtable.md"
url = f"https://wokwi.com/api/projects/{self.wokwi_id}/{truthtable_file}"
try:
git_utils.fetch_file(url, os.path.join(self.local_dir, "src", truthtable_file))
logging.info(f'Wokwi project {self.wokwi_id} has a truthtable included, will test!')
self.install_wokwi_testing()
except FileNotFoundError:
pass
def install_wokwi_testing(self, destination_dir='src', resource_dir=None):
if resource_dir is None or not len(resource_dir):
resource_dir = os.path.join(os.path.dirname(__file__), 'testing')
# directories in testing/lib to copy over
pyLibsDir = os.path.join(resource_dir, 'lib')
# src template dir
srcTplDir = os.path.join(resource_dir, 'src-tpl')
for libfullpath in glob.glob(os.path.join(pyLibsDir, '*')):
logging.info(f'Copying {libfullpath} to {destination_dir}')
shutil.copytree(
libfullpath,
os.path.join(destination_dir, os.path.basename(libfullpath)),
dirs_exist_ok=True)
for srcTemplate in glob.glob(os.path.join(srcTplDir, '*')):
with open(srcTemplate, 'r') as f:
contents = f.read()
customizedContents = re.sub('WOKWI_ID', str(self.wokwi_id), contents)
outputFname = os.path.basename(srcTemplate)
with open(os.path.join(destination_dir, outputFname), 'w') as outf:
logging.info(f'writing src tpl to {outputFname}')
outf.write(customizedContents)
outf.close()
def create_user_config(self): def create_user_config(self):
if self.is_wokwi():
self.fetch_wokwi_files()
logging.info("creating include file") logging.info("creating include file")
filename = 'user_config.tcl' filename = 'user_config.tcl'
with open(os.path.join(self.local_dir, 'src', filename), 'w') as fh: with open(os.path.join(self.local_dir, 'src', filename), 'w') as fh: