#!/usr/bin/env ruby # -*- coding: utf-8 -*- # # Triggers: # CreateThumbnails change-commit ... "%//triggers/CreateThumbnails.rb% # %serverport% %change%" # # Description: # Goes through the changelist looking for files that can be given a # thumbnail. Creates the PNG thumbnails using imagemagick, then sends # the thumbnail to the server as a hex string. # SET THESE OR TRIGGER WILL NOT WORK # I don't know if I need all these, or if this is even how you intended for it # to be done. p4bin = '/usr/local/bin/p4' convertbin = '/usr/local/bin/convert' user = 'jbrower' client = 'jbrower_primary' client_path = '/Users/jbrower/ws/local/primary' passwd = 'fake' # ALL SET # This regex is scary, but it works. describe_regex = /^...\s+(\/\/[^\/]+(\/[^\.]+)(\.([^\.#]+)){1}#([0-9]+))\s+.+$/ def bin_to_hex(s) s.each_byte.map {|b| b.to_s(16).rjust(2, '0')}.join end begin serverport = ARGV[0] change = ARGV[1] p4 = "#{p4bin} -p #{serverport} -u #{user} -c #{client} -P #{passwd}" files = [] output = `#{p4} describe -s #{change}` output.each_line do |line| if line =~ describe_regex files << line end end files.each do |file| depot_file_name = file.gsub(describe_regex, '\1').chomp right_side = file.gsub(describe_regex, '\2').chomp extension = file.gsub(describe_regex, '\4').chomp # revision = file.gsub(describe_regex, '\5').chomp local_file_name = "#{client_path}#{right_side}" thumb_name = "#{local_file_name}_thumb.png" hex_name = "#{local_file_name}_hex" =begin I think the problem is down here. I've tested my swap from bin to hex by doing the reverse, so I'm pretty sure I have that correct. when I do 'p4 fstat -Oa ..' on the file I've set the thumbnail to, the attr_thumb field says '?PNG', which is probably wrong, but I don't know why. =end if system("#{convertbin} #{local_file_name}.#{extension} \ -thumbnail 240x240^ #{thumb_name}") image_string = File.read(thumb_name) hex_image = bin_to_hex(image_string) File.open(hex_name, "w") {|file| file.write(hex_image)} `cat #{hex_name} | #{p4} attribute -e -f -n thumb -i #{depot_file_name}` end end end exit 0