add -n --name flag to worlddump

We're worlddumping at success points in grenade, and it would be much
handier to explain when that happens via a symbolic name in the
filename. Add a --name option to worlddump to allow it.

Change-Id: I644200fe08e404dc7ca2006478ae4e11ca020672
This commit is contained in:
Sean Dague 2015-07-27 13:33:30 -04:00
parent a3210822ce
commit ac9313e5a5

View File

@ -31,12 +31,19 @@ def get_options():
parser.add_argument('-d', '--dir', parser.add_argument('-d', '--dir',
default='.', default='.',
help='Output directory for worlddump') help='Output directory for worlddump')
parser.add_argument('-n', '--name',
default='',
help='Additional name to tag into file')
return parser.parse_args() return parser.parse_args()
def filename(dirname): def filename(dirname, name=""):
now = datetime.datetime.utcnow() now = datetime.datetime.utcnow()
return os.path.join(dirname, now.strftime("worlddump-%Y-%m-%d-%H%M%S.txt")) fmt = "worlddump-%Y-%m-%d-%H%M%S"
if name:
fmt += "-" + name
fmt += ".txt"
return os.path.join(dirname, now.strftime(fmt))
def warn(msg): def warn(msg):
@ -125,7 +132,7 @@ def guru_meditation_report():
def main(): def main():
opts = get_options() opts = get_options()
fname = filename(opts.dir) fname = filename(opts.dir, opts.name)
print "World dumping... see %s for details" % fname print "World dumping... see %s for details" % fname
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
with open(fname, 'w') as f: with open(fname, 'w') as f: