Changeset 7e639860f58c8c25ebe5ce1b714a54a6d668112a


Ignore:
Timestamp:
30.07.2013 02:50:28 (7 years ago)
Author:
Stanislaw Klekot <dozzie@…>
Branches:
b66903eafbcb1d49112014abc82c8bf683413db0
Children:
a87b728b31cead3ea82bed5a282b3b730df56491
Parents:
ea93e3cf09ad21475511b78b6daa2e16669788c2
git-author:
Stanislaw Klekot <dozzie@…> (30.07.2013 02:49:26)
git-committer:
Stanislaw Klekot <dozzie@…> (30.07.2013 02:50:28)
Message:

First stab at actually using remote objects cache.

Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • dashwiki/macros/models.py

    r65833c r7e6398  
    3333    from dashwiki.plugins import load_plugin 
    3434    plugin_instance = load_plugin(self) 
    35     result = plugin_instance.call(args) 
     35 
     36    from django.conf import settings 
     37    from django.core.urlresolvers import reverse 
     38    from dashwiki.resource_cache import ResourceCache 
     39    cache = ResourceCache( 
     40      settings.DASHWIKI_CACHE_ROOT, 
     41      reverse('cached_files'), 
     42    ) 
     43 
     44    result = plugin_instance.call(args, cache) 
    3645    return result 
    3746 
  • dashwiki/plugins/FlatFile.py

    rbc6a4f r7e6398  
    66 
    77class FlatFile(ProtocolPlugin): 
    8   def call(self, args): 
     8  def call(self, args, cache): 
    99    # args: [...] 
    1010    self.set_args(args) 
  • dashwiki/plugins/HTTP.py

    r3c1e8b r7e6398  
    55import os 
    66 
     7from dashwiki.logging import getLogger, message as log 
     8 
     9logger = getLogger(__name__) 
     10 
    711#----------------------------------------------------------------------------- 
    812 
    913class HTTP(ProtocolPlugin): 
    10   def call(self, args): 
     14  @staticmethod 
     15  def fetch(url, filename): 
     16    logger.info(log( 
     17      'fetching file', 
     18      url = url, 
     19      filename = filename, 
     20    )) 
     21    urlfetcher = urllib.URLopener() 
     22    urlfetcher.retrieve(url, filename) 
     23 
     24  def call(self, args, cache): 
    1125    # args: [...] 
    1226    self.set_args(args) 
    1327 
    14     # TODO: remove when DashWiki serves images by itself (a cache) 
    15     if self.result_type == 'graph': 
    16       return self.make_image() 
    17  
    18     urlfetcher = urllib.URLopener() 
    19     (tempfilename, headers) = urlfetcher.retrieve(self.url) 
    20     data = open(tempfilename).read() 
    21     os.unlink(tempfilename) 
     28    # FIXME: how to choose filename? 
     29    filename = 'foo' 
    2230 
    2331    if self.result_type == 'list': 
     32      data = cache.get(filename, lambda(g): HTTP.fetch(self.url, g.path())) 
    2433      return data.split('\n') 
    2534    elif self.result_type == 'graph': 
    26       return self.make_image() 
     35      url = cache.get_url(filename, lambda(g): HTTP.fetch(self.url, g.path())) 
     36      return { 
     37        'image': { 'image_target': url } 
     38      } 
    2739    else: 
     40      data = cache.get(filename, lambda(g): HTTP.fetch(self.url, g.path())) 
    2841      return data 
    2942 
  • dashwiki/plugins/XMLRPC.py

    rf9e4bb r7e6398  
    77 
    88class XMLRPC(ProtocolPlugin): 
    9   def call(self, args): 
     9  def call(self, args, cache): 
    1010    # args: [...] 
    1111    self.set_args(args) 
  • dashwiki/settings.py

    rb2817c r7e6398  
    6060# Example: "/home/media/media.lawrence.com/" 
    6161MEDIA_ROOT = '%s/static' % (app_root_dir) 
     62 
     63# Absolute path to the directory that holds media. 
     64# Example: "/home/media/media.lawrence.com/" 
     65DASHWIKI_CACHE_ROOT = '%s/cache' % (app_root_dir) 
    6266 
    6367# URL that handles the media served from MEDIA_ROOT. Make sure to use a 
  • dashwiki/urls.py

    r8298e0 r7e6398  
    3131    name = "static_files" 
    3232  ), 
     33  url( 
     34    r'^cache/(?P<path>.+)?$', 
     35    'django.views.static.serve', { 'document_root': settings.DASHWIKI_CACHE_ROOT }, 
     36    name = "cached_files" 
     37  ), 
    3338) 
    3439 
     
    3843 
    3944#----------------------------------------------------------------------------- 
    40 # vim:ft=python:foldmethod=marker 
     45# vim:ft=python:nowrap:foldmethod=marker 
Note: See TracChangeset for help on using the changeset viewer.