- move things a bit and add Guga's Open3.popen3 method
This commit is contained in:
parent
e56ce0bd36
commit
6337713fb8
@ -1,6 +1,7 @@
|
||||
path = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
|
||||
$LOAD_PATH << path
|
||||
require 'recordandplayback/archiver'
|
||||
require 'recordandplayback/audio_archiver'
|
||||
require 'recordandplayback/collectors/events'
|
||||
require 'recordandplayback/collectors/audio'
|
||||
require 'recordandplayback/generators/events'
|
||||
@ -10,6 +11,12 @@ require 'recordandplayback/generators/audio_processor'
|
||||
require 'recordandplayback/generators/deskshare'
|
||||
|
||||
module BigBlueButton
|
||||
class MissingDirectoryException < Exception
|
||||
end
|
||||
|
||||
class FileNotFoundException < Exception
|
||||
end
|
||||
|
||||
# BigBlueButton logs information about its progress.
|
||||
# Replace with your own logger if you desire.
|
||||
#
|
||||
@ -29,6 +36,20 @@ module BigBlueButton
|
||||
@logger = logger
|
||||
end
|
||||
|
||||
def self.dir_exists?(dir)
|
||||
FileTest.directory?(dir)
|
||||
end
|
||||
|
||||
|
||||
def self.execute(command)
|
||||
Open3.popen3(command) do | stdin, stdout, stderr|
|
||||
BigBlueButton.logger.info("Executing: #{command}")
|
||||
errors = stderr.readlines
|
||||
BigBlueButton.logger.info( "Output: #{stdout.readlines} ")
|
||||
BigBlueButton.logger.info( "Error: stderr: #{errors}"); raise errors.to_s unless errors.empty?
|
||||
end
|
||||
end
|
||||
|
||||
module Archive
|
||||
# BigBlueButton logs information about its progress.
|
||||
# Replace with your own logger if you desire.
|
||||
|
32
record-and-playback/rap/lib/recordandplayback/audio_archiver.rb
Executable file
32
record-and-playback/rap/lib/recordandplayback/audio_archiver.rb
Executable file
@ -0,0 +1,32 @@
|
||||
require 'fileutils'
|
||||
|
||||
module BigBlueButton
|
||||
class AudioArchiver
|
||||
def initialize(logger)
|
||||
@log = logger
|
||||
end
|
||||
|
||||
def archive(meeting_id, from_dir, to_dir)
|
||||
if BigBlueButton.dir_exists?(from_dir)
|
||||
@log.info("#{from_dir} exists")
|
||||
if BigBlueButton.dir_exists?(to_dir)
|
||||
@log.info("#{to_dir} exists")
|
||||
if not Dir.glob("#{from_dir}/#{meeting_id}*.wav").empty?
|
||||
Dir.glob("#{from_dir}/#{meeting_id}*.wav").each do |file|
|
||||
@log.info("Copying file #{file} to #{to_dir}")
|
||||
FileUtils.cp(file, to_dir)
|
||||
end
|
||||
else
|
||||
@log.warn("Audio for #{meeting-id} not found.")
|
||||
end
|
||||
else
|
||||
@log.warn("#{to_dir} directory not found.")
|
||||
raise MissingDirectoryException, "Directory not found: [#{to_dir}]"
|
||||
end
|
||||
else
|
||||
@log.warn("#{from_dir} directory not found.")
|
||||
raise MissingDirectoryException, "Directory not found: [#{from_dir}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
7
record-and-playback/rap/lib/recordandplayback/helper.rb
Executable file
7
record-and-playback/rap/lib/recordandplayback/helper.rb
Executable file
@ -0,0 +1,7 @@
|
||||
module BigBlueButton
|
||||
def self.directory_exist?(location)
|
||||
FileTest.directory?(location)
|
||||
end
|
||||
end
|
||||
|
||||
|
21
record-and-playback/rap/spec/recordandplayback/archive_audio_spec.rb
Executable file
21
record-and-playback/rap/spec/recordandplayback/archive_audio_spec.rb
Executable file
@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
require 'fileutils'
|
||||
|
||||
module BigBlueButton
|
||||
describe AudioArchiver do
|
||||
context "#success" do
|
||||
it "should copy audio recording to archive" do
|
||||
FileTest.stub(:directory?).and_return(true)
|
||||
FileUtils.stub(:cp)
|
||||
Dir.stub(:glob).and_return(['file1.wav', 'file2.wav'])
|
||||
from_dir = '/from/dir/'
|
||||
to_dir = '/to/dir/'
|
||||
meeting_id = 'meeting-id'
|
||||
logger = Logger.new(STDOUT)
|
||||
logger.level = Logger::INFO
|
||||
archiver = AudioArchiver.new(logger)
|
||||
archiver.archive(meeting_id, from_dir, to_dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user