jobsfeed.rb #1

  • //
  • guest/
  • matt_attaway/
  • seymour/
  • main/
  • lib/
  • jobsfeed.rb
  • View
  • Commits
  • Open Download .zip Download (4 KB)
class JobsFeed < Feed
    
    require 'PP'

	def initialize( link, token=nil, regex=nil )
		super( link, token, "^Jobs:(.*)" )
	end

	def buildFeed( date )

		# setup Iconv to translate most everything to UTF8
		trans = Iconv.new('UTF-8//IGNORE', 'LATIN1' )
		
		@rss = RSS::Maker.make( version ) do |m|

			m.channel.title = title
			m.channel.link = link
			m.channel.description = description
			m.items.do_sort = true 
		end

		changes = $p4.run_jobs( "-e modifieddate>" + date + " " + match[1] )
		changes.each do |c|

			next if( !isValidJob?( c ) )

			i = RSS::Rss::Channel::Item.new( )
			i.title = c["Job"] + ": " + truncate_cleanly( trans.iconv(c["Description"]) )
			i.link = @link + c["Job"] + "?ac=111"
			i.date = Time.parse( c["ModifiedDate"] )

            i.description =  "<b>" + c["Status"] + " " + c["Subsystem"] + " " + c["Severity"] + " " + c["Type"] + " modified by " + c["ModifiedBy"] + "</b><p>" # + "<pre>" + c["Description"].gsub(/[\a\b\e]/, "") + "</pre>"
            
            # add some diffs
            begin
                pd = i.date - 30
                fd = i.date + 30
                
                fpd = pd.strftime("%Y/%m/%d:%H:%M:%S")
                ffd = fd.strftime("%Y/%m/%d:%H:%M:%S")
                
                diff = $p4.run_diff2( "//spec/job/" + c["Job"] + "@" + fpd, "//spec/job/" + c["Job"] + "@" + ffd )

                if( diff[0]["status"] == "content" )
                    # turn off tagged output
                    $p4.tagged = false
                    
                    # run diff
                    diff = $p4.run_diff2( "-dv", "//spec/job/" + c["Job"] + "@" + fpd, "//spec/job/" + c["Job"] + "@" + ffd )
                    
                    i.description += "<p><b>Diffs:</b>"
                    diff.shift
                    i.description += "<pre>" 
                    diff.each do |d|
                        trans.iconv(d).gsub(/[\a\b\e]/, "").each_line do |l|
                            if( l.start_with?( "#" ) )
                                next
                            end
                            i.description += l
                        end
                    end
                    i.description += "</pre>"
                    
                    # turn on tagged output
                    $p4.tagged = true
                else
                    i.description += "<pre>" + trans.iconv(c["Description"]).gsub(/[\a\b\e]/, "") + "</pre>"
                    
                    # add in the blog field
                    if( c["P4Blog"] && c["P4Blog"].length > 0 )
                        i.description += "<p><b>P4Blog:</b>"
                        i.description += "<pre>" + trans.iconv(c["P4Blog"]).gsub(/[\a\b\e]/, "") + "</pre>"
                    end
                    
                    # add in the callnumbers field
                    if( c["CallNumbers"] && c["CallNumbers"].length > 0 )
                         i.description += "<p><b>Call Numbers:</b>"
                         i.description += "<pre>" 
                    
                         c["CallNumbers"].gsub(/[\a\b\e]/, "").each_line("\n") {|l|
                             i.description += "<a href=http://calltrack.perforce.com/cgi-bin/detail?call=" + l + ">" + l + "</a>"
                         }
                    
                        i.description += "</pre>"
                    end
                    
                    # add in the customers field
                    if( c["Customers"] && c["Customers"].length > 0 )
                        i.description += "<p><b>Customers:</b>"
                        i.description += "<pre>" + trans.iconv(c["Customers"]).gsub(/[\a\b\e]/, "") + "</pre>"
                    end
                end
            rescue
                
            end
            
            

            
			@rss.items << i	
		end
	end


	def isValidJob?( job )
		result = false

		if( true )
			result = true
		end
			
		result
	end

	def title
		if( match != nil )
			"Jobs matching " + match[1]
		else
			@title
		end
	end

	def description
		if( match != nil )
			"Jobs matching " + match[1]
		else
			@description
		end
	end

end


begin
	
	$ids["Jobs:"] = JobsFeed.method( 'new' )
	
end
# Change User Description Committed
#1 14058 Matt Attaway Rename p4tter to Seymour so that I can actually find it