def logToFileNow(folderName, fileNameBase, append=1): print 'start log to file now: folderName: %s, fileNameBase: %s, append: %s'% \ (folderName, fileNameBase, append) t = natqh.getClipboard() if t: utilsqh.createFolderIfNotExistent(folderName) try: if append: base, ext = os.path.split(fileNameBase) ext = ext or '.txt' name = os.path.join(folderName, base+ext) ## print 'open for append: %s'% name fout = open(name, 'a') else: name = findNewFile(folderName, fileNameBase) if name: fout = open(name, 'w') else: print 'cannot find valid logfile' return fout.write(t) fout.write('\n\n') fout.close() return name except IOError: print 'Grammar _editcomments: cannot log to file: %s:::%s'% (folderName, fileName) else: print 'nothing to log'
def getLogFileName(): """get name with date and time, record hour in logHour""" global logHour, logFile utilsqh.createFolderIfNotExistent(logFolder) lTime = time.localtime(time.time()) logFile = time.strftime("%Y-%m-%d %H%M", lTime) + '.txt' logHour = lTime[3] logFile = os.path.join(logFolder, logFile)
def gotResults_documentation(self,words,fullResults): oldPath = os.getcwd() uniGrammars = self.ini.getList('documentation', 'unimacro grammars') uniModules = self.ini.getList('documentation', 'unimacro modules') otherGrammars = self.ini.getList('documentation', 'other grammars') otherModules = self.ini.getList('documentation', 'other modules') base = natqh.getUnimacroUserDirectory() docPath = os.path.join(base, 'doc') pickleFile = os.path.join(docPath, '@unimacro.pickle') try: psock = open(pickleFile, 'r') memory = pickle.load(psock) psock.close() print '--------------------memory from pickle: %s'% pickleFile except: memory = {} print '--------------------no or invalid pickle file: %s'% pickleFile utilsqh.createFolderIfNotExistent(docPath) os.chdir(docPath) self.DisplayMessage('writing documentation to: %s'% docPath) pydoc.writedocs(base) self.DisplayMessage('checking unimacro grammars, modules and other grammars, modules') loadedGrammars = natlinkmain.loadedFiles.keys() if 'unimacro grammars' not in memory: memory['unimacro grammars'] = {} mem = memory['unimacro grammars'] for m in uniGrammars: if m in loadedGrammars: mem[m] = sys.modules[m].__doc__ else: if not m in mem: mem[m] = '' if 'unimacro modules' not in memory: memory['unimacro modules'] = {} mem = memory['unimacro modules'] for m in uniModules: if m in sys.modules: mem[m] = sys.modules[m].__doc__ else: try: M = __import__(m) except ImportError: print 'cannot import module: %s'% m continue mem[m] = M.__doc__ mem[m] = M.__doc__ del M print 'writing to pickle file: %s'% pickleFile psock = open(pickleFile, 'w') pickle.dump(memory, psock) psock.close() L = [] htmlFiles = filter(isHtmlFile, os.listdir(docPath)) categories = self.ini.get('documentation') if not categories: self.DisplayMessage('please fill in documentation categories') for c in categories: if not c in memory: continue L.append("<H1>%s</H1>"% c) mem = memory[c] for m in mem: file = m+'.html' if os.path.isfile(os.path.join(docPath, m+'.html')): link = "<a href=%s.html>%s</a>"% (m, m) htmlFiles.remove(file) else: link = "???%s"% m if mem[m] == None: text = 'no doc string for this module' elif mem[m] == '': text = 'module could not be loaded, possibly start program and do "Make documentation" again' else: text = mem[m] if text.find('\n\n'): T = text.split('\n\n') text = T[0] L.append("<p>%s: %s</p>"% (link, text)) if htmlFiles: M = [] L.append("<H1>%s</H1>"% "other files") for f in htmlFiles: if f == 'index.html': continue name = f.split('.')[0] link = "<a href=%s>%s</a>"% (f, name) M.append(link) L.append("<p>%s</p>"% ', '.join(M)) HTMLpage = '''<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Natlink grammars and modules documentations</title> <style type="text/css"><!-- TT { font-family: lucidatypewriter, lucida console, courier } --></style></head><body bgcolor="#f0f0f8"> %s </body></html>''' % '\n'.join(L) fsock = open(os.path.join(docPath, 'index.html'), 'w') fsock.write(HTMLpage) fsock.close() os.chdir(oldPath) self.DisplayMessage('okay')
'normal words': ( natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing ), # extra space(do one space): 'extra space': ( natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing | natqh.wf_AddAnExtraSpaceFollowingThisWord ), } version = natqh.getDNSVersion() user = natlink.getCurrentUser()[0] wordsFolder = os.path.split( sys.modules[__name__].__dict__['__file__'])[0] + \ '\\' + language + "_words" + \ '\\' + user utilsqh.createFolderIfNotExistent(wordsFolder) files = [os.path.splitext(f)[0] for f in os.listdir(wordsFolder)] ## print '_general, files in wordsFolder %s: %s'% (wordsFolder, files) if language == 'enx': nameList = {'Q. H.': 'QH', 'R. A.': 'RA', 'underscore': '', } elif language == 'nld': nameList = {'QH': 'QH', 'er aa': 'RA', 'underscore': '', } else: nameList = {}
def gotResults_documentation(self, words, fullResults): oldPath = os.getcwd() uniGrammars = self.ini.getList('documentation', 'unimacro grammars') uniModules = self.ini.getList('documentation', 'unimacro modules') otherGrammars = self.ini.getList('documentation', 'other grammars') otherModules = self.ini.getList('documentation', 'other modules') base = natqh.getUnimacroUserDirectory() docPath = os.path.join(base, 'doc') pickleFile = os.path.join(docPath, '@unimacro.pickle') try: psock = open(pickleFile, 'r') memory = pickle.load(psock) psock.close() print '--------------------memory from pickle: %s' % pickleFile except: memory = {} print '--------------------no or invalid pickle file: %s' % pickleFile utilsqh.createFolderIfNotExistent(docPath) os.chdir(docPath) self.DisplayMessage('writing documentation to: %s' % docPath) pydoc.writedocs(base) self.DisplayMessage( 'checking unimacro grammars, modules and other grammars, modules') loadedGrammars = natlinkmain.loadedFiles.keys() if 'unimacro grammars' not in memory: memory['unimacro grammars'] = {} mem = memory['unimacro grammars'] for m in uniGrammars: if m in loadedGrammars: mem[m] = sys.modules[m].__doc__ else: if not m in mem: mem[m] = '' if 'unimacro modules' not in memory: memory['unimacro modules'] = {} mem = memory['unimacro modules'] for m in uniModules: if m in sys.modules: mem[m] = sys.modules[m].__doc__ else: try: M = __import__(m) except ImportError: print 'cannot import module: %s' % m continue mem[m] = M.__doc__ mem[m] = M.__doc__ del M print 'writing to pickle file: %s' % pickleFile psock = open(pickleFile, 'w') pickle.dump(memory, psock) psock.close() L = [] htmlFiles = filter(isHtmlFile, os.listdir(docPath)) categories = self.ini.get('documentation') if not categories: self.DisplayMessage('please fill in documentation categories') for c in categories: if not c in memory: continue L.append("<H1>%s</H1>" % c) mem = memory[c] for m in mem: file = m + '.html' if os.path.isfile(os.path.join(docPath, m + '.html')): link = "<a href=%s.html>%s</a>" % (m, m) htmlFiles.remove(file) else: link = "???%s" % m if mem[m] == None: text = 'no doc string for this module' elif mem[m] == '': text = 'module could not be loaded, possibly start program and do "Make documentation" again' else: text = mem[m] if text.find('\n\n'): T = text.split('\n\n') text = T[0] L.append("<p>%s: %s</p>" % (link, text)) if htmlFiles: M = [] L.append("<H1>%s</H1>" % "other files") for f in htmlFiles: if f == 'index.html': continue name = f.split('.')[0] link = "<a href=%s>%s</a>" % (f, name) M.append(link) L.append("<p>%s</p>" % ', '.join(M)) HTMLpage = '''<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Natlink grammars and modules documentations</title> <style type="text/css"><!-- TT { font-family: lucidatypewriter, lucida console, courier } --></style></head><body bgcolor="#f0f0f8"> %s </body></html>''' % '\n'.join(L) fsock = open(os.path.join(docPath, 'index.html'), 'w') fsock.write(HTMLpage) fsock.close() os.chdir(oldPath) self.DisplayMessage('okay')
| natqh.wf_DoNotApplyFormattingToThisWord), # normal words: 'normal words': (natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing), # extra space(do one space): 'extra space': (natqh.wf_RestoreNormalCapitalization | natqh.wf_RestoreNormalSpacing | natqh.wf_AddAnExtraSpaceFollowingThisWord), } version = natqh.getDNSVersion() user = natlink.getCurrentUser()[0] wordsFolder = os.path.split( sys.modules[__name__].__dict__['__file__'])[0] + \ '\\' + language + "_words" + \ '\\' + user utilsqh.createFolderIfNotExistent(wordsFolder) files = [os.path.splitext(f)[0] for f in os.listdir(wordsFolder)] ## print '_general, files in wordsFolder %s: %s'% (wordsFolder, files) if language == 'enx': nameList = { 'Q. H.': 'QH', 'R. A.': 'RA', 'underscore': '', } elif language == 'nld': nameList = { 'QH': 'QH', 'er aa': 'RA', 'underscore': '', }