def main(): # Read command line options globals.probsettings = parse.parseopts() # Initialize problem helper.makedir(globals.sandboxdir) if globals.getprob() is not None: globals.probdir = os.path.join(globals.tmpdir, 'probs', globals.getprob()) globals.probsettingsfile = os.path.join(globals.probdir, 'probsettings.dat') helper.makedir(globals.probdir) # Merge dictionary with command line options if globals.getprob() is not None: opts = helper.readdict(globals.probsettingsfile) # Previous settings for key in opts: if key not in globals.probsettings or globals.probsettings[ key] is None: globals.probsettings[key] = opts[key] # Assert that basic values are present in settings if globals.getext() is None: globals.probsettings['langext'] = settings.defaultlangext if globals.getmode() is None: globals.probsettings['mode'] = settings.defaultmode # Execute command print settings.bigdivider globals.commands[globals.probsettings['command']]() # Write new settings dict to file if globals.getprob() is not None: helper.writedict(globals.probsettingsfile, globals.probsettings) # Clear sandbox directory helper.deldir(globals.sandboxdir) print settings.bigdivider
def main (): # Read command line options globals.probsettings = parse.parseopts() # Initialize problem helper.makedir(globals.sandboxdir) if globals.getprob() is not None: globals.probdir = os.path.join(globals.tmpdir, 'probs', globals.getprob()) globals.probsettingsfile = os.path.join(globals.probdir, 'probsettings.dat') helper.makedir(globals.probdir) # Merge dictionary with command line options if globals.getprob() is not None: opts = helper.readdict(globals.probsettingsfile) # Previous settings for key in opts: if key not in globals.probsettings or globals.probsettings[key] is None: globals.probsettings[key] = opts[key] # Assert that basic values are present in settings if globals.getext() is None: globals.probsettings['langext'] = settings.defaultlangext if globals.getmode() is None: globals.probsettings['mode'] = settings.defaultmode # Execute command print settings.bigdivider globals.commands[globals.probsettings['command']]() # Write new settings dict to file if globals.getprob() is not None: helper.writedict(globals.probsettingsfile, globals.probsettings) # Clear sandbox directory helper.deldir(globals.sandboxdir) print settings.bigdivider
def getfile (ext): file = parse.parseopts()['filename'] type = exttotype[ext] testid = globals.gettestid() print 'Getting test case {} {} for problem {}'.format(testid, type, globals.getprob()) output = helper.read(os.path.join(globals.probdir, testid + ext)) if output is None: print 'Did not find {} file'.format(type) return False if file is None: print 'File found: {} below'.format(type) print settings.smalldivider print output + ('' if settings.eof is None else settings.eof) else: try: file.write(output) file.close() print 'Wrote {} to {}'.format(type, file.name) except IOError: print 'Unable to write to ' + file.name return False return True
def getfile(ext): file = parse.parseopts()['filename'] type = exttotype[ext] testid = globals.gettestid() print 'Getting test case {} {} for problem {}'.format( testid, type, globals.getprob()) output = helper.read(os.path.join(globals.probdir, testid + ext)) if output is None: print 'Did not find {} file'.format(type) return False if file is None: print 'File found: {} below'.format(type) print settings.smalldivider print output + ('' if settings.eof is None else settings.eof) else: try: file.write(output) file.close() print 'Wrote {} to {}'.format(type, file.name) except IOError: print 'Unable to write to ' + file.name return False return True