Skip to content

Instantly share code, notes, and snippets.

@vsalbaba
Created August 27, 2009 14:14
Show Gist options
  • Save vsalbaba/176303 to your computer and use it in GitHub Desktop.
Save vsalbaba/176303 to your computer and use it in GitHub Desktop.
def self.pkg(platform, opt)
# first try internet
# On the url there should be link to latest revision of our release.
# so programs writen for raisins will use latest revision of raisins and will not break with possible changes in future releases.
# I presume http://shoes.heroku.com/
url =
case opt
when I_YES; "http://rock.nalinuxu.cz/~darktatka/pkg/#{RELEASE_NAME.downcase}/#{platform}/shoes"
when I_NOV; "http://shoes.heroku.com/pkg/#{RELEASE_NAME.downcase}/#{platform}/shoes-novideo"
end
begin
url = open(url).read.strip
debug url
rescue Exception => e
error e
url = nil
end
if url then
# Now, we have the real url. The idea is to donload it only if we dont have it yet.
# I suspect something like
# shoes#{RELEASE_ID}-#{RELEASE_NAME}-#{REVISION}-#{video/novideo}.#{PLATFORM_DEPENDENT_EXTENSION}
# example: shoes2-raisins-1134-novideo.exe
# would be a good idea for filename.
filename = File.basename(url)
local_file_path = File.join(LIB_DIR, RELEASE_NAME.downcase, platform, filename)
debug local_file_path
if File.exists? local_file_path then
open(local_file_path)
else
FileUtils.makedirs File.dirname(local_file_path)
#here it can fail if the link downloaded from heroku is dead FIXME
File.open(local_file_path, "wb") do |f|
f.write(open(url))
end
open(local_file_path)
end
else
# shoes.heroku.com is probably down or whatever. Try to use previously downloaded file.
extension = case platform
when "win32" then
"exe"
when "linux" then
"run"
when "osx" then
"dmg"
else
raise "Unknown platform"
end
# it should probably use the latest downloaded version, not based on current revision. FIXME
filename =
case opt
when I_YES then
"shoes#{RELEASE_ID}-#{RELEASE_NAME.downcase}-#{REVISION}-video.#{extension}"
when I_NOV then
"shoes#{RELEASE_ID}-#{RELEASE_NAME.downcase}-#{REVISION}-novideo.#{extension}"
end
FileUtils.makedirs File.join(LIB_DIR, RELEASE_NAME.downcase, platform)
debug Dir.entries(File.join(LIB_DIR, RELEASE_NAME.downcase, platform))
local_file_path = File.join(LIB_DIR, RELEASE_NAME.downcase, platform, filename)
if File.exists? local_file_path; open(local_file_path)
else
alert "Couldnt find file #{filename} remotely or localy."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment