[DRE-commits] [SCM] shelr.git branch, master, updated. upstream/0.11.6-17-g9cb47e8
Antono Vasiljev
self at antono.info
Sat Apr 7 12:11:19 UTC 2012
The following commit has been merged in the master branch:
commit 9cb47e851db8afefa98aa38602c15b9f89e9f108
Author: Antono Vasiljev <self at antono.info>
Date: Sat Apr 7 15:10:49 2012 +0300
Lock record while recording. Disable publishing when locked
diff --git a/lib/shelr/publisher.rb b/lib/shelr/publisher.rb
index ff57273..4485d89 100644
--- a/lib/shelr/publisher.rb
+++ b/lib/shelr/publisher.rb
@@ -5,6 +5,7 @@ module Shelr
class Publisher
def publish(id)
+ ensure_unlocked(id)
with_exception_handler do
uri = URI.parse(Shelr::API_URL + '/records')
params = { 'record' => prepare(id) }
@@ -24,6 +25,17 @@ module Shelr
private
+ def ensure_unlocked(id)
+ lock_path = File.join(Shelr.data_dir(id), 'lock')
+ if File.exist?(lock_path)
+ puts "=> Cannot publish"
+ puts "=> Record locked on #{File.read(lock_path)}"
+ puts "=> Esure no other shelr process running"
+ puts "=> Or remove lock file manually: #{lock_path}"
+ exit 0
+ end
+ end
+
def with_exception_handler(&block)
yield
rescue => e
diff --git a/lib/shelr/recorder.rb b/lib/shelr/recorder.rb
index f35c6f4..53fad6b 100644
--- a/lib/shelr/recorder.rb
+++ b/lib/shelr/recorder.rb
@@ -14,19 +14,21 @@ module Shelr
def record!
check_record_dir
- init_terminal
- request_metadata
- STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
- STDOUT.puts "=> Your session started"
- STDOUT.puts "=> Please, do not resize your terminal while recording"
- STDOUT.puts "=> Press Ctrl+D or 'exit' to finish recording"
- system(recorder_cmd)
- save_as_typescript if Shelr.backend == 'ttyrec'
- STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
- STDOUT.puts "=> Session finished"
- STDOUT.puts
- STDOUT.puts "Replay : #{Shelr::APP_NAME} play last"
- STDOUT.puts "Publish : #{Shelr::APP_NAME} push last"
+ with_lock_file do
+ init_terminal
+ request_metadata
+ STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
+ STDOUT.puts "=> Your session started"
+ STDOUT.puts "=> Please, do not resize your terminal while recording"
+ STDOUT.puts "=> Press Ctrl+D or 'exit' to finish recording"
+ system(recorder_cmd)
+ save_as_typescript if Shelr.backend == 'ttyrec'
+ STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
+ STDOUT.puts "=> Session finished"
+ STDOUT.puts
+ STDOUT.puts "Replay : #{Shelr::APP_NAME} play last"
+ STDOUT.puts "Publish : #{Shelr::APP_NAME} push last"
+ end
end
def request_metadata
@@ -43,6 +45,15 @@ module Shelr
private
+ def with_lock_file
+ lock_path = record_file('lock')
+ File.open(lock_path, 'w') do |f|
+ f.puts Time.now.to_s
+ end
+ yield
+ FileUtils.rm(lock_path)
+ end
+
def save_as_typescript
puts '=> Converting ttyrec -> typescript'
diff --git a/spec/shelr/publisher_spec.rb b/spec/shelr/publisher_spec.rb
index fd0039f..577cd9f 100644
--- a/spec/shelr/publisher_spec.rb
+++ b/spec/shelr/publisher_spec.rb
@@ -9,12 +9,20 @@ describe Shelr::Publisher do
end
describe "#publish(id)" do
- it "prepares record as json" do
+ before do
STDIN.stub(:gets).and_return('something')
subject.stub(:handle_response)
subject.stub(:prepare).and_return(Fixture::load('record1.json'))
+ end
+
+ it "prepares record as json" do
subject.should_receive(:prepare).with('hello')
+ subject.publish('hello')
+ end
+ it "it checks that file is not locked" do
+ subject.stub(:ensure_unlocked)
+ subject.should_receive(:ensure_unlocked).with('hello')
subject.publish('hello')
end
end
diff --git a/spec/shelr/recorder_spec.rb b/spec/shelr/recorder_spec.rb
index 8b4f199..8a7f32e 100644
--- a/spec/shelr/recorder_spec.rb
+++ b/spec/shelr/recorder_spec.rb
@@ -12,12 +12,19 @@ describe Shelr::Recorder do
describe "#record!" do
before do
subject.stub(:system).with(anything).and_return(true)
+ subject.stub(:record_id => "1")
+ subject.stub(:with_lock_file).and_yield
end
it "starts script session" do
subject.should_receive(:system).with(/script/)
subject.record!
end
+
+ it "creates lock file" do
+ subject.should_receive(:with_lock_file)
+ subject.record!
+ end
end
describe "#request_metadata" do
--
shelr.git
More information about the Pkg-ruby-extras-commits
mailing list