require "P4" require "word_salad" # gem install word-salad def wrap_text(txt, col = 80) txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3\n") end client_root = '/Users/mbishop/dev/localhost_1999/mbishop-test' p4 = P4.new p4.port="localhost:1999" p4.user="mbishop" p4.connect userNames = [{"User" => "mbishop", "Email" => "numericalgarden@me.com", "FullName" => "Michael Bishop"}, {"User" => "marnie", "Email" => "mbishop@me.com", "FullName" => "Marnie Anderson"} ] # MAKE USERS userNames.each { |user| begin p4.user=user["User"] spec = p4.fetch_user(p4.user) user.each{ |key, value| spec[key] = value } p4.save_user( spec ) rescue P4Exception # If any errors occur, we'll jump in here. Just log them # and raise the exception up to the higher level p4.errors.each { |e| $stderr.puts( e ) } raise end } clients = [ {"Client" => "mbishop-test", "Host" => ""}, {"Client" => "marnie-dev", "Host" => ""}, {"Client" => "marnie-main", "Host" => ""}, {"Client" => "mbishop-nihongo", "Host" => ""}, {"Client" => "mbishop-project", "Host" => ""} ] clientNames = ["mbishop-test", "marnie-dev", "numericalgarden-main", "marnie-nihongo", "jim-project"] # MAKE CLIENTS clients.each { |client| begin clientName = client["Client"] userName = clientName.scan(/\w+/)[0] p4.user = userName root = "/Users/mbishop/dev/localhost_1999/" + clientName spec = p4.fetch_client(clientName) client.each{ |key, value| spec[key] = value } spec[ "Options" ] = spec[ "Options" ].sub( "normdir", "rmdir" ) spec[ "Root" ] = root p4.save_client( spec ) rescue P4Exception # If any errors occur, we'll jump in here. Just log them # and raise the exception up to the higher level p4.errors.each { |e| $stderr.puts( e ) } raise end } # First retrieve the jobspec so you have values to make random entires rawJobSpec = p4.fetch_jobspec() values = Hash.new rawJobSpec["Values"].each { |value| valueBits = value.scan(/\w+/) values[valueBits[0]] = valueBits[1..-1] } maxWords = 200 5000.times { |index| begin p4.user= userNames[index%userNames.count]["User"] spec = p4.fetch_job( "new") # Now edit the fields in the form values.each {|key, value| spec[key] = value[index%value.count] } spec[ "Description" ] = wrap_text(((index%5) + 1).paragraphs.join("\n\n"), 72) # Now save the updated spec p4.save_job( spec ) # Point to the newly-created client rescue P4Exception # If any errors occur, we'll jump in here. Just log them # and raise the exception up to the higher level p4.errors.each { |e| $stderr.puts( e ) } raise end }