Exemplo n.º 1
0
async def status(api, args):
    '''Determines the status of at least one challenge
    '''
    if not args.yes and not cli.confirm('do you really want to check status?'):
        app_log.warning("operation cancelled by user.")
        return False
    err_sep = format_text(f'{HSEP[:35]} [STDERR] {HSEP[:35]}', 'red')
    out_sep = format_text(f'{HSEP[:35]} [STDOUT] {HSEP[:35]}', 'blue')
    exc_sep = format_text(f'{HSEP[:35]} [EXCEPT] {HSEP[:35]}', 'magenta')
    chall_sep = format_text(HSEP, 'blue', attrs=['bold'])
    success = True
    async for build_result in api.status(args.tags, args.slug, args.timeout):
        rcode = build_result['rcode']
        chall_desc = format_text(f"{build_result['slug']}", 'blue')
        chall_status = format_rcode2str(rcode)
        print(chall_sep)
        print(f"{chall_desc} {chall_status}")
        if rcode < 0:
            success = False
            print(exc_sep)
            print(build_result['exception'])
        elif rcode > 0:
            print(out_sep)
            print(build_result['stdout'].decode().strip())
            print(err_sep)
            print(build_result['stderr'].decode().strip())
    return success
Exemplo n.º 2
0
 def delete_chall(self, slug):
     '''Deletes a challenge
     '''
     chall = self.find_chall(slug)
     if chall is None:
         return False
     if not cli.confirm(f"do you really want to remove {slug}?"):
         app_log.warning("operation cancelled by user.")
         return False
     rmtree(str(chall.working_dir()))
     return True
Exemplo n.º 3
0
 def __make_chall_conf(self, prev={}, override=None):
     '''[summary]
     '''
     repo_conf = self.get_conf()
     if prev is None:
         prev = {}
     if override:
         conf = prev
         conf.update(override)
     else:
         flag = prev.get('flag', Challenge.make_flag(repo_conf))
         name = cli.readline("enter challenge name:",
                             default=prev.get('name'))
         tags = cli.choose_many("select one or more tags:",
                                repo_conf['tags'],
                                default=prev.get('tags'))
         points = cli.readline("enter number of points:",
                               default=prev.get('points'),
                               expect_digit=True)
         enabled = prev.get('enabled', False)
         difficulties = repo_conf['difficulties']
         difficulty = cli.choose_one("how difficult is your challenge?",
                                     repo_conf['difficulties'],
                                     default=prev.get('difficulty', ))
         parameters = prev.get('parameters', {})
         standalone = cli.confirm("is it a standalone challenge?",
                                  default=prev.get('standalone'))
         static_url = prev.get('static_url', '')
         company_logo_url = prev.get('company_logo_url', '')
         conf = {
             'name': name,
             'tags': tags,
             'slug': slugify(name),
             'flag': flag,
             'points': points,
             'enabled': enabled,
             'difficulty': difficulty,
             'parameters': parameters,
             'standalone': standalone,
             'static_url': static_url,
             'company_logo_url': company_logo_url
         }
     return conf