import os
from argparse import ArgumentParser
parser = ArgumentParser(description="Generate stamps.def from stamp files. TPT does that out of the box too.")
parser.add_argument("-b", "--nobackup",
action="store_true", help="Don't backup stamps.def before running.")
parser.add_argument("-w", "--nowait",
action="store_true", help="Don't wait for input after running.")
parser.add_argument("-q", "--quiet",
action="store_true", help="Shut up")
args = parser.parse_args()
qp = lambda s: None if args.quiet else print(s)
# Backup
if not args.nobackup:
with open("stamps/stamps.def", 'r') as f:
with open("stamps/stamps.def~", 'w') as g:
for line in f:
g.write(line)
# True stuff
dirlist = os.listdir(os.getcwd() + os.sep + "stamps" + os.sep)
dirlist.remove("stamps.def")
with open('stamps/stamps.def', 'w') as f:
for i in range(0, len(dirlist)-1):
f.write(dirlist[i].rstrip(".stm"))
qp (repr(dirlist[i]) + " added to stamps.def")
qp ("Success.")
if not args.nowait:
input()
# 2011 original, 2013 rewritten for Python 3 support and arguments.
# by boxmein. Use as you wish.