andhapp-players 1.1.0 → 1.1.1

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