Example #1
0
 def check_for_update (self) :
     update = False
     if self.parameter_file :
         p_m_time = os.stat (self.parameter_file.name) [stat.ST_MTIME]
         update   = p_m_time != self.p_m_time
     t_m_time = os.stat (self.template.name) [stat.ST_MTIME]
     update   = update or (t_m_time != self.t_m_time)
     if update :
         self.create_css_file ()
Example #2
0
 def check_for_update(self):
     update = False
     if self.parameter_file:
         p_m_time = os.stat(self.parameter_file.name)[stat.ST_MTIME]
         update = p_m_time != self.p_m_time
     t_m_time = os.stat(self.template.name)[stat.ST_MTIME]
     update = update or (t_m_time != self.t_m_time)
     if update:
         self.create_css_file()
Example #3
0
 def create_css_file(self, overrides={}):
     try:
         self.pdict = {}  ### lets clear it again before we read everything
         self._update_dependencies()
         filename = self.template.name
         ct = open(filename).read()
         if self.polling:
             self.t_m_time = os.stat(filename)[stat.ST_MTIME]
         ct, _ = self.fix_percent_pat.subn \
             (lambda m : "%%%s" % (m.group (0), ), ct)
         outf = open(self.css_file.name, "wb")
         outf.write(ct % Scope(globs=self.pdict, locls=overrides))
         outf.close()
         print \
             ( "[%04d] CSS file created `%s`"
             % (self.count, self.css_file.name, )
             )
         self.count += 1
     except:
         traceback.print_exc()
Example #4
0
 def _update_dependencies(self, filename=None):
     if filename is None:
         filename = self.parameter_file.name
     self.parameter_files[os.path.abspath(filename)].add(self)
     new_dir = TFL.Filename(filename).directory
     if new_dir:
         old_dir = os.getcwd()
         os.chdir(new_dir)
     if self.polling:
         self.p_m_time = os.stat(filename)[stat.ST_MTIME]
     execfile \
          ( filename
          , dict
              ( R       = TFL.Record
              , include = self._update_dependencies
              )
          , self.pdict
          )
     if new_dir:
         os.chdir(old_dir)
Example #5
0
 def create_css_file (self, overrides = {}) :
     try :
         self.pdict = {} ### lets clear it again before we read everything
         self._update_dependencies ()
         filename   = self.template.name
         ct    = open         (filename).read ()
         if self.polling :
             self.t_m_time = os.stat (filename) [stat.ST_MTIME]
         ct, _ = self.fix_percent_pat.subn \
             (lambda m : "%%%s" % (m.group (0), ), ct)
         outf  = open  (self.css_file.name, "wb")
         outf.write    (ct % Scope (globs = self.pdict, locls = overrides))
         outf.close    ()
         print \
             ( "[%04d] CSS file created `%s`"
             % (self.count, self.css_file.name, )
             )
         self.count += 1
     except :
         traceback.print_exc ()
Example #6
0
 def _update_dependencies (self, filename = None) :
     if filename is None :
         filename = self.parameter_file.name
     self.parameter_files [os.path.abspath (filename)].add (self)
     new_dir = TFL.Filename (filename).directory
     if new_dir :
         old_dir = os.getcwd ()
         os.chdir (new_dir)
     if self.polling :
         self.p_m_time = os.stat (filename) [stat.ST_MTIME]
     execfile \
          ( filename
          , dict
              ( R       = TFL.Record
              , include = self._update_dependencies
              )
          , self.pdict
          )
     if new_dir :
         os.chdir (old_dir)
Example #7
0
 def file_entry(self, gallery, obj):
     path = self.abs_path(obj)
     mime_type = self.mime_type(obj, path)
     stat = os.stat(path)
     result    = dict \
         ( mime      = mime_type
         , ts        = stat.st_mtime
         , hash      = "%s_%s_%s" % (self.hash, gallery.pid, obj.pid)
         , phash     = "%s_%s"    % (self.hash, gallery.pid)
         , read      = self.allow_read
         , write     = self.allow_write
         , size      = stat.st_size
         , name      = obj.name
         , date      = datetime.datetime.fromtimestamp
             (stat.st_mtime).strftime ("%c")
         , dim       = "%dx%d" % (obj.photo.width, obj.photo.height)
         )
     if self.media_domain:
         result["url"] = "%s/%s" % (self.media_domain, obj.photo.path)
         result["tmb"] = "%s/%s" % (self.media_domain, obj.thumb.path)
     return result
Example #8
0
 def file_entry (self, gallery, obj) :
     path      = self.abs_path   (obj)
     mime_type = self.mime_type  (obj, path)
     stat      = os.stat         (path)
     result    = dict \
         ( mime      = mime_type
         , ts        = stat.st_mtime
         , hash      = "%s_%s_%s" % (self.hash, gallery.pid, obj.pid)
         , phash     = "%s_%s"    % (self.hash, gallery.pid)
         , read      = self.allow_read
         , write     = self.allow_write
         , size      = stat.st_size
         , name      = obj.name
         , date      = datetime.datetime.fromtimestamp
             (stat.st_mtime).strftime ("%c")
         , dim       = "%dx%d" % (obj.photo.width, obj.photo.height)
         )
     if self.media_domain :
         result ["url"] = "%s/%s" % (self.media_domain, obj.photo.path)
         result ["tmb"] = "%s/%s" % (self.media_domain, obj.thumb.path)
     return result