Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improving upload behavior

  • Loading branch information...
commit d16064f59377d42fa6704f30ec640b39fd8413bc 1 parent f84ab76
@ryanb authored
Showing with 56 additions and 18 deletions.
  1. +1 −5 bin/rcencode
  2. +3 −3 bin/rcpush
  3. +52 −10 bin/rcupload
View
6 bin/rcencode
@@ -9,11 +9,7 @@ class RailsCastsEncoder
def initialize(path)
@source = File.expand_path(path)
@name = File.basename(@source, ".*")
- if File.exist? "#{File.dirname(@source)}/upload/pro"
- @out_dir = "#{File.dirname(@source)}/upload/pro/videos"
- else
- @out_dir = "#{File.dirname(@source)}/upload/videos"
- end
+ @out_dir = "#{File.dirname(@source)}/videos"
end
def process
View
6 bin/rcpush
@@ -4,7 +4,7 @@
# rcpush
require "rubygems"
-require "rest_client" # gem install rest-client
+require "octokit" # gem install octokit
class EpisodePusher
attr_reader :name
@@ -19,8 +19,8 @@ class EpisodePusher
end
def create_repo
- options = {login: ENV["GITHUB_USER"], token: ENV["GITHUB_TOKEN"], :name => "railscasts/#{name}", public: 1}
- RestClient.post("https://github.com/api/v2/json/repos/create", options)
+ client = Octokit::Client.new(login: ENV["GITHUB_LOGIN"], token: ENV["GITHUB_TOKEN"])
+ client.create_repository(name, organization: "railscasts")
end
def push
View
62 bin/rcupload
@@ -1,17 +1,59 @@
#!/usr/bin/env ruby
# Uploads compressed files to media.railscasts.com
-# rcupload path/to/123-foo-bar
+# rcupload [video,still,code] [path]
-require "fileutils"
+class EpisodeUploader
+ attr_reader :type, :root
-def run(command)
- puts "Running: #{command}"
- system(command)
-end
+ def initialize(type, path = ".")
+ @type = type
+ @root = File.expand_path(path)[/.+\/[0-9]{3}+-[^\/]+/]
+ end
+
+ def run
+ case type.to_sym
+ when :mp4, :m4v, :ogv, :webm then upload_video(type)
+ when :video then upload_video
+ when :still then upload_still
+ when :code then upload_code
+ else puts "unknown type, must be: video, still, code"
+ end
+ end
+
+ def upload_video(ext = "*")
+ Dir["#{root}/video/*.#{ext}"].each do |file|
+ command "scp '#{file}' media.railscasts.com:/home/rbates/media.railscasts.com/assets/episodes#{pro_path}/videos"
+ end
+ end
+
+ def upload_still
+ command "scp '#{root}/still/#{name}.png' railscasts.com:~/code/railscasts/shared/assets/episodes/stills/"
+ end
-path = ($*.first || ".") + "/upload/**/*.*"
-Dir[path].each do |file|
- run "scp '#{file}' media.railscasts.com:/home/rbates/media.railscasts.com/assets/episodes/#{file.sub('./upload/', '')}"
- run "scp '#{file}' railscasts.com:~/code/railscasts/shared/assets/episodes/stills/" if file =~ /stills\/.*\.png/
+ def upload_code
+ zip = "/tmp/#{name}.zip"
+ command "cd '#{root}/code' && git archive --format zip --output '#{zip}' master"
+ command "scp '#{zip}' media.railscasts.com:/home/rbates/media.railscasts.com/assets/episodes/sources/#{name}.zip"
+ command "rm '#{zip}'"
+ end
+
+ def pro_path
+ if name =~ /revised$/ || name.to_i % 2 > 0
+ "/pro"
+ else
+ ""
+ end
+ end
+
+ def name
+ File.basename(root)
+ end
+
+ def command(command)
+ puts "Running: #{command}"
+ system command
+ end
end
+
+EpisodeUploader.new(*$*).run
Please sign in to comment.
Something went wrong with that request. Please try again.