def createOutlineFromCacheList(self, parent_v, aList, fileName, top=True): """ Create outline structure from recursive aList built by makeCacheList. """ trace = False and not g.unitTesting c = self.c if not c: g.internalError('no c') if top: if trace: g.trace(g.shortFileName(fileName)) c.cacheListFileName = fileName if not aList: if trace: g.trace('no list') return h, b, gnx, children = aList if h is not None: v = parent_v v._headString = g.toUnicode(h) # 2017/01/16 v._bodyString = g.toUnicode(b) # 2017/01/16 for z in children: h, b, gnx, grandChildren = z isClone, child_v = self.fastAddLastChild(parent_v, gnx) if isClone: self.reportChangedClone(child_v, b, h, gnx) else: self.createOutlineFromCacheList( child_v, z, fileName, top=False)
def createOutlineFromCacheList(self, parent_v, aList, fileName, top=True): ''' Create outline structure from recursive aList built by makeCacheList. ''' trace = False and not g.unitTesting # and fileName.endswith('leoFileCommands.py') c = self.c if not c: g.internalError('no c') return if top: if trace: g.trace(g.shortFileName(fileName)) c.cacheListFileName = fileName if not aList: if trace: g.trace('no list') return h, b, gnx, children = aList if h is not None: v = parent_v # Does this destroy the ability to handle the rare case? v._headString = g.toUnicode(h) v._bodyString = g.toUnicode(b) for child_tuple in children: h, b, gnx, grandChildren = child_tuple if trace: g.trace('%30s %3s %s' % (gnx, len(grandChildren), h.strip())) isClone, child_v = self.fastAddLastChild(fileName, gnx, parent_v) if isClone: self.checkForChangedNodes(child_tuple, fileName, parent_v) else: self.createOutlineFromCacheList(child_v, child_tuple, fileName, top=False)
def createOutlineFromCacheList(self, parent_v, aList, fileName, top=True): ''' Create outline structure from recursive aList built by makeCacheList. ''' c = self.c if not c: g.internalError('no c') return if top: c.cacheListFileName = fileName if not aList: return h, b, gnx, children = aList if h is not None: v = parent_v # Does this destroy the ability to handle the rare case? v._headString = g.toUnicode(h) v._bodyString = g.toUnicode(b) for child_tuple in children: h, b, gnx, grandChildren = child_tuple isClone, child_v = self.fastAddLastChild(fileName, gnx, parent_v) if isClone: self.checkForChangedNodes(child_tuple, fileName, parent_v) else: self.createOutlineFromCacheList(child_v, child_tuple, fileName, top=False)
def createOutlineFromCacheList(self,parent_v,aList,fileName,top=True): """ Create outline structure from recursive aList built by makeCacheList.""" trace = False and not g.unitTesting verbose = False c = self.c if not c: g.internalError('no c') if top: if trace and verbose: g.trace(fileName) c.cacheListFileName = fileName h,b,gnx,children = aList if h is not None: v = parent_v v._headString = h v._bodyString = b for z in children: h,b,gnx,grandChildren = z isClone,child_v = self.fastAddLastChild(parent_v,gnx) if isClone: self.reportChangedClone(child_v,b,h,gnx) else: self.createOutlineFromCacheList( child_v,z,fileName,top=False)
def writeFile(self, p, fileKey): '''Update the cache after reading the file.''' # Check g.enableDB before giving internal error. if not g.enableDB: pass elif not fileKey: g.trace(g.callers(5)) g.internalError('empty fileKey') elif self.db.get(fileKey): pass else: self.db[fileKey] = self.makeCacheList(p)
def checkForChangedNodes(self, child_tuple, fileName, parent_v): ''' Update the outline described by child_tuple, including all descendants. ''' junk_h, junk_b, gnx, grand_children = child_tuple child_v = self.c.fileCommands.gnxDict.get(gnx) if child_v: self.reportIfNodeChanged(child_tuple, child_v, fileName, parent_v) for grand_child in grand_children: self.checkForChangedNodes(grand_child, fileName, child_v) elif not self.update_warning_given: self.update_warning_given = True g.internalError('no vnode', child_tuple)
def writeFile(self, p, fileKey): '''Update the cache after reading the file.''' trace = (False or g.app.debug) and not g.unitTesting # Check g.enableDB before giving internal error. if not g.enableDB: if trace: g.trace('cache disabled') elif not fileKey: g.trace(g.callers(5)) g.internalError('empty fileKey') elif self.db.get(fileKey): if trace: g.trace('already cached', fileKey) else: if trace: g.trace('caching ', p.h, fileKey) self.db[fileKey] = self.makeCacheList(p)
def writeFile(self,p,fileKey): trace = False and not g.unitTesting # Bug fix: 2010/05/26: check g.enableDB before giving internal error. if not g.enableDB: if trace: g.trace('cache disabled') elif not fileKey: g.trace(g.callers(5)) g.internalError('empty fileKey') elif self.db.get(fileKey): if trace: g.trace('already cached',fileKey) else: if trace: g.trace('caching ',p.h,fileKey) self.db[fileKey] = self.makeCacheList(p)
def setCachedStringPosition(self, str_pos): c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) self.db['current_position_%s' % key] = str_pos
def createMasterMenuCallback(self, dynamicMenu, command, commandName): # pylint: disable=no-else-return # This code is simpler as it is. c = self.c def setWidget(): w = c.frame.getFocus() if w and g.isMac: # 2012/01/11: redirect (MacOS only). wname = c.widget_name(w) if wname.startswith('head'): w = c.frame.tree.edit_widget(c.p) # 2015/05/14: return a wrapper if possible. if not g.isTextWrapper(w): w = getattr(w, 'wrapper', w) return w if dynamicMenu: if command: def masterDynamicMenuCallback(c=c, command=command): # 2012/01/07: set w here. w = setWidget() event = g.app.gui.create_key_event(c, w=w) return c.k.masterCommand(func=command, event=event) return masterDynamicMenuCallback else: g.internalError('no callback for dynamic menu item.') def dummyMasterMenuCallback(): pass return dummyMasterMenuCallback else: def masterStaticMenuCallback(c=c, commandName=commandName): # 2011/10/28: Use only the command name to dispatch the command. # 2012/01/07: Bug fix: set w here. w = setWidget() event = g.app.gui.create_key_event(c, w=w) return c.k.masterCommand(commandName=commandName, event=event) return masterStaticMenuCallback
def fileKey(self, s, content, requireEncodedString=False): ''' Compute the hash of s (usually a headline) and content. s may be unicode, content must be bytes (or plain string in Python 2.x) ''' ### Changed for reversion testing. ### This comment will be reverted in git to attempt to recreate the caching problem. m = hashlib.md5() if g.isUnicode(s): s = g.toEncodedString(s) if g.isUnicode(content): if requireEncodedString: g.internalError('content arg must be str/bytes') content = g.toEncodedString(content) m.update(s) m.update(content) return "fcache/" + m.hexdigest()
def setCachedStringPosition(self, str_pos): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) self.db['current_position_%s' % key] = str_pos if trace: g.trace(c.shortFileName(), str_pos)
def fileKey(self, s, content, requireEncodedString=False): ''' Compute the hash of s (usually a headline) and content. s may be unicode, content must be bytes (or plain string in Python 2.x) ''' trace = False and not g.unitTesting m = hashlib.md5() if g.isUnicode(s): s = g.toEncodedString(s) if g.isUnicode(content): if requireEncodedString: g.internalError('content arg must be str/bytes') content = g.toEncodedString(content) m.update(s) m.update(content) if trace: g.trace(m.hexdigest()) return "fcache/" + m.hexdigest()
def getCachedStringPosition(self): c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) str_pos = self.db.get('current_position_%s' % key) return str_pos
def getCachedWindowPositionDict(self, fn): '''Return a dict containing window positions.''' c = self.c if not c: g.internalError('no commander') return {} key = self.fileKey(c.mFileName, self.globals_tag) data = self.db.get('window_position_%s' % (key)) # pylint: disable=unpacking-non-sequence if data: top, left, height, width = data top, left, height, width = int(top), int(left), int(height), int( width) d = {'top': top, 'left': left, 'height': height, 'width': width} else: d = {} return d
def createMasterMenuCallback(self, dynamicMenu, command, commandName): trace = False and not g.unitTesting c = self.c def setWidget(): w = c.frame.getFocus() if w and sys.platform.startswith('darwin'): # 2012/01/11: redirect (MacOS only). wname = c.widget_name(w) if wname.startswith('head'): w = c.frame.tree.edit_widget(c.p) # 2015/05/14: return a wrapper if possible. if not g.isTextWrapper(w): w = getattr(w, 'wrapper', w) return w if dynamicMenu: if command: def masterDynamicMenuCallback(c=c, command=command): # 2012/01/07: set w here. w = setWidget() if trace: g.trace(command.__name__, w) event = g.app.gui.create_key_event(c, None, None, w) return c.k.masterCommand(func=command, event=event) return masterDynamicMenuCallback else: g.internalError('no callback for dynamic menu item.') def dummyMasterMenuCallback(): pass return dummyMasterMenuCallback else: def masterStaticMenuCallback(c=c, commandName=commandName): # 2011/10/28: Use only the command name to dispatch the command. # 2012/01/07: Bug fix: set w here. w = setWidget() if trace: g.trace(commandName, w, c) event = g.app.gui.create_key_event(c, None, None, w) return c.k.masterCommand(commandName=commandName, event=event) return masterStaticMenuCallback
def setCachedStringPosition(self, str_pos): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') globals_tag = 'leo3k.globals' if g.isPython3 else 'leo2k.globals' # globals_tag = g.toEncodedString(globals_tag,'ascii') key = self.fileKey(c.mFileName, globals_tag) self.db['current_position_%s' % key] = str_pos if trace: g.trace(str_pos, key)
def getCachedWindowPositionDict (self,fn): '''Return a dict containing window positions.''' trace = False and not g.unitTesting c = self.c if not c: g.internalError('no commander') return {} globals_tag = 'leo3k.globals' if g.isPython3 else 'leo2k.globals' key = self.fileKey(fn,globals_tag) data = self.db.get('window_position_%s' % (key)) # pylint: disable=unpacking-non-sequence if data: top,left,height,width = data top,left,height,width = int(top),int(left),int(height),int(width) d = {'top':top,'left':left,'height':height,'width':width} else: d = {} if trace: g.trace(fn,key,data) return d
def getCachedWindowPositionDict(self, fn): '''Return a dict containing window positions.''' trace = False and not g.unitTesting c = self.c if not c: g.internalError('no commander') return {} key = self.fileKey(c.mFileName, self.globals_tag) if trace: g.trace(self.db.__class__.__name__) data = self.db.get('window_position_%s' % (key)) # pylint: disable=unpacking-non-sequence if data: top, left, height, width = data top, left, height, width = int(top), int(left), int(height), int(width) d = {'top': top, 'left': left, 'height': height, 'width': width} else: d = {} if trace: g.trace(c.shortFileName(), key[-10:], d) return d
def getCachedWindowPositionDict(self, fn): '''Return a dict containing window positions.''' trace = False and not g.unitTesting c = self.c if not c: g.internalError('no commander') return {} globals_tag = 'leo3k.globals' if g.isPython3 else 'leo2k.globals' key = self.fileKey(fn, globals_tag) data = self.db.get('window_position_%s' % (key)) # pylint: disable=unpacking-non-sequence if data: top, left, height, width = data top, left, height, width = int(top), int(left), int(height), int(width) d = {'top': top, 'left': left, 'height': height, 'width': width} else: d = {} if trace: g.trace(fn, key, data) return d
def getCachedGlobalFileRatios(self): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) ratio = float(self.db.get('body_outline_ratio_%s' % (key), '0.5')) ratio2 = float(self.db.get('body_secondary_ratio_%s' % (key), '0.5')) if trace: g.trace(' %s %1.2f %1.2f' % (c.shortFileName(), ratio, ratio2)) return ratio, ratio2
def fileKey(self, fileName, content, requireEncodedString=False): ''' Compute the hash of fileName and content. fileName may be unicode, content must be bytes (or plain string in Python 2.x). ''' m = hashlib.md5() if g.isUnicode(fileName): fileName = g.toEncodedString(fileName) if g.isUnicode(content): if requireEncodedString: g.internalError('content arg must be str/bytes') content = g.toEncodedString(content) # New in Leo 5.6: Use the git branch name in the key. branch = g.gitBranchName() branch = g.toEncodedString(branch) # Fix #475. m.update(branch) m.update(fileName) m.update(content) return "fcache/" + m.hexdigest()
def setCachedGlobalsElement(self, fn): c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) self.db['body_outline_ratio_%s' % key] = str(c.frame.ratio) self.db['body_secondary_ratio_%s' % key] = str(c.frame.secondary_ratio) width, height, left, top = c.frame.get_window_info() self.db['window_position_%s' % key] = (str(top), str(left), str(height), str(width))
def getCachedGlobalFileRatios(self): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') globals_tag = 'leo3k.globals' if g.isPython3 else 'leo2k.globals' # globals_tag = g.toEncodedString(globals_tag,'ascii') key = self.fileKey(c.mFileName, globals_tag) ratio = float(self.db.get('body_outline_ratio_%s' % (key), '0.5')) ratio2 = float(self.db.get('body_secondary_ratio_%s' % (key), '0.5')) if trace: g.trace('key', key, '%1.2f %1.2f' % (ratio, ratio2)) return ratio, ratio2
def getCachedWindowPositionDict (self,fn): trace = False and not g.unitTesting c = self.c if not c: g.internalError('no commander') return {} globals_tag = g.choose(g.isPython3,'leo3k.globals','leo2k.globals') key = self.fileKey(fn,globals_tag) data = self.db.get('window_position_%s' % (key)) if data: top,left,height,width = data top,left,height,width = int(top),int(left),int(height),int(width) d = {'top':top,'left':left,'height':height,'width':width} else: d = {} if trace: g.trace(fn,key,data) return d
def fileKey(self, fileName, content, requireEncodedString=False): ''' Compute the hash of fileName and content. fileName may be unicode, content must be bytes (or plain string in Python 2.x). ''' trace = False and not g.unitTesting m = hashlib.md5() if g.isUnicode(fileName): fileName = g.toEncodedString(fileName) if g.isUnicode(content): if requireEncodedString: g.internalError('content arg must be str/bytes') content = g.toEncodedString(content) # New in Leo 5.6: Use the git branch name in the key. branch = g.gitBranchName() # g.trace(type(branch), repr(branch)) branch = g.toEncodedString(branch) # Fix #475. m.update(branch) m.update(fileName) m.update(content) if trace: g.trace(m.hexdigest()) return "fcache/" + m.hexdigest()
def getCachedGlobalFileRatios(self): c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) try: ratio = float(self.db.get('body_outline_ratio_%s' % (key), '0.5')) except TypeError: ratio = 0.5 try: ratio2 = float( self.db.get('body_secondary_ratio_%s' % (key), '0.5')) except TypeError: ratio2 = 0.5 return ratio, ratio2
def getCachedStringPosition(self): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') globals_tag = g.choose(g.isPython3,'leo3k.globals','leo2k.globals') # globals_tag = g.toEncodedString(globals_tag,'ascii') key = self.fileKey(c.mFileName,globals_tag) str_pos = self.db.get('current_position_%s' % key) if trace: g.trace(str_pos,key) return str_pos
def setCachedGlobalsElement(self, fn): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') key = self.fileKey(c.mFileName, self.globals_tag) self.db['body_outline_ratio_%s' % key] = str(c.frame.ratio) self.db['body_secondary_ratio_%s' % key] = str(c.frame.secondary_ratio) if trace: g.trace('ratios: %1.2f %1.2f' % ( c.frame.ratio, c.frame.secondary_ratio)) width, height, left, top = c.frame.get_window_info() self.db['window_position_%s' % key] = ( str(top), str(left), str(height), str(width)) if trace: g.trace(c.shortFileName(), 'top', top, 'left', left, 'height', height, 'width', width)
def setCachedGlobalsElement(self, fn): trace = False and not g.unitTesting c = self.c if not c: return g.internalError('no commander') globals_tag = 'leo3k.globals' if g.isPython3 else 'leo2k.globals' key = self.fileKey(fn, globals_tag) if trace: g.trace(c.mFileName, key, g.callers(5)) self.db['body_outline_ratio_%s' % key] = str(c.frame.ratio) self.db['body_secondary_ratio_%s' % key] = str(c.frame.secondary_ratio) if trace: g.trace('ratios: %1.2f %1.2f' % ( c.frame.ratio, c.frame.secondary_ratio)) width, height, left, top = c.frame.get_window_info() self.db['window_position_%s' % key] = ( str(top), str(left), str(height), str(width)) if trace: g.trace('top', top, 'left', left, 'height', height, 'width', width)