def fast_search_file(name): res = pykpathsea.find_file(san(name)) if res is None or not os.path.isfile(res): cache_db[name] = "none" return -1 else: cache_db[name] = res return 0
def openers(self, filename, names, extensions, mode): if not has_pykpathsea: return [] for name in names: full_filename = pykpathsea_module.find_file(filename, name) if full_filename: break else: return [] def _opener(): try: return builtinopen(full_filename, mode) except IOError: warnings.warn("'%s' should be available at '%s' according to libkpathsea, " "but the file is not available at this location; " "update your kpsewhich database" % (filename, full_filename)) return [_opener]
def openers(self, filename, names, extensions): if not has_pykpathsea: return [] for name in names: full_filename = pykpathsea_module.find_file(filename, name) if full_filename: break else: return [] def _opener(): try: return builtinopen(full_filename, "rb") except IOError: logger.warning("'%s' should be available at '%s' according to libkpathsea, " "but the file is not available at this location; " "update your kpsewhich database" % (filename, full_filename)) return [_opener]
def fetch_file(filename): if filename.endswith(".fmt"): #Dont do kpathsea search if os.path.exists(filename): return send_file(filename) else: return "Format File not found", 301 if filename in cache_hit_db: urls = cache_hit_db[filename] return send_file(urls) if filename in file_miss_db: return "File not found", 301 res = pykpathsea.find_file(san(filename)) if res is None or not os.path.isfile(res): if len(file_miss_db) > 102400: file_miss_db.clear() file_miss_db[filename] = 1; return "File not found", 301 else: cache_hit_db[filename] = res return send_file(res)
def __init__(self, x, y, filename, width=None, height=None, scale=None, align="bl", clip=1, translatebbox=1, bbox=None, kpsearch=0): """inserts epsfile Object for an EPS file named filename at position (x,y). Width, height, scale and aligment can be adjusted by the corresponding parameters. If clip is set, the result gets clipped to the bbox of the EPS file. If translatebbox is not set, the EPS graphics is not translated to the corresponding origin. If bbox is not None, it overrides the bounding box in the epsfile itself. If kpsearch is set then filename is searched using the kpathsea library. """ self.x_pt = unit.topt(x) self.y_pt = unit.topt(y) if kpsearch: self.filename = pykpathsea.find_file(filename, pykpathsea.kpse_pict_format) else: self.filename = filename self.mybbox = bbox or _readbbox(self.filename) # determine scaling in x and y direction self.scalex = self.scaley = scale if width is not None or height is not None: if scale is not None: raise ValueError( "cannot set both width and/or height and scale simultaneously" ) if height is not None: self.scaley = unit.topt(height) / (self.mybbox.ury_pt - self.mybbox.lly_pt) if width is not None: self.scalex = unit.topt(width) / (self.mybbox.urx_pt - self.mybbox.llx_pt) if self.scalex is None: self.scalex = self.scaley if self.scaley is None: self.scaley = self.scalex # set the actual width and height of the eps file (after a # possible scaling) self.width_pt = self.mybbox.urx_pt - self.mybbox.llx_pt if self.scalex: self.width_pt *= self.scalex self.height_pt = self.mybbox.ury_pt - self.mybbox.lly_pt if self.scaley: self.height_pt *= self.scaley # take alignment into account self.align = align if self.align[0] == "b": pass elif self.align[0] == "c": self.y_pt -= self.height_pt / 2.0 elif self.align[0] == "t": self.y_pt -= self.height_pt else: raise ValueError( "vertical alignment can only be b (bottom), c (center), or t (top)" ) if self.align[1] == "l": pass elif self.align[1] == "c": self.x_pt -= self.width_pt / 2.0 elif self.align[1] == "r": self.x_pt -= self.width_pt else: raise ValueError( "horizontal alignment can only be l (left), c (center), or r (right)" ) self.clip = clip self.translatebbox = translatebbox self.trafo = trafo.translate_pt(self.x_pt, self.y_pt) if self.scalex is not None: self.trafo = self.trafo * trafo.scale_pt(self.scalex, self.scaley) if translatebbox: self.trafo = self.trafo * trafo.translate_pt( -self.mybbox.llx_pt, -self.mybbox.lly_pt)
import pykpathsea print(pykpathsea.find_file("tcrm0700.600pk"))
def __init__(self, x, y, filename, width=None, height=None, scale=None, align="bl", clip=1, translatebbox=1, bbox=None, kpsearch=0): """inserts epsfile Object for an EPS file named filename at position (x,y). Width, height, scale and aligment can be adjusted by the corresponding parameters. If clip is set, the result gets clipped to the bbox of the EPS file. If translatebbox is not set, the EPS graphics is not translated to the corresponding origin. If bbox is not None, it overrides the bounding box in the epsfile itself. If kpsearch is set then filename is searched using the kpathsea library. """ self.x_pt = unit.topt(x) self.y_pt = unit.topt(y) if kpsearch: self.filename = pykpathsea.find_file(filename, pykpathsea.kpse_pict_format) else: self.filename = filename self.mybbox = bbox or _readbbox(self.filename) # determine scaling in x and y direction self.scalex = self.scaley = scale if width is not None or height is not None: if scale is not None: raise ValueError("cannot set both width and/or height and scale simultaneously") if height is not None: self.scaley = unit.topt(height)/(self.mybbox.ury_pt-self.mybbox.lly_pt) if width is not None: self.scalex = unit.topt(width)/(self.mybbox.urx_pt-self.mybbox.llx_pt) if self.scalex is None: self.scalex = self.scaley if self.scaley is None: self.scaley = self.scalex # set the actual width and height of the eps file (after a # possible scaling) self.width_pt = self.mybbox.urx_pt-self.mybbox.llx_pt if self.scalex: self.width_pt *= self.scalex self.height_pt = self.mybbox.ury_pt-self.mybbox.lly_pt if self.scaley: self.height_pt *= self.scaley # take alignment into account self.align = align if self.align[0]=="b": pass elif self.align[0]=="c": self.y_pt -= self.height_pt/2.0 elif self.align[0]=="t": self.y_pt -= self.height_pt else: raise ValueError("vertical alignment can only be b (bottom), c (center), or t (top)") if self.align[1]=="l": pass elif self.align[1]=="c": self.x_pt -= self.width_pt/2.0 elif self.align[1]=="r": self.x_pt -= self.width_pt else: raise ValueError("horizontal alignment can only be l (left), c (center), or r (right)") self.clip = clip self.translatebbox = translatebbox self.trafo = trafo.translate_pt(self.x_pt, self.y_pt) if self.scalex is not None: self.trafo = self.trafo * trafo.scale_pt(self.scalex, self.scaley) if translatebbox: self.trafo = self.trafo * trafo.translate_pt(-self.mybbox.llx_pt, -self.mybbox.lly_pt)