1

add: initial AI support

This commit is contained in:
diSabler
2014-05-01 14:07:44 +04:00
parent 5ffac3efcf
commit e5295eb994
217 changed files with 78827 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

View File

@@ -0,0 +1,179 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------------- #
# #
# Locale generator for iSida Jabber Bot #
# Copyright (C) diSabler <dsy@dsy.name> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# --------------------------------------------------------------------------- #
import os,re,time
def L(t): return t
def GT(t):
if t in ['disco_exclude','lfm_api']: return ''
elif t in ['html_logs_enable']: return 0
else: return None
def readfile(filename):
fp = file(filename)
data = fp.read()
fp.close()
return data
def writefile(filename, data):
fp = file(filename, 'wb')
fp.write(data)
fp.close()
def regenerate(ptl,locale_name):
global execute,exec_yes,comms
def L(text):
if not len(text): return text
try: return locales[text]
except: return text
path_to_locale = '%s/%s' % (ptl,locale_name)
root_files = os.listdir(path_to_source)
plugins_files = os.listdir(path_to_plugins)
plugins_files.sort()
file_list,localez = [],[]
regex = r'L\(u?\'(.*?)\'[,|\)]'
for tmp in root_files:
if tmp[-3:] == '.py' and tmp[0] not in ['.','_']: file_list.append('%s/%s' % (path_to_source,tmp))
for tmp in plugins_files:
if tmp[-3:] == '.py' and tmp[0] not in ['.','_']: file_list.append('%s/%s' % (path_to_plugins,tmp))
locales = {}
if os.path.isfile(path_to_locale):
lf = readfile(path_to_locale).decode('UTF').replace('\r','').split('\n')
for c in lf:
if ('#' not in c[:3]) and len(c) and '\t' in c: locales[c.split('\t',1)[0]] = c.split('\t',1)[1]
else: print 'Locale not found!'
result = locale_header + '\n\n'
error_count = 0
for tmp in file_list:
execute,exec_yes,comms = [],[],[]
if 'plugin' in tmp: execfile(tmp,globals())
body = str(readfile(tmp)).replace('\\\'','\'').replace('\\\"','\"').replace('\\\\','\\')
tm = re.findall(regex,body,re.S+re.U)
for t in execute+exec_yes+comms: tm.append(t[4].replace('\n','\\n'))
tm2 = re.findall('# translate: (.*)',body)
if tm2: tm2 = tm2[0].split(',')
if tm or tm2:
for tmp2 in tm:
if tmp2 not in localez:
localez.append(tmp2)
tm2.append(tmp2)
if tm2:
result += '%s%s\n' % (file_mark,'/'.join(tmp.split('/')[2:]))
for tmp2 in tm2:
tr = L(tmp2)
if tmp2 == tr:
error_count += 1
loc = locale_mark
else: loc = tr
result += '%s\t%s\n' % (tmp2,loc)
result += '\n'
execfile(path_to_mainpy,globals())
tm2 = []
for t in config_prefs.keys():
if config_prefs[t][0] not in localez:
localez.append(config_prefs[t][0])
tm2.append(config_prefs[t][0])
if config_prefs[t][1] not in localez:
localez.append(config_prefs[t][1])
tm2.append(config_prefs[t][1])
for t in config_groups:
if t[0] not in localez:
localez.append(t[0])
tm2.append(t[0])
for t in owner_prefs.keys():
if owner_prefs[t][0] not in localez:
localez.append(owner_prefs[t][0])
tm2.append(owner_prefs[t][0])
for t in owner_groups:
if t[0] not in localez:
localez.append(t[0])
tm2.append(t[0])
if tm2:
result += '%s%s\n' % (file_mark,'Generic')
for tmp2 in tm2:
tr = L(tmp2)
if tmp2 == tr:
error_count += 1
loc = locale_mark
else: loc = tr
result += '%s\t%s\n' % (tmp2,loc)
result += '\n'
result += '# write locale file: %s' % locale_name
result += '\n# total: %s' % len(localez)
msg = 'write locale file: %s' % locale_name
if error_count:
msg += '\nmissed translations: %s\n' % error_count
result += '\n# missed translations: %s\n' % error_count
else:
msg += '\nregenarated without mistakes!\n'
result += '\n# regenarated without mistakes!\n'
return msg, result, len(localez)
path_to_source = '../..'
path_to_locale = '%s/data/locales/' % path_to_source
path_to_plugins = '%s/plugins' % path_to_source
path_to_mainpy = '%s/main.py' % path_to_plugins
smiles_dirs = []
data_folder = path_to_source + '/data/%s'
loc_folder = data_folder % 'locales/%s.txt'
log_folder = data_folder % 'conflogs/%s'
public_log = log_folder % 'chatlogs/%s'
system_log = log_folder % 'syslogs/%s'
locale_mark = 'NO_TRANSLATE'
file_mark = '# file: '
locale_header = '''#---------------------------------------------
# Autogenerate for locales
# (c) Disabler Production Lab.
#---------------------------------------------'''
smiles_dirs_case = logs_css_path = ''
execute,exec_yes,comms = [],[],[]
if __name__ == "__main__" :
print '\n',locale_header.replace('#',''),'\n'
lf = os.listdir(path_to_locale)
for tmp in lf:
if tmp[-4:] == '.txt':
msg, result, lz = regenerate(path_to_locale,tmp)
writefile(tmp,'%s\n' % result.encode('utf-8'))
print msg
print 'Total found definitions: %s\n' % lz
print 'Done!'

