This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
a3cfgreader.py
74 lines (67 loc) · 2.26 KB
/
a3cfgreader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#import os
import linecache
#import re
import builtins as __builtin__
import logging
logging.basicConfig(filename='error.log',
level=logging.INFO,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
def print(*args, **kwargs):
if(len(args)>0):
logging.info(args[0])
return __builtin__.print(*args, **kwargs)
class readcfg:
def __init__(self, server_cfg, cycle_cfg):
self.server_cfg = server_cfg
self.cycle_cfg = cycle_cfg
def getLine(self, pos):
return linecache.getline(self.cycle_cfg, cline)
def parseMissions(self):
cycle = []
file = open(self.cycle_cfg, "r")
for line in file:
if("MAP:=" in line):
cycle.append([line.split(":=")[1].strip()])
cycle[-1].append("")
else:
cycle[-1][1] += line
return cycle
def newCycleOrder(self, cycle, Map):
index_nmap = -1
new_cycle = []
for num, val in enumerate(cycle):
if(val[0] == Map):
index_nmap = num
if(index_nmap >= 0):
new_cycle.append(val)
if(index_nmap >= 0):
for i in range(0, index_nmap):
new_cycle.append(cycle[i])
else:
print("[MapCycle] Error map not found:", Map, index_nmap)
return new_cycle
def writeMission(self, cycle, Map):
new_cycle = self.newCycleOrder(cycle, Map)
file = open(self.server_cfg, "r")
#print(new_cycle)
newfile = ""
write = False
for line in file:
if("class Missions {" in line):
write = True
newfile += line
for map in new_cycle:
newfile += map[1]
if(write==True):
if(line.rstrip() == "};"):
write=False
newfile += line
else:
newfile += line
f = open(self.server_cfg, "w")
f.write(newfile)
#rcfg = readcfg("D:/Server/discord/server.cfg","D:/Server/discord/jmwBOT/modules/jmw/mission_cycle.cfg")
#
#pcycle = rcfg.parseMissions()
#pcycle = rcfg.writeMission(pcycle, "Malden")