Merge from working branch

This commit is contained in:
Steven Miers 2014-12-15 12:15:44 -06:00
parent ac2daed4da
commit 6407d2f22a
3 changed files with 38 additions and 12 deletions

0
ruby/bin/jamtrack.rb Normal file → Executable file
View File

View File

@ -1,20 +1,36 @@
require 'json'
require 'tempfile'
require 'open3'
module JamRuby
# describes an audio track (like the drums, or guitar) that comprises a JamTrack
# Interact with external python tools to create the JKZ
class JamTracksManager
class << self
def save_jam_track(jam_track, user)
spec = Gem::Specification.find_by_name("jam_ruby")
py_root = spec.gem_dir + "/lib/py/jam_tracks/"
puts "Executing python in #{py_root}"
def save_jam_track_jkz(user, jam_track)
py_root = File.expand_path(File.join("..", "..", "jamtracks"))
tmp_dir = Dir::Tmpname.make_tmpname("/tmp/jamtrack", nil)
puts "Executing python in #{py_root}, outputting to #{tmp_dir}"
sku=""#jam_track.sku
public_key=""
private_key=""
tracks_filename=""
output_jkz=""
title=""
`python #{py_root}jkcreate.py -D -k #{sku} -c art.png -p #{public_key} -s #{private_key} -I #{tracks_filename} -o #{output_jkz} -t '#{title}'`
sku=jam_track.id
tracks_filename=tmp_dir + "/jamtrack.info"
output_jkz="tmp_dir/#{jam_track.name.tableize}.jkz"
title=jam_track.name
# From http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby/5970819#5970819:
#Open3.popen3("ls") do |stdin, stdout, stderr, wait_thr|
Open3.popen3("python",
"#{py_root}/jkcreate.py",
"-D -k #{sku} -c art.png -p #{tmp_dir}/pkey.pem -s #{tmp_dir}/skey.pem -I #{tracks_filename} -o #{output_jkz} -t '#{title}'"
) do |stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid
exit_status = wait_thr.value
err = stderr.read(1000)
raise ArgumentError, "Error calling python script: #{err}" if err.present?
end
tmp_dir
end
end
end

View File

@ -27,5 +27,15 @@ describe JamTrackRight do
right_2.errors[:user_id].should == ['has already been taken']
end
end
it "saves JKZ" do
user = FactoryGirl.create(:user)
jam_track = FactoryGirl.create(:jam_track)
right = JamTrackRight.create(:user=>user, :jam_track=>jam_track)
expect {
JamRuby::JamTracksManager.save_jam_track_jkz(user, jam_track)
}.to_not raise_error
end
end