View File

@@ -0,0 +1,256 @@
#!/usr/bin/python
about_txt = '''
# --------------------------------------------------------------------------- #
# #
# GUI for Locale Generator #
# Copyright (C) Vit@liy <vitaliy@root.ua> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# --------------------------------------------------------------------------- #
'''
import sys
import os
import locale_generator
from PyQt4 import QtGui, QtCore, Qt
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setWindowIcon(Qt.QIcon("icons/isida.png"))
if self.regenerate():
self.resize(400, 150)
self.setWindowTitle('GUI for Locale Generator')
self.window = Qt.QWidget()
self.layout_main = Qt.QGridLayout()
self.layout_main.setContentsMargins(3, 3, 3, 3)
self.layout_main.setSpacing(3)
self.window.setLayout(self.layout_main)
self.textLabelEN = QtGui.QLabel('<center><b>EN<\b><\center>')
self.textEditEN = Qt.QTextEdit()
self.textEditEN.setReadOnly(1)
self.textEditEN.setPlainText(self.loc_dict.values()[0][self.nontrans[0]].split('\t')[0].replace('\\n', '\n').replace('\\t', '\t'))
self.layout_main.addWidget(self.textLabelEN, 0, 0)
self.layout_main.addWidget(self.textEditEN, 0, 1)
self.textLabel = {}
self.textEdit = {}
for n, k in enumerate(self.loc_dict.keys()):
self.textLabel[k] = QtGui.QLabel('<center><b>%s<\b><\center>' % k.upper())
self.textEdit[k] = Qt.QTextEdit()
self.textEdit[k].setPlainText(self.loc_dict[k][self.nontrans[0]].split('\t')[1].replace('\\n', '\n').replace('\\t', '\t'))
self.layout_main.addWidget(self.textLabel[k], n + 1, 0)
self.layout_main.addWidget(self.textEdit[k], n + 1, 1)
self.setCentralWidget(self.window)
exit_act = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self)
exit_act.setShortcut('Ctrl+Q')
exit_act.setStatusTip('Exit application')
self.connect(exit_act, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
info_act = QtGui.QAction(QtGui.QIcon('icons/dialog-information.png'), 'Info', self)
info_act.setShortcut('Ctrl+I')
info_act.setStatusTip('Informations about locales')
self.connect(info_act, QtCore.SIGNAL('triggered()'), self.show_locales_info)
prev_act = QtGui.QAction(QtGui.QIcon('icons/go-previous.png'), 'Previous', self)
prev_act.setShortcut('Ctrl+P')
prev_act.setStatusTip('Previous non-translate')
self.connect(prev_act, QtCore.SIGNAL('triggered()'), self.prev_notrans)
save_act = QtGui.QAction(QtGui.QIcon('icons/document-save.png'), 'Save', self)
save_act.setShortcut('Ctrl+S')
save_act.setStatusTip('Save locales')
self.connect(save_act, QtCore.SIGNAL('triggered()'), self.save_locales)
save_l = {}
for k in self.loc_dict.keys():
save_l[k] = QtGui.QAction(QtGui.QIcon('icons/document-save.png'), 'Save %s' % k.upper(), self)
save_l[k].setStatusTip('Save locale: %s' % k.upper())
self.connect(save_l[k], QtCore.SIGNAL('triggered()'), lambda: self.save_locales(k))
next_act = QtGui.QAction(QtGui.QIcon('icons/go-next.png'), 'Next', self)
next_act.setShortcut('Ctrl+N')
next_act.setStatusTip('Next non-translate')
self.connect(next_act, QtCore.SIGNAL('triggered()'), self.next_notrans)
about_act = QtGui.QAction(QtGui.QIcon('icons/help-browser.png'), 'About...', self)
about_act.setStatusTip('About...')
self.connect(about_act, QtCore.SIGNAL('triggered()'), self.about_info)
self.connect(self, Qt.SIGNAL('triggered()'), self.closeEvent)
self.statusBar()
menubar = self.menuBar()
menu_f = menubar.addMenu('&Menu')
menu_f.addAction(save_act)
for k in self.loc_dict.keys():
menu_f.addAction(save_l[k])
menu_f.addAction(info_act)
menu_f.addAction(exit_act)
menu_e = menubar.addMenu('&Edit')
menu_e.addAction(prev_act)
menu_e.addAction(next_act)
menu_i = menubar.addMenu('&Info')
menu_i.addAction(about_act)
toolbar_f = self.addToolBar('File')
toolbar_f.addAction(exit_act)
toolbar_f.addAction(save_act)
toolbar_f.addAction(info_act)
toolbar_e = self.addToolBar('Edit')
toolbar_e.addAction(prev_act)
toolbar_e.addAction(next_act)
else:
self.save_locales(None,None)
self.setWindowTitle('Info')
self.window = Qt.QWidget()
self.layout_main = Qt.QVBoxLayout()
self.layout_main.setContentsMargins(3, 3, 3, 3)
self.layout_main.setSpacing(3)
self.window.setLayout(self.layout_main)
lbl = QtGui.QLabel('<center>Regenerated without mistakes!<\center>')
self.layout_main.addWidget(lbl)
quit_act = QtGui.QPushButton('Quit')
self.layout_main.addWidget(quit_act)
self.connect(quit_act, QtCore.SIGNAL('clicked()'), QtGui.qApp, QtCore.SLOT('quit()'))
self.setCentralWidget(self.window)
def regenerate(self):
path_to_locale = locale_generator.path_to_locale
lf = os.listdir(path_to_locale)
self.loc_dict = {}
self.label_inf = ''
for tmp in lf:
if tmp[-4:] == '.txt':
msg, result, lz = locale_generator.regenerate(path_to_locale,tmp)
self.label_inf += '%s\n' % msg.replace('write', 'Found')
self.loc_dict[tmp[:-4]] = result.split('\n')
self.label_inf += 'Total found definitions: %s\n' % lz
self.nontrans = []
#self.show_locales_info()
for k in self.loc_dict.keys():
self.nontrans += [i[0] for i in enumerate(self.loc_dict[k]) if locale_generator.locale_mark in i[1] and i[1][0] != '#']
self.nontrans = list(set(self.nontrans))
self.nontrans.sort()
self.curs = 0
self.count = len(self.nontrans)
self.save = True
if not self.count:
return False
else:
return True
def closeEvent(self, event):
if self.count:
tmp_en = self.textEditEN.toPlainText().replace('\n', '\\n').replace('\t', '\\t')
for k in self.loc_dict.keys():
if self.loc_dict[k][self.nontrans[self.curs]] != '%s\t%s' % (tmp_en, self.textEdit[k].toPlainText().replace('\n', '\\n').replace('\t', '\\t')):
self.save = False
if not self.save:
reply = QtGui.QMessageBox.question(self, 'Quit', "Are you sure to quit without saving?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.No:
event.ignore()
return
event.accept()
def show_locales_info(self):
self.show_info(self.label_inf)
def show_info(self, txt):
QtGui.QMessageBox.information(self, 'Info', txt, QtGui.QMessageBox.Ok)
def next_notrans(self):
tmp_en = self.textEditEN.toPlainText().replace('\n', '\\n').replace('\t', '\\t')
for k in self.loc_dict.keys():
tmp_k = '%s\t%s' % (tmp_en, self.textEdit[k].toPlainText().replace('\n', '\\n').replace('\t', '\\t'))
if self.loc_dict[k][self.nontrans[self.curs]] != tmp_k:
self.save = False
self.loc_dict[k][self.nontrans[self.curs]] = tmp_k
self.curs = (self.curs + 1) % self.count
self.textEditEN.setText(self.loc_dict.values()[0][self.nontrans[self.curs]].split('\t')[0].replace('\\n', '\n').replace('\\t', '\t'))
for k in self.loc_dict.keys():
self.textEdit[k].setText(self.loc_dict[k][self.nontrans[self.curs]].split('\t')[1].replace('\\n', '\n').replace('\\t', '\t'))
def prev_notrans(self):
tmp_en = self.textEditEN.toPlainText().replace('\n', '\\n').replace('\t', '\\t')
for k in self.loc_dict.keys():
tmp_k = '%s\t%s' % (tmp_en, self.textEdit[k].toPlainText().replace('\n', '\\n').replace('\t', '\\t'))
if self.loc_dict[k][self.nontrans[self.curs]] != tmp_k:
self.save = False
self.loc_dict[k][self.nontrans[self.curs]] = tmp_k
self.curs = (self.curs - 1) % self.count
self.textEditEN.setText(self.loc_dict.values()[0][self.nontrans[self.curs]].split('\t')[0].replace('\\n', '\n').replace('\\t', '\t'))
for k in self.loc_dict.keys():
self.textEdit[k].setText(self.loc_dict[k][self.nontrans[self.curs]].split('\t')[1].replace('\\n', '\n').replace('\\t', '\t'))
def save_locales(self, locale_for_saving=None, main_interface=True):
if main_interface: tmp_en = self.textEditEN.toPlainText().replace('\n', '\\n').replace('\t', '\\t')
if not locale_for_saving:
ls = self.loc_dict.keys()
else:
ls = [locale_for_saving]
for k in ls:
if main_interface: self.loc_dict[k][self.nontrans[self.curs]] = '%s\t%s' % (tmp_en, self.textEdit[k].toPlainText().replace('\n', '\\n').replace('\t', '\\t'))
result = '\n'.join(self.loc_dict[k])
if not result.endswith('\n\n'): result = '%s\n' % result
locale_generator.writefile('%s.txt' % k,result.encode('utf-8'))
tmp_body = []
for t in result.split('\n\n',1)[1].split('\n'):
if locale_generator.locale_mark not in t: tmp_body.append(t)
tmp2_body,cnt = [],0
for t in range(0,len(tmp_body)-2):
if tmp_body[cnt].startswith(locale_generator.file_mark) and tmp_body[cnt+2].startswith(locale_generator.file_mark): cnt += 2
tmp2_body.append(tmp_body[cnt])
cnt += 1
original_file = '%s\n\n%s' % (locale_generator.readfile('%s/%s.txt' % (locale_generator.path_to_locale,k)).decode('UTF').replace('\r','').split('\n\n',1)[0],'\n'.join(tmp2_body))
if not original_file.endswith('\n\n'): original_file = '%s\n' % original_file
locale_generator.writefile('%s/%s.txt' % (locale_generator.path_to_locale,k),original_file.encode('utf-8'))
if main_interface:
if not self.regenerate():
self.show_info('Regenerated without mistakes!')
self.close()
else:
for n, k in enumerate(self.loc_dict.keys()):
self.textEditEN.setPlainText(self.loc_dict.values()[0][self.nontrans[0]].split('\t')[0].replace('\\n', '\n').replace('\\t', '\t'))
self.textEdit[k].setPlainText(self.loc_dict[k][self.nontrans[0]].split('\t')[1].replace('\\n', '\n').replace('\\t', '\t'))
self.show_info('Done!')
def about_info(self):
self.show_info(about_txt.replace('#', '').replace('-', ''))
if __name__ == "__main__" :
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())

View File

@@ -0,0 +1,70 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------------- #
# #
# Locale generator for iSida Jabber Bot #
# Copyright (C) diSabler <dsy@dsy.name> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# --------------------------------------------------------------------------- #
import re,os
def readfile(filename):
fp = file(filename)
data = fp.read()
fp.close()
return data
_path = '../branch/%s'
f = [_path % 'kernel.py']
for root,folder,files in os.walk(_path % 'plugins'):
for _file in files:
if _file[0] not in ['_','.'] and _file.endswith('.py'):
f.append(os.path.join(root,_file))
print 'Found files: %s' % len(f)
_func = []
for t in f:
_file = readfile(t)
_func += re.findall('def\ (.*?)\(',_file)
print 'Found functions: %s' % len(_func)
_unused = []
_once = []
for fn in _func:
cnt = 0
for t in f:
_file = readfile(t)
func = re.findall('(?<!def\ )(%s)\(' % fn,_file)
if func: cnt += len(func)
func = re.findall('[\,\(\[\=]{1}\ ?(%s)[\,\]\)]{1}' % fn,_file)
if func: cnt += len(func)
func = re.findall('\.(%s)' % fn,_file)
if func: cnt += len(func)
if cnt == 0:
_unused.append(fn)
print fn
elif cnt == 1:
_once.append(fn)
_once.sort()
print 'Total unused functions: %s' % len(_unused)
print 'Total once time used: %s' % len(_once)
#print ' | '.join(_once)