pwup 0.0.1 → 0.0.2
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/lib/pwup.rb +32 -14
- metadata +1 -1
data/lib/pwup.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'pathname'
|
2
2
|
require 'tmpdir'
|
3
|
+
|
3
4
|
require 'picasa'
|
4
5
|
|
5
6
|
module PwUp
|
@@ -10,7 +11,7 @@ module PwUp
|
|
10
11
|
".rar" => "unrar x -ep \"%<file>s\" %<target_dir>s",
|
11
12
|
".zip" => "unzip -j \"%<file>s\" -d %<target_dir>s",
|
12
13
|
}
|
13
|
-
IMAGE_TYPES = %w[
|
14
|
+
IMAGE_TYPES = %w[*.jpg *.png *.gif]
|
14
15
|
|
15
16
|
def initialize(email, password)
|
16
17
|
@email = email
|
@@ -22,9 +23,12 @@ module PwUp
|
|
22
23
|
def process!(files, album_name)
|
23
24
|
# create a tmp folder
|
24
25
|
target_dir = Dir.mktmpdir('pwup', '/tmp')
|
25
|
-
# these are the compressed ones
|
26
|
+
# these are the compressed ones or directories
|
27
|
+
unless files.respond_to? :each
|
28
|
+
files = [files]
|
29
|
+
end
|
26
30
|
files.each do |file|
|
27
|
-
|
31
|
+
unless process? file
|
28
32
|
puts "Skipping, can't process file #{file}"
|
29
33
|
next
|
30
34
|
end
|
@@ -33,22 +37,29 @@ module PwUp
|
|
33
37
|
unpack file, target_dir
|
34
38
|
end
|
35
39
|
# filter only the images
|
36
|
-
|
40
|
+
p1 = Pathname.new target_dir
|
41
|
+
images = Dir.glob(IMAGE_TYPES.map {|i| p1 + "**" + i} ,File::FNM_CASEFOLD)
|
37
42
|
puts "Found #{images.length} images"
|
38
43
|
# exit if no images where found
|
39
44
|
return if images.length == 0
|
40
45
|
puts "Uploading to #{album_name}"
|
41
46
|
# create album
|
42
|
-
album = @picasa.create_album(
|
43
|
-
|
44
|
-
|
47
|
+
album = @picasa.create_album(
|
48
|
+
title: album_name,
|
49
|
+
summary: album_name,
|
50
|
+
location: "",
|
51
|
+
keywords: "",
|
52
|
+
timestamp: Time.now.to_i
|
53
|
+
)
|
45
54
|
puts "album name = #{album.name}"
|
46
55
|
images.each do |image|
|
47
56
|
file_name = File.join(target_dir, image)
|
48
57
|
puts "Reading #{file_name}"
|
49
58
|
image_data = open(file_name, "rb").read
|
50
|
-
|
51
|
-
|
59
|
+
@picasa.post_photo(
|
60
|
+
image_data, :album => album.name,
|
61
|
+
:summary => file_name, :title => file_name
|
62
|
+
)
|
52
63
|
puts "photo #{file_name} uploaded to #{album.name}"
|
53
64
|
end
|
54
65
|
end
|
@@ -56,13 +67,20 @@ module PwUp
|
|
56
67
|
private
|
57
68
|
def process?(file)
|
58
69
|
ext = File.extname(file)
|
59
|
-
COMMANDS.include? ext.downcase and File.exists? file
|
70
|
+
COMMANDS.include? ext.downcase and File.exists? file or File.directory? file
|
60
71
|
end
|
61
72
|
|
62
73
|
def unpack(file, target_dir)
|
63
|
-
|
64
|
-
|
65
|
-
|
74
|
+
# if it's a dir, copy all content to the target_dir
|
75
|
+
if File.directory? file
|
76
|
+
p1 = Pathname.new file
|
77
|
+
images = Dir.glob(IMAGE_TYPES.map {|i| p1 + "**" + i} ,File::FNM_CASEFOLD)
|
78
|
+
FileUtils.cp(images, target_dir)
|
79
|
+
else
|
80
|
+
ext = File.extname(file)
|
81
|
+
command = COMMANDS[ext] % {:file=>file, :target_dir=>target_dir}
|
82
|
+
system(command)
|
83
|
+
end
|
66
84
|
end
|
67
85
|
end
|
68
86
|
end
|