class Commands::Init::ChangelistModel
Attributes
adds[RW]
description[RW]
edits[RW]
user[RW]
view[RW]
Public Class Methods
abstract()
click to toggle source
new()
click to toggle source
# File lib/commands/init/changelist_model.rb, line 39 def initialize @description = self.class.description @adds = self.class.adds @edits = self.class.edits @user = self.class.user @view = self.class.view end
Public Instance Methods
execute(p4, models, super_user)
click to toggle source
# File lib/commands/init/changelist_model.rb, line 47 def execute(p4, models, super_user) # Set up our options with a user context if specified by searching the # defined models. options = {:p4 => p4} if user model = models.find {|m| m.class < UserModel && m.login == user } options[:user] = model.login options[:password] = model.password options[:olduser] = super_user.login options[:oldpass] = super_user.password end if view options[:view] = view end # Define the logic of what the changelist model really does: make adds # and edits for the most part open_client(options) do |client_path, name| change_spec = p4.fetch_change change_spec._description = description results = p4.save_change(change_spec) change_id = results[0].gsub(/^Change (\d+) created./, '\1') puts "Preparing changelist #{change_id} with #{@adds.length} adds and #{@edits.length} edits" @adds.each do |add| add_path = File.join(client_path, add.path) dir = File.dirname(add_path) if dir && !dir.empty? if !Dir.exist?(dir) FileUtils.mkpath(dir) end end if add.content IO.write(add_path, add.content) elsif add.local_path FileUtils.copy(add.local_path, add_path) end results = p4.run_add('-c', change_id, add_path) puts "Added file #{add_path} to #{change_id}: #{results}" end @edits.each do |edit| edit_path = File.join(client_path, edit.path) results = p4.run_edit('-c', change_id, edit_path) puts "Editing file #{edit_path} on #{change_id}: #{results}" if edit.content IO.write(edit_path, edit.content) else FileUtils.copy(edit.local_path, edit_path) end end p4.run_submit('-c', change_id) end end