movie_organizer 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7885aa1f3f8cb1095d8710d11f6bbfcb06ae97016b1d068a3380f56f5eea650
4
- data.tar.gz: e234282cbc7fcc5bf81406f0f5705041023fa3d14960a46cd3f783a7e9c46f08
3
+ metadata.gz: 7f54c3650fd6f47604caa55e65e6849c3e205dbf56682c1a4e152992bde76ddd
4
+ data.tar.gz: 62dac5e6ffc9548d7f7560a3246bdd304d122c0bafd9a98e4f6a2d34b39ac769
5
5
  SHA512:
6
- metadata.gz: bab5fc2431675860b49fb64fd32b4bc8b8dc31bc83a061c93ccfa398eb1423546cdf968dd66abb3a7132b1272be089161da5c13377daa468218a68f636633c93
7
- data.tar.gz: a89986894a78352fa1135236b997b7832b3d28a0896c4c6e7a30f8a1dc4589c9d6413471b2617582758485d6e88cc31d6fa0ae14afe876647b85de854f010df8
6
+ metadata.gz: e3663b3c36305f0c5f8906c9273be61764dec2d1e57e5bc9d9b5e81fbf9427522c84b5f244a3b2282c0f045e283ac92d9856a8d75d97442498ca86e73646583c
7
+ data.tar.gz: 000717141ad377bf135acad6ba2b88a1abb14e9c6cc21c07d2d91cf9130182cb05beba1bcc9d6f1bc4607a8185d468d0062ea79eb30cef3127cfc2dd05276af5
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.9* (March 09, 2018)
2
+
3
+ * Handle timeouts for remote SSH hosts
4
+
1
5
  *0.1.8* (March 03, 2018)
2
6
 
3
7
  * Prompt for movie directory setting if missing
@@ -3,12 +3,13 @@
3
3
  module MovieOrganizer
4
4
  class FileCopier
5
5
  attr_accessor :filename, :target_file, :options
6
- attr_reader :username, :hostname, :remote_filename
6
+ attr_reader :username, :hostname, :remote_filename, :logger
7
7
 
8
8
  def initialize(filename, target_file, options)
9
9
  @filename = filename
10
10
  @target_file = target_file
11
11
  @options = options
12
+ @logger = Logger.instance
12
13
  end
13
14
 
14
15
  def copy
@@ -29,12 +30,8 @@ module MovieOrganizer
29
30
  def remote_copy
30
31
  parse_target
31
32
  return do_dry_run if options[:dry_run]
32
- Net::SSH.start(hostname, username) do |ssh|
33
- ssh.exec("mkdir -p '#{target_dir}'")
34
- end
35
- Net::SCP.start(hostname, username) do |scp|
36
- scp.upload!(filename, remote_filename)
37
- end
33
+ create_remote_dir
34
+ copy_file_to_remote
38
35
  end
39
36
 
40
37
  def do_dry_run
@@ -58,12 +55,28 @@ module MovieOrganizer
58
55
  @hostname = md[2]
59
56
  @remote_filename = md[3]
60
57
  if @username.nil? || @hostname.nil? || @remote_filename.nil?
61
- fail 'SSH path not formatted properly. Use [ssh://username@hostname/absolute/path]'
58
+ raise 'SSH path not formatted properly. Use [ssh://username@hostname/absolute/path]'
62
59
  end
63
60
  end
64
61
 
65
62
  def ssh?
66
63
  target_file.match?(/^ssh:/)
67
64
  end
65
+
66
+ def create_remote_dir
67
+ Net::SSH.start(hostname, username, timeout: 5) do |ssh|
68
+ ssh.exec("mkdir -p '#{target_dir}'")
69
+ end
70
+ rescue Net::SSH::ConnectionTimeout, Errno::EHOSTUNREACH, Errno::EHOSTDOWN
71
+ logger.error("ConnectionTimeout: the host '#{hostname}' is unreachable.".red)
72
+ end
73
+
74
+ def copy_file_to_remote
75
+ Net::SCP.start(hostname, username) do |scp|
76
+ scp.upload!(filename, remote_filename)
77
+ end
78
+ rescue Net::SSH::ConnectionTimeout, Errno::EHOSTUNREACH, Errno::EHOSTDOWN
79
+ logger.error("ConnectionTimeout: the host '#{hostname}' is unreachable.".red)
80
+ end
68
81
  end
69
82
  end
@@ -12,7 +12,7 @@ module MovieOrganizer
12
12
  def process!
13
13
  target_dir = File.join(MovieOrganizer.movie_directory, "#{title} (#{year})")
14
14
  target_file = File.join(target_dir, processed_filename)
15
- logger.info(" target dir: [#{target_dir}]")
15
+ # logger.info(" target dir: [#{target_dir}]")
16
16
  logger.info(" target file: [#{target_file.green.bold}]")
17
17
  fc = FileCopier.new(filename, target_file, options)
18
18
  fc.copy
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MovieOrganizer
4
- VERSION = '0.1.8'.freeze
4
+ VERSION = '0.1.9'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: movie_organizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blackburn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-03 00:00:00.000000000 Z
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler