go_import 3.0.10 → 3.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/go-import +43 -4
- data/lib/go_import/model/file.rb +7 -10
- data/lib/go_import/model/rootmodel.rb +2 -2
- data/sources/easy/.go_import/runner.rb +12 -2
- data/spec/file_spec.rb +9 -9
- metadata +2 -2
data/bin/go-import
CHANGED
@@ -42,6 +42,10 @@ class GoImportCommandLine < Thor
|
|
42
42
|
:desc => "Name of the file where the converted source will be saved. This file should be sent to LIME Go. If the file already exist it will be replaced.",
|
43
43
|
:type => :string,
|
44
44
|
:required => false)
|
45
|
+
option(:ignore_missing_files,
|
46
|
+
:desc => "Output will be created even if the import contains missing files",
|
47
|
+
:type => :boolean,
|
48
|
+
:required => false)
|
45
49
|
def run_import()
|
46
50
|
if !is_valid_goimport_project?
|
47
51
|
return
|
@@ -61,23 +65,58 @@ class GoImportCommandLine < Thor
|
|
61
65
|
puts "WARNING: This means that files with an absolute path will be imported with their original path. Set this constant if you want to get files from the FILES_FOLDER directory."
|
62
66
|
end
|
63
67
|
|
64
|
-
is_ok, error_msg = can_be_serialized?(model)
|
68
|
+
is_ok, error_msg = can_be_serialized?(model, options.ignore_missing_files)
|
65
69
|
if is_ok
|
70
|
+
if options.ignore_missing_files && model.documents.files.length > 0
|
71
|
+
log_and_remove_missing_files model
|
72
|
+
end
|
73
|
+
|
66
74
|
go_data_zip = options.output.nil? == true ? "go.zip" : options.output
|
67
75
|
model.save_to_zip(go_data_zip)
|
68
76
|
puts "Source has been been converted into '#{go_data_zip}'."
|
69
77
|
else
|
70
|
-
puts "Source could not be converted due to"
|
78
|
+
puts "ERROR: Source could not be converted due to:"
|
71
79
|
puts error_msg
|
80
|
+
|
81
|
+
if !options.ignore_missing_files &&
|
82
|
+
model.documents.files.any? {|file| !::File.exists?(file.path_for_project)}
|
83
|
+
puts "go-import detected missing files (see above), you can ignore these with the option --ignore-missing-files."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
def log_and_remove_missing_files(model)
|
90
|
+
if model.documents.files.length > 0
|
91
|
+
puts "Trying to log files that can't be found..."
|
92
|
+
file_log_header = "name;integration_id;path;organization.integrationid;organization.name;deal.integrationid;deal.name"
|
93
|
+
file_log = ""
|
94
|
+
model.documents.files.each do |file|
|
95
|
+
if !::File.exists?(file.path_for_project)
|
96
|
+
file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name}\n"
|
97
|
+
model.documents.files.delete file
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
if file_log.length > 0
|
102
|
+
log_filename = 'go-import-missing-files.csv'
|
103
|
+
::File.open(log_filename, 'w') { |f|
|
104
|
+
f.puts file_log_header
|
105
|
+
f.puts file_log
|
106
|
+
}
|
107
|
+
puts "WARNING: go-import has ignored files. Filenames of all ignored files has been written to '#{log_filename}'."
|
108
|
+
else
|
109
|
+
puts "All files are OK."
|
110
|
+
end
|
72
111
|
end
|
73
112
|
end
|
74
113
|
|
75
114
|
private
|
76
|
-
def can_be_serialized?(rootmodel)
|
115
|
+
def can_be_serialized?(rootmodel, ignore_missing_files)
|
77
116
|
is_ok = false
|
78
117
|
error = rootmodel.sanity_check
|
79
118
|
if error.empty?
|
80
|
-
error = rootmodel.validate
|
119
|
+
error = rootmodel.validate(ignore_missing_files)
|
81
120
|
|
82
121
|
if error.empty?
|
83
122
|
is_ok = true
|
data/lib/go_import/model/file.rb
CHANGED
@@ -15,9 +15,9 @@ module GoImport
|
|
15
15
|
|
16
16
|
attr_reader :name
|
17
17
|
|
18
|
-
#
|
19
|
-
# zip file that is sent to LIME Go. You should
|
20
|
-
# property
|
18
|
+
# location_in_zip_file is used internally when the file is
|
19
|
+
# stored in the zip file that is sent to LIME Go. You should
|
20
|
+
# not modify this property
|
21
21
|
attr_accessor :location_in_zip_file
|
22
22
|
|
23
23
|
def initialize(opt = nil)
|
@@ -150,17 +150,14 @@ module GoImport
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def add_to_zip_file(zip_file)
|
153
|
-
|
154
|
-
@location_in_zip_file = "files/#{@path}"
|
155
|
-
else
|
156
|
-
@location_in_zip_file = "files/__abs/#{SecureRandom.uuid}/#{::File.basename(@path).to_s}"
|
157
|
-
end
|
153
|
+
@location_in_zip_file = "files/#{SecureRandom.uuid}#{::File.extname(@path).to_s}"
|
158
154
|
|
159
155
|
zip_file.add(@location_in_zip_file, path_for_project)
|
160
156
|
end
|
161
157
|
|
162
|
-
def validate
|
158
|
+
def validate(ignore_missing_files = false)
|
163
159
|
error = String.new
|
160
|
+
warning = String.new
|
164
161
|
|
165
162
|
if @name.nil? || @name.empty?
|
166
163
|
error = "#{error}A file must have a name.\n"
|
@@ -169,7 +166,7 @@ module GoImport
|
|
169
166
|
if @path.nil? || @path.empty?
|
170
167
|
error = "Path is required for file.\n"
|
171
168
|
else
|
172
|
-
if !::File.exists?(path_for_project())
|
169
|
+
if !ignore_missing_files && !::File.exists?(path_for_project())
|
173
170
|
error = "#{error}Can't find file with name '#{@name}' and original path '#{@path}' at '#{path_for_project()}'."
|
174
171
|
end
|
175
172
|
end
|
@@ -304,7 +304,7 @@ module GoImport
|
|
304
304
|
return error.strip
|
305
305
|
end
|
306
306
|
|
307
|
-
def validate()
|
307
|
+
def validate(ignore_missing_files = false)
|
308
308
|
error = String.new
|
309
309
|
|
310
310
|
@organizations.each do |o|
|
@@ -339,7 +339,7 @@ module GoImport
|
|
339
339
|
end
|
340
340
|
|
341
341
|
@documents.files.each do |file|
|
342
|
-
validation_message = file.validate
|
342
|
+
validation_message = file.validate(ignore_missing_files)
|
343
343
|
if !validation_message.empty?
|
344
344
|
error = "#{error}\n#{validation_message}"
|
345
345
|
end
|
@@ -174,7 +174,12 @@ def to_organization_document(row, rootmodel)
|
|
174
174
|
file.name = row['Comment']
|
175
175
|
|
176
176
|
file.created_by = rootmodel.find_coworker_by_integration_id(row['idUser-Created'])
|
177
|
-
|
177
|
+
|
178
|
+
org = rootmodel.find_organization_by_integration_id(row['idCompany'])
|
179
|
+
if org.nil?
|
180
|
+
return nil
|
181
|
+
end
|
182
|
+
file.organization = org
|
178
183
|
|
179
184
|
return file
|
180
185
|
end
|
@@ -189,7 +194,12 @@ def from_project_document_to_organization_document(row, includes, rootmodel)
|
|
189
194
|
file.created_by = rootmodel.find_coworker_by_integration_id(row['idUser-Created'])
|
190
195
|
|
191
196
|
organization_id = includes[row['idProject']]
|
192
|
-
|
197
|
+
org = rootmodel.find_organization_by_integration_id(organization_id)
|
198
|
+
if org.nil?
|
199
|
+
return nil
|
200
|
+
end
|
201
|
+
|
202
|
+
file.organization = org
|
193
203
|
|
194
204
|
return file
|
195
205
|
end
|
data/spec/file_spec.rb
CHANGED
@@ -27,16 +27,16 @@ describe "File" do
|
|
27
27
|
file.validate.should eq ""
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# # when, then
|
30
|
+
it "is valid when it has name, invalid path, created_by and deal but ignores the path" do
|
31
|
+
# given
|
32
|
+
file.name = "Offert"
|
33
|
+
file.path = "c:\\mydocs\\offert.docx"
|
34
|
+
file.created_by = GoImport::CoworkerReference.new( { :integration_id => "123" } )
|
35
|
+
file.deal = GoImport::DealReference.new( { :integration_id => "456" } )
|
38
36
|
|
39
|
-
|
37
|
+
# when, then
|
38
|
+
file.validate(true).should eq ""
|
39
|
+
end
|
40
40
|
|
41
41
|
|
42
42
|
it "is not valid when it has path and deal" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-10-
|
15
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: iso_country_codes
|