def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir PS2PDF = "/usr/bin/ps2pdf" PDFTK = "/usr/bin/pdftk" os.chdir(data_dir) output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) lines = [] for row in output.splitlines(): cols = row.split() try: if cols[0] is "The": break x = cols[2] y = cols[5] z = cols[8] stellar_type = cols[12] name = pretty_star(stellar_type) lines.append("%s, %s, %s, %s, %s.\n" % (x, y, z, name, stellar_type)) except IndexError: continue fd = tempfile.NamedTemporaryFile(delete=False) fd.writelines(lines) fd.flush() os.fsync(fd) fhutils.run(bin_dir, "PrintMap", ["-d", "-t", "%s"%(fd.name)]) subprocess.call(["%s" % (PS2PDF), "-dAutoRotatePages=/None",fd.name+".ps", data_dir+"/galaxy_map_3d.pdf"]) fhutils.run(bin_dir, "PrintMap", ["-d", "%s"%(fd.name)]) subprocess.call(["%s" % (PS2PDF), "-dAutoRotatePages=/None",fd.name+".ps", data_dir+"/galaxy_map.pdf"]) fd.close() subprocess.call(["%s" % (PDFTK), data_dir+"/galaxy_map_3d.pdf", data_dir+"/galaxy_map.pdf", "cat", "output", data_dir+"/galaxy.map.pdf"])
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir turn = fhutils.run(bin_dir, "TurnNumber").strip() print "Will now perform save for turn %s" % (turn) os.chdir(data_dir) if not os.path.isdir(data_dir + "/backup"): print "Sorry backup directory %s does not exist." % (data_dir + "/backup") sys.exit(1) if not os.path.isdir(data_dir + "/reports"): print "Sorry reports directory %s does not exist." % (data_dir + "/reports") sys.exit(1) print 'Moving sp*.ord files to backup/ ...' os.system("mkdir -p backup/turn%s" % (turn)) os.system("mv sp*.ord backup/turn%s/" % (turn)) os.system("cp *.dat backup/turn%s/" % (turn)) print 'Moving all report files to reports/ ...' os.system("mv *.rpt.* %s" % (data_dir + "/reports/")) print "Writing statistics for turn %s to reports/stats/stats.t%s..." % ( turn, turn) os.system("mkdir -p %s" % (data_dir + "reports/stats")) os.system("%s/Stats > reports/stats/stats.t%s" % (bin_dir, turn)) print "Deleting temporary files..." os.system("rm -f interspecies.dat") os.system("rm -f *.log") print "Done!"
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir turn = fhutils.run(bin_dir, "TurnNumber").strip() print "Will now perform save for turn %s" % (turn) os.chdir(data_dir) if not os.path.isdir(data_dir+"/backup"): print "Sorry backup directory %s does not exist." % (data_dir+"/backup") sys.exit(1) if not os.path.isdir(data_dir+"/reports"): print "Sorry reports directory %s does not exist." % (data_dir+"/reports") sys.exit(1) print 'Moving sp*.ord files to backup/ ...' os.system("mkdir -p backup/turn%s" %(turn)) os.system("mv sp*.ord backup/turn%s/" %(turn)) os.system("cp *.dat backup/turn%s/" %(turn)) print 'Moving all report files to reports/ ...' os.system("mv *.rpt.* %s" %(data_dir+"/reports/")) print "Writing statistics for turn %s to reports/stats/stats.t%s..." % (turn, turn) os.system("mkdir -p %s" % (data_dir+"reports/stats")) os.system("%s/Stats > reports/stats/stats.t%s" %(bin_dir, turn)) print "Deleting temporary files..." os.system("rm -f interspecies.dat") os.system("rm -f *.log") print "Done!"
def main(argv): config_file = None test_flag = False try: opts, args = getopt.getopt(argv, "hc:t", ["help", "config=", "test"]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) if not os.path.isdir(bin_dir): print("Sorry bin directory %s does not exist." % (bin_dir)) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() inject = sys.stdin.read() for player in players: inject_p = inject.replace("SP_NAME", player['name']) report_name = "%s/sp%s.rpt.t%s" % (data_dir, player['num'], turn) with open(report_name, 'r') as original: report = original.read() if test_flag: print(inject_p + "\n\n" + report) else: with open(report_name, 'w') as modified: modified.write(inject_p + "\n\n" + report)
def main(argv): config_file = None test_flag = False try: opts, args = getopt.getopt(argv, "hc:t", ["help", "config=","test"]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print "Sorry data directory %s does not exist." % (data_dir) sys.exit(2) if not os.path.isdir(bin_dir): print "Sorry bin directory %s does not exist." % (bin_dir) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() inject = sys.stdin.read() for player in players: inject_p = inject.replace("SP_NAME", player['name']) report_name = "%s/sp%s.rpt.t%s" %(data_dir, player['num'], turn) with file(report_name, 'r') as original: report = original.read() if test_flag: print inject_p + "\n\n" + report else: with file(report_name, 'w') as modified: modified.write( inject_p + "\n\n" + report)
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game["name"] data_dir = game["datadir"] bin_dir = config.bindir os.chdir(data_dir) # prepare galaxy list output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) with open("galaxy.list.txt", "w") as f: f.write(output) players = fhutils.Game().players for p in players: try: subprocess.check_call( [ "zip", "sp%s.zip" % (p["num"]), "sp%s.rpt.t1" % (p["num"]), "galaxy.map.pdf", "galaxy.map.txt", "game_policies.pdf", "galaxy.list.txt", ] ) except CalledProcessError: print "ERROR making zip: sp%s.zip" % (p["num"])
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir os.chdir(data_dir) # prepare galaxy list output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) with open("galaxy.list.txt", "w") as f: f.write(output) players = fhutils.Game().players for p in players: try: subprocess.check_call([ "zip", "sp%s.zip" % (p['num']), "sp%s.rpt.t1" % (p['num']), "galaxy.map.pdf", "galaxy.map.txt", "game_policies.pdf", "galaxy.list.txt" ]) except CalledProcessError: print "ERROR making zip: sp%s.zip" % (p['num'])
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir turn = fhutils.run(bin_dir, "TurnNumber").strip() print("Will now perform save for turn %s" % (turn)) os.chdir(data_dir) backup_path = data_dir + "/backup" reports_path = data_dir + "/reports" stats_path = data_dir + "/reports/stats" turn_path = data_dir + "/backup/turn%s" % (turn) if not os.path.isdir(backup_path): os.makedirs(backup_path) if not os.path.isdir(reports_path): os.makedirs(reports_path) if not os.path.isdir(stats_path): os.makedirs(stats_path) if not os.path.isdir(turn_path): os.makedirs(turn_path) print("Moving sp*.ord files to backup/ ...") for order in glob.glob(data_dir + "/sp*.ord"): fname = os.path.basename(order) os.rename(order, "%s/%s" % (turn_path, fname)) print("Moving *.dat files to backup/ ...") for dat in glob.glob(data_dir + "/*.dat"): fname = os.path.basename(dat) shutil.copyfile(dat, "%s/%s" % (turn_path, fname)) for hs in glob.glob(data_dir + "/HS*"): fname = os.path.basename(hs) os.rename(hs, "%s/%s" % (turn_path, fname)) print("Moving all report files to reports/ ...") for rpt in glob.glob(data_dir + "/*.rpt.*"): fname = os.path.basename(rpt) dest = "%s/%s" % (reports_path, fname) os.rename(rpt, dest) stats = fhutils.run(bin_dir, "Stats").strip() stats_fname = "%s/stats.t%s" % (stats_path, turn) print("Writing stats for turn %s to %s" % (turn, stats_fname)) with open(stats_fname, 'w') as f: f.write(stats) print("Deleting temporary files...") interspecies_path = data_dir + "/interspecies.dat" if os.path.isfile(interspecies_path): os.remove(interspecies_path) for log in glob.glob(data_dir + "/*.log"): os.remove(log) print("Done!")
def main(argv): config_file = '' discard = False try: opts, args = getopt.getopt(argv, "hc:d", ["help", "config=","discard"]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-d", "--discard"): discard = True if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) if not os.path.isdir(bin_dir): print("Sorry bin directory %s does not exist." % (bin_dir)) sys.exit(2) os.chdir(data_dir) if os.path.isfile("interspecies.dat"): print("interspecies.dat present. Have you forgotten to fhclean?") sys.exit(2) try: tempdir = game['tmpdir'] if tempdir != '' and not discard: print("Temp directory exists (%s). Do you need to save? Maybe you need --discard?" % (game['tmpdir'])) sys.exit(2) elif not os.path.isdir(tempdir) and discard: config.write_tmpdir(game_name, "") elif tempdir and discard: shutil.rmtree(tempdir) except KeyError: pass tempdir = tempfile.mkdtemp("fhtest") config.write_tmpdir(game_name, tempdir) print("Using tempdir %s" % (tempdir)) print("Copying all needed files to /tmp/fhtest.dir/ ...") os.system("cp -p *.ord %s" % (tempdir)) os.system("cp -p *.dat %s" % (tempdir)) os.system("cp -p *.txt %s" % (tempdir)) os.system("cp -p *.msg %s" % (tempdir)) os.system("cp -p *.log %s" % (tempdir)) os.chdir(tempdir) t = fhutils.run(bin_dir, "TurnNumber").strip() if t != '0': print("Running NoOrders...") fhutils.run(bin_dir, "NoOrders") else: print("Turn 1 hasn't happened yet, running Locations") fhutils.run(bin_dir, "Locations") print("Running Combat...") ret = fhutils.run(bin_dir, "Combat") print("Running PreDeparture...") fhutils.run(bin_dir, "PreDeparture") print("Running Jump...") fhutils.run(bin_dir, "Jump") print("Running Production...") fhutils.run(bin_dir, "Production") print("Running PostArrival...") fhutils.run(bin_dir, "PostArrival") print("Running Locations...") fhutils.run(bin_dir, "Locations") print("Running Strike...") fhutils.run(bin_dir, "Strike") print("Running Finish...") fhutils.run(bin_dir, "Finish") print("Running Report...") fhutils.run(bin_dir, "Report") print("Success! Verify turn results: %s" % (tempdir))
def main(argv): config_file = None test_flag = False species_num = None try: opts, args = getopt.getopt(argv, "hc:ts:", ["help", "config=","test","species"]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True elif opt in ("-s", "--species"): species_num = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print "Sorry data directory %s does not exist." % (data_dir) sys.exit(2) if not os.path.isdir(bin_dir): print "Sorry bin directory %s does not exist." % (bin_dir) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() global message,deadline_msg, start_msg next_deadline = deadline_rule.after(datetime.now(dateutil.tz.tzutc())) est = zoneinfo.gettz('America/New_York') pst = zoneinfo.gettz('America/Los_Angeles') poland = zoneinfo.gettz('Europe/Warsaw') day = next_deadline.strftime("%A %B %d") time = next_deadline.strftime("%H:%M (%I:%M %p) %Z") time += "\n= %s" % (next_deadline.astimezone(est).strftime("%I:%M %p %Z")) time += "\n= %s" % (next_deadline.astimezone(pst).strftime("%I:%M %p %Z")) time += "\n= %s" % (next_deadline.astimezone(poland).strftime("%H:%M %Z")) deadline_msg = deadline_msg %(day, time,game_stub, game_stub) msg = message %(game_name, deadline_msg) for player in players: if species_num != None and species_num != player['num']: print "skipping %s - %s" %(player['num'], player['name']) continue orders = "%s/sp%s.ord" %(data_dir, player['num']) if os.path.isfile(orders): print "found orders for %s" %(player['name']) continue subject = "FH %s Orders Reminder - %s" % (game_stub, player['name']) if not test_flag: print "Mailing reminder to %s (sp %s)" %(player['email'], player['name']) config.send_mail(subject, player['email'], msg) else: print "Writing .test file" with open("sp%s.test"%(player['num']), "w") as f: f.write("To: %s\n" %( player['email'])) f.write("Subject: %s\n" %( subject)) f.write(msg)
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir os.chdir(data_dir) reader = csv.reader(sys.stdin, delimiter=',') data = [] for row in reader: data.append(row) num_species = len(data) print("%s species defined." % (num_species)); print("Executing NewGalaxy ") # Galaxy size is calculated based on default star density and fixed number of stars per race # Adjust it here to create less crowded galaxy, players are asking for that adjusted_num_species = str(int(( num_species * 3) / 2)) fhutils.run(bin_dir, "NewGalaxy", [adjusted_num_species]) print("Executing MakeHomes") fhutils.run(bin_dir, "MakeHomes") print("Executing ListGalaxy") output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) star_list = [s for s in output.splitlines() if s] # strips empty lines from output uniq_list = list(set(star_list)) # uniques the list if len(star_list) != len(uniq_list): print("Galaxy contains duplicate stars!!!") sys.exit(1) curr_sp_number = 1 try: fh_names = open("fh_names", "w") fh_names.truncate() except IOError: print("cannot open fh_names") sys.exit(1) for col in data: email, sp_name, home_planet, gov_name, gov_type, ML, GV, LS, BI = col print("\t Executing HomeSystemAuto (%s) " % (curr_sp_number)) output = fhutils.run(bin_dir, "HomeSystemAuto", ["12"]) x,y,z,n = output.split(" ") print("\t Executing AddSpecies (%s) " % (curr_sp_number)) arg = [ str(curr_sp_number), sp_name, home_planet, gov_name, gov_type, x, y, z, n, ML, GV, LS, BI] output = fhutils.run(bin_dir, "AddSpeciesAuto", arg) try: fh_names.write("%02d\n%s\n%s\n" % (curr_sp_number, sp_name, email)) except IOError: print("cannot write to fh_names") sys.exit(1) curr_sp_number += 1 fh_names.close() print("\t Preparing Turn 1: executing Finish") fhutils.run(bin_dir, "Finish") print("\t Reporting Turn 1: executing Report") fhutils.run(bin_dir, "Report") print("DONE")
def main(argv): config_file = None test_flag = False species_num = None file_name = None subject = None try: opts, args = getopt.getopt(argv, "hc:ts:f:u:", ["help", "config=","test","species","file","subject"]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True elif opt in ("-s", "--species"): species_num = arg elif opt in ("-f", "--file"): file_name = arg elif opt in ("-u", "--subject"): subject = arg if (file_name != None and subject == None) or (file_name == None and subject != None): print("if you specify file_name, you must specify subject."); sys.exit(1) if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) if not os.path.isdir(bin_dir): print("Sorry bin directory %s does not exist." % (bin_dir)) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() global message,deadline_msg, start_msg next_deadline = deadline_rule.after(datetime.now(dateutil.tz.tzutc())) est = zoneinfo.gettz('America/New_York') pst = zoneinfo.gettz('America/Los_Angeles') day = next_deadline.strftime("%A %B %d") time = next_deadline.strftime("%H:%M (%I:%M %p) %Z") time += "\n= " + next_deadline.astimezone(est).strftime("%I:%M %p %Z") time += "\n= " + next_deadline.astimezone(pst).strftime("%I:%M %p %Z") deadline_msg = deadline_msg %(day, time,game_stub, game_stub) msg = start_msg %(game_name, deadline_msg) if turn == "1" else message %(game_name, deadline_msg) for player in players: if species_num != None and species_num != player['num']: print("skipping %s - %s" %(player['num'], player['name'])) continue if player['email'] == "player_dropped": print("skipping dropped player %s - %s" %(player['num'], player['name'])) continue if file_name != None: report = "%s/%s" %(data_dir, file_name) elif turn == "1": report = "%s/sp%s.zip" %(data_dir, player['num']) subject ="FH %s Game Start - %s" % (game_stub, player['name']) else: report = "%s/sp%s.rpt.t%s" %(data_dir, player['num'], turn) subject = "FH %s Turn Results - %s turn %s" % (game_stub, player['name'], turn) if not test_flag: print("Mailing %s to %s (sp %s)" %(report, player['email'], player['name'])) config.send_mail(subject, player['email'], msg, report) else: print("Writing .test file") with open(report+".test", "w") as f: f.write("To: %s\n" %( player['email'])) f.write("Subject: %s\n" %( subject)) f.write(msg) f.write("Attached: %s\n" % (report))
def main(argv): config_file = None test_flag = False species_num = None file_name = None subject = None try: opts, args = getopt.getopt( argv, "hc:ts:f:u:", ["help", "config=", "test", "species", "file", "subject"]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True elif opt in ("-s", "--species"): species_num = arg elif opt in ("-f", "--file"): file_name = arg elif opt in ("-u", "--subject"): subject = arg if (file_name != None and subject == None) or (file_name == None and subject != None): print("if you specify file_name, you must specify subject.") sys.exit(1) if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) if not os.path.isdir(bin_dir): print("Sorry bin directory %s does not exist." % (bin_dir)) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() global message, deadline_msg, start_msg next_deadline = deadline_rule.after(datetime.now(dateutil.tz.tzutc())) est = zoneinfo.gettz('America/New_York') pst = zoneinfo.gettz('America/Los_Angeles') day = next_deadline.strftime("%A %B %d") time = next_deadline.strftime("%H:%M (%I:%M %p) %Z") time += "\n= " + next_deadline.astimezone(est).strftime("%I:%M %p %Z") time += "\n= " + next_deadline.astimezone(pst).strftime("%I:%M %p %Z") deadline_msg = deadline_msg % (day, time, game_stub, game_stub) msg = start_msg % (game_name, deadline_msg) if turn == "1" else message % ( game_name, deadline_msg) for player in players: if species_num != None and species_num != player['num']: print("skipping %s - %s" % (player['num'], player['name'])) continue if player['email'] == "player_dropped": print("skipping dropped player %s - %s" % (player['num'], player['name'])) continue if file_name != None: report = "%s/%s" % (data_dir, file_name) elif turn == "1": report = "%s/sp%s.zip" % (data_dir, player['num']) subject = "FH %s Game Start - %s" % (game_stub, player['name']) else: report = "%s/sp%s.rpt.t%s" % (data_dir, player['num'], turn) subject = "FH %s Turn Results - %s turn %s" % ( game_stub, player['name'], turn) if not test_flag: print("Mailing %s to %s (sp %s)" % (report, player['email'], player['name'])) config.send_mail(subject, player['email'], msg, report) else: print("Writing .test file") with open(report + ".test", "w") as f: f.write("To: %s\n" % (player['email'])) f.write("Subject: %s\n" % (subject)) f.write(msg) f.write("Attached: %s\n" % (report))
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir turn = fhutils.run(bin_dir, "TurnNumber").strip() print("Will now perform save for turn %s" % (turn)) os.chdir(data_dir) backup_path = data_dir+"/backup" reports_path = data_dir+"/reports" stats_path = data_dir+"/reports/stats" turn_path = data_dir+"/backup/turn%s" %(turn) if not os.path.isdir(backup_path): os.makedirs(backup_path) if not os.path.isdir(reports_path): os.makedirs(reports_path) if not os.path.isdir(stats_path): os.makedirs(stats_path) if not os.path.isdir(turn_path): os.makedirs(turn_path) print("Moving sp*.ord files to backup/ ...") for order in glob.glob(data_dir+"/sp*.ord"): fname = os.path.basename(order) os.rename(order, "%s/%s" % (turn_path, fname)) print("Moving *.dat files to backup/ ...") for dat in glob.glob(data_dir+"/*.dat"): fname = os.path.basename(dat) shutil.copyfile(dat, "%s/%s" % (turn_path, fname)) for hs in glob.glob(data_dir+"/HS*"): fname = os.path.basename(hs) os.rename(hs, "%s/%s" % (turn_path, fname)) print("Moving all report files to reports/ ...") for rpt in glob.glob(data_dir+"/*.rpt.*"): fname = os.path.basename(rpt) dest = "%s/%s" % (reports_path, fname) os.rename(rpt, dest) stats = fhutils.run(bin_dir, "Stats").strip() stats_fname = "%s/stats.t%s" % (stats_path, turn) print("Writing stats for turn %s to %s" % (turn, stats_fname)) with open(stats_fname, 'w') as f: f.write(stats) print("Deleting temporary files...") interspecies_path = data_dir + "/interspecies.dat" if os.path.isfile(interspecies_path): os.remove(interspecies_path) for log in glob.glob(data_dir+"/*.log"): os.remove(log) print("Done!")
def main(argv): config_file = None test_flag = False species_num = None try: opts, args = getopt.getopt(argv, "hc:ts:", ["help", "config=", "test", "species"]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True elif opt in ("-s", "--species"): species_num = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print "Sorry data directory %s does not exist." % (data_dir) sys.exit(2) if not os.path.isdir(bin_dir): print "Sorry bin directory %s does not exist." % (bin_dir) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() global message, deadline_msg, start_msg next_deadline = deadline_rule.after(datetime.now(dateutil.tz.tzutc())) est = zoneinfo.gettz('America/New_York') pst = zoneinfo.gettz('America/Los_Angeles') poland = zoneinfo.gettz('Europe/Warsaw') day = next_deadline.strftime("%A %B %d") time = next_deadline.strftime("%H:%M (%I:%M %p) %Z") time += "\n= %s" % (next_deadline.astimezone(est).strftime("%I:%M %p %Z")) time += "\n= %s" % (next_deadline.astimezone(pst).strftime("%I:%M %p %Z")) time += "\n= %s" % (next_deadline.astimezone(poland).strftime("%H:%M %Z")) deadline_msg = deadline_msg % (day, time, game_stub, game_stub) msg = message % (game_name, deadline_msg) for player in players: if species_num != None and species_num != player['num']: print "skipping %s - %s" % (player['num'], player['name']) continue orders = "%s/sp%s.ord" % (data_dir, player['num']) if os.path.isfile(orders): print "found orders for %s" % (player['name']) continue subject = "FH %s Orders Reminder - %s" % (game_stub, player['name']) if not test_flag: print "Mailing reminder to %s (sp %s)" % (player['email'], player['name']) config.send_mail(subject, player['email'], msg) else: print "Writing .test file" with open("sp%s.test" % (player['num']), "w") as f: f.write("To: %s\n" % (player['email'])) f.write("Subject: %s\n" % (subject)) f.write(msg)
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir PS2PDF = shutil.which("ps2pdf") PDFTK = shutil.which("pdftk") PDFUNITE = shutil.which("pdfunite") os.chdir(data_dir) output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) lines = [] for row in output.splitlines(): cols = row.split() try: if cols[0] is "The": break x = cols[2] y = cols[5] z = cols[8] stellar_type = cols[12] name = pretty_star(stellar_type) lines.append("%s, %s, %s, %s, %s.\n" % (x, y, z, name, stellar_type)) except IndexError: continue fd = tempfile.NamedTemporaryFile(mode='w', delete=False) fd.writelines(lines) fd.flush() os.fsync(fd) fhutils.run(bin_dir, "PrintMap", ["-d", "-t", "%s"%(fd.name)]) subprocess.call(["%s" % (PS2PDF), "-dAutoRotatePages=/None",fd.name+".ps", data_dir+"/galaxy_map_3d.pdf"]) fhutils.run(bin_dir, "PrintMap", ["-d", "%s"%(fd.name)]) subprocess.call(["%s" % (PS2PDF), "-dAutoRotatePages=/None",fd.name+".ps", data_dir+"/galaxy_map.pdf"]) fd.close() if PDFTK is not None: subprocess.call(["%s" % (PDFTK), data_dir+"/galaxy_map_3d.pdf", data_dir+"/galaxy_map.pdf", "cat", "output", data_dir+"/galaxy.map.pdf"]) elif PDFUNITE is not None: subprocess.call(["%s" % (PDFUNITE), data_dir+"/galaxy_map_3d.pdf", data_dir+"/galaxy_map.pdf", data_dir+"/galaxy.map.pdf"]) else: print("""Error: could not find pdftk nor pdfunite to merge the galaxy map pdfs. You should manually merge galaxy_map_3d.pdf and galaxy_map_2d.pdf into a single galaxy.map.pdf file before running game_packet.py.""")
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir PS2PDF = shutil.which("ps2pdf") PDFTK = shutil.which("pdftk") PDFUNITE = shutil.which("pdfunite") os.chdir(data_dir) output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) lines = [] for row in output.splitlines(): cols = row.split() try: if cols[0] is "The": break x = cols[2] y = cols[5] z = cols[8] stellar_type = cols[12] name = pretty_star(stellar_type) lines.append("%s, %s, %s, %s, %s.\n" % (x, y, z, name, stellar_type)) except IndexError: continue fd = tempfile.NamedTemporaryFile(mode='w', delete=False) fd.writelines(lines) fd.flush() os.fsync(fd) fhutils.run(bin_dir, "PrintMap", ["-d", "-t", "%s" % (fd.name)]) subprocess.call([ "%s" % (PS2PDF), "-dAutoRotatePages=/None", fd.name + ".ps", data_dir + "/galaxy_map_3d.pdf" ]) fhutils.run(bin_dir, "PrintMap", ["-d", "%s" % (fd.name)]) subprocess.call([ "%s" % (PS2PDF), "-dAutoRotatePages=/None", fd.name + ".ps", data_dir + "/galaxy_map.pdf" ]) fd.close() if PDFTK is not None: subprocess.call([ "%s" % (PDFTK), data_dir + "/galaxy_map_3d.pdf", data_dir + "/galaxy_map.pdf", "cat", "output", data_dir + "/galaxy.map.pdf" ]) elif PDFUNITE is not None: subprocess.call([ "%s" % (PDFUNITE), data_dir + "/galaxy_map_3d.pdf", data_dir + "/galaxy_map.pdf", data_dir + "/galaxy.map.pdf" ]) else: print( """Error: could not find pdftk nor pdfunite to merge the galaxy map pdfs. You should manually merge galaxy_map_3d.pdf and galaxy_map_2d.pdf into a single galaxy.map.pdf file before running game_packet.py.""")