def findSuspiciousModules(self, folder, rootName): "Get all modul paths with non-Unix-like first line." firstLinePat = re.compile('^#!.*python.*') paths = [] for file in GlobDirectoryWalker(folder, '*.py'): if os.path.basename(file) == '__init__.py': continue firstLine = open_and_readlines(file)[0] if not firstLinePat.match(firstLine): paths.append(file) return paths
def parseAFMFile(afmFileName): """Quick and dirty - gives back a top-level dictionary with top-level items, and a 'widths' key containing a dictionary of glyph names and widths. Just enough needed for embedding. A better parser would accept options for what data you wwanted, and preserve the order.""" lines = open_and_readlines(afmFileName, 'r') if len(lines)<=1: #likely to be a MAC file if lines: lines = lines[0].split('\r') if len(lines)<=1: raise ValueError('AFM file %s hasn\'t enough data' % afmFileName) topLevel = {} glyphLevel = [] lines = [l.strip() for l in lines] lines = [l for l in lines if not l.lower().startswith('comment')] #pass 1 - get the widths inMetrics = 0 # os 'TOP', or 'CHARMETRICS' for line in lines: if line[0:16] == 'StartCharMetrics': inMetrics = 1 elif line[0:14] == 'EndCharMetrics': inMetrics = 0 elif inMetrics: chunks = line.split(';') chunks = [chunk.strip() for chunk in chunks] cidChunk, widthChunk, nameChunk = chunks[0:3] # character ID l, r = cidChunk.split() assert l == 'C', 'bad line in font file %s' % line cid = int(r) # width l, r = widthChunk.split() assert l == 'WX', 'bad line in font file %s' % line width = int(r) # name l, r = nameChunk.split() assert l == 'N', 'bad line in font file %s' % line name = r glyphLevel.append((cid, width, name)) # pass 2 font info inHeader = 0 for line in lines: if line[0:16] == 'StartFontMetrics': inHeader = 1 if line[0:16] == 'StartCharMetrics': inHeader = 0 elif inHeader: if line[0:7] == 'Comment': pass try: left, right = line.split(' ',1) except: raise ValueError("Header information error in afm %s: line='%s'" % (afmFileName, line)) try: right = int(right) except: pass topLevel[left] = right return (topLevel, glyphLevel)