28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/googletastic/sync/form.rb', line 28
def process(forms, options = {})
options[:key] ||= "forms"
options[:max_size] ||= 3000000
forms_processed = []
updated_forms = []
counted_size = 0
forms.each_with_index do |form, index|
if form.formkey.nil?
puts "Missing formkey... #{form.title}"
if forms_processed.length > 0 and index == forms.length - 1
Googletastic::Sync.push(options[:username], options[:password], options)
cleanup(forms_processed, options.merge(:ext => ".html"))
end
next
end
remote = form.remote
content = nil
puts "Processing Form... #{form.title}"
begin
form.remote.form_key = form.formkey
title = form.formkey + ".html"
content = form.remote.body
tempfile = Tempfile.new("googltastic-form-tempfiles-#{title}-#{Time.now}-#{rand(10000)}")
tempfile.write(content)
path = File.join(options[:folder], options[:key])
Dir.mkdir(path) unless File.exists?(path)
path = File.join(path, title)
if tempfile.size + counted_size >= options[:max_size] || index == forms.length - 1
Googletastic::Sync.push(options[:username], options[:password], options)
cleanup(forms_processed, options.merge(:ext => ".html"))
counted_size = 0
forms_processed = []
end
content = Googletastic::PrettyPrint.xml(content)
File.open(path, 'w') {|f| f.write(content) }
forms_processed << form
counted_size += tempfile.size
tempfile.close
updated_forms << form
rescue Exception => e
puts "Error... #{e.inspect}"
end
end
updated_forms
end
|