Skip to content

Commit

Permalink
Implement silent autoconfig mode (#239)
Browse files Browse the repository at this point in the history
* Allow for silent mode

`-s` or `--silent`

* Parse arguments in main

* Make it work right

* Shut racket up

* Stop using drugs

* Some fixes
  • Loading branch information
BinAccel authored and Xyene committed Feb 5, 2017
1 parent e87df76 commit 4b8ec02
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions dmoj/executors/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
import yaml
import yaml.representer

import argparse

from dmoj import judgeenv
from dmoj.executors import get_available, load_executor
from dmoj.executors.mixins import NullStdoutMixin
from dmoj.utils.ansi import ansi_style


def main():
parser = argparse.ArgumentParser(description='Automatically configures runtimes')
parser.add_argument('-s', '--silent', action='store_true', help='silent mode')
silent = parser.parse_args().silent

result = {}

if os.name == 'nt':
Expand All @@ -29,35 +36,46 @@ def main():
if executor is None or not hasattr(executor, 'Executor'):
continue

if hasattr(executor.Executor, 'autoconfig'):
print ansi_style('%-43s%s' % ('Auto-configuring #ansi[%s](|underline):' % name, '')),
Executor = executor.Executor
if silent and not issubclass(Executor, NullStdoutMixin):
# if you are printing errors into stdout, you may do so in your own blood
# *cough* Racket *cough*
Executor = type('Executor', (NullStdoutMixin, Executor), {})

if hasattr(Executor, 'autoconfig'):
if not silent:
print ansi_style('%-43s%s' % ('Auto-configuring #ansi[%s](|underline):' % name, '')),
try:
data = executor.Executor.autoconfig()
data = Executor.autoconfig()
config = data[0]
success = data[1]
feedback = data[2]
errors = '' if len(data) < 4 else data[3]
except Exception:
print ansi_style('#ansi[Not supported](red|bold)')
traceback.print_exc()
if not silent:
print ansi_style('#ansi[Not supported](red|bold)')
traceback.print_exc()
else:
print ansi_style(['#ansi[%s](red|bold)', '#ansi[%s](green|bold)'][success] %
if not silent:
print ansi_style(['#ansi[%s](red|bold)', '#ansi[%s](green|bold)'][success] %
(feedback or ['Failed', 'Success'][success]))

if not success:
if config:
print ' Attempted:'
print ' ', yaml.dump(config, default_flow_style=False).rstrip().replace('\n', '\n' + ' ' * 4)
if not silent:
if config:
print ' Attempted:'
print ' ', yaml.dump(config, default_flow_style=False).rstrip().replace('\n', '\n' + ' ' * 4)

if errors:
print ' Errors:'
print ' ', errors.replace('\n', '\n' + ' ' * 4)
if errors:
print ' Errors:'
print ' ', errors.replace('\n', '\n' + ' ' * 4)

if success:
result.update(config)

print
print ansi_style('#ansi[Configuration result](green|bold|underline):')
if not silent:
print
print ansi_style('#ansi[Configuration result](green|bold|underline):')
print yaml.dump({'runtime': result}, default_flow_style=False).rstrip()

if __name__ == '__main__':
Expand Down

0 comments on commit 4b8ec02

Please sign in to comment.