def main(argv): config_file = '' discard = False try: opts, args = getopt.getopt(argv, "hc:d", ["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 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) tempdir = '' try: tempdir = game['tmpdir'] print(tempdir) if not os.path.isdir(tempdir): raise KeyError except KeyError: print( "Temp directory doesn't exist for this game. You should use turn_run.py first." ) sys.exit(2) os.chdir(tempdir) print("Copying *.dat files to $odn...") os.system("cp -p *.dat %s" % (data_dir)) print("Copying order files to $odn...") os.system("cp -p *.ord %s" % (data_dir)) print("Copying report files to $odn...") os.system("cp -p *.rpt.* %s" % (data_dir)) os.chdir(data_dir) print("Turn Complete") shutil.rmtree(tempdir)
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 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 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(): global server, port, ssl config = fhutils.GameConfig() data_dir = config.gameslist[0]['datadir'] #only support one game now game_stub = config.gameslist[0]['stub'] try: game = fhutils.Game() except IOError: print "Could not read fh_names" sys.exit(2) if not os.path.isdir(data_dir): print "Sorry data directory %s does not exist." % (data_dir) sys.exit(2) longest_name = len(max([x['name'] for x in game.players], key=len)) for player in game.players: name = player['name'].center(longest_name) orders = "%s/sp%s.ord" % (data_dir, player['num']) try: with file(orders, "r+") as f: p = subprocess.Popen([ "/usr/bin/perl", "/home/ramblurr/src/fh/engine/bash/orders.pl" ], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) verify = p.communicate(input=f.read())[0] if "No errors found" in verify: print "%s - %s - Ready" % (player['num'], name) else: print "%s - %s - Errors" % (player['num'], name) except IOError: print "%s - %s - No Orders" % (player['num'], name)
def main(): global server, port, ssl config = fhutils.GameConfig() data_dir = config.gameslist[0]['datadir'] #only support one game now game_stub = config.gameslist[0]['stub'] try: game = fhutils.Game() except IOError: print("Could not read fh_names") sys.exit(2) if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) for player in game.players: orders = "%s/sp%s.ord" % (data_dir, player['num']) try: with file(orders, "r+") as f: text = f.read() text2 = os.linesep.join([s for s in text.splitlines() if s]) f.seek(0) f.write(text2) except IOError: print("Couldn't open %s" % (orders))
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(): config = fhutils.GameConfig() spreadsheet = config.registrations() rows = spreadsheet.get_registrations() messages = {} playerlist = [] emaillist = [] emaillist.append("Name, Email Address\n") for idx, row in enumerate(rows): # email,sp_name,,home_planet_name,gov_name,gov_type,ML,GV,LS,BI email = row.custom["email"].text if email is None: continue if row.custom["validated"].text != "Yes": print("%s not validated" % (email)) continue species = row.custom["speciesname"].text gov_name = row.custom["governmentname"].text home_planet = row.custom["homeplanetname"].text gov_type = row.custom["governmenttype"].text bio = row.custom["biology"].text grav = row.custom["gravitics"].text mil = row.custom["military"].text life = row.custom["lifesupport"].text playercsv_row = "%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % ( email, species, home_planet, gov_name, gov_type, mil, grav, life, bio) playerlist.append(playercsv_row) emailcsv_row = "%s,%s\n" % (species, email) emaillist.append(emailcsv_row) player_csv = open('players.csv', "w") player_csv.writelines(playerlist) player_csv.close email_csv = open('players_email.csv', "w") email_csv.writelines(emaillist) email_csv.close
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 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(): config = fhutils.GameConfig() spreadsheet = config.registrations() rows = spreadsheet.get_registrations() messages = {} for idx, row in enumerate(rows): if row.custom["validated"].text == "Yes": continue recipient = row.custom["email"].text if recipient is None: continue if len(recipient.strip()) == 0: continue print "Validating %s - %s" % (row.custom["speciesname"].text, row.custom["email"].text) error_msg = "" if not check_length(row.custom["speciesname"].text): error_msg += "* Species name must be between 7 and 31 character.\n" if not check_length(row.custom["governmentname"].text): error_msg += "* Government name must be between 7 and 31 character.\n" if not check_length(row.custom["homeplanetname"].text): error_msg += "* Homeplanet name must be between 7 and 31 character.\n" if not check_length(row.custom["governmenttype"].text): error_msg += "* Government type must be between 7 and 31 character.\n" bio = 0 grav = 0 mil = 0 life = 0 converted = True try: bio = int(row.custom["biology"].text) except (TypeError, ValueError): error_msg += "* Biology tech value must be a number\n" converted = False try: grav = int(row.custom["gravitics"].text) except (TypeError, ValueError): error_msg += "* Gravitics tech value must be a number\n" converted = False try: mil = int(row.custom["military"].text) except (TypeError, ValueError): error_msg += "* Military tech value must be a number\n" converted = False try: life = int(row.custom["lifesupport"].text) except (TypeError, ValueError): error_msg += "* Life Support tech value must be a number\n" converted = False if converted: total = bio + grav + mil + life if total != 15: error_msg += "* The total number of points allocated to technologies must be equal to 15\n" if len(error_msg) > 0: print "\tErrors found" messages[recipient] = email_template_fail % (error_msg) else: messages[recipient] = email_template_success % ( row.custom["speciesname"].text, row.custom["homeplanetname"].text, row.custom["governmentname"].text, row.custom["governmenttype"].text) d = {} for k in row.custom: d[k] = row.custom[k].text d["validated"] = "Yes" spreadsheet.update_row(row, d) for email, msg in messages.iteritems(): config.send_mail("FH Player Registration", email, msg) print "All done"
def main(): global server, port, ssl config = fhutils.GameConfig() data_dir = config.gameslist[0]['datadir'] #only support one game now game_stub = config.gameslist[0]['stub'] try: game = fhutils.Game() except IOError: print("Could not read fh_names") sys.exit(2) if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) server = IMAPClient(server, use_uid=True, ssl=ssl) server.login(config.user, config.password) select_info = server.select_folder('INBOX') messages = server.search(['UNSEEN', 'SUBJECT "FH Orders"']) response = server.fetch(messages, ['RFC822']) for k in response: mail = email.message_from_string(response[k]['RFC822']) addressor = mail.get("From") from_address = email.utils.parseaddr(addressor)[1] if 'wait' in mail.get("Subject"): wait = True else: wait = False for player in game.players: if from_address == player['email']: orders_file = "%s/sp%s.ord" % (data_dir, player['num']) fd = codecs.open(orders_file, 'w', 'utf-8') orders = None if mail.is_multipart(): print( "Multipart Message detected, searching for plain text payload!" ) for part in mail.walk(): # multipart/* are just containers if part.get_content_maintype() == 'multipart': continue filename = part.get_filename() if not filename: continue if part.get_content_type() != "text/plain": print( "Error: attachment found, but not a plain text file for " + from_address) else: print("found orders in attachment") orders = part.get_payload(decode=True) if orders is None: # ok, no attachment, lets try the actual content payloads = mail.get_payload() try: found = False for loads in payloads: if loads.get_content_type() == "text/plain": mail = loads found = True print("found orders in multipart payload") orders = loads.get_payload(decode=True) break if not found: raise email.errors.MessageError except email.errors.MessageError: print("Could not find text/plain payload for " + from_address) else: print("using orders in plain body") orders = mail.get_payload(decode=True) orders = orders.replace('\r\n', '\n').replace('\r', '\n') orders = str(orders, 'utf-8') orders = orders.replace("\u00A0", " ").encode('utf-8') fd.write(orders) fd.close() p = subprocess.Popen([ "/usr/bin/perl", "/home/ramblurr/src/fh/engine/bash/orders.pl" ], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) verify = p.communicate(input=orders)[0] subject = "FH Orders, %s received" % (game_stub) if wait: subject += " - wait set" else: subject += " - wait not set" config.send_mail(subject, from_address, verify, orders_file) print("Retrieved orders %s for sp%s - %s - %s" % ("[WAIT]" if wait else "", player['num'], player['name'], from_address))
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 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 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 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.""")