Skip to content

Commit

Permalink
Convert build-addon-index.py and sexpr.py to Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Dec 17, 2018
1 parent 22d3902 commit 2328c74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
19 changes: 14 additions & 5 deletions tools/build-addon-index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# SuperTux
# Copyright (C) 2014 Ingo Ruhnke <[email protected]>
Expand Down Expand Up @@ -31,7 +31,8 @@ def escape_str(string):
return "\"%s\"" % string.replace("\"", "\\\"")


class Addon(object):
class Addon:

def __init__(self, filename):
lst = sexpr.parse(filename)
if lst[0][0] != "supertux-addoninfo":
Expand Down Expand Up @@ -95,7 +96,7 @@ def generate_index(fout, directory, base_url, zipdir):
for addon_dir in os.listdir(directory):
addon_dir = os.path.join(directory, addon_dir)
if os.path.isdir(addon_dir):
print addon_dir
# print(addon_dir)
nfos = glob.glob(os.path.join(addon_dir, "*.nfo"))
if len(nfos) == 0:
raise Exception(".nfo file missing from %s" % addon_dir)
Expand All @@ -104,13 +105,20 @@ def generate_index(fout, directory, base_url, zipdir):
else:
try:
process_addon(fout, addon_dir, nfos[0], base_url, zipdir)
except Exception, e:
except Exception as e:
sys.stderr.write("%s: ignoring addon because: %s\n" % (addon_dir, e))
fout.write(")\n\n;; EOF ;;\n")


EXAMPLE_TEXT="""Example:
./build-addon-index.py -z ../../addons/repository/ ../../addons/src/"""


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Addon Index/Zip Generator')
parser = argparse.ArgumentParser(description="Addon Index/Zip Generator",
epilog=EXAMPLE_TEXT,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('DIRECTORY', type=str, nargs=1,
help="directory containing the mods")
parser.add_argument('-o', '--output', metavar='FILE', type=str, required=False,
Expand All @@ -129,4 +137,5 @@ def generate_index(fout, directory, base_url, zipdir):
with open(args.output, "w") as fout:
generate_index(fout, args.DIRECTORY[0], args.url, args.zipdir)


# EOF #
18 changes: 9 additions & 9 deletions tools/sexpr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright (c) 2014 Ingo Ruhnke <[email protected]>
#
Expand Down Expand Up @@ -97,15 +97,15 @@ def parse(text):
raise Exception("error: list not closed")

if __name__ == "__main__":
print "parsing..."
print("parsing...")
result = parse(r'(() ("bar" foo) ()) () bar ')
print "1.", result
print "2.", parse(""";;comment
("Hello World" 5 1 123) ("Hello" 123 123 "foobar") ;; comment""")
print "3.", parse(r'(8(8)8)')
print "4.", parse(r'')
print "5.", parse(r' ')
print("1.", result)
print("2.", parse(""";;comment
("Hello World" 5 1 123) ("Hello" 123 123 "foobar") ;; comment"""))
print("3.", parse(r'(8(8)8)'))
print("4.", parse(r''))
print("5.", parse(r' '))
with codecs.open("white.stf", encoding='utf-8') as fin:
print "6.", parse(fin.read())
print("6.", parse(fin.read()))

# EOF #

0 comments on commit 2328c74

Please sign in to comment.