Skip to content

Commit

Permalink
Merge pull request aria2#1672 from sleepymac/python3-bash-completion
Browse files Browse the repository at this point in the history
Updates the make_bash_completion script to Python3.
  • Loading branch information
tatsuhiro-t authored Aug 13, 2021
2 parents 63f6ed7 + 5d77701 commit ca4179e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions doc/bash_completion/make_bash_completion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import subprocess
from StringIO import StringIO
from io import StringIO
import re
import sys

Expand All @@ -19,7 +19,7 @@ def get_all_options(cmd):
stdoutdata, stderrdata = proc.communicate()
cur_option = None
opts = {}
for line in StringIO(stdoutdata):
for line in StringIO(stdoutdata.decode('utf-8')):
match = opt_pattern.match(line)
if match:
long_opt = match.group(2)
Expand All @@ -35,8 +35,8 @@ def get_all_options(cmd):
if cur_option:
opts[cur_option.long_opt] = cur_option

# for opt in opts.itervalues():
# print opt.short_opt, opt.long_opt, opt.optional, opt.values
# for opt in opts.values():
# print(opt.short_opt, opt.long_opt, opt.optional, opt.values)

return opts

Expand Down Expand Up @@ -77,7 +77,7 @@ def output_case(out, opts):
""")
bool_opts = []
nonbool_opts = []
for opt in opts.itervalues():
for opt in opts.values():
if opt.values == ['true', 'false']:
bool_opts.append(opt)
else:
Expand Down Expand Up @@ -105,7 +105,7 @@ def output_case(out, opts):
output_value_case(out, opt.long_opt, opt.values)
# Complete directory
dir_opts = []
for opt in opts.itervalues():
for opt in opts.values():
if opt.values and opt.values[0] == '/path/to/directory':
dir_opts.append(opt)
# Complete file
Expand All @@ -123,7 +123,7 @@ def output_case(out, opts):
COMPREPLY=( $( compgen -W '\
""")
bool_values = [ 'true', 'false' ]
for opt in opts.itervalues():
for opt in opts.values():
out.write(opt.long_opt)
out.write(' ')
# Options which takes optional argument needs "=" between
Expand Down Expand Up @@ -159,8 +159,8 @@ def output_case(out, opts):

if __name__ == '__main__':
if len(sys.argv) < 2:
print "Generates aria2c(1) bash_completion using `aria2c --help=#all'"
print "Usage: make_bash_completion.py /path/to/aria2c"
print("Generates aria2c(1) bash_completion using `aria2c --help=#all'")
print("Usage: make_bash_completion.py /path/to/aria2c")
exit(1)
opts = get_all_options(sys.argv[1])
output_case(sys.stdout, opts)

0 comments on commit ca4179e

Please sign in to comment.