-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua.py
More file actions
71 lines (61 loc) · 1.67 KB
/
lua.py
File metadata and controls
71 lines (61 loc) · 1.67 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
def strip(s):
"Removes non-ASCII characters from a string."
return ''.join(c for c in str(s) if 0 < ord(c) < 127)
def remove_commas(f):
"Remove double commas from a Lua file."
with open(f, 'r') as fr:
lines = fr.readlines()
o = ''
for line in lines:
o = o + line.replace(",,",",")
with open(f, 'w') as fw:
fw.write(o)
def clean_file(f):
"Clean up a Lua file."
remove_commas(f)
def wvts(vname, vdata, nline=True, comma=True):
"Write a variable to a string."
if vdata == "":
return ""
vname = strip(vname)
vdata = strip(vdata)
if " " in vname:
vname = "[\"" + vname + "\"]"
if nline:
return vname + "=" + vdata + ",\n"
if comma:
return vname + "=" + vdata + ","
return vname + "=" + vdata
"Naming scheme: Write [Variable/List] to [Wiki file/String]."
def wvtw(f, vname, vdata, nline=True):
"Write a variable to the wiki file."
f.write(bytes(wvts(vname, vdata, nline), "UTF-8"))
def wlts(vname, lst, nline=True):
"Write a list to a string containing an equivalent Lua table."
s = ""
if len(lst) == 0:
return s
for x in lst:
if not x:
continue
s = s + x
if "," not in x:
s = s + ","
if nline:
s = s + "\n"
return wvts(vname, "{" + s + "},", nline, False)
def wltw(f, vname, lst, nline=True):
"Write a list to the wiki file."
f.write(bytes(wlts(vname, lst, nline), "UTF-8"))
def english(f):
"Makes sure a file is in English."
if "de" in f or "ja" in f or "fr" in f:
return False
return True
import os
def find_file(fname):
"Finds the path to a file."
for root, dirs, files in os.walk("."):
for f in files:
if name in f and english(f):
return os.path.join(root, name)