Changeset 65

Show
Ignore:
Timestamp:
12/19/05 22:15:48 (3 years ago)
Author:
tim
Message:

fixed problem with acquire causing its target to be resaved on the context

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/timcommithook/pyramid/flatteners.py

    r62 r65  
    9696        parentdata = getParentData(self,ctx,dir,name) 
    9797        # Add the template data (locals,globals and template) to self.original 
    98         getFragmentData(self,ctx,dir,name,parentdata) 
     98        data = getFragmentData(self,ctx,dir,name,parentdata) 
    9999        # inherit data from parent and merge the result with any 'local' data 
    100         data = inheritAndMergeLocals(self,ctx,dir,name,parentdata).get(key,{}) 
     100        data = inheritAndMergeLocals(self,ctx,dir,None,data,parentdata).get(key,{}) 
    101101        return flatten(data, ctx, dir) 
    102102 
     
    130130 
    131131        # Add the template data (locals,globals and template) to self.original 
    132         getFragmentData(self,ctx,dir,name,parentdata) 
     132        data = getFragmentData(self,ctx,dir,name,parentdata) 
     133        file = self.original.file 
     134        self.original = data 
     135        self.original.file = file 
    133136 
    134137        # inherit data from parent and merge the result with any 'local' data 
    135         mergedData = inheritAndMergeLocals(self,ctx,dir,name,parentdata) 
     138        mergedData = inheritAndMergeLocals(self,ctx,dir,name,data,parentdata) 
    136139 
    137140        # Flatten the resultant data ready for use in the template 
     
    165168 
    166169            # inherit data from parent and merge the result with any 'local' data 
    167             mergedData = inheritAndMergeLocals(self,ctx,dir,name,parentdata) 
     170            mergedData = inheritAndMergeLocals(self,ctx,dir,name,data,parentdata) 
    168171     
    169172            # Flatten the resultant data ready for use in the template 
     
    183186    # must have come from the cache so return it 
    184187    if ctx.data.get(ctx.path,{}).has_key(name): 
    185         self.original = copy.deepcopy(ctx.data[ctx.path][name]) 
     188        return copy.deepcopy(ctx.data[ctx.path][name]) 
    186189    else: 
    187190        try: 
    188191            yaml = file(os.path.join(dir,name)).read() 
    189             selffile = self.original.file 
    190             self.original = syck.load(yaml,Loader=Y.Loader, implicit_typing=False) 
    191             self.original.file = selffile 
     192            return syck.load(yaml,Loader=Y.Loader, implicit_typing=False) 
    192193        except: 
    193194            # if the file can't be read. fall back to the parent data 
    194             self.original = copy.deepcopy(parentdata) 
     195            return copy.deepcopy(parentdata) 
    195196 
    196197def getParentData(self,ctx,dir,name): 
     
    202203    return parentdata 
    203204 
    204 def inheritAndMergeLocals(self,ctx,dir,name,parentdata): 
     205def inheritAndMergeLocals(self,ctx,dir,name,data,parentdata): 
    205206    ''' store a copy of the data (merged with it's parentdata) on the context and then merge it with the current local data 
    206207    ''' 
    207208    # for clarity/terseness define a few varibales 
    208     globals =  self.original.globals 
    209     locals = self.original.locals 
     209    globals =  data.globals 
     210    locals = data.locals 
    210211 
    211212    if ctx.verbose: 
    212         logFragmentData(path(self.original.template),parentdata, globals, locals) 
     213        logFragmentData(path(data.template),parentdata, globals, locals) 
    213214 
    214215    # store it on the context 
     
    216217    # Also assigning the locals with the current local data 
    217218    node = Y.fragment( { 
    218         'template':self.original.template, 
    219         'global':dictutils.merge(parentdata.globals.copy(),globals,dir=path(dir).normpath(),partialbuild=ctx.partialbuild), 
    220         'local':locals
    221         'file':self.original.file 
     219        'template':data.template, 
     220        'global':dictutils.merge(parentdata.globals.copy(),globals.copy(),dir=path(dir).normpath(),partialbuild=ctx.partialbuild), 
     221        'local':locals.copy()
     222        'file':data.file 
    222223        } ) 
    223224    # set this fragment on the context with a key of the yaml file name 
    224     if not ctx.partialbuild
     225    if not ctx.partialbuild and name is not None
    225226        ctx.data.setdefault(str(ctx.path),{})[name] = node 
    226227    # merge the parentdata and globals and render the item 
    227228    globals = node.globals 
    228229 
    229     data = dictutils.merge(node.globals.copy(),locals,partialbuild=ctx.partialbuild) 
     230    data = dictutils.merge(node.globals.copy(),locals.copy(),partialbuild=ctx.partialbuild) 
    230231    return data 
    231232