Skip to content

Commit

Permalink
* change main method name from "copy" to "execute"
Browse files Browse the repository at this point in the history
 * return the number of imported files at execute method
 * use Find.find method to get processing filename
  • Loading branch information
tach committed Aug 8, 2008
1 parent a28a6e8 commit 6a780ad
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/rbphoto/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

require 'getoptlong'
require 'fileutils'
require 'find'
require 'exif'
require 'gettext'
require 'gtk2'
Expand All @@ -41,8 +42,6 @@ class Import

def initialize(opt)
@opt = opt
@fileopts = { :verbose => @opt.verbose, :noop => @opt.no_act }
@postfix = '-' + ENV['USER']

if ( @opt.version )
print self.version
Expand All @@ -65,16 +64,24 @@ def prepare_target(args = ARGV)
@target = []
args.each do |arg|
if (File.directory?(arg))
@target.concat(Dir.glob("#{arg}/*.{jpg,jpeg,JPG,JPEG}"))
@target.concat(Dir.glob("#{arg}/*.{avi,AVI,mpg,MPG}")) if ( @opt.with_movie )
Find.find(arg) do |f|
if ( f.match(/\.jpe?g$/i) )
@target.push(f)
elsif ( f.match(/\.(?:avi|mpe?g)$/i) && @opt.with_movie )
@target.push(f)
end
end
else
@target.push(arg)
end
end
return @target.size > 0 ? @target.size : false
end

def copy
def execute
@fileopts = { :verbose => @opt.verbose, :noop => @opt.no_act }
@postfix = '-' + @opt.photographer
count = 0
@target.each do |file|
target_file = @opt.without_rename ? file : self.rename(file)
target_dir = File.dirname(target_file)
Expand All @@ -90,6 +97,7 @@ def copy
if ( @opt.move )
begin
FileUtils.mv(file, target_file, @fileopts)
count += 1
rescue => e
if ( e.is_a?(Errno::EACCES) && @opt.force && !File.writable?(target_file))
FileUtils.chmod(0644, target_file, @fileopts)
Expand All @@ -100,6 +108,7 @@ def copy
else
begin
FileUtils.cp(file, target_file, @fileopts)
count += 1
rescue => e
show_error("ERROR: cp failed: #{e.to_s}")
end
Expand All @@ -110,6 +119,7 @@ def copy
show_error("ERROR: chmod failed: #{e.to_s}")
end
end
return count
end

def rename(filename)
Expand Down Expand Up @@ -189,6 +199,7 @@ def initialize
arg = true if (arg == "")
self[name.sub(/^--/, '').gsub(/-/, '_').downcase] = arg
end
self['photographer'] ||= ENV['USER']
rescue
self['help'] = true
end
Expand Down

0 comments on commit 6a780ad

Please sign in to comment.