forked from gesori-pro/PSO2ENPatchCSV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
executable file
·156 lines (136 loc) · 3.06 KB
/
Copy pathcommand.py
File metadata and controls
executable file
·156 lines (136 loc) · 3.06 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import codecs
import csv
import multiprocessing as mp
import os
import sys
def cutinamount(li):
extra = 0
value = None
for n, word in enumerate(li):
if n == 0:
None
if n == 1:
try:
value = int(word)
extra = 1
except ValueError:
value = None
elif value is None:
None
elif not (value is None):
None
else:
print(word)
return extra
def cutoutcommands(i):
try:
i = i[1:-1]
# most strings do not have commands, skip them
if i.rstrip() == "/":
return "\"\""
elif i[0] != "/":
return "\"\""
# by default, most strings do not have a command
ce = 0
li = i.split()
# which one have the last string?
for n, word in enumerate(li):
if word[0] == "/" and word != "/":
ce = n
if "/ci" in li[ce]:
ce += cutinamount(li[ce:])
elif "/mn" in li[ce]:
ce += 0
elif "/toge" in li[ce]:
ce += 0
elif "/face" in li[ce]:
ce += 0
elif "/atime" in li[ce]:
ce += 0
elif "/moya" in li[ce]:
ce += 0
elif "/start" in li[ce]:
ce += 0
elif "/voice11_voice_nav" in li[ce]:
ce += 0
elif "/rt_time60" in li[ce]:
ce += 0
elif "/ceall" in li[ce]:
ce += 0
elif "/ce" in li[ce]:
ce += 0
elif "/voice11_sound_voice_magat_qu00" in li[ce]:
ce += 0
else:
print("warning: can not handle {} in {}".format(li[ce], i))
return "\"" + " ".join(li[0: ce]) + "\""
except Exception as e:
print("Error processing string for commands: {}".format(e))
return None
def check(i):
err = 0
try:
w = i.replace("JP/", "WC/")
with codecs.open(i, encoding="utf-8") as JP:
bp = os.path.basename(i)
try:
jpcsv = csv.reader(JP, strict=True)
except Exception as e:
print("Error reading {}: {}".format(i, e))
if err == 0:
err = os.EX_DATAERR
return
try:
wc = codecs.open(w, encoding="utf-8")
wccsv = csv.reader(wc, strict=True)
except Exception as e:
print("Error reading of {}: {}".format(w, e))
if err == 0:
err = os.EX_UNAVAILABLE
return
while True:
jstr = None
wstr = None
try:
wc_ = next(wccsv)
except StopIteration:
wc_ = None
try:
jp_ = next(jpcsv)
except StopIteration:
jp_ = None
if jp_ is None and wc_ is None:
break
elif jp_ == wc_:
next
if wc_:
wstr = cutoutcommands(wc_[1])
col = wccsv.line_num
if jp_:
jstr = cutoutcommands(jp_[1])
col = jpcsv.line_num
if wstr is None:
print("WC File {} have bad command string at line {}".format(bp, col))
err = 1
elif jstr is None:
print("JP File {} have bad command string at line {}".format(bp, col))
err = 1
elif wstr != jstr:
print("File {} have mismatch commands at line {}: {} vs {}".format(bp, col, jstr, wstr))
err = 1
except Exception as e:
err = 1
print("File {} is badly formatted: {}".format(w, e))
return err
if __name__ == '__main__':
err = os.EX_OK
if len(sys.argv) == 1:
sys.exit(os.EX_NOINPUT)
p = mp.Pool(mp.cpu_count())
erra = p.map(check, sys.argv[1:])
p.close()
p.join()
err = max(erra)
sys.exit(err)