Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
A few touches on flasher, and complete rework of prosconductor
Browse files Browse the repository at this point in the history
  • Loading branch information
edjubuh committed Jun 26, 2016
1 parent a7dd1ad commit 03f185b
Show file tree
Hide file tree
Showing 32 changed files with 671 additions and 533 deletions.
Binary file removed Drawing1.vsdx
Binary file not shown.
93 changes: 93 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import sys

from cx_Freeze import Executable, setup

if sys.platform == 'win32':
targetName = 'pros.exe'
else:
targetName = 'pros'

setup(
name='purdueros-cli',
version='2.0',
packages=['prosflasher', 'proscli'],
url='https://github.com/purduesigbots/purdueros-cli',
license='',
author='Purdue ACM Sigbots',
author_email='[email protected]',
description='',
install_requires=[
'click',
'pyserial',
'cx_Freeze'
],
executables=[Executable('proscli/main.py', targetName=targetName)]
)

# from esky import bdist_esky
# from setuptools import setup
# from esky.bdist_esky import Executable
# targetName = None
#
# if sys.platform == "win32":
# targetName = "pros.exe"
#
# setup(
# name='pros',
# version='2.0.0',
# install_requires=[
# 'click',
# 'pyserial',
# 'cx_Freeze',
# 'esky'
# ],
# options={'bdist_esky': {
# 'freezer_module': 'cxfreeze',
# "freezer_options": dict(compress=True)
# }},
# scripts=[Executable('proscli/main.py', targetName=targetName)]
# )


# if sys.argv[1] == 'build':
# from cx_Freeze import setup, Executable
#
# build_exe_options = {
# "packages": [
# "os"
# ]
# }
#
# setup(
# name='purdueros-cli',
# version='2.0',
# packages=['prosflasher', 'proscli'],
# url='https://github.com/purduesigbots/purdueros-cli',
# license='',
# author='Purdue ACM Sigbots',
# author_email='[email protected]',
# description='',
# install_requires=[
# 'click',
# 'pyserial',
# 'cx_Freeze'
# ],
# options={"build_exe": build_exe_options},
# executables=[Executable("proscli/main.py", targetName=targetName)]
# )
# elif sys.argv[1] == 'bdist_esky':
# from distutils.core import setup
# from esky.bdist_esky import bdist_esky, Executable
# setup(
# name='purdueros-cli',
# version='2.0',
# packages=['prosflasher', 'proscli'],
# options={
# "bdist_esky": {
# "freezer_module": "cxfreeze",
# "compress": "ZIP"
# }},
# scripts=[Executable('proscli/main.py')]
# )
# else:

2 changes: 2 additions & 0 deletions proscli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
from proscli.conductor import conductor_cli
from proscli.build import build_cli
from proscli.flasher import flasher_cli

from proscli.utils import pass_state, State, verbosity_option
22 changes: 17 additions & 5 deletions proscli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import sys
import os
import prosconfig


@click.group()
Expand All @@ -11,9 +12,20 @@ def build_cli():

@build_cli.command()
@click.argument('build-args', nargs=-1)
def build(build_args):
"""Invokes make. If on Windows, will invoke make located in on the PROS_TOOLCHAIN"""
def make(build_args):
"""Invokes make.
If on Windows, will invoke make located in on the PROS_TOOLCHAIN.
Also has the added benefit of looking for the config.pros file"""
click.echo('Invoking make...')
subprocess.run(os.path.join(os.environ['PROS_TOOLCHAIN'], 'bin', 'make') if os.name == 'nt' else
'make' + ' ' + ' '.join(build_args),
stdout=sys.stdout, stderr=sys.stderr)
cfg = prosconfig.find_project()
cwd = '.'
if cfg is not None:
cwd = cfg.path
cmd = (os.path.join(os.environ['PROS_TOOLCHAIN'], 'bin', 'make') if os.name == 'nt' else 'make')
if os.path.exists(cmd):
subprocess.Popen(executable=cmd, args=build_args, cwd=cwd,
stdout=sys.stdout, stderr=sys.stderr)
else:
click.echo('Error... make not found.', err=True)
125 changes: 49 additions & 76 deletions proscli/conductor.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import os

from proscli.utils import default_cfg, default_options
import prosconductor.updatesite
import click

import prosconductor


class ArgPayload:
def __init__(self):
self.verbosity = 0


pass_args = click.make_pass_decorator(ArgPayload, ensure=True)


def verbosity(context, param, value):
context.obj.verbosity += value
prosconductor.verbosity = context.obj.verbosity
import sys


