datashift 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +12 -0
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/datashift.gemspec +13 -12
- data/lib/datashift/delimiters.rb +87 -0
- data/lib/datashift/method_detail.rb +5 -0
- data/lib/datashift/method_details_manager.rb +5 -1
- data/lib/datashift/method_dictionary.rb +3 -1
- data/lib/exporters/csv_exporter.rb +158 -10
- data/lib/exporters/excel_exporter.rb +6 -2
- data/lib/exporters/exporter_base.rb +6 -0
- data/lib/helpers/spree_helper.rb +2 -1
- data/lib/loaders/paperclip/image_loader.rb +32 -2
- data/lib/loaders/spree/product_loader.rb +3 -2
- data/lib/thor/export.thor +111 -0
- data/lib/thor/{import_excel.thor → import.thor} +40 -2
- data/lib/thor/spree/bootstrap_cleanup.thor +7 -4
- data/lib/thor/spree/products_images.thor +26 -17
- data/lib/thor/spree/reports.thor +30 -40
- data/lib/thor/tools.thor +63 -0
- data/spec/Gemfile +3 -2
- data/spec/csv_exporter_spec.rb +101 -0
- data/spec/excel_exporter_spec.rb +1 -1
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/test_model_defs.rb +5 -0
- data/spec/spree_loader_spec.rb +28 -131
- data/spec/spree_method_mapping_spec.rb +1 -1
- data/spec/spree_variants_loader_spec.rb +189 -0
- metadata +193 -167
- data/lib/thor/export_excel.thor +0 -74
- data/sandbox/app/controllers/application_controller.rb +0 -3
- data/sandbox/config/application.rb +0 -59
- data/sandbox/config/database.yml +0 -20
- data/sandbox/config/environment.rb +0 -5
- data/sandbox/config/environments/development.rb +0 -37
- data/tasks/import/csv.rake +0 -51
@@ -27,6 +27,8 @@ module DataShift
|
|
27
27
|
|
28
28
|
# Create an Excel file from list of ActiveRecord objects
|
29
29
|
def export(records, options = {})
|
30
|
+
|
31
|
+
raise ArgumentError.new('Please supply array of records to export') unless records.is_a? Array
|
30
32
|
|
31
33
|
excel = JExcelFile.new()
|
32
34
|
|
@@ -35,11 +37,14 @@ module DataShift
|
|
35
37
|
else
|
36
38
|
excel.create_sheet( records.first.class.name )
|
37
39
|
end
|
38
|
-
|
40
|
+
|
39
41
|
excel.ar_to_headers(records)
|
40
42
|
|
41
43
|
excel.ar_to_xls(records)
|
42
44
|
|
45
|
+
|
46
|
+
# => :methods => List of methods to additionally export on each record
|
47
|
+
|
43
48
|
excel.save( filename() )
|
44
49
|
end
|
45
50
|
|
@@ -90,7 +95,6 @@ module DataShift
|
|
90
95
|
|
91
96
|
excel.set_headers( headers )
|
92
97
|
|
93
|
-
|
94
98
|
row_index = 1
|
95
99
|
|
96
100
|
items.each do |datum|
|
data/lib/helpers/spree_helper.rb
CHANGED
@@ -97,9 +97,10 @@ module DataShift
|
|
97
97
|
|
98
98
|
store_path = Dir.pwd
|
99
99
|
|
100
|
-
spree_sanbox_app = File.expand_path('../../../sandbox', __FILE__)
|
100
|
+
spree_sanbox_app = File.expand_path('../../../spec/sandbox', __FILE__)
|
101
101
|
|
102
102
|
unless(File.exists?(spree_sanbox_app))
|
103
|
+
puts "Creating new Rails sandbox for Spree : #{spree_sanbox_app}"
|
103
104
|
Dir.chdir( File.expand_path( "#{spree_sanbox_app}/..") )
|
104
105
|
system('rails new sandbox')
|
105
106
|
end
|
@@ -13,10 +13,16 @@ module DataShift
|
|
13
13
|
|
14
14
|
include DataShift::Logging
|
15
15
|
|
16
|
+
# Get all image files (based on file extensions) from supplied path.
|
17
|
+
# Options :
|
18
|
+
# :glob : The glob to use to find files
|
19
|
+
# => :recursive : Descend tree looking for files rather than just supplied path
|
20
|
+
|
16
21
|
def self.get_files(path, options = {})
|
17
|
-
glob =
|
22
|
+
glob = options[:glob] ? options[:glob] : image_magik_glob
|
23
|
+
glob = (options['recursive'] || options[:recursive]) ? "**/#{glob}" : glob
|
18
24
|
|
19
|
-
Dir.glob("#{path}/#{glob}")
|
25
|
+
Dir.glob("#{path}/#{glob}", File::FNM_CASEFOLD)
|
20
26
|
end
|
21
27
|
|
22
28
|
def get_file( attachment_path )
|
@@ -70,6 +76,30 @@ module DataShift
|
|
70
76
|
puts e.inspect, e.backtrace
|
71
77
|
end
|
72
78
|
end
|
79
|
+
|
80
|
+
# Set of file extensions ImageMagik can process so default glob
|
81
|
+
# we use to find image files within directories
|
82
|
+
def self.image_magik_glob
|
83
|
+
@im_glob ||= %w{*.3FR *.AAI *.AI *.ART *.ARW *.AVI *.AVS *.BGR *.BGRA
|
84
|
+
*.BIE *.BMP *.BMP2 *.BMP3 *.BRF *.CAL *.CALS *.CANVAS
|
85
|
+
*.CIN *.CIP *.CLIP *.CMYK *.CMYKA *.CR2 *.CRW *.CUR *.CUT *.DCM *.DCR *.DCX
|
86
|
+
*.DDS *.DFONT *.DJVU *.DNG *.DOT *.DPS *.DPX
|
87
|
+
*.EMF *.EPDF *.EPI *.EPS *.EPS2 *.EPS3 *.EPSF *.EPSI
|
88
|
+
*.EPT *.EPT2 *.EPT3 *.ERF *.EXR *.FITS *.FPX *.FTS *.G3 *.GIF *.GIF87
|
89
|
+
*.GRAY *.HALD *.HDR *.HRZ *.ICB *.ICO *.ICON *.IPL
|
90
|
+
*.ISOBRL *.J2C *.JBG *.JBIG *.JNG *.JP2 *.JPC *.JPEG *.JPG *.JPX *.K25 *.KDC
|
91
|
+
*.LABEL *.M2V *.M4V *.MAC *.MAP *.MAT *.MATTE *.MIFF *.MNG *.MONO
|
92
|
+
*.MOV *.MP4 *.MPC *.MPEG *.MPG *.MRW *.MSL *.MSVG *.MTV *.MVG *.NEF *.ORF *.OTB *.OTF *.PAL *.PALM
|
93
|
+
*.PAM *.PBM *.PCD *.PCDS *.PCL *.PCT *.PCX *.PDB *.PDF *.PDFA *.PEF
|
94
|
+
*.PES *.PFA *.PFB *.PFM *.PGM *.PGX *.PICON *.PICT *.PIX *.PJPEG *.PLASMA
|
95
|
+
*.PNG *.PNG24 *.PNG32 *.PNG8 *.PNM *.PPM *.PS *.PS2 *.PS3 *.PSB *.PSD *.PTIF *.PWP *.RAF *.RAS *.RGB
|
96
|
+
*.RGBA *.RGBO *.RLA *.RLE *.SCR *.SCT *.SFW *.SGI *.SR2 *.SRF
|
97
|
+
*.SUN *.SVG *.SVGZ *.TGA *.TIFF *.TIFF64 *.TILE *.TIM *.TTC *.TTF *.UBRL *.UIL *.UYVY *.VDA *.VICAR
|
98
|
+
*.VID *.VIFF *.VST *.WBMP *.WEBP *.WMF *.WMV *.WMZ *.WPG *.X3F
|
99
|
+
*.XBM *.XC *.XCF *.XPM *.XPS *.XV *.XWD *.YCbCr *.YCbCrA *.YUV
|
100
|
+
}
|
101
|
+
"{#{@im_glob.join(',')}}"
|
102
|
+
end
|
73
103
|
end
|
74
104
|
|
75
105
|
end
|
@@ -97,13 +97,14 @@ module DataShift
|
|
97
97
|
values = current_value.to_s.split(LoaderBase::multi_assoc_delim)
|
98
98
|
|
99
99
|
if(@load_object.variants.size == values.size)
|
100
|
-
@load_object.variants.each_with_index {|v, i| v.on_hand = values[i].to_i
|
100
|
+
@load_object.variants.each_with_index {|v, i| v.on_hand = values[i].to_i }
|
101
|
+
@load_object.save
|
101
102
|
else
|
102
103
|
puts "WARNING: Count on hand entries did not match number of Variants - None Set"
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
|
-
|
107
|
+
# Can only set count on hand on Product if no Variants exist, else model throws
|
107
108
|
|
108
109
|
elsif(@load_object.variants.size == 0)
|
109
110
|
if(current_value.to_s.include?(LoaderBase::multi_assoc_delim))
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2012
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: April 2012
|
4
|
+
# License:: MIT.
|
5
|
+
#
|
6
|
+
# Usage::
|
7
|
+
#
|
8
|
+
# To pull Datashift commands into your main application :
|
9
|
+
#
|
10
|
+
# require 'datashift'
|
11
|
+
#
|
12
|
+
# DataShift::load_commands
|
13
|
+
#
|
14
|
+
# Cmd Line:
|
15
|
+
#
|
16
|
+
# => bundle exec thor datashift:export:excel -m <active record class> -r <output_template.xls> -a
|
17
|
+
#
|
18
|
+
require 'datashift'
|
19
|
+
|
20
|
+
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
21
|
+
module Datashift
|
22
|
+
|
23
|
+
|
24
|
+
class Export < Thor
|
25
|
+
|
26
|
+
include DataShift::Logging
|
27
|
+
|
28
|
+
desc "excel", "export any active record model (with optional associations)"
|
29
|
+
method_option :model, :aliases => '-m', :required => true, :desc => "The active record model to export"
|
30
|
+
method_option :result, :aliases => '-r', :required => true, :desc => "Create template of model in supplied file"
|
31
|
+
method_option :assoc, :aliases => '-a', :type => :boolean, :desc => "Include all associations in the template"
|
32
|
+
method_option :exclude, :aliases => '-e', :type => :array, :desc => "Use with -a : Exclude association types. Any from #{DataShift::MethodDetail::supported_types_enum.to_a.inspect}"
|
33
|
+
|
34
|
+
def excel()
|
35
|
+
|
36
|
+
# TODO - We're assuming run from a rails app/top level dir...
|
37
|
+
# ...can we make this more robust ? e.g what about when using active record but not in Rails app,
|
38
|
+
require File.expand_path('config/environment.rb')
|
39
|
+
|
40
|
+
require 'excel_exporter'
|
41
|
+
|
42
|
+
model = options[:model]
|
43
|
+
result = options[:result]
|
44
|
+
|
45
|
+
logger.info "Datashift: Start Excel export to #{result}"
|
46
|
+
|
47
|
+
klass = ModelMapper::class_from_string(model) #Kernel.const_get(model)
|
48
|
+
|
49
|
+
raise "ERROR: No such Model [#{model}] found - check valid model supplied via -model <Class>" if(klass.nil?)
|
50
|
+
|
51
|
+
begin
|
52
|
+
gen = DataShift::ExcelExporter.new(result)
|
53
|
+
|
54
|
+
if(options[:assoc])
|
55
|
+
opts = (options[:exclude]) ? {:exclude => options[:exclude]} : {}
|
56
|
+
logger.info("Datashift: Exporting with associations")
|
57
|
+
gen.export_with_associations(klass, klass.all, opts)
|
58
|
+
else
|
59
|
+
gen.export(klass.all, :sheet_name => klass.name)
|
60
|
+
end
|
61
|
+
rescue => e
|
62
|
+
puts e
|
63
|
+
puts e.backtrace
|
64
|
+
puts "Warning: Error during export, data may be incomplete"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "csv", "export any active record model (with optional associations)"
|
70
|
+
method_option :model, :aliases => '-m', :required => true, :desc => "The active record model to export"
|
71
|
+
method_option :result, :aliases => '-r', :required => true, :desc => "Create template of model in supplied file"
|
72
|
+
method_option :assoc, :aliases => '-a', :type => :boolean, :desc => "Include all associations in the template"
|
73
|
+
method_option :exclude, :aliases => '-e', :type => :array, :desc => "Use with -a : Exclude association types. Any from #{DataShift::MethodDetail::supported_types_enum.to_a.inspect}"
|
74
|
+
method_option :methods, :aliases => '-c', :type => :array, :desc => "List of additional methods to call on model, useful for situations like delegated methods"
|
75
|
+
|
76
|
+
def csv()
|
77
|
+
|
78
|
+
# TODO - We're assuming run from a rails app/top level dir...
|
79
|
+
# ...can we make this more robust ? e.g what about when using active record but not in Rails app,
|
80
|
+
require File.expand_path('config/environment.rb')
|
81
|
+
|
82
|
+
require 'csv_exporter'
|
83
|
+
|
84
|
+
model = options[:model]
|
85
|
+
result = options[:result]
|
86
|
+
|
87
|
+
logger.info "Datashift: Start CSV export to #{result}"
|
88
|
+
|
89
|
+
klass = ModelMapper::class_from_string(model) #Kernel.const_get(model)
|
90
|
+
|
91
|
+
raise "ERROR: No such Model [#{model}] found - check valid model supplied via -model <Class>" if(klass.nil?)
|
92
|
+
|
93
|
+
begin
|
94
|
+
gen = DataShift::CsvExporter.new(result)
|
95
|
+
|
96
|
+
if(options[:assoc])
|
97
|
+
logger.info("Datashift: Exporting with associations")
|
98
|
+
gen.export_with_associations(klass, klass.all, options)
|
99
|
+
else
|
100
|
+
gen.export(klass.all, options)
|
101
|
+
end
|
102
|
+
rescue => e
|
103
|
+
puts e
|
104
|
+
puts e.backtrace
|
105
|
+
puts "Warning: Error during export, data may be incomplete"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -33,7 +33,8 @@ module Datashift
|
|
33
33
|
method_option :config, :aliases => '-c', :desc => "YAML config file with defaults, over-rides etc"
|
34
34
|
method_option :assoc, :aliases => '-a', :type => :boolean, :desc => "Include any associations supplied in the input"
|
35
35
|
method_option :exclude, :aliases => '-e', :type => :array, :desc => "Use with -a : Exclude association types. Any from #{DataShift::MethodDetail::supported_types_enum.to_a.inspect}"
|
36
|
-
|
36
|
+
method_option :verbose, :aliases => '-v', :type => :boolean, :desc => "Verbose logging"
|
37
|
+
|
37
38
|
def excel()
|
38
39
|
|
39
40
|
# TODO - We're assuming run from a rails app/top level dir...
|
@@ -70,13 +71,50 @@ module Datashift
|
|
70
71
|
end
|
71
72
|
|
72
73
|
logger.info("ARGS #{options.inspect}")
|
73
|
-
loader.logger.verbose if(
|
74
|
+
loader.logger.verbose if(options['verbose'])
|
74
75
|
|
75
76
|
loader.configure_from( options[:config] ) if(options[:config])
|
76
77
|
|
77
78
|
|
78
79
|
loader.perform_load(options[:input])
|
79
80
|
end
|
81
|
+
|
82
|
+
desc "csv", "import CSV file for specified active record model"
|
83
|
+
method_option :model, :aliases => '-m', :required => true, :desc => "The related active record model"
|
84
|
+
method_option :input, :aliases => '-i', :required => true, :desc => "The input .xls file"
|
85
|
+
method_option :config, :aliases => '-c', :desc => "YAML config file with defaults, over-rides etc"
|
86
|
+
method_option :assoc, :aliases => '-a', :type => :boolean, :desc => "Include any associations supplied in the input"
|
87
|
+
method_option :exclude, :aliases => '-e', :type => :array, :desc => "Use with -a : Exclude association types. Any from #{DataShift::MethodDetail::supported_types_enum.to_a.inspect}"
|
88
|
+
method_option :verbose, :aliases => '-v', :type => :boolean, :desc => "Verbose logging"
|
89
|
+
|
90
|
+
def csv()
|
91
|
+
|
92
|
+
# TODO - We're assuming run from a rails app/top level dir...
|
93
|
+
# ...can we make this more robust ? e.g what about when using active record but not in Rails app,
|
94
|
+
require File.expand_path('config/environment.rb')
|
95
|
+
|
96
|
+
require 'csv_loader'
|
97
|
+
|
98
|
+
model = options[:model]
|
99
|
+
begin
|
100
|
+
# support modules e.g "Spree::Property")
|
101
|
+
klass = ModelMapper::class_from_string(model)
|
102
|
+
rescue NameError
|
103
|
+
raise "ERROR: No such AR Model found - check valid model supplied with -m <Class>"
|
104
|
+
end
|
105
|
+
|
106
|
+
raise "ERROR: No such AR Model found - check valid model supplied with -m <Class>" if(klass.nil?)
|
107
|
+
|
108
|
+
|
109
|
+
loader = DataShift::CsvLoader.new(klass)
|
110
|
+
|
111
|
+
loader.logger.verbose if(options['verbose'])
|
112
|
+
|
113
|
+
loader.configure_from( options[:config] ) if(options[:config])
|
114
|
+
|
115
|
+
loader.perform_load(options[:input])
|
116
|
+
end
|
117
|
+
|
80
118
|
end
|
81
119
|
|
82
120
|
end
|
@@ -9,9 +9,6 @@
|
|
9
9
|
#
|
10
10
|
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
11
11
|
|
12
|
-
require File.expand_path('config/environment.rb')
|
13
|
-
|
14
|
-
|
15
12
|
module Datashift
|
16
13
|
|
17
14
|
class Spreeboot < Thor
|
@@ -22,6 +19,8 @@ module Datashift
|
|
22
19
|
|
23
20
|
def cleanup()
|
24
21
|
|
22
|
+
require File.expand_path('config/environment.rb')
|
23
|
+
|
25
24
|
require 'spree_helper'
|
26
25
|
|
27
26
|
require File.expand_path('config/environment.rb')
|
@@ -37,7 +36,11 @@ module Datashift
|
|
37
36
|
klass = DataShift::SpreeHelper::get_spree_class(k)
|
38
37
|
if(klass)
|
39
38
|
puts "Clearing model #{klass}"
|
40
|
-
|
39
|
+
begin
|
40
|
+
klass.delete_all
|
41
|
+
rescue => e
|
42
|
+
puts e
|
43
|
+
end
|
41
44
|
else
|
42
45
|
puts "WARNING - Could not find AR model for class name #{k}"
|
43
46
|
end
|
@@ -92,12 +92,13 @@ module Datashift
|
|
92
92
|
desc "images", "Populate the DB with images from a directory\nwhere image names contain somewhere the Product Sku/Name"
|
93
93
|
|
94
94
|
# :dummy => dummy run without actual saving to DB
|
95
|
-
method_option :input, :aliases => '-i', :required => true, :desc => "The input path containing images
|
95
|
+
method_option :input, :aliases => '-i', :required => true, :desc => "The input path containing images "
|
96
96
|
|
97
|
+
method_option :glob, :aliases => '-g', :desc => 'The glob to use to find files e.g. \'{*.jpg,*.gif,*.png}\' '
|
97
98
|
method_option :recursive, :aliases => '-r', :type => :boolean, :desc => "Scan sub directories of input for images"
|
98
99
|
|
99
100
|
method_option :sku, :aliases => '-s', :desc => "Lookup Product based on image name starting with sku"
|
100
|
-
method_option :sku_prefix, :aliases => '-p', :desc => "
|
101
|
+
method_option :sku_prefix, :aliases => '-p', :desc => "SKU prefix to add to each image name before attempting Product lookup"
|
101
102
|
method_option :dummy, :aliases => '-d', :type => :boolean, :desc => "Dummy run, do not actually save Image or Product"
|
102
103
|
|
103
104
|
method_option :process_when_no_assoc, :aliases => '-f', :type => :boolean, :desc => "Process image even if no Product found - force loading"
|
@@ -156,36 +157,44 @@ module Datashift
|
|
156
157
|
|
157
158
|
# try splitting up filename in various ways looking for the SKU
|
158
159
|
split_on = loader_config['split_file_name_on'] || options[:split_file_name_on]
|
159
|
-
|
160
|
-
puts "Will scan image names splitting on delimiter : #{split_on}"
|
161
|
-
|
160
|
+
|
162
161
|
image_cache = DataShift::ImageLoading::get_files(@image_path, options)
|
163
162
|
|
163
|
+
puts "Found #{image_cache.size} image files - splitting names on delimiter : #{split_on}"
|
164
|
+
|
164
165
|
image_cache.each do |image_name|
|
165
166
|
|
166
167
|
image_base_name = File.basename(image_name)
|
167
|
-
|
168
|
+
|
169
|
+
logger.info "Processing image file #{image_base_name} "
|
170
|
+
|
168
171
|
base_name = File.basename(image_name, '.*')
|
169
172
|
base_name.strip!
|
170
|
-
|
171
|
-
logger.info "Processing image file #{base_name} : #{File.exists?(image_name)}"
|
172
|
-
|
173
|
+
|
173
174
|
record = nil
|
174
175
|
|
175
176
|
record = image_loader.get_record_by(attachment_klazz, attachment_field, base_name)
|
176
|
-
|
177
|
-
#
|
178
|
-
|
177
|
+
|
178
|
+
# TODO move into the ImageLoading module
|
179
|
+
#
|
180
|
+
# try the seperate individual portions of the filename, front -> back
|
181
|
+
base_name.split(split_on).each do |x|
|
182
|
+
x = "#{options[:sku_prefix]}#{x}" if(options[:sku_prefix])
|
183
|
+
|
179
184
|
record = image_loader.get_record_by(attachment_klazz, attachment_field, x)
|
180
185
|
break if record
|
181
186
|
end unless(record)
|
182
187
|
|
183
|
-
# this time try sequentially scanning
|
184
|
-
base_name.split(split_on).inject("") do |str, x|
|
185
|
-
|
188
|
+
# this time try sequentially and incrementally scanning
|
189
|
+
base_name.split(split_on).inject("") do |str, x|
|
190
|
+
z = (options[:sku_prefix]) ? "#{options[:sku_prefix]}#{str}#{x}": "#{str}#{x}"
|
191
|
+
puts z
|
192
|
+
record = image_loader.get_record_by(attachment_klazz, attachment_field, z)
|
186
193
|
break if record
|
187
194
|
x
|
188
195
|
end unless(record)
|
196
|
+
|
197
|
+
# END TODO
|
189
198
|
|
190
199
|
record = record.product if(record && record.respond_to?(:product)) # SKU stored on Variant but we want it's master Product
|
191
200
|
|
@@ -225,9 +234,9 @@ module Datashift
|
|
225
234
|
FileUtils.mkdir_p('MissingRecords') unless File.directory?('MissingRecords')
|
226
235
|
|
227
236
|
puts "WARNING : #{missing_records.size} of #{image_cache.size} images could not be attached to a Product"
|
228
|
-
puts '
|
237
|
+
puts 'For your convenience a copy of images with MISSING Products will be saved to : ./MissingRecords'
|
229
238
|
missing_records.each do |i|
|
230
|
-
puts "
|
239
|
+
puts "Copying #{i} to MissingRecords folder" if(options[:verbose])
|
231
240
|
FileUtils.cp( i, 'MissingRecords') unless(options[:dummy] == 'true')
|
232
241
|
end
|
233
242
|
else
|
data/lib/thor/spree/reports.thor
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# License:: MIT. Free, Open Source.
|
5
5
|
#
|
6
6
|
# Usage::
|
7
|
-
# bundle exec thor help datashift:
|
7
|
+
# bundle exec thor help datashift:reports:missing_images
|
8
8
|
# bundle exec thor datashift:spreeboot:cleanup
|
9
9
|
#
|
10
10
|
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
@@ -13,54 +13,44 @@ require 'excel_exporter'
|
|
13
13
|
|
14
14
|
module Datashift
|
15
15
|
|
16
|
-
|
16
|
+
class Spreereports < Thor
|
17
17
|
|
18
|
-
|
18
|
+
include DataShift::Logging
|
19
19
|
|
20
|
-
|
20
|
+
desc "no_image", "Spree Products without an image"
|
21
21
|
|
22
|
-
|
22
|
+
def no_image(report = nil)
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
require 'spree_helper'
|
25
|
+
require 'csv_exporter'
|
26
|
+
require 'image_loader'
|
26
27
|
|
27
|
-
|
28
|
+
require File.expand_path('config/environment.rb')
|
28
29
|
|
29
|
-
|
30
|
+
klass = DataShift::SpreeHelper::get_spree_class('Product')
|
30
31
|
|
31
|
-
|
32
|
+
missing = klass.all.find_all {|p| p.images.size == 0 }
|
32
33
|
|
33
|
-
|
34
|
+
puts "There are #{missing.size} Products (of #{klass.count}) without an associated Image"
|
34
35
|
|
35
|
-
|
36
|
-
fname = report ? report : "missing_images.xls"
|
37
|
-
DataShift::ExcelExporter.new( fname ).export( missing )
|
38
|
-
else
|
39
|
-
puts missing.collect(&:name).inspect
|
40
|
-
end
|
36
|
+
fname = report ? report : "missing_images"
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
04Spain
|
51
|
-
|
52
|
-
07SignsJohnAllFolders
|
53
|
-
07_Mar
|
54
|
-
09Powerpointsermonaids
|
55
|
-
}
|
56
|
-
|
57
|
-
options = { :recursive => true }
|
58
|
-
|
59
|
-
images = @image_list.collect do |p|
|
60
|
-
DataShift::ImageLoading::get_files(File.join(@drop_box,p), options)
|
61
|
-
end
|
38
|
+
if(DataShift::Guards::jruby?)
|
39
|
+
puts "Creating report #{fname}.xls"
|
40
|
+
DataShift::ExcelExporter.new( fname + '.xls' ).export( missing, :methods => ['sku'] )
|
41
|
+
else
|
42
|
+
puts "Creating report #{fname}.csv"
|
43
|
+
DataShift::CsvExporter.new( fname + '.csv' ).export( missing, :methods => ['sku'] )
|
44
|
+
puts missing.collect(&:name).join('\n')
|
45
|
+
end
|
62
46
|
|
63
|
-
|
47
|
+
# TODO - cross check file locations for possible candidates
|
48
|
+
#image_cache = DataShift::ImageLoading::get_files(@cross_check_location, options)
|
49
|
+
|
50
|
+
# missing.each {
|
51
|
+
|
52
|
+
# puts images.inspect
|
53
|
+
end
|
64
54
|
end
|
65
|
-
|
66
|
-
end
|
55
|
+
|
56
|
+
end
|