def __init__ (self, directory, error_cb = None, scope = None) : self.directory = directory self.error_cb = error_cb if not sos.path.exists (directory) : sos.mkdir_p (directory) elif not sos.path.isdir (directory) : raise ValueError ("Path %r is not a directory" % (directory, )) if scope is not None : scope.add_after_commit_callback (self)
def __init__(self, directory, error_cb=None, scope=None): self.directory = directory self.error_cb = error_cb if not sos.path.exists(directory): sos.mkdir_p(directory) elif not sos.path.isdir(directory): raise ValueError("Path %r is not a directory" % (directory, )) if scope is not None: scope.add_after_commit_callback(self)
def _open_stub (self, doc_base, pns, name) : dir = doc_base if pns is not None : dir = sos.path.join (dir, * pns.__name__.split (".")) if not sos.path.isdir (dir) : if sos.path.exists (dir) : raise IOError ("Path %s exists but isn't a directory" % dir) sos.mkdir_p (dir) with open (sos.path.join (dir, name + ".rst"), "wb") as f: yield f
def _generate (cao, p, root, tail = None) : name = pjoin (root, tail or p.href_static.lstrip ("/")) dir = sos.path.dirname (name) if not sos.path.exists (dir) : sos.mkdir_p (dir) if cao.verbose : print (name, "...", end = " ") asp = p.as_static_page () if asp is not None : with open (name, "wb") as f : f.write (pyk.encoded (asp)) if cao.verbose : print ("done")
def _create_cache (self, name, map, minifier = None) : media_dir = self.media_dir if not sos.path.isdir (media_dir) : sos.mkdir_p (media_dir) else : for f in sos.listdir_ext (media_dir, name.lower ()) : sos.remove (f) for k, (href, fn, attr) in pyk.iteritems (map) : with open (fn, "wb") as file : if minifier is not None : attr = minifier (attr) file.write (attr) if self.verbose : print ("Wrote template media cache file", fn)
def _main (cmd) : font = ImageFont.load_default () color = cmd.color fmt = cmd.format ext = fmt.lower () if ext == "jpeg" : ext = "jpg" holder = cmd.photographer x_off = cmd.x_off y_off = cmd.y_off year = cmd.year i_size = cmd.i_size, cmd.i_size t_size = cmd.t_size, cmd.t_size td = sos.expanded_path (cmd.target_dir) with TFL.temp_dir () as temp_dir : if cmd.add_to_dir : if not sos.path.isdir (td) : print ("Making directory %s" % (td, )) sos.mkdir_p (td) for src in cmd.argv [1:] : src, name = src.split ("=") if not name : name = src name = Filename (name).base imp = sos.path.join (td, "%s_im.%s" % (name, ext)) thp = sos.path.join (td, "%s_th.%s" % (name, ext)) convert_one \ ( src, name, i_size, t_size, holder, year, font, imp, thp , fmt, color, x_off, y_off , temp_dir ) else : td_im = sos.path.join (td, "im") td_th = sos.path.join (td, "th") for x in td_im, td_th : if not sos.path.isdir (x) : print ("Making directory %s" % (x, )) sos.mkdir_p (x) pid = cmd.start_pid for src in sorted (sos.expanded_globs (* cmd.argv [1:])) : pid += 1 name = "%04d.%s" % (pid, ext) imp = sos.path.join (td_im, name) thp = sos.path.join (td_th, name) convert_one \ ( src, name, i_size, t_size, holder, year, font, imp, thp , fmt, color, x_off, y_off , temp_dir )
def __call__(self, scope, change_summary): if change_summary: directory = self.directory + datetime.datetime.now ().strftime \ ("/%Y/%m/%d/") try: if not sos.path.exists(directory): sos.mkdir_p(directory) elif not sos.path.isdir(directory): raise ValueError \ ("Path %r is not a directory" % (directory, )) max_cid = scope.max_cid fn = TFL.Filename \ ("%08d" % (max_cid, ), default_dir = directory) cargo = change_summary.as_json_cargo TFL.json_dump.to_file(cargo, fn.name, indent=2) except Exception as exc: error_cb = self.error_cb if error_cb is not None: error_cb(self, scope, change_summary, exc) else: logging.exception \ ("Exception during change journal callback")
def __call__ (self, scope, change_summary) : if change_summary : directory = self.directory + datetime.datetime.now ().strftime \ ("/%Y/%m/%d/") try : if not sos.path.exists (directory) : sos.mkdir_p (directory) elif not sos.path.isdir (directory) : raise ValueError \ ("Path %r is not a directory" % (directory, )) max_cid = scope.max_cid fn = TFL.Filename \ ("%08d" % (max_cid, ), default_dir = directory) cargo = change_summary.as_json_cargo TFL.json_dump.to_file (cargo, fn.name, indent = 2) except Exception as exc : error_cb = self.error_cb if error_cb is not None : error_cb (self, scope, change_summary, exc) else : logging.exception \ ("Exception during change journal callback")