Poodletooth-iLand/dev/tools/whitelist/whitelist_tool.py

86 lines
2.4 KiB
Python
Raw Normal View History

2015-03-04 12:24:11 -06:00
import os
2015-05-29 05:03:48 -05:00
os.chdir('../../../')
2015-03-04 12:24:11 -06:00
2015-06-08 11:54:21 -05:00
from otp.chat import WhiteListData
2015-03-04 12:24:11 -06:00
def acceptWord():
word = raw_input('> ').rstrip().lower()
if word == 'exit()':
saveChanges()
return
if word.startswith('r '):
word = word.replace('r ', '')
if word not in LOCAL_LIST:
print 'Could not remove unknown word "%s" from the whitelist.' % word
else:
LOCAL_LIST.remove(word)
print 'Removed "%s" from the whitelist.' % word
2015-06-08 11:54:21 -05:00
elif word.startswith('m '):
merge = word.replace('m ', '')
if os.path.isfile(merge):
print 'Opening %s...' % merge
with open(merge) as file:
for line in file.readlines():
line = line.replace('\r', '').replace('\n', '').lower()
print 'Adding %s...' % line
LOCAL_LIST.append(line)
else:
print 'No file named %s!' % merge
2015-03-04 12:24:11 -06:00
elif word in LOCAL_LIST:
print 'The word "%s" is already whitelisted.' % word
else:
LOCAL_LIST.append(word)
print 'Added the word "%s" to the whitelist.' % word
acceptWord()
2015-06-09 10:46:16 -05:00
def removeDuplicates(list):
seen = set()
seen_add = seen.add
return [x for x in list if not (x in seen or seen_add(x))]
2015-03-04 12:24:11 -06:00
def saveChanges():
2015-06-08 11:54:21 -05:00
global LOCAL_LIST
2015-03-04 12:24:11 -06:00
print 'Saving the whitelist...'
2015-06-08 11:54:21 -05:00
with open('otp/chat/WhiteListData.py', 'w') as f:
2015-03-04 12:24:11 -06:00
f.write('WHITELIST = [\n')
LOCAL_LIST.sort()
2015-06-09 10:46:16 -05:00
LOCAL_LIST = removeDuplicates(LOCAL_LIST)
2015-03-04 12:24:11 -06:00
for word in LOCAL_LIST:
2015-06-09 10:46:16 -05:00
2015-06-09 11:00:08 -05:00
if '\\' in word:
print 'Word contains illegal characters: %s' % word
2015-06-09 10:46:16 -05:00
continue
try:
word.decode('ascii')
except:
2015-06-09 11:00:08 -05:00
print 'Word cannot be decoded in ASCII mode: %s' % word
2015-03-04 12:24:11 -06:00
continue
if "'" in word:
f.write(' "%s",\n' % word)
else:
f.write(" '%s',\n" % word)
f.write(']')
print 'Your changes have been saved! Make sure to push your changes!'
LOCAL_LIST = WhiteListData.WHITELIST
print 'Welcome to the Toontown Stride Whitelist Tool!'
2015-03-04 12:24:11 -06:00
print 'Type any word you want to add to the whitelist.'
print 'If you wish to remove a word, type "r <word>".'
2015-06-08 11:54:21 -05:00
print 'If you wish to merge a file, type "m <file>".'
2015-03-04 12:24:11 -06:00
print 'When you are done and want to save your changes, type "exit()".'
2015-05-29 05:03:48 -05:00
acceptWord()