sftp-sync 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 404cae2c789dc731fe17476a72cd43af89e29a99
4
+ data.tar.gz: 16d2695386b3c0dfda62a6ba5b1c5e942b5e8187
5
+ SHA512:
6
+ metadata.gz: 43eec1ee6f897a35894fcf89d3eecc1c795ef3e3d643e98455ca299c15eba04ab55a16f6db0544a6f5e61ba66de3af10137fbd5533fc9eefd07cef334a625ea7
7
+ data.tar.gz: beb1c3b5d8428bd05f1573e790e6b04cb89f5c4d5d899356ab24e04009c3433cd5051ab6065dc1cd613e66d1599bda00867ee74d0ec2cf2a13ef3e939f9be39f
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sftp-sync.gemspec
4
+ gemspec
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Benjamin Bryant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Sftp::Sync
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sftp/sync`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sftp-sync'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sftp-sync
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sftp-sync.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sftp/sync"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require "bundler/setup"
5
+ require 'sftp/sync'
6
+
7
+ Sftp::Sync::CLI.start( ARGV )
@@ -0,0 +1,47 @@
1
+ class FileDiffMap
2
+
3
+ class Entry < Struct.new(:name, :size, :status);end
4
+
5
+ attr_reader :diff_map
6
+ def initialize
7
+ @diff_map = {}
8
+ end
9
+
10
+
11
+ def add(name, size)
12
+ raise "file #{name} already exists!" if(diff_map[name])
13
+ diff_map[name] = Entry.new(name, size, :local)
14
+
15
+ :local
16
+ end
17
+
18
+
19
+ def update(name, size)
20
+ if(diff_map[name])
21
+
22
+ if diff_map[name].size == size
23
+ diff_map[name].status = :match
24
+
25
+ else
26
+ diff_map[name].status = :diff
27
+ end
28
+
29
+ else
30
+
31
+ diff_map[name] = Entry.new(name, size, :remote)
32
+ :remote
33
+ end
34
+
35
+ end
36
+
37
+
38
+ def entries
39
+ diff_map.values
40
+ end
41
+
42
+ def local_entries
43
+ diff_map.values.find_all {|e| e.status == :local}
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,64 @@
1
+ require "sftp/sync/glob_builder"
2
+
3
+ # maybe move int git_ignore/filter
4
+
5
+ module Filters
6
+ class GitIgnore
7
+
8
+ attr_reader :globs, :negative_globs
9
+
10
+ def initialize(patterns = [])
11
+
12
+
13
+ @globs = []
14
+ @negative_globs = []
15
+
16
+ patterns.each do |pattern|
17
+
18
+ pattern.strip!
19
+
20
+ next if /^\#/.match(pattern)
21
+
22
+ if /^\\\#/.match(pattern)
23
+ add_globs Sftp::Sync::GlobBuilder.new(pattern.slice(1,pattern.length - 1))
24
+ else
25
+ add_globs Sftp::Sync::GlobBuilder.new(pattern)
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+
33
+ def match(filename)
34
+
35
+
36
+ @globs.each do |glob|
37
+ if File.fnmatch(glob, filename, File::FNM_PATHNAME) # removeing path thing? (or be mor specific w/ glob)
38
+
39
+
40
+ @negative_globs.each do |n_glob|
41
+ return false if File.fnmatch(n_glob, filename, File::FNM_PATHNAME)
42
+ end
43
+
44
+ return true
45
+
46
+ end
47
+ end
48
+ false
49
+ end
50
+
51
+ private
52
+
53
+ def add_globs(builder)
54
+
55
+ if builder.negative?
56
+ @negative_globs = (@negative_globs + builder.globs).uniq
57
+ else
58
+ @globs = (@globs + builder.globs).uniq
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,8 @@
1
+ module Filters
2
+ class Pass
3
+
4
+ def match(filename)
5
+ false
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ module Globs
2
+ class ExtGlob
3
+
4
+ MATCH_REGEXP = /(\\).|([@?!+*]\(.*\))/
5
+
6
+ def initialize(glob)
7
+ @glob = glob
8
+ end
9
+
10
+ def valid?
11
+
12
+
13
+ return false unless @glob && @glob.kind_of?(String) && @glob != ""
14
+
15
+ glob = @glob.dup
16
+
17
+ while(match = MATCH_REGEXP.match(glob)) do
18
+ return true if match[2]
19
+
20
+
21
+ glob.slice!(match.begin(0), match[0].length)
22
+
23
+
24
+
25
+ end
26
+
27
+ false
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,30 @@
1
+ require 'globs/ext_glob'
2
+ module Globs
3
+ class Glob
4
+
5
+ MATCH_REGEXP = /(\\).|([*?]|\[.*\]|\{.*\}|\(.*\|.*\)|^!)/
6
+
7
+ def initialize(glob)
8
+ @glob = glob
9
+ end
10
+
11
+ def valid?
12
+
13
+ return false unless @glob && @glob.kind_of?(String) && @glob != ""
14
+
15
+ return true if Globs::ExtGlob.new(@glob).valid?
16
+
17
+ glob = @glob.dup
18
+
19
+ while(match = MATCH_REGEXP.match(glob)) do
20
+ return true if match[2]
21
+
22
+ glob.slice!(match.begin(0), match[0].length)
23
+
24
+ end
25
+
26
+ false
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require "sftp/sync/version"
2
+ require "sftp/sync/cli"
3
+
4
+ require 'active_support'
5
+ require 'active_support/core_ext/object'
6
+
7
+
8
+ require "sftp/sync/config"
9
+ require "sftp/sync/client"
10
+
11
+ require "filters/git_ignore"
12
+ require "filters/pass"
13
+
14
+
15
+
16
+ module Sftp
17
+ module Sync
18
+
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ require 'thor'
2
+ require "sftp/sync/runner"
3
+
4
+ module Sftp
5
+ module Sync
6
+ class CLI < Thor
7
+
8
+ desc "pull", "Syncs files from remote SFTP"
9
+ option :filter
10
+ option :output_dir
11
+ option :remove_local, :type => :boolean
12
+ option :gitignore, :type => :boolean, :default => true
13
+
14
+ def pull
15
+ runner = Sftp::Sync::Runner.new(options)
16
+ runner.pull
17
+ end
18
+
19
+
20
+ desc "diff", "Diffs local files from remote SFTP"
21
+ option :filter
22
+ option :output_dir
23
+
24
+ def diff
25
+ runner = Sftp::Sync::Runner.new(options)
26
+ runner.diff
27
+ end
28
+
29
+
30
+ desc "list", "Lists files to be synced from remote SFTP"
31
+ option :filter
32
+ def list
33
+ runner = Sftp::Sync::Runner.new(options)
34
+ runner.list
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,177 @@
1
+ require 'net/sftp'
2
+
3
+ require 'pathname'
4
+
5
+ require "filters/pass"
6
+ require "filters/git_ignore"
7
+
8
+ require "file_diff_map"
9
+
10
+ module Sftp
11
+ module Sync
12
+ class Client
13
+
14
+ attr_reader :config, :session, :filter
15
+
16
+
17
+ def initialize(_config)
18
+ @config = _config
19
+ @session = Net::SFTP.start(config.host, config.username, config.sftp_opts)
20
+
21
+ # set filter
22
+ @filter = Filters::Pass.new
23
+
24
+ if config.filter?
25
+ @filter = Filters::GitIgnore.new(IO.readlines(config.filter))
26
+ end
27
+ end
28
+
29
+ def close
30
+
31
+ @session.close
32
+ end
33
+
34
+ def list
35
+
36
+
37
+
38
+ # list the entries in a directory
39
+ session.dir.glob("/", "**/*") do |entry|
40
+ puts entry.name unless entry.directory? || filter.match(entry.name)
41
+ end
42
+
43
+
44
+ end
45
+
46
+
47
+ def diff
48
+
49
+ diff_map = build_diff_map
50
+
51
+
52
+ # list the entries in a directory
53
+ session.dir.glob("/", "**/*") do |entry|
54
+
55
+ unless entry.directory? || filter.match(entry.name)
56
+ case diff_map.update(entry.name , entry.attributes.size )
57
+ when :diff
58
+ puts "* #{entry.name}"
59
+ when :match
60
+ puts " #{entry.name}"
61
+ when :remote
62
+ puts "+ #{entry.name}"
63
+ end
64
+
65
+ end
66
+ end
67
+
68
+ diff_map.local_entries.each do |entry|
69
+
70
+ puts "- #{entry.name}"
71
+
72
+ end
73
+ end
74
+
75
+
76
+
77
+ def pull
78
+
79
+ downloads = []
80
+
81
+ diff_map = build_diff_map
82
+
83
+ # list the entries in a directory
84
+ session.dir.glob("/", "**/*") do |entry|
85
+
86
+ unless entry.directory? || filter.match(entry.name)
87
+
88
+ src = entry.name
89
+ dest = File.join(config.output_dir, entry.name)
90
+
91
+ dest_dir = File.dirname(dest)
92
+ FileUtils.mkdir_p dest_dir unless Dir.exists?(dest_dir)
93
+
94
+ puts "#{src} => #{dest}"
95
+
96
+ downloads << session.download(src , dest)
97
+
98
+ ##
99
+ diff_map.update(entry.name , entry.attributes.size )
100
+
101
+
102
+
103
+ end
104
+
105
+
106
+ end
107
+
108
+ downloads.each { |d| d.wait }
109
+
110
+
111
+
112
+ diff_map.local_entries.each do |entry|
113
+
114
+ target = File.join(config.output_dir, entry.name)
115
+
116
+
117
+ if config.remove_local?
118
+ if File.exist?(target)
119
+ puts "removing #{target}"
120
+ File.delete(target)
121
+ end
122
+ else
123
+ puts "#{target} in local but not remote, use --remove_local flag to auto remove"
124
+ end
125
+
126
+ end
127
+
128
+
129
+
130
+ end
131
+
132
+
133
+
134
+ private
135
+
136
+ def build_diff_map
137
+ diff_map = FileDiffMap.new
138
+
139
+ ## enumerate local files
140
+ Dir[ File.join(config.output_dir, '**', '*') ].each do |local_entry|
141
+
142
+ relative_path = Pathname.new(local_entry).relative_path_from(Pathname.new(config.output_dir)).to_s
143
+
144
+ diff_map.add(relative_path, (File.size?(local_entry)|| 0)) unless File.directory?(local_entry) || filter.match(relative_path)
145
+ end
146
+
147
+ diff_map
148
+ end
149
+
150
+
151
+
152
+
153
+ # # upload a file or directory to the remote host
154
+ # sftp.upload!("/path/to/local", "/path/to/remote")
155
+
156
+ # # download a file or directory from the remote host
157
+ # sftp.download!("/path/to/remote", "/path/to/local")
158
+
159
+ # # grab data off the remote host directly to a buffer
160
+ # data = sftp.download!("/path/to/remote")
161
+
162
+ # # open and write to a pseudo-IO for a remote file
163
+ # sftp.file.open("/path/to/remote", "w") do |f|
164
+ # f.puts "Hello, world!\n"
165
+ # end
166
+
167
+ # # open and read from a pseudo-IO for a remote file
168
+ # sftp.file.open("/path/to/remote", "r") do |f|
169
+ # puts f.gets
170
+ # end
171
+
172
+ # # create a directory
173
+ # sftp.mkdir! "/path/to/directory"
174
+
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,75 @@
1
+ require "active_support/hash_with_indifferent_access"
2
+
3
+ module Sftp
4
+ module Sync
5
+ class Config
6
+
7
+ attr_reader :options
8
+ def initialize(_options = {})
9
+ @options = ActiveSupport::HashWithIndifferentAccess.new(_options)
10
+
11
+
12
+ #required
13
+ options[:host] = ENV["SFTP_SYNC_HOST"] unless options[:host].present?
14
+ raise "missing host. Set SFTP_SYNC_HOST env." unless options[:host].present?
15
+
16
+ options[:username] = ENV["SFTP_SYNC_USERNAME"] unless options[:username].present?
17
+ raise "missing username. Set SFTP_SYNC_USERNAME env." unless options[:username].present?
18
+
19
+
20
+ #optional
21
+ options[:port] = ENV["SFTP_SYNC_PORT"] unless options[:port].present?
22
+ options[:password] = ENV["SFTP_SYNC_PASSWORD"] unless options[:password].present?
23
+
24
+
25
+
26
+ end
27
+
28
+
29
+ def host
30
+ options[:host]
31
+ end
32
+
33
+ def username
34
+ options[:username]
35
+ end
36
+
37
+ def password
38
+ options[:password]
39
+ end
40
+
41
+ def port
42
+ options[:port]
43
+ end
44
+
45
+ def sftp_opts
46
+ {}.tap do |opts|
47
+ opts[:password] = password unless password.nil?
48
+ opts[:port] = port unless port.nil?
49
+ end
50
+ end
51
+
52
+ def filter?
53
+ filter.present?
54
+ end
55
+
56
+ def filter
57
+ if options[:filter].present?
58
+ options[:filter]
59
+ elsif File.exist?(".gitignore") && options[:gitignore]
60
+ ".gitignore"
61
+ else
62
+ nil
63
+ end
64
+ end
65
+
66
+ def output_dir
67
+ options[:output_dir] || ""
68
+ end
69
+
70
+ def remove_local?
71
+ options[:remove_local]
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,118 @@
1
+ require "globs/glob"
2
+
3
+ module Sftp
4
+ module Sync
5
+ class GlobBuilder
6
+
7
+ def initialize(line)
8
+ @line = line
9
+ end
10
+
11
+
12
+
13
+
14
+ def globs
15
+
16
+ line = @line.dup
17
+
18
+ out = []
19
+
20
+ #!pattern
21
+ if negative?
22
+ line.slice!(0,1) # trim negative token
23
+ end
24
+
25
+ ## allow for escaping of !
26
+ if /^\\!/.match(line)
27
+ line.slice!(0,1)
28
+ end
29
+
30
+ #
31
+
32
+ # puts "LINE #{line} #{Globs::Glob.new(line).valid?}"
33
+
34
+
35
+ unless Globs::Glob.new(line).valid?
36
+
37
+ if /^\/[\w.]/.match(line) #/a
38
+ line.slice!(0,1)
39
+
40
+
41
+ if /\/$/.match(line) #/a/ => a/**
42
+ out << (line + '**/**')
43
+
44
+ else # /\w$/.match(line) #/a => a, a/**
45
+ out << line
46
+ out << (line + '/**/**')
47
+
48
+ end
49
+
50
+ elsif /^[\w.]/.match(line) #a
51
+
52
+
53
+ if (/\/$/.match(line)) #a/ => **/a/**, a/**
54
+
55
+ out << (line + '**/**')
56
+ out << ('**/' + line + '**/**')
57
+ else #/\w$/.match(line) #a => a, **/a, a/**
58
+ out << line
59
+ out << (line + '/**/**')
60
+ out << ( '**/' + line )
61
+ out << ('**/' + line + '/**/**')
62
+
63
+ end
64
+ else
65
+
66
+ if (/\/$/.match(line)) #a/ => a/**, a/**
67
+
68
+ out << (line + '**/**')
69
+
70
+ else
71
+ out << line
72
+ out << (line + '/**/**')
73
+ end
74
+ end
75
+
76
+ else
77
+
78
+
79
+ if /^\/\*\.\w+/.match(line) #/*.xcv
80
+ line.slice!(0,1)
81
+ out << line
82
+ elsif /^\*\.\w+/.match(line) #*.xcv
83
+ out << line
84
+ out << ( '**/' + line)
85
+ else
86
+
87
+ if /\w$/.match(line) #*/a => */a, */a/**
88
+ out << line
89
+ out << (line + '/**/**')
90
+
91
+ elsif (/\/$/.match(line)) #*/a/ => */a/**
92
+ out << (line + '**/**')
93
+
94
+ elsif /\*$/.match(line) #a/* =>
95
+ out << line
96
+ out << (line + '/**/**')
97
+ else
98
+ out << line
99
+ end
100
+
101
+ end
102
+
103
+
104
+
105
+ end
106
+
107
+
108
+ out
109
+ end
110
+
111
+ def negative?
112
+ @line[0] == "!"
113
+ end
114
+
115
+
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,41 @@
1
+
2
+ require "sftp/sync/config"
3
+
4
+
5
+ module Sftp
6
+ module Sync
7
+ class Runner
8
+
9
+ def initialize(options = {})
10
+ @config = Config.new(options)
11
+ end
12
+
13
+
14
+
15
+ def list
16
+ client = Sftp::Sync::Client.new(@config)
17
+
18
+ client.list
19
+ end
20
+
21
+
22
+ def pull
23
+ client = Sftp::Sync::Client.new(@config)
24
+
25
+ client.pull
26
+ end
27
+
28
+
29
+
30
+ def diff
31
+ client = Sftp::Sync::Client.new(@config)
32
+
33
+ client.diff
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+
40
+
41
+ end
@@ -0,0 +1,5 @@
1
+ module Sftp
2
+ module Sync
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sftp/sync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sftp-sync"
8
+ spec.version = Sftp::Sync::VERSION
9
+ spec.authors = ["Benjamin Bryant"]
10
+ spec.email = ["benjaminhbryant@gmail.com"]
11
+
12
+ spec.summary = %q{Syncs a list of files from remote sftp server }
13
+ #spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "thor", "~> 0.19.1"
30
+ spec.add_dependency "net-sftp", "~> 2.1.2"
31
+ spec.add_dependency "activesupport", "~> 5.0.0.1"
32
+
33
+
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.11"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sftp-sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Bryant
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-sftp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.0.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.0.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.7'
111
+ description:
112
+ email:
113
+ - benjaminhbryant@gmail.com
114
+ executables:
115
+ - sftp-sync
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Guardfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - exe/sftp-sync
130
+ - lib/file_diff_map.rb
131
+ - lib/filters/git_ignore.rb
132
+ - lib/filters/pass.rb
133
+ - lib/globs/ext_glob.rb
134
+ - lib/globs/glob.rb
135
+ - lib/sftp/sync.rb
136
+ - lib/sftp/sync/cli.rb
137
+ - lib/sftp/sync/client.rb
138
+ - lib/sftp/sync/config.rb
139
+ - lib/sftp/sync/glob_builder.rb
140
+ - lib/sftp/sync/runner.rb
141
+ - lib/sftp/sync/version.rb
142
+ - sftp-sync.gemspec
143
+ homepage:
144
+ licenses:
145
+ - MIT
146
+ metadata:
147
+ allowed_push_host: https://rubygems.org
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.5.1
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Syncs a list of files from remote sftp server
168
+ test_files: []