All pastes #157089 Raw Edit

tuxplorer

public text v1 · immutable
·published 2006-09-01 08:14 UTC
rendered paste body
def find_node(node,name)
        if node.find_first(name)
                return node
        else
                if node.child?
                        child_node = node.child
#                       new_node = find_node(child_node,name)
                        begin
                                return find_node(child_node,name)
                                if child_node.next?
                                child_node=child_node.next
                                end
                        end while child_node.next?
                end
        end
end

def patch_scriptlet(desc_file,scriptlet_file)
        puts "Patching the file #{desc_file} with #{scriptlet_file}"
        xmldesc = XML::Document.file(desc_file)
        xmlscript = XML::Document.file(scriptlet_file)
        scriptroot = xmlscript.root
        descroot = xmldesc.root
        if scriptroot.child?
        if_nodeset = scriptroot.find('if')
        puts if_nodeset.length
        if_nodeset.each do |node_item|
                if node_item['distro'].chomp==Pkgvars.get_distro.chomp && node_item['version']==nil || node_item['distro'].chomp==Pkgvars.get_distro.chomp && node_item['version']==Pkgvars.get_version || node_item['distro'].chomp==nil && node_item['version']==Pkgvars.get_version
                        if node_item.child?
                        child_node = node_item.child
                        begin
                                parent_node = find_node(descroot,child_node.name)
                                if(parent_node!=nil)
                                puts parent_node.name
                                parent_node << child_node
                                end
                                if child_node.next?
                                child_node=child_node.next
                                end
                        end while child_node.next?
                        end
                end
        end
        end
        puts "writing to file"
        format = true
        xmldesc.save("#{get_homedir}/.apbd/patched.xml", format)
end