diff --git a/README.rdoc b/README.rdoc index 94d9ae2..374ef1e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -7,18 +7,18 @@ without storing the media in Git itself. Setup the attributes filter settings. - (once after install) - $ git config filter.media.clean "git-media filter-clean" - $ git config filter.media.smudge "git-media filter-smudge" + (once after install) + $ git config filter.media.clean "git-media filter-clean" + $ git config filter.media.smudge "git-media filter-smudge" Setup the .gitattributes file to map extensions to the filter. - (in repo - once) - $ echo "*.mov filter=media -crlf" > .gitattributes + (in repo - once) + $ echo "*.mov filter=media -crlf" > .gitattributes -Staging files with those extensions will automatically copy them to the +Staging files with those extensions will automatically copy them to the media buffer area (.git/media) until you run 'git media sync' wherein they -are uploaded. Checkouts that reference media you don't have yet will try to +are uploaded. Checkouts that reference media you don't have yet will try to be automatically downloaded, otherwise they are downloaded when you sync. Next you need to configure git to tell it where you want to store the large files. @@ -28,72 +28,78 @@ There are four options: 2. Storing locally in a filesystem path 3. Storing remotely via SCP (should work with any SSH server) 4. Storing remotely in atmos +5. Storing remotely in Google Drive Here are the relevant sections that should go either in ~/.gitconfig (for global settings) or in clone/.git/config (for per-repo settings). - [git-media] - transport = - - # settings for scp transport - scpuser= - scphost= - scppath= + [git-media] + transport = - # settings for local transport - path= + # settings for scp transport + scpuser= + scphost= + scppath= - # settings for s3 transport - s3bucket= - s3key= - s3secret= + # settings for local transport + path= - # settings for atmos transport - endpoint= - uid= - secret= - tag= + # settings for s3 transport + s3bucket= + s3key= + s3secret= + # settings for atmos transport + endpoint= + uid= + secret= + tag= + + # settings for drive transport + email= + asp= + collection= == Usage - (in repo - repeatedly) - $ (hack, stage, commit) - $ git media sync + (in repo - repeatedly) + $ (hack, stage, commit) + $ git media sync -You can also check the status of your media files via +You can also check the status of your media files via - $ git media status + $ git media status Which will show you files that are waiting to be uploaded and how much data that is. If you want to upload & delete the local cache of media files, run: - $ git media clear + $ git media clear == Config Settings - $ git config --global media.auto-download false + $ git config --global media.auto-download false -== Installing +== Installing $ sudo gem install trollop $ sudo gem install s3 + $ sudo gem install google_drive $ sudo gem install ruby-atmos-pure $ sudo gem install right_aws $ gem build git-media.gemspec $ sudo gem install git-media-0.1.1.gem == Notes for Windows -It is important to switch off git smart newline character support for media files. +It is important to switch off git smart newline character support for media files. Use "-crlf" switch in .gitattributes (for example "*.mov filter=media -crlf") or config option "core.autocrlf = false". If installing on windows, you might run into a problem verifying certificates for S3 or something. If that happens, modify - C:\Ruby191\lib\ruby\gems\1.9.1\gems\right_http_connection-1.2.4\lib\right_http_connection.rb + C:\Ruby191\lib\ruby\gems\1.9.1\gems\right_http_connection-1.2.4\lib\right_http_connection.rb And add at line 310, right before "@http.start": - @http.verify_mode = OpenSSL::SSL::VERIFY_NONE + @http.verify_mode = OpenSSL::SSL::VERIFY_NONE == Copyright diff --git a/git-media.gemspec b/git-media.gemspec index 74a25c1..abc23ae 100644 --- a/git-media.gemspec +++ b/git-media.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = %q{git-media} - s.version = "0.1.2" + s.version = "0.1.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Scott Chacon"] @@ -33,6 +33,7 @@ Gem::Specification.new do |s| "lib/git-media/transport/s3.rb", "lib/git-media/transport/atmos_client.rb", "lib/git-media/transport/scp.rb", + "lib/git-media/transport/drive.rb", "lib/git-media/transport.rb", "lib/git-media.rb" ] diff --git a/lib/git-media.rb b/lib/git-media.rb index 3c32810..49c2131 100644 --- a/lib/git-media.rb +++ b/lib/git-media.rb @@ -15,9 +15,9 @@ def self.get_media_buffer def self.media_path(sha) buf = self.get_media_buffer - File.join(buf, sha) + File.join(buf, sha) end - + # TODO: select the proper transports based on settings def self.get_push_transport self.get_transport @@ -34,20 +34,20 @@ def self.get_transport path = `git config git-media.scppath`.chomp port = `git config git-media.scpport`.chomp if user === "" - raise "git-media.scpuser not set for scp transport" + raise "git-media.scpuser not set for scp transport" end if host === "" - raise "git-media.scphost not set for scp transport" + raise "git-media.scphost not set for scp transport" end if path === "" - raise "git-media.scppath not set for scp transport" + raise "git-media.scppath not set for scp transport" end GitMedia::Transport::Scp.new(user, host, path, port) when "local" path = `git config git-media.localpath`.chomp if path === "" - raise "git-media.localpath not set for local transport" + raise "git-media.localpath not set for local transport" end GitMedia::Transport::Local.new(path) when "s3" @@ -55,13 +55,13 @@ def self.get_transport key = `git config git-media.s3key`.chomp secret = `git config git-media.s3secret`.chomp if bucket === "" - raise "git-media.s3bucket not set for s3 transport" + raise "git-media.s3bucket not set for s3 transport" end if key === "" - raise "git-media.s3key not set for s3 transport" + raise "git-media.s3key not set for s3 transport" end if secret === "" - raise "git-media.s3secret not set for s3 transport" + raise "git-media.s3secret not set for s3 transport" end GitMedia::Transport::S3.new(bucket, key, secret) when "atmos" @@ -83,6 +83,21 @@ def self.get_transport raise "git-media.secret not set for atmos transport" end GitMedia::Transport::AtmosClient.new(endpoint, uid, secret, tag) + when "drive" + require 'git-media/transport/drive' + email = `git config git-media.email`.chomp + asp = `git config git-media.asp`.chomp + collection = `git config git-media.collection`.chomp + if email == "" + raise "git-media.email not set for drive transport" + end + if asp == "" + raise "git-media.asp (application specific password) not set for drive transport" + end + if collection == "" + raise "git-media.collection not set for drive transport" + end + GitMedia::Transport::Drive.new(email, asp, collection) else raise "Invalid transport #{transport}" end @@ -94,7 +109,7 @@ def self.get_pull_transport module Application def self.run! - + cmd = ARGV.shift # get the subcommand cmd_opts = case cmd when "filter-clean" # parse delete options @@ -125,7 +140,7 @@ def self.run! EOF end - + end end end diff --git a/lib/git-media/transport/drive.rb b/lib/git-media/transport/drive.rb new file mode 100644 index 0000000..bee8a58 --- /dev/null +++ b/lib/git-media/transport/drive.rb @@ -0,0 +1,45 @@ +require 'git-media/transport' +require 'google_drive' + +# git-media.transport drive +# git-media.email youname@gmail.com +# git-media.asp application specific password +# git-media.collection collectionName (should be shared with all users) + +module GitMedia + module Transport + class Drive < Base + + def initialize(email, asp, collection) + @drive = GoogleDrive.login(email, asp) + @collection = @drive.collection_by_title(collection) + end + + def read? + true + end + + def get_file(sha, to_file) + file = @collection.files("title" => sha, "title-exact" => true).first + file.download_to_file(to_file) + end + + def write? + true + end + + def put_file(sha, from_file) + f = @drive.upload_from_file(from_file, sha, :convert => false) + @collection.add(f) + end + + def get_unpushed(files) + keys = @collection.files.map { |f| f.title } + files.select do |f| + !keys.include?(f) + end + end + + end + end +end