diff --git a/.gitignore b/.gitignore index 00c0b86..136fd69 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage rdoc pkg +git-media-*.gem diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ae2d268 --- /dev/null +++ b/Gemfile @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem 'curb' +gem 'trollop' +gem 's3' +gem 'ruby-atmos-pure' +gem 'right_aws' +gem 'net_dav', :git => 'git://github.com/devrandom/net_dav.git', :branch => 'master' \ No newline at end of file diff --git a/README.md b/README.md index 823cf86..aaccfda 100644 --- a/README.md +++ b/README.md @@ -22,19 +22,20 @@ 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. -There are four options: +Here are the options: -1. Storing remotely in Amazon's S3 -2. Storing locally in a filesystem path -3. Storing remotely via SCP (should work with any SSH server) -4. Storing remotely in atmos +1. Storing locally in a filesystem path +2. Storing remotely via SCP (should work with any SSH server) +3. Storing remotely via WEBDAV (including SSL enabled servers) +4. Storing remotely in Amazon's S3 +5. Storing remotely in atmos Here are the relevant sections that should go either in `~/.gitconfig` (for global settings) or in `clone/.git/config` (for per-repo settings). -```ini +```gitconfig [git-media] - transport = + transport = # settings for scp transport scpuser = @@ -44,6 +45,11 @@ or in `clone/.git/config` (for per-repo settings). # settings for local transport path = + # settings for webdav transport + webdavurl = + webdavusername = + webdavpassword = + # settings for s3 transport s3bucket = s3key = @@ -56,7 +62,6 @@ or in `clone/.git/config` (for per-repo settings). tag = ``` - ## Usage (in repo - repeatedly) @@ -76,15 +81,15 @@ that is. If you want to upload & delete the local cache of media files, run: $ git config --global media.auto-download false - ## Installing $ sudo gem install trollop + $ sudo gem install net_dav $ sudo gem install s3 $ 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 + $ sudo gem install git-media-0.1.2.gem ## Notes for Windows diff --git a/git-media.gemspec b/git-media.gemspec index 74a25c1..547cee7 100644 --- a/git-media.gemspec +++ b/git-media.gemspec @@ -12,13 +12,13 @@ Gem::Specification.new do |s| s.executables = ["git-media"] s.extra_rdoc_files = [ "LICENSE", - "README.rdoc" + "README.md" ] s.files = [ ".document", ".gitignore", "LICENSE", - "README.rdoc", + "README.md", "Rakefile", "VERSION", "bin/git-media", @@ -30,6 +30,7 @@ Gem::Specification.new do |s| "lib/git-media/sync.rb", "lib/git-media/transport", "lib/git-media/transport/local.rb", + "lib/git-media/transport/webdav.rb", "lib/git-media/transport/s3.rb", "lib/git-media/transport/atmos_client.rb", "lib/git-media/transport/scp.rb", diff --git a/lib/git-media.rb b/lib/git-media.rb index 3c32810..3ff8bd8 100644 --- a/lib/git-media.rb +++ b/lib/git-media.rb @@ -1,6 +1,7 @@ require 'trollop' require 'fileutils' require 'git-media/transport/local' +require 'git-media/transport/webdav' require 'git-media/transport/s3' require 'git-media/transport/scp' @@ -44,12 +45,28 @@ def self.get_transport end GitMedia::Transport::Scp.new(user, host, path, port) + when "webdav" + username = `git config git-media.webdavusername`.chomp + if username === "" + raise "git-media.webdavusername not set for webdav transport" + end + password = `git config git-media.webdavpassword`.chomp + if password === "" + raise "git-media.webdavpassword not set for webdav transport" + end + url = `git config git-media.webdavurl`.chomp + if url === "" + raise "git-media.webdavurl not set for webdav transport" + end + GitMedia::Transport::Webdav.new(url, username, password) + when "local" path = `git config git-media.localpath`.chomp if path === "" raise "git-media.localpath not set for local transport" end GitMedia::Transport::Local.new(path) + when "s3" bucket = `git config git-media.s3bucket`.chomp key = `git config git-media.s3key`.chomp @@ -64,6 +81,7 @@ def self.get_transport raise "git-media.s3secret not set for s3 transport" end GitMedia::Transport::S3.new(bucket, key, secret) + when "atmos" require 'git-media/transport/atmos_client' endpoint = `git config git-media.endpoint`.chomp diff --git a/lib/git-media/transport/webdav.rb b/lib/git-media/transport/webdav.rb new file mode 100644 index 0000000..0044ac2 --- /dev/null +++ b/lib/git-media/transport/webdav.rb @@ -0,0 +1,64 @@ +require 'git-media/transport' +require 'net/dav' + +# move large media to webdav share +# git-media.transport webdav +# git-media.webdavurl +# git-media.webdavusername +# git-media.webdavpassword + +module GitMedia + module Transport + class Webdav < Base + + def initialize(url,username,password) + @url = url + @username = username + @password = password + @webdav = Net::DAV.new(url) + @webdav.credentials(@username, @password) + end + + def exist?(file) + @webdav.exists?(file) + end + + def read? + @webdav.exists?(file) + end + + def get_file(sha, to_file) + dest_file = File.new(to_file, File::CREAT|File::RDWR) + if sha.exist? + @webdav.get(sha) do |stream| + dest_file.write(stream) + end + dest_file.close + return true + end + return false + end + + def write? + @webdav.exists?(file) + end + + def put_file(sha, from_file) + if File.exists?(from_file) + File.open(from_file, "r") do |stream| + @webdav.put(sha, stream, File.size(from_file)) + return true + end + end + return false + end + + def get_unpushed(files) + files.select do |f| + !File.exist?(f) + end + end + + end + end +end \ No newline at end of file diff --git a/shippable.yml b/shippable.yml new file mode 100644 index 0000000..fb95f77 --- /dev/null +++ b/shippable.yml @@ -0,0 +1,4 @@ +language: ruby +rvm: + - 1.9.3 +script: gem build git-media.gemspec