@click.group()
Expand All @@ -24,69 +10,56 @@ def conductor_cli():


@conductor_cli.group()
@click.option('--verbose', '-v', count=True)
@pass_args
def conduct(config, verbose):
config.verbosity += verbose
@default_options
def conduct():
pass


@conduct.command()
@click.option('--kernel', '-k', default='latest', metavar='<version>',
help='Specify kernel version to target.')
@click.option('--drop-in', '-d', multiple=True)
@click.option('--verbose', '-v', count=True)
@click.option('--force', '-f', is_flag=True)
@click.argument('directory', type=click.Path())
@pass_args
def create(config, kernel, drop_in, verbose, force, directory):
config.verbosity += verbose
if config.verbosity > 0:
click.echo('Verbosity level set to: ' + repr(config.verbosity))
kernels = prosconductor.resolve.resolve_kernel_request(kernel)
if len(kernels) == 0:
click.echo('No kernels were matched to the pattern ' + kernel +
' Try a new pattern or fetching the kernel using \'pros conduct fetch ' + kernel + '\'',
err=True)
exit(1)
elif len(kernels) == 1:
kernel = kernels[0]
else:
while kernel not in kernels:
kernel = click.prompt('Multiple kernels were matched. Please select one (' + ', '.join(kernels) + ')')
if kernel not in kernels and config.verbosity > 0:
click.echo('Not a valid response', err=True)
exit(1)

directory = os.path.normpath(os.path.expanduser(directory))
if os.path.isfile(directory):
if not force:
click.confirm('Directory specified is already a file. Delete it?', abort=True)
os.remove(directory)
if os.path.isdir(directory) and len(os.listdir(directory)) > 0 and not force:
click.confirm('Non-empty directory specified. Copy files regardless? ' +
'Note: this option will overwrite any existing files', abort=True)

# TODO: verify drop-ins exist
print(prosconductor.dropins.get_available_dropins(kernel))

# TODO: determine kernel loader
prosconductor.create_project(kernel, directory, drop_in)


def add_update_site(context, param, value):
if value is tuple:
[add_update_site(context, param, val) for val in value]
else:
if value not in prosconductor.config.get_update_sites().keys():
prosconductor.config.add_update_site(value)
@default_cfg
def hello(cfg):
# click.echo(repr(cfg.proj_cfg))
# click.echo(repr(prosconductor.updatesite.get_kernels()))
cfg.proj_cfg.save()


@conduct.command()
@click.option('--verbose', '-v', count=True, callback=verbosity)
@click.option('--site', '-s', multiple=True, default=prosconductor.config.get_update_sites(),
callback=add_update_site, expose_value=False)
@click.option('--add-site', callback=add_update_site, expose_value=False)
@pass_args
def fetch(config, verbose):
click.echo(prosconductor.config.get_update_sites())
@click.option('-p', '--update-site', metavar='KEY', default=None,
help='Specify the registrar key to download the kernel with')
@click.option('-k', '--kernel', metavar='KERNEL', default='latest', help='Specify the kernel to use.')
@click.option('-f', '--force', is_flag=True, default=False, help='Overwrite any existing files without prompt.')
@click.argument('dir', default='.')
@default_cfg
def create(cfg, force, update_site, kernel, dir):
kernels = list(prosconductor.updatesite.get_kernels())
kernels.sort()
if kernel.lower() == 'latest':
kernel = kernels[-1]
elif kernel not in kernels:
kernel = None
if kernel is None:
click.echo('Error! Kernel not found!')
exit(1)

options = [p.id for p in prosconductor.updatesite.get_kernels()[kernel]]
if update_site is None:
if len(options) > 1:
update_site = click.prompt('Please select a update_site to obtain {} from'.format(kernel),
type=click.Choice(options), show_default=True,
default='cache' if 'cache' in options else options[0])
else:
update_site = options[0]

if update_site not in options:
click.echo('update_site not in available providers')
exit(1)
update_site = [u for u in prosconductor.updatesite.get_kernels()[kernel] if u.id == update_site][0]
provider = prosconductor.updatesite.get_all_providers()[update_site.registrar]
try:
update_site.registrar_options['_force'] = force
provider.create_proj(update_site, kernel, dir, update_site.registrar_options)
except FileExistsError as e:
click.echo('Error! File {} already exists! Delete it or run '
'\'pros {} --force\' to automatically overwrite any pre-existing files'.format(e.args[0], ' '.join(sys.argv[1:])),
err=True)
exit(1)
Loading

0 comments on commit 03f185b

Please sign in to comment.