andhapp-players 1.0.0 → 1.1.0
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/VERSION.yml +1 -1
- data/bin/players +2 -3
- data/lib/convert_images_to_photoshop_layers.vbs +13 -4
- data/lib/options.yaml +2 -2
- data/lib/pconstants.rb +0 -2
- data/lib/players.rb +13 -34
- data/players.gemspec +2 -2
- data/test/ts_players.rb +8 -19
- metadata +2 -2
data/VERSION.yml
CHANGED
data/bin/players
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
|
2
2
|
Dim appRef
|
3
3
|
Dim originalRulerUnits
|
4
|
-
Dim docRef, artLayerRef, imageLayerRef, currentDoc
|
5
|
-
Dim fso, folder, files
|
4
|
+
Dim docRef, artLayerRef, textItemRef, imageLayerRef, currentDoc
|
5
|
+
Dim fso, folder, files, srcFolderName, srcFolderLocation, destFolderLocation, destFileName
|
6
6
|
|
7
7
|
Set appRef = CreateObject("Photoshop.Application")
|
8
8
|
|
9
|
-
' Remember current unit settings and then set units to
|
9
|
+
' Remember current unit settings and then set units to
|
10
|
+
' the value expected by this script
|
10
11
|
originalRulerUnits = appRef.Preferences.RulerUnits
|
11
12
|
appRef.Preferences.RulerUnits = 2
|
12
13
|
|
14
|
+
'set srcFolderName = Wscript.Arguments(0)
|
15
|
+
'WScript.Echo directoryName
|
16
|
+
|
17
|
+
'Set srcFolderLocation = "J:\Projects\GitRepository\photoshopScripts\jobBag1232774143\"
|
18
|
+
'Set destFolderLocation = "J:\Projects\GitRepository\photoshopScripts\"
|
19
|
+
'Set destFileName = srcFolderName + "_collated_psd_version"
|
20
|
+
|
13
21
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
14
22
|
Set folder = fso.GetFolder(Wscript.Arguments(0))
|
15
23
|
Set files = folder.Files
|
@@ -40,5 +48,6 @@ photoshopSaveOptions, True, 2
|
|
40
48
|
|
41
49
|
' don�t save anything we did
|
42
50
|
appRef.ActiveDocument.Close(2)
|
51
|
+
'the enumerated value Close(2) = PsSaveOptions >2 (psDoNotSaveChanges)
|
43
52
|
|
44
|
-
appRef.Quit
|
53
|
+
appRef.Quit
|
data/lib/options.yaml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
website_address: 'http://geekandpoke.smugmug.com/gallery/5297189_ToNCK#323502743_kns4p'
|
2
2
|
destination_folder: final
|
3
3
|
destination_filename: final.psd
|
4
|
-
extension_of_files_to_download: jpg #
|
5
|
-
close_photoshop_after_processing:
|
4
|
+
extension_of_files_to_download: jpg # jpg or gif or png
|
5
|
+
close_photoshop_after_processing: 0 # yes(0) | no(1)
|
data/lib/pconstants.rb
CHANGED
data/lib/players.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
%w(net/http hpricot ftools yaml).each {|x| require x}
|
2
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'pconstants')
|
1
|
+
%w(net/http hpricot ftools yaml ..\lib\pconstants).each {|x| require x}
|
3
2
|
|
4
3
|
module Players
|
5
4
|
|
@@ -9,45 +8,25 @@ module Players
|
|
9
8
|
|
10
9
|
attr_reader :options
|
11
10
|
|
12
|
-
def sinit
|
13
|
-
create_player_init_directory
|
14
|
-
copy_options_file_in_init_dir
|
15
|
-
load_options
|
16
|
-
end
|
17
|
-
|
18
11
|
def run
|
19
|
-
|
20
|
-
all_image_elements = collect_source_of_image_element(reponse)
|
21
|
-
required_image_elements = select_the_supplied_extension_elements(all_image_elements, @options["extension_of_files_to_download"])
|
22
|
-
create_destination_directory("#{Pconstants::INIT_DIR}#{File::SEPARATOR}#{@options['destination_folder']}")
|
23
|
-
elements_with_full_url = build_full_url(get_host_name_from_protocol_sanitised_url(get_protocol_sanitised_url(@options["website_address"])), required_image_elements)
|
24
|
-
download_the_images("#{Pconstants::INIT_DIR}#{File::SEPARATOR}#{@options['destination_folder']}", elements_with_full_url)
|
25
|
-
make_call_to_external_vb_script("#{Pconstants::INIT_DIR}#{File::SEPARATOR}#{@options['destination_folder']}")
|
26
|
-
end
|
27
|
-
|
28
|
-
def create_player_init_directory
|
29
|
-
FileUtils.mkdir_p("#{Pconstants::INIT_DIR}")
|
30
|
-
end
|
31
|
-
|
32
|
-
def copy_options_file_in_init_dir
|
33
|
-
File.copy(File.join(File.dirname(__FILE__), '..', 'lib', "#{Pconstants::OPTIONS_FILE}"), "#{Pconstants::INIT_DIR}#{File::SEPARATOR}#{Pconstants::OPTIONS_FILE}")
|
12
|
+
load_options
|
34
13
|
end
|
35
14
|
|
36
15
|
def load_options(name = nil)
|
37
|
-
fail "no options file to load" if !files_in_a_folder(
|
38
|
-
@options = YAML::load(
|
16
|
+
fail "no options file to load" if !files_in_a_folder("..\\lib").index("#{name || Pconstants::OPTIONS_FILE}")
|
17
|
+
@options = YAML::load(File.open("..\\lib\\#{Pconstants::OPTIONS_FILE}"))
|
39
18
|
end
|
40
19
|
|
41
20
|
def files_in_a_folder(name)
|
42
|
-
Dir.entries(name).each {|x| [] << x if !File.directory?(x)}
|
21
|
+
Dir.entries(name).each {|x| [] << x if !File.directory?(x)}
|
43
22
|
end
|
44
23
|
|
45
24
|
def get_protocol_sanitised_url(url)
|
46
|
-
url.split(
|
25
|
+
url.split(Pconstants::HTTP).last
|
47
26
|
end
|
48
27
|
|
49
28
|
def get_host_name_from_protocol_sanitised_url(url)
|
50
|
-
url.split("
|
29
|
+
url.split("/").first
|
51
30
|
end
|
52
31
|
|
53
32
|
def get_remaining_url_from_protocol_sanitised_url(url)
|
@@ -60,7 +39,7 @@ module Players
|
|
60
39
|
remaining_address = get_remaining_url_from_protocol_sanitised_url(url)
|
61
40
|
result = Net::HTTP.get_response(main_host_name, remaining_address)
|
62
41
|
fail "could not connect to the site" if result.nil?
|
63
|
-
result.body
|
42
|
+
@response = result.body
|
64
43
|
end
|
65
44
|
|
66
45
|
def collect_source_of_image_element(response)
|
@@ -74,7 +53,7 @@ module Players
|
|
74
53
|
end
|
75
54
|
|
76
55
|
def create_destination_directory(name)
|
77
|
-
FileUtils.
|
56
|
+
FileUtils.mkdir(name)
|
78
57
|
end
|
79
58
|
|
80
59
|
def build_full_url(host_name, elements)
|
@@ -82,7 +61,7 @@ module Players
|
|
82
61
|
end
|
83
62
|
|
84
63
|
def get_image_name(value)
|
85
|
-
value[value.rindex("
|
64
|
+
value[value.rindex("/")+1..value.length]
|
86
65
|
end
|
87
66
|
|
88
67
|
def download_the_images(destination_dir, elements)
|
@@ -92,12 +71,12 @@ module Players
|
|
92
71
|
image_name = get_image_name(query_string)
|
93
72
|
Net::HTTP.start(host) { |http|
|
94
73
|
resp = http.get(query_string)
|
95
|
-
open(destination_dir + "
|
74
|
+
open(destination_dir + "/" + image_name, "wb") { |file| file.write(resp.body) }
|
96
75
|
}
|
97
76
|
}
|
98
77
|
end
|
99
|
-
|
100
|
-
def make_call_to_external_vb_script
|
78
|
+
|
79
|
+
def make_call_to_external_vb_script
|
101
80
|
system "cscript convert_images_to_photoshop_layers.vbs #{directory_name}"
|
102
81
|
end
|
103
82
|
|
data/players.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{players}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Anuj Dutta"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-04-29}
|
10
10
|
s.default_executable = %q{players}
|
11
11
|
s.description = %q{Players - Photoshop Layers}
|
12
12
|
s.email = %q{anuj@andhapp.com}
|
data/test/ts_players.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
%w(test/unit redgreen shoulda rr fileutils ftools).each{|x| require x}
|
2
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'players')
|
1
|
+
%w(test/unit redgreen shoulda rr fileutils ..\lib\players ftools).each{|x| require x}
|
3
2
|
|
4
3
|
class TestPlayers < Test::Unit::TestCase
|
5
4
|
|
6
5
|
include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
|
7
6
|
|
8
7
|
def files_in_a_folder(name)
|
9
|
-
Dir.entries(name).each {|x| [] << x if !File.directory?(x)}
|
8
|
+
Dir.entries(name).each {|x| [] << x if !File.directory?(x)}
|
10
9
|
end
|
11
10
|
|
12
11
|
def dir_in_a_folder(name)
|
@@ -16,8 +15,6 @@ class TestPlayers < Test::Unit::TestCase
|
|
16
15
|
context "" do
|
17
16
|
setup do
|
18
17
|
@player = Players::Pscript.new
|
19
|
-
@player.create_player_init_directory
|
20
|
-
@player.copy_options_file_in_init_dir
|
21
18
|
@options = @player.load_options
|
22
19
|
|
23
20
|
@response = '<div id="photos">
|
@@ -28,15 +25,7 @@ class TestPlayers < Test::Unit::TestCase
|
|
28
25
|
</div>'
|
29
26
|
|
30
27
|
end
|
31
|
-
|
32
|
-
should "initialise the player script in a folder called players in the directory where it is run" do
|
33
|
-
dir_in_a_folder(".").include?("players-init")
|
34
|
-
end
|
35
|
-
|
36
|
-
should "copy the options file in this folder and use this options file" do
|
37
|
-
files_in_a_folder(".").include?("options.yaml")
|
38
|
-
end
|
39
|
-
|
28
|
+
|
40
29
|
should "raise exception if the options file is not present" do
|
41
30
|
assert_raises(RuntimeError) {@player.load_options('some_options.yaml')}
|
42
31
|
end
|
@@ -47,7 +36,7 @@ class TestPlayers < Test::Unit::TestCase
|
|
47
36
|
assert_equal @options["destination_folder"], 'final'
|
48
37
|
assert_equal @options["destination_filename"], 'final.psd'
|
49
38
|
assert_equal @options["extension_of_files_to_download"], 'jpg'
|
50
|
-
assert_equal @options["close_photoshop_after_processing"],
|
39
|
+
assert_equal @options["close_photoshop_after_processing"], 0
|
51
40
|
end
|
52
41
|
|
53
42
|
should "get protocal sanitised url" do
|
@@ -81,8 +70,8 @@ class TestPlayers < Test::Unit::TestCase
|
|
81
70
|
end
|
82
71
|
|
83
72
|
should "create destination directory" do
|
84
|
-
@player.create_destination_directory("
|
85
|
-
assert dir_in_a_folder("
|
73
|
+
@player.create_destination_directory("test_final")
|
74
|
+
assert dir_in_a_folder(".").include?("test_final")
|
86
75
|
end
|
87
76
|
|
88
77
|
should "build required images full url" do
|
@@ -98,11 +87,11 @@ class TestPlayers < Test::Unit::TestCase
|
|
98
87
|
|
99
88
|
should "download the images" do
|
100
89
|
@player.download_the_images(".", ["geekandpoke.smugmug.com/photos/323503251_vdoAH-Th.jpg"])
|
101
|
-
files_in_a_folder(".").include?("
|
90
|
+
files_in_a_folder(".").include?("spacer.gif")
|
102
91
|
end
|
103
92
|
|
104
93
|
teardown do
|
105
|
-
FileUtils.
|
94
|
+
FileUtils.rmdir("test_final") if test(?d, "test_final")
|
106
95
|
FileUtils.rm("323503251_vdoAH-Th.jpg") if File.exists?("323503251_vdoAH-Th.jpg")
|
107
96
|
end
|
108
97
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: andhapp-players
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anuj Dutta
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-29 00:00:00 -07:00
|
13
13
|
default_executable: players
|
14
14
|
dependencies: []
|
15
15
|
|