142 lines
4.7 KiB
Python
Executable File
142 lines
4.7 KiB
Python
Executable File
#!/usr/bin/python
|
|
import csv
|
|
import os
|
|
import getopt
|
|
import sys
|
|
import re
|
|
import datetime
|
|
|
|
class html_links_generator(object):
|
|
def __init__( self ):
|
|
self.project = None # read from commando line: guez, ahtct etc
|
|
self.languge = 'de_DE' # read from commando line: de_DE, en_GB, en_US
|
|
self.csv_file = None # file exported from Excel, filtered on project (ex. guez.csv)
|
|
self.help_links = list() # html links generated from csv file
|
|
self.out_file = None # result file is project+language+.txt
|
|
self.html_folder = '/shd/CTC/WS/share/Lts/help/' # where to look for existing help files, can be given also on commando line
|
|
|
|
self.rootPath = '../../..' # executing from Lts/Tools/OnlineHelp
|
|
self.functionName = 'setOnlineHelpFilename' # function name to search recursively in source code
|
|
self.htmlLinks = list() # current needed html links in source code (for all projects)
|
|
self.helpFile = None # where to write all current links
|
|
|
|
def initialize(self):
|
|
if self.project == None:
|
|
print >> sys.stderr, "No project given"
|
|
sys.exit(1)
|
|
|
|
def execute(self):
|
|
print >> sys.stderr, "Looking for %s" % self.functionName
|
|
self.find_current_links()
|
|
|
|
self.helpFile = 'current_links.txt'
|
|
print >> sys.stderr, "Writing current links in file %s " % self.helpFile
|
|
f = open(self.helpFile, 'wt')
|
|
f.write('DATE: %s\n-------------------------------\n' % datetime.datetime.today())
|
|
f.write('\n'.join(str(e) for e in self.htmlLinks))
|
|
|
|
print >> sys.stderr, "Reading csv file %s" % self.csv_file
|
|
self.csv_file = self.project+'.csv'
|
|
self.read_csv(self.csv_file);
|
|
|
|
self.out_file = self.project+'_'+self.language+'.txt'
|
|
print >> sys.stderr, "Writing project links in file %s " % self.out_file
|
|
f = open(self.out_file, 'wt')
|
|
f.write('PROJECT: %s \nLANGUAGE: %s \nDATE: %s\nHTML LINKS: %s\n-------------------------------\n' % (self.project, self.language, datetime.datetime.today(), self.html_folder))
|
|
f.write('\n'.join(str(e) for e in self.help_links))
|
|
|
|
def read_csv(self, filename):
|
|
reader = csv.reader(open(os.path.join(filename), 'rt'), delimiter = ';')
|
|
for a in reader:
|
|
self.html_link(a)
|
|
|
|
def find_current_links(self):
|
|
pattern = re.compile('%s\(QStringLiteral\((.*)\)\)' % self.functionName)
|
|
for folder, dirs, files in os.walk(self.rootPath):
|
|
for file in files:
|
|
if file.endswith('.cpp') or file.endswith('.h'):
|
|
fullpath = os.path.join(folder, file)
|
|
with open(fullpath, 'r') as f:
|
|
for line in f:
|
|
if self.functionName in line:
|
|
# print(line)
|
|
# print(fullpath)
|
|
for match in pattern.findall(line):
|
|
# print(match)
|
|
new_line = match.strip('"')+';'+fullpath
|
|
self.htmlLinks.append(new_line)
|
|
|
|
def toBool(self, val):
|
|
if val == '':
|
|
return 'false'
|
|
if val == 'true' or val == '1':
|
|
return 'true'
|
|
if val == 'false' or val == '0':
|
|
return 'false'
|
|
if bool(val):
|
|
return 'true'
|
|
return 'false'
|
|
|
|
def toInt(self, val):
|
|
if val == '':
|
|
return 'NULL'
|
|
return int(val, 0)
|
|
|
|
def toFloat(self, val):
|
|
val = val.replace(',', '.')
|
|
if val == '':
|
|
return 0
|
|
return float(val)
|
|
|
|
def toString(self, val):
|
|
return val.strip()
|
|
|
|
def toJson(self, val):
|
|
return self.toString(val) # for now
|
|
|
|
def html_link(self, line):
|
|
if len(line[0]) == 0:
|
|
return
|
|
html_file = self.toString(line[0]) + '.htm'
|
|
html_path = self.html_folder + '/' + self.language + '/'
|
|
if (not os.path.exists(os.path.join(html_path, html_file))):
|
|
html_file += '; ############# MISSING ################'
|
|
self.help_links.append(html_file)
|
|
|
|
def usage():
|
|
print "Usage: %s <Options>" % sys.argv[0]
|
|
print "usage: $0 -p <project> -l <language_code> -f <html_folder>"
|
|
print " -p (--project) : guez / ahtc "
|
|
print " -l (--language) : de_DE / en_GB / en_US"
|
|
print " -f (--folder) : HTML folder to compare with"
|
|
|
|
def main():
|
|
|
|
p = html_links_generator()
|
|
|
|
try:
|
|
opts, args = getopt.getopt(sys.argv[1:], "p:l:f:", ["project","language","folder"])
|
|
except getopt.GetoptError, err:
|
|
print >> sys.stderr, err
|
|
usage()
|
|
sys.exit(2)
|
|
for o, a in opts:
|
|
if o in ("-p", "--project"):
|
|
p.project = a
|
|
print >> sys.stderr, "PROJECT: %s" % a
|
|
if o in ("-l", "--language"):
|
|
p.language = a
|
|
print >> sys.stderr, "LANGUAGE: %s" % a
|
|
if o in ("-f", "--folder"):
|
|
p.html_folder = a
|
|
print >> sys.stderr, "FOLDER: %s" % a
|
|
|
|
p.initialize()
|
|
|
|
p.execute()
|
|
|
|
sys.exit(0)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|