def command(shell: DTShell, args):
        from duckietown_challenges.rest_methods import dtserver_auth
        token = shell.get_dt1_token()

        parser = argparse.ArgumentParser()
        parser.add_argument('--cmd', required=True)
        parser.add_argument('--impersonate', default=None)

        parsed = parser.parse_args(args)

        cmd = parsed.cmd

        with wrap_server_operations():
            res = dtserver_auth(token=token,
                                cmd=cmd,
                                impersonate=parsed.impersonate)

        results: List[dict] = res['results']
        shell.sprint(json.dumps(results, indent=2))
        for result in results:
            ok = result['ok']
            msg = result.get('msg')
            line = result.get('line')
            if msg is None:
                msg = ''
            qr = result.get('query_result')

            shell.sprint('query: %s' % line)
            s = 'OK' if ok else "ERR"
            shell.sprint('processed: %s' % s)
            shell.sprint('   result: %s' % qr)
            shell.sprint('message: %s' % msg)
    def command(shell, args):
        prog = 'dts challenges follow'

        parser = argparse.ArgumentParser(prog=prog, usage=usage)
        parser.add_argument('--submission', required=True, type=int)
        parsed = parser.parse_args(args)

        token = shell.get_dt1_token()

        submission_id = parsed.submission

        with wrap_server_operations():
            follow_submission(shell, token, submission_id)
예제 #3
0
    def command(shell, args):
        parser = argparse.ArgumentParser()
        parser.add_argument('--impersonate', type=str, default=None)

        parsed = parser.parse_args(args)

        token = shell.get_dt1_token()

        with wrap_server_operations():
            info = get_dtserver_user_info(token,
                                          impersonate=parsed.impersonate)

            NOT_PROVIDED = termcolor.colored('missing', 'red')

            if 'profile' in info:
                profile = href(info.get('profile'))
            else:
                profile = NOT_PROVIDED

            user_login = info.get('user_login', NOT_PROVIDED)
            display_name = info.get('name', NOT_PROVIDED)
            uid = info.get('uid', NOT_PROVIDED)

            s = '''
            
    You are succesfully authenticated:
    
             ID: {uid}
           name: {display_name}    
          login: {user_login}
        profile: {profile}
            
    '''.format(uid=bold(uid),
               user_login=bold(user_login),
               display_name=bold(display_name),
               profile=profile).strip()

            server = get_duckietown_server_url()

            url = server + '/humans/users/%s' % info['uid']

            s += '''
    
    You can find the list of your submissions at the page:
    
        {url}        
    
            '''.format(url=href(url))

            shell.sprint(s)
    def command(shell: DTShell, args):
        prog = 'dts challenges retire'

        parser = argparse.ArgumentParser(prog=prog, usage=usage)
        parser.add_argument('--submission', required=True, type=int)
        parsed = parser.parse_args(args)

        token = shell.get_dt1_token()

        submission_id = parsed.submission

        with wrap_server_operations():
            submission_id = dtserver_retire(token, submission_id)

        shell.sprint('Successfully retired submission %s' % submission_id)
예제 #5
0
    def command(shell, args):
        token = shell.get_dt1_token()
        parser = argparse.ArgumentParser(prog='dts challenges reset')
        parser.add_argument("--job",
                            default=None,
                            help='Only reset this particular job',
                            type=int)
        parser.add_argument("--submission",
                            default=None,
                            type=int,
                            help='Reset this particular submission')
        parser.add_argument("--step",
                            default=None,
                            help='Only reset this particular step')
        parser.add_argument("--impersonate", default=None)
        parsed = parser.parse_args(args)

        if parsed.submission is None and parsed.job is None:
            msg = 'You need to specify either --job or --submission.'
            raise UserError(msg)

        with wrap_server_operations():
            if parsed.submission is not None:
                from duckietown_challenges.rest_methods import dtserver_reset_submission
                submission_id = dtserver_reset_submission(
                    token,
                    submission_id=parsed.submission,
                    impersonate=parsed.impersonate,
                    step_name=parsed.step)
                shell.sprint('Successfully reset %s' % submission_id)
            elif parsed.job is not None:
                from duckietown_challenges.rest_methods import dtserver_reset_job
                job_id = dtserver_reset_job(token,
                                            job_id=parsed.job,
                                            impersonate=parsed.impersonate)
                shell.sprint('Successfully reset %s' % job_id)
            else:
                assert False
예제 #6
0
    def command(shell, args):
        token = shell.get_dt1_token()

        with wrap_server_operations():
            submissions = dtserver_get_user_submissions(token)

        def key(x):
            return submissions[x]['date_submitted']

        challenge_id2name = {}
        for submission_id, submission in list(submissions.items()):

            if not submission.get('challenge_is_open', True):
                continue

            challenge_id = submission['challenge_id']
            challenge_name = submission.get('challenge_name',
                                            '%s' % challenge_id)
            challenge_id2name[challenge_id] = challenge_name

        challenges = sorted(challenge_id2name)
        out = []

        for challenge_id in challenges:
            out.append('')
            out.append(bold('Challenge %s' % challenge_id2name[challenge_id]))
            out.append('')
            for submission_id in sorted(submissions, key=key):
                submission = submissions[submission_id]

                if submission['challenge_id'] != challenge_id:
                    continue

                def d(dt):
                    return dt.strftime("%Y-%m-%d %H:%M")

                from duckietown_challenges import get_duckietown_server_url
                server = get_duckietown_server_url()

                url = server + '/humans/submissions/%s' % submission_id

                user_label = submission.get('user_label',
                                            None) or dark('(no user label)')

                M = 30
                if len(user_label) > M:
                    user_label = user_label[:M - 5] + ' ...'

                user_label = user_label.ljust(M)

                s = (
                    '%4s  %s  %10s %s  %s' %
                    (submission_id, d(submission['date_submitted']),
                     pad_to_screen_length(colored_status(submission['status']),
                                          10), user_label, href(url)))

                out.append(s)
            out.append('')

        msg = u"\n".join(out)
        if hasattr(shell, 'sprint'):
            shell.sprint(msg)
        else:
            print(msg)
예제 #7
0
    def command(shell, args):
        check_docker_environment()

        token = shell.get_dt1_token()

        prog = 'dts challenges submit'
        usage = """
        

Submission:

    %(prog)s --challenge NAME



## Building options

Rebuilds ignoring Docker cache

    %(prog)s --no-cache



## Attaching user data
    
Submission with an identifying label:

    %(prog)s --user-label  "My submission"    
    
Submission with an arbitrary JSON payload:

    %(prog)s --user-meta  '{"param1": 123}'   
        

        
        
"""
        parser = argparse.ArgumentParser(prog=prog, usage=usage)

        group = parser.add_argument_group("Submission identification")
        parser.add_argument('--challenge',
                            help="Specify challenge name.",
                            default=None)
        group.add_argument('--user-label',
                           dest='message',
                           default=None,
                           type=str,
                           help="Submission message")
        group.add_argument(
            '--user-meta',
            dest='metadata',
            default=None,
            type=str,
            help="Custom JSON structure to attach to the submission")

        group = parser.add_argument_group("Building settings.")

        group.add_argument('--no-cache',
                           dest='no_cache',
                           action='store_true',
                           default=False)
        group.add_argument('--impersonate', type=int, default=None)

        group.add_argument('-C',
                           dest='cwd',
                           default=None,
                           help='Base directory')

        parsed = parser.parse_args(args)
        impersonate = parsed.impersonate
        if parsed.cwd is not None:
            dtslogger.info('Changing to directory %s' % parsed.cwd)
            os.chdir(parsed.cwd)

        if not os.path.exists('submission.yaml'):
            msg = 'Expected a submission.yaml file in %s.' % (os.path.realpath(
                os.getcwd()))
            raise UserError(msg)

        sub_info = read_submission_info('.')

        with wrap_server_operations():
            ri = get_registry_info(token=token, impersonate=impersonate)

            registry = ri.registry

            compat = dtserver_get_compatible_challenges(
                token=token,
                impersonate=impersonate,
                submission_protocols=sub_info.protocols)
            if not compat.compatible:
                msg = 'There are no compatible challenges with protocols %s,\n' \
                      ' or you might not have the necessary permissions.' % sub_info.protocols
                raise UserError(msg)

            if parsed.message:
                sub_info.user_label = parsed.message
            if parsed.metadata:
                sub_info.user_metadata = json.loads(parsed.metadata)
            if parsed.challenge:
                sub_info.challenge_names = parsed.challenge.split(',')
            if sub_info.challenge_names is None:
                sub_info.challenge_names = compat.compatible

            print('I will submit to the challenges %s' %
                  sub_info.challenge_names)

            for c in sub_info.challenge_names:
                if not c in compat.available_submit:
                    msg = 'The challenge "%s" does not exist among %s.' % (
                        c, list(compat.available_submit))
                    raise UserError(msg)
                if not c in compat.compatible:
                    msg = 'The challenge "%s" is not compatible with protocols %s .' % (
                        c, sub_info.protocols)
                    raise UserError(msg)
            username = get_dockerhub_username(shell)

            print('')
            print('')
            br = submission_build(username=username,
                                  registry=registry,
                                  no_cache=parsed.no_cache)

            data = {
                'image': dataclasses.asdict(br),
                'user_label': sub_info.user_label,
                'user_payload': sub_info.user_metadata,
                'protocols': sub_info.protocols
            }

            data = dtserver_submit2(token=token,
                                    challenges=sub_info.challenge_names,
                                    data=data,
                                    impersonate=impersonate)

            # print('obtained:\n%s' % json.dumps(data, indent=2))
            component_id = data['component_id']
            submissions = data['submissions']
            # url_component = href(get_duckietown_server_url() + '/humans/components/%s' % component_id)

            msg = f'''
    
    Successfully created component.
    
    This component has been entered in {len(submissions)} challenge(s).
    
            '''

            for challenge_name, sub_info in submissions.items():
                submission_id = sub_info['submission_id']
                url_submission = href(get_duckietown_server_url() +
                                      '/humans/submissions/%s' % submission_id)
                challenge_title = sub_info['challenge']['title']
                submission_id_color = termcolor.colored(submission_id, 'cyan')
                P = dark('$')
                head = bright(
                    f'## Challenge {challenge_name} - {challenge_title}')
                msg += '\n\n' + f'''
                
    {head}
    
    Track this submission at:
    
        {url_submission}
             
    You can follow its fate using:
    
        {P} dts challenges follow --submission {submission_id_color}
        
    You can speed up the evaluation using your own evaluator:
    
        {P} dts challenges evaluator --submission {submission_id_color}
        
    '''.strip()
                manual = href('http://docs.duckietown.org/DT19/AIDO/out/')
                msg += f'''
    
    For more information, see the manual at {manual}
    '''

            shell.sprint(msg)