Commit 973ef7ba authored by Thomas Nadovich's avatar Thomas Nadovich 🌸
Browse files

Gitlab download working

parent bc89dcc2
Pipeline #17035 passed with stage
in 5 seconds
......@@ -187,7 +187,8 @@ def setup_cli():
cli.add_command(elbow)
cli.add_command(p3)
cli.add_command(jtag)
cli.add_command(setup_jlink)
cli.add_command(test_gl_dl)
cli.add_command(test_smb_dl)
if permissions >= PERMISSIONS_ENGINEER:
cli.add_command(sdo_upload)
......
......@@ -29,6 +29,7 @@ from ..utils import get_inspection_artifacts, echo_banner, continue_prompt, conf
from .flashloader import set_node_id, flash, reset_all
from .jtag import jlink
from .can import ping, configure, reset
from .smb import smb_download, gitlab_download
logger = logging.getLogger(__name__)
......@@ -143,6 +144,20 @@ def nuke_eeprom(ctx, device, verbose):
click.echo("Nuking EEPROM {0} using multilink".format(nuke_eeprom_elf))
ctx.invoke(multilink, filename=nuke_eeprom_elf)
@click.command()
@click.option("--token", "-t", default=None, help="Gitlab Token")
@click.pass_context
def test_gl_dl(ctx, token):
config = ctx.obj['config']
if not token:
token = config_get(config, "gitlab.token")
gitlab_download(token)
@click.command()
@click.pass_context
def test_smb_dl(ctx):
smb_download("scarif.local/web/temp/test.txt", "tn", "QrTVD!<yMl6Y")
@click.command()
@click.option("--token", "-t", default=None, help="Gitlab Token")
@click.option("--gitlab_url", "-g", default="https://git.barrett.com", help="Gitlab URL")
......@@ -151,7 +166,7 @@ def nuke_eeprom(ctx, device, verbose):
@click.pass_context
def setup_inspection(ctx, token, gitlab_url, output_path, verbose):
"""
Download the inspection firmwares
Download the inspection firmwares and J-Link driver
"""
config = ctx.obj['config']
......@@ -170,6 +185,15 @@ def setup_inspection(ctx, token, gitlab_url, output_path, verbose):
gitlab_url=gitlab_url, output_path=output_path, verbose=verbose)
fileserver = config_get(config, "smb.url")
click.echo("Downloading driver for J-Link from " + fileserver)
user = input(fileserver + "username:")
passwd = getpass.getpass("Password for " + user + ":")
try:
smb_download(fileserver + '/web/temp/test.txt', user, passwd)
except(urllib.error.URLError, smb.base.NotReadyError):
click.echo('Error: Unable to authenticate with server')
def enumerate_artifacts(artifacts):
if isinstance(artifacts, dict):
return artifacts.items()
......
import requests
import click
import getpass
import urllib
import smb
from smb.SMBHandler import SMBHandler
@click.command()
@click.pass_context
def setup_jlink(ctx):
user = input("Username:")
passwd = getpass.getpass("Password for " + user + ":")
try:
smb_download('scarif.local/web/temp/test.txt', user, passwd)
except(urllib.error.URLError, smb.base.NotReadyError):
click.echo('Error: Unable to authenticate with server')
def smb_download(url, username, password):
opener = urllib.request.build_opener(SMBHandler)
with opener.open('smb://{0}:{1}@{2}'.format(username, password, url)) as fh:
data = fh.read()
click.echo(data)
def gitlab_download(gl_token):
h = {"PRIVATE-TOKEN": gl_token}
response = requests.get("https://git.barrett.com/api/v4/projects/149/reposi"
+ "tory/files/mfg%2Dlaptop%2FJLink%5FLinux%5FV632h%5Fx86%5F64%2Edeb/raw"
+ "?ref=devel", headers=h)
open('jlink_driver.deb', 'wb').write(response.content)
# def gitlab_download(gitlab_url, project_id, file_path, ref, token)
......@@ -123,7 +123,8 @@ p386 = "p3"
odg = "objdict-generate"
[smb]
url = "scarif.local"
software_tools = "scarif.local/controlled_docs/Software Tools/"
download_path = "~/Downloads"
""".format(__version__))
......
Markdown is supported
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