- Timestamp:
- 01/24/11 17:59:27 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sara_cmt/sara_cmt/cluster/templatetags/ramonb_extras.py
r12427 r12429 1 import os 2 import re 1 import os, re, string 3 2 4 3 # Inspired by Django tips on: … … 51 50 52 51 52 @stringfilter 53 def base_net(value): 54 ip_blocks = value.split('.') 55 56 return string.join( ip_blocks[:3], '.' ) 57 58 register.filter( 'base_net', base_net ) 59 60 @stringfilter 61 def ip_last_digit(value): 62 ip_blocks = value.split('.') 63 64 return ip_blocks[3] 65 66 register.filter( 'ip_last_digit', ip_last_digit ) 67 53 68 @register.tag(name='store') 54 69 #@stringfilter … … 56 71 """ 57 72 Compilation function to use for meta-info. 58 """ 59 # RB: {% store '/path/to/file' %} 60 # RB: {% store variable %} # variable = '/path/to/string' 73 74 Usage: {% store '/path/to/file' %} 75 {% store variable %} # variable = '/path/to/file' 76 """ 61 77 try: 62 78 # RB: split_contents respects quoted 'strings containing spaces' … … 76 92 path_str = '' 77 93 else: 94 # RB: remove the quotes 78 95 path_str = path_str[1:-1] 79 96 … … 82 99 parser.delete_first_token() 83 100 84 return WriteRamonCrap(tag, path, path_str, nodelist) 85 86 class WriteRamonCrap(template.Node): 101 # RB: Now lets start writing output files 102 return WriteFiles(tag, path, path_str, nodelist) 103 104 class WriteFiles(template.Node): 87 105 88 106 def __init__(self, tag, path, path_str, nodelist): … … 97 115 self.path_str = self.path.resolve(context) 98 116 except template.VariableDoesNotExist: 99 raise template.TemplateSyntaxError, '%r tag argument 1: cannot resolve variable %r' %( self.tag, s elf.path_str)117 raise template.TemplateSyntaxError, '%r tag argument 1: cannot resolve variable %r' %( self.tag, str( self.path ) ) 100 118 101 119 output = self.nodelist.render(context) … … 106 124 my_fp.close() 107 125 126 context['stored'] = True 127 108 128 # RB: we wrote output to file so we return nothing 109 129 return '' 110 # RB: wes done bitches cyyaa111 130 112 131 class ScriptNode(template.Node):
Note: See TracChangeset
for help on using the changeset viewer.