diff --git a/nebula/downloader.py b/nebula/downloader.py index 7aa0af30..5f790614 100644 --- a/nebula/downloader.py +++ b/nebula/downloader.py @@ -37,6 +37,15 @@ def convert_to_datetime(date): return datetime.strptime(date[:10], "%Y_%m_%d") +def get_firmware_version(links): + version = None + for link in links: + file = link.split("/")[-1] + if "zip" in file: + version = file + return version + + def get_latest_release(links): latest = "0000_r1" for link in links: @@ -279,10 +288,7 @@ def __init__(self, http_server_ip=None, yamlfilename=None, board_name=None): yamlfilename, __class__.__name__, board_name=board_name ) - def _download_firmware(self, device, release=None): - if release == "master" or release == "release": - release = None - + def _download_firmware(self, device, source="github", release=None): if "m2k" in device.lower() or "adalm-2000" in device.lower(): dev = "m2k" elif "pluto" in device.lower(): @@ -290,29 +296,44 @@ def _download_firmware(self, device, release=None): else: raise Exception("Unknown device " + device) - if not release: - # Get latest - log.info("Release not set. Checking github for latest") - g = Github() - repo = g.get_repo("analogdevicesinc/{}-fw".format(dev)) - rel = repo.get_releases() - p = rel.get_page(0) - r = p[0] - release = r.tag_name - log.info("Using release: " + release) - - matched = re.match("v[0-1].[0-9][0-9]", release) - is_match = bool(matched) - assert is_match, "Version name invalid" - - url = "https://github.com/analogdevicesinc/{dev}-fw/releases/download/{rel}/{dev}-fw-{rel}.zip".format( - dev=dev, rel=release - ) - dest = "outs" - if not os.path.isdir(dest): - os.mkdir(dest) - release = os.path.join(dest, dev + "-fw-" + release + ".zip") - self.download(url, release) + if source == "github": + if release == "master" or release == "release": + release = None + if not release: + # Get latest + log.info("Release not set. Checking github for latest") + g = Github() + repo = g.get_repo("analogdevicesinc/{}-fw".format(dev)) + rel = repo.get_releases() + p = rel.get_page(0) + r = p[0] + release = r.tag_name + log.info("Using release: " + release) + + matched = re.match("v[0-1].[0-9][0-9]", release) + is_match = bool(matched) + assert is_match, "Version name invalid" + + url = "https://github.com/analogdevicesinc/{dev}-fw/releases/download/{rel}/{dev}-fw-{rel}.zip".format( + dev=dev, rel=release + ) + dest = "outs" + if not os.path.isdir(dest): + os.mkdir(dest) + filename = os.path.join(dest, dev + "-fw-" + release + ".zip") + elif source == "artifactory": + url_template = "https://artifactory.analog.com/artifactory/sdg-generic-development/m2k_and_pluto/{}-fw/{}/{}" + url = url_template.format(dev, "", "") + build_date = get_newest_folder(listFD(url)) + url = url_template.format(dev, build_date, "") + # get version + ver = get_firmware_version(listFD(url)) + url = url_template.format(dev, build_date, ver) + dest = "outs" + if not os.path.isdir(dest): + os.mkdir(dest) + filename = os.path.join(dest, ver) + self.download(url, filename) def _get_file( self, @@ -707,7 +728,7 @@ def _get_files( or "m2k" in details["carrier"].lower() or "adalm-2000" in details["carrier"].lower() ), "Firmware downloads only available for pluto and m2k" - self._download_firmware(details["carrier"], branch) + self._download_firmware(details["carrier"], source, branch) else: if source == "local_fs": # to fix diff --git a/nebula/manager.py b/nebula/manager.py index ed1cdbe5..fb185406 100644 --- a/nebula/manager.py +++ b/nebula/manager.py @@ -620,12 +620,17 @@ def board_reboot_auto_folder( log.info("Firmware based device selected") if jtag_mode: raise Exception("jtag_mode not supported for firmware device") - files = glob.glob(os.path.join(folder, "*.zip")) + try: + files = glob.glob(os.path.join(folder, "*.zip")) + print(files[0]) + except IndexError: + files = glob.glob(os.path.join(folder, "*.frm")) if not files: - raise Exception("No zip files found in folder: " + folder) + raise Exception("No files found in folder: " + folder) if len(files) > 1: - raise Exception("Too many zip files found in folder: " + folder) + raise Exception("Too manyfiles found in folder: " + folder) + log.info(files[0]) self.usbdev.update_firmware(files[0], device=design_name) time.sleep(3) if not self.usbdev.wait_for_usb_mount(device=design_name): diff --git a/nebula/network.py b/nebula/network.py index 1b4f7006..072e4f3f 100644 --- a/nebula/network.py +++ b/nebula/network.py @@ -263,7 +263,7 @@ def check_dmesg(self, error_on_warnings=False): tmp_filename_err = "/tmp/" + tmp_filename_root + "_err" tmp_filename_war = "/tmp/" + tmp_filename_root + "_warn" - if self.board_name == "pluto": + if self.board_name == "pluto" or self.board_name == "m2k": with open(tmp_filename_root, "w") as outfile: outfile.write(self.run_ssh_command("dmesg").stdout) with open(tmp_filename_root + "_warn", "w") as outfile: diff --git a/tests/test_downloader.py b/tests/test_downloader.py index fe9c19e6..e212765e 100644 --- a/tests/test_downloader.py +++ b/tests/test_downloader.py @@ -7,7 +7,7 @@ # Must be connected to analog VPN -def downloader_test(board_name, branch, filetype): +def downloader_test(board_name, branch, filetype, source="artifactory"): file = { "firmware": None, "boot_partition": None, @@ -24,7 +24,7 @@ def downloader_test(board_name, branch, filetype): d = downloader(yamlfilename=yamlfilename, board_name=board_name) d.download_boot_files( board_name, - source="artifactory", + source=source, source_root="artifactory.analog.com", branch=branch, firmware=file["firmware"], @@ -110,10 +110,12 @@ def test_rpi_downloader(test_downloader, board_name, branch, filetype): @pytest.mark.parametrize("board_name", ["pluto"]) -@pytest.mark.parametrize("branch", ["master", "v0.33"]) +@pytest.mark.parametrize( + "source, branch", [("github", "v0.33"), ("artifactory", "master")] +) @pytest.mark.parametrize("filetype", ["firmware"]) -def test_firmware_downloader(test_downloader, board_name, branch, filetype): - test_downloader(board_name, branch, filetype) +def test_firmware_downloader(test_downloader, board_name, branch, filetype, source): + test_downloader(board_name, branch, filetype, source=source) if branch == "v0.33": assert os.path.isfile("outs/plutosdr-fw-v0.33.zip") else: