scccp 0.0.3 → 0.0.4

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scccp (0.0.2)
4
+ scccp (0.0.4)
5
5
  net-scp
6
6
 
7
7
  GEM
data/example/sample.rb CHANGED
@@ -1,18 +1,11 @@
1
- # https://github.com/pacojp/batchbase
2
- require 'batchbase'
3
1
  require 'scccp'
4
2
 
5
- include Batchbase::Core
6
- #create_logger('/tmp/batchbase_test_sample1.log')
7
- create_logger(STDERR)
8
-
9
3
  REMOTE_HOST = 'localhost'
10
4
  REMOTE_USER_NAME = 'paco'
11
5
  REMOTE_USER_PASSWORD = nil
12
6
  WORK_SPACE = '/tmp/test/scccp_sample/'
13
7
  REMOTE_PATH = WORK_SPACE + 'remote/'
14
8
  QUEUE_FOLDER = WORK_SPACE + 'from/'
15
- LOCKFILE = WORK_SPACE + '.scccp.lock'
16
9
  OK_FOLDER = WORK_SPACE + 'ok'
17
10
  NG_FOLDER = WORK_SPACE + 'ng'
18
11
 
@@ -26,16 +19,12 @@ touch /tmp/test/scccp_sample/from/file2.tmp
26
19
  touch /tmp/test/scccp_sample/from/file3.ok
27
20
  MKDIR
28
21
 
29
- execute do
30
- scccp = Scccp::Scp.new()
31
- scccp.logger = logger
32
- scccp.remote_host = REMOTE_HOST
33
- scccp.remote_user_name = REMOTE_USER_NAME
34
- scccp.remote_user_password = REMOTE_USER_PASSWORD
35
- scccp.remote_path = REMOTE_PATH
36
- scccp.queue_folder = QUEUE_FOLDER
37
- scccp.lockfile = LOCKFILE
38
- scccp.ok_folder = OK_FOLDER
39
- scccp.ng_folder = NG_FOLDER
40
- scccp.proceed
41
- end
22
+ scccp = Scccp::Scp.new
23
+ scccp.remote_host = REMOTE_HOST
24
+ scccp.remote_user_name = REMOTE_USER_NAME
25
+ scccp.remote_user_password = REMOTE_USER_PASSWORD
26
+ scccp.remote_path = REMOTE_PATH
27
+ scccp.queue_folder = QUEUE_FOLDER
28
+ scccp.ok_folder = OK_FOLDER
29
+ scccp.ng_folder = NG_FOLDER
30
+ scccp.proceed
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'scccp'
4
+
5
+ require 'batchbase'
6
+ include Batchbase::Core
7
+ # https://github.com/pacojp/batchbase
8
+ #
9
+ # 2重起動防止
10
+ # シグナル管理
11
+ # デーモン化
12
+ #
13
+
14
+ #create_logger('/tmp/batchbase_test_sample1.log')
15
+ create_logger(STDOUT)
16
+ def receive_signal(signal)
17
+ logger.info("receive signal #{signal}")
18
+ @stop = true
19
+ end
20
+ set_signal_observer(:receive_signal,self)
21
+ @stop = false
22
+
23
+ REMOTE_HOST = 'localhost'
24
+ REMOTE_USER_NAME = 'paco'
25
+ REMOTE_USER_PASSWORD = nil
26
+ WORK_SPACE = '/tmp/test/scccp_sample/'
27
+ REMOTE_PATH = WORK_SPACE + 'remote/'
28
+ QUEUE_FOLDER = WORK_SPACE + 'from/'
29
+ LOCKFILE = WORK_SPACE + '.scccp.lock'
30
+ OK_FOLDER = WORK_SPACE + 'ok'
31
+ NG_FOLDER = WORK_SPACE + 'ng'
32
+
33
+ <<`MKDIR`
34
+ mkdir -p /tmp/test/scccp_sample/from
35
+ mkdir -p /tmp/test/scccp_sample/ok
36
+ mkdir -p /tmp/test/scccp_sample/ng
37
+ mkdir -p /tmp/test/scccp_sample/remote
38
+ touch /tmp/test/scccp_sample/from/file1
39
+ touch /tmp/test/scccp_sample/from/file2.tmp
40
+ touch /tmp/test/scccp_sample/from/file3.ok
41
+ MKDIR
42
+
43
+ execute(:pid_file=>LOCKFILE) do
44
+ scccp = Scccp::Scp.new()
45
+ scccp.logger = logger
46
+ scccp.remote_host = REMOTE_HOST
47
+ scccp.remote_user_name = REMOTE_USER_NAME
48
+ scccp.remote_user_password = REMOTE_USER_PASSWORD
49
+ scccp.remote_path = REMOTE_PATH
50
+ scccp.queue_folder = QUEUE_FOLDER
51
+ scccp.ok_folder = OK_FOLDER
52
+ scccp.ng_folder = NG_FOLDER
53
+ set_signal_observer(:receive_signal,scccp)
54
+
55
+ loop do
56
+ cnt = scccp.proceed
57
+ logger.info "#{cnt} files uploaded"
58
+ break_loop = false
59
+ 5.times do
60
+ sleep 1
61
+ if @stop
62
+ break_loop = true
63
+ break
64
+ end
65
+ end
66
+ break if break_loop
67
+ end
68
+ end
data/lib/scccp/scp.rb CHANGED
@@ -3,8 +3,6 @@ require 'fileutils'
3
3
 
4
4
  module Scccp
5
5
  class Scp
6
- SIGNALS = [ :QUIT, :INT, :TERM, :USR1, :USR2, :HUP ]
7
-
8
6
  ATTRS = [
9
7
  :remote_host,
10
8
  :remote_user_name,
@@ -15,7 +13,6 @@ module Scccp
15
13
  :ok_folder,
16
14
  :ng_folder,
17
15
  :timeout,
18
- :lockfile,
19
16
  :logger2ssh,
20
17
  :logger
21
18
  ]
@@ -24,10 +21,11 @@ module Scccp
24
21
  end
25
22
 
26
23
  def initialize(opts={})
24
+ self.remote_port = 22
25
+ self.logger = Logger.new(STDOUT)
27
26
  opts.each do |k, v|
28
27
  send("#{k}=", v)
29
28
  end
30
- self.remote_port ||= 22
31
29
  end
32
30
 
33
31
  def attrs_ok?
@@ -35,7 +33,7 @@ module Scccp
35
33
  #v = instance_variable_get("@#{attr.to_s}")
36
34
  v = send(attr)
37
35
  case attr
38
- when :remote_user_name,:remote_user_password,:timeout,:logger2ssh,:lockfile
36
+ when :remote_user_name,:remote_user_password,:timeout,:logger2ssh
39
37
  next
40
38
  when :queue_folder,:ok_folder,:ng_folder
41
39
  unless File.directory?(v)
@@ -56,7 +54,6 @@ module Scccp
56
54
 
57
55
  def proceed
58
56
  attrs_ok?
59
- SIGNALS.each { |sig| trap(sig){receive_signal(sig)} }
60
57
 
61
58
  opt = {}
62
59
  opt[:port] = remote_port
@@ -76,16 +73,11 @@ module Scccp
76
73
  !(o =~ /\.(tmp|ok)$/)
77
74
  end
78
75
 
79
- if lockfile
80
- if File.exists?(lockfile)
81
- logger.warn("lockfile:#{lockfile} already exists")
82
- return :lockfile_error
83
- end
84
- File.open(lockfile, "w"){|f|f.write $$}
76
+ unless @__not_first_time_to_proceed
77
+ logger.info("queue_folder is #{queue_folder}")
78
+ logger.info("target is #{remote_user_name}@#{remote_host}:#{remote_port}:#{remote_path}")
79
+ @__not_first_time_to_proceed = true
85
80
  end
86
-
87
- logger.info("queue_folder is #{queue_folder}")
88
- logger.info("target is #{remote_host}:#{remote_port}:#{remote_path}")
89
81
  #logger.info(files.inspect)
90
82
  uploaded_count = 0
91
83
 
@@ -126,9 +118,6 @@ module Scccp
126
118
  if scp
127
119
  scp.session.close
128
120
  end
129
- if lockfile
130
- FileUtils.rm lockfile
131
- end
132
121
  end
133
122
 
134
123
  uploaded_count
data/lib/scccp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scccp
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/test/test.rb CHANGED
@@ -85,43 +85,6 @@ class TestScccp < Test::Unit::TestCase
85
85
  end
86
86
  end
87
87
 
88
-
89
- def test_signal
90
- prepare_heavy_test
91
-
92
- th = Thread.new do
93
- scccp = Scccp::Scp.new(attr.merge({:lockfile=>LOCK_FILE}))
94
- scccp.proceed
95
- end
96
-
97
- sleep 1
98
-
99
- assert_equal true, File.exists?(LOCK_FILE)
100
- `kill #{File.read(LOCK_FILE)}`
101
-
102
- sleep 1
103
- assert_equal false, File.exists?(LOCK_FILE)
104
-
105
- th.join
106
- end
107
-
108
-
109
- def test_lockfile
110
- prepare_heavy_test
111
-
112
- th = Thread.new do
113
- scccp = Scccp::Scp.new(attr.merge({:lockfile=>LOCK_FILE}))
114
- scccp.proceed
115
- end
116
-
117
- sleep 1
118
- assert_equal true, File.exists?(LOCK_FILE)
119
-
120
- scccp2 = Scccp::Scp.new(attr.merge({:lockfile=>LOCK_FILE}))
121
- assert_equal :lockfile_error, scccp2.proceed
122
- th.join
123
- end
124
-
125
88
  def test_connection_error
126
89
  scccp = Scccp::Scp.new(attr)
127
90
  scccp.remote_host = 'sefisfejisfe.sefijsefij.esfij'
@@ -133,7 +96,6 @@ class TestScccp < Test::Unit::TestCase
133
96
  assert_true File.exists?(QUEUE_FOLDER + "testfile2")
134
97
  end
135
98
 
136
-
137
99
  def test_scccp
138
100
  assert_true File.exists?(@l_file)
139
101
  assert_true File.exists?(@l_file1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scccp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-scp
@@ -40,6 +40,7 @@ files:
40
40
  - README.md
41
41
  - Rakefile
42
42
  - example/sample.rb
43
+ - example/sample_with_batchbase.rb
43
44
  - lib/scccp.rb
44
45
  - lib/scccp/scp.rb
45
46
  - lib/scccp/version.rb