Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: select submit language by name #172

Merged
merged 1 commit into from
Jul 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions onlinejudge/implementation/command/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,24 @@ def submit(args):
with utils.with_cookiejar(utils.new_default_session(), path=args.cookie) as sess:
# language
langs = problem.get_language_dict(session=sess)

if args.language not in langs:
log.error('language is unknown')
log.info('supported languages are:')
for lang in sorted(langs.keys()):
log.emit('%s (%s)', lang, langs[lang]['description'])
sys.exit(1)
matched_language = search_matched_language(args.language, langs)
if len(matched_language) == 1:
args.language = matched_language[0]
log.info('choosed language: %s', matched_language)
elif not matched_language:
log.error('language is unknown')
log.info('supported languages are:')
for lang in sorted(langs.keys()):
log.emit('%s (%s)', lang, langs[lang]['description'])
sys.exit(1)
else:
log.error('Matched languages were not narrowed down to one.')
log.info('You have to choose:')
for lang in sorted(matched_language):
log.emit('%s', lang)
sys.exit(1)

# confirm
if args.wait:
Expand Down Expand Up @@ -75,3 +87,12 @@ def submit(args):
else:
log.info('open the submission page with: %s', args.open)
subprocess.check_call([ args.open, submission.get_url() ], stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)

def search_matched_language(language, language_dict):
# Search partial matched language name (not case sensitive)

matched_language = []
for supported_lang in language_dict.values():
if language.lower() in supported_lang['description'].lower():
matched_language.append(supported_lang['description'])
return matched_language