kinksync 0.1.0

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: ac32beb8f7f8fb7d4337fa4212d2522e882892bf
4
+ data.tar.gz: 4601135a9316309ab48935d379a4b1d10a91de9c
5
+ SHA512:
6
+ metadata.gz: 79d3de36c2a138a4fb4542ff35f24b841df064dd960b9105c1fd31ceee8175a9a0f51f6d6b1eae66325fb825e048141935a6f85ca2fe8cc9148c00b836aaf097
7
+ data.tar.gz: bdb85af153e96625c769b3ce1295fe21620ff166517bc1bbab2e90cb9947839d46930ed96fdfba74716d779a8010bbd55f37ec47b4a730cf3c4f59396d83c4cf
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kinksync.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Pablo
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,50 @@
1
+ # Kinksync
2
+
3
+ Kinksync is a simple gem that let's you synchronize files all over your directory tree with any cloud storage mounted on your file system. If you have two similar systems in different computers and want to share certain configuration files, Kinksync will help you do it easily.
4
+
5
+ ## Installation
6
+
7
+ Install it from RubyGems:
8
+
9
+ ```
10
+ $ gem install kinksync
11
+ ```
12
+
13
+ Kinksync was made to be used as a CLI, but you can also include in your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'kinksync'
17
+ ```
18
+
19
+ And then execute:
20
+ ```
21
+ $ bundle
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Simple run it from your terminal.
27
+ ```
28
+ $ kinksync [-h] [PATHS_LIST]
29
+ ```
30
+
31
+ ### Without arguments
32
+ Sync all files under remote cloud path with local storage
33
+
34
+ ### Optional arguments
35
+ * `-h, --help` Show this help message and exit
36
+ * `[FILE_OR_PATHS_LIST]` Sync all files inside each path, or the file itself
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/Pizzicato/kinksync>.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -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
File without changes
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'kinksync'
4
+
5
+ # -h or --help as argument
6
+ unless (ARGV & ['-h', '--help']).empty?
7
+ STDOUT.puts <<-EOF
8
+ Usage: kinksync [-h] [PATHS_LIST]
9
+
10
+ Sync files located all over the directory tree in different computers using any cloud storage
11
+
12
+ Without arguments:
13
+ Sync all files under remote cloud path with local storage
14
+
15
+ Optional arguments:
16
+ -h, --help Show this help message and exit
17
+ [FILE_OR_PATHS_LIST] Sync all files inside each path, or the file itself
18
+ EOF
19
+ exit
20
+ end
21
+
22
+ # normal execution
23
+ Kinksync.configure do |config|
24
+ config.remote_path = '~/MEGA/kinksync'
25
+ end
26
+
27
+ puts "Using #{Kinksync.configuration.remote_path} as remote path."
28
+ puts 'Kinksyncing...'
29
+ synced = Kinksync.sync(ARGV)
30
+ puts 'Done!'
31
+ if synced.empty?
32
+ puts 'All up to date, nothing synced.'
33
+ else
34
+ puts 'Naughtily synced files:'
35
+ synced.each { |f| puts f.sub(Kinksync.configuration.remote_path, '') }
36
+ end
@@ -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,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kinksync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kinksync'
8
+ spec.version = Kinksync::VERSION
9
+ spec.authors = ['Pablo']
10
+ spec.email = ['pabloguaza@gmail.com']
11
+
12
+ spec.summary = 'Sync files all over directory tree with any cloud storage mounted on your file system'
13
+ spec.homepage = 'https://github.com/Pizzicato/kinksync'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables << 'kinksync'
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.14'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'fakefs', '~> 0.10'
27
+ end
@@ -0,0 +1,69 @@
1
+ require 'find'
2
+
3
+ require 'kinksync/version'
4
+ require 'kinksync/configuration'
5
+ require 'kinksync/path_2_sync'
6
+ require 'kinksync/file_2_sync'
7
+
8
+ ##
9
+ # Kynsync parent module for all classes.
10
+ # Provides methods for configuration and synchronization of a group of files
11
+ # and/or directories
12
+ ##
13
+ module Kinksync
14
+ class << self
15
+ # Configuration class instance
16
+ attr_writer :configuration
17
+ end
18
+
19
+ # Configures a Kynksync module with the values provided through the block
20
+ # it recieves
21
+ #
22
+ # @param [block]
23
+ # Values:
24
+ # - remote_path: path to mounting cloud storage location
25
+ #
26
+ # @example
27
+ # Kinksync.configure do |config|
28
+ # config.remote_path = '/home/pablo/MEGA/kinksync/'
29
+ # config.log_file = config.remote_path + 'kinksync.log'
30
+ # end
31
+ #
32
+ def self.configure
33
+ yield(configuration)
34
+ end
35
+
36
+ # Returns current configuration or initializes an empty one and returns it
37
+ #
38
+ # @return Configuration object
39
+ def self.configuration
40
+ @configuration ||= Configuration.new
41
+ end
42
+
43
+ # Resets configuration: all attributes are set to nil
44
+ #
45
+ # @return Empty Configuration object
46
+ def self.reset
47
+ @configuration = nil
48
+ end
49
+
50
+ # Syncs lists of files and paths recieved as arguments. If no arg is provided
51
+ # syncs all files in remote path
52
+ #
53
+ # @param paths_to_sync [Array] List of files and paths to sync
54
+ #
55
+ # @example
56
+ # Kinksync.sync([
57
+ # 'a_file.mp3',
58
+ # '/an/absolute/path/',
59
+ # 'another_file.avi',
60
+ # 'a/relative/path'
61
+ # ])
62
+ #
63
+ def self.sync(paths_to_sync = [])
64
+ synced = []
65
+ paths_to_sync = [Kinksync.configuration.remote_path] if paths_to_sync.empty?
66
+ paths_to_sync.each { |p| synced += Path2Sync.new(p).sync }
67
+ synced
68
+ end
69
+ end
@@ -0,0 +1,21 @@
1
+ module Kinksync
2
+ # Configuration class
3
+ #
4
+ class Configuration
5
+ # absolute path to mounted cloud storage location
6
+ attr_reader :remote_path
7
+
8
+ # initializes Configuration with nil value for remote_path
9
+ #
10
+ def initialize
11
+ @remote_path = nil
12
+ end
13
+
14
+ # Returns absolute path of remote path
15
+ #
16
+ # @return [String] remote path
17
+ def remote_path=(remote_path)
18
+ @remote_path = File.expand_path(remote_path)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,65 @@
1
+ module Kinksync
2
+ #
3
+ # Class that represents a duple of files with *absolute* path which
4
+ # can be synced
5
+ #
6
+ class File2Sync
7
+ #
8
+ # Configures a File2Sync class
9
+ #
10
+ # @param file [String] local or remote file to sync
11
+ #
12
+ def initialize(file)
13
+ @file = file
14
+ @twin_file = twin_file(file)
15
+ end
16
+
17
+ #
18
+ # Sync a file, copying origin over destination
19
+ #
20
+ # @return file or nil if file is already synced
21
+ #
22
+ def sync
23
+ if File.exist?(@twin_file) && FileUtils.identical?(@file, @twin_file)
24
+ nil
25
+ else
26
+ origin = newer
27
+ destination = twin_file(origin)
28
+ FileUtils.mkdir_p(File.dirname(@twin_file))
29
+ FileUtils.cp(origin, destination)
30
+ @file
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ #
37
+ # Return newer file
38
+ #
39
+ def newer
40
+ FileUtils.uptodate?(@file, [@twin_file]) ? @file : @twin_file
41
+ end
42
+
43
+ #
44
+ # Gets twin file of file provided
45
+ #
46
+ # @param file [String] file to get twin from
47
+ #
48
+ def twin_file(file)
49
+ if remote? file
50
+ file.sub(Kinksync.configuration.remote_path, '')
51
+ else
52
+ Kinksync.configuration.remote_path + file
53
+ end
54
+ end
55
+
56
+ #
57
+ # Decides whether a file is remote or local
58
+ #
59
+ # @param file [String]
60
+ #
61
+ def remote?(file)
62
+ File.dirname(file).start_with?(Kinksync.configuration.remote_path)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,30 @@
1
+ module Kinksync
2
+ #
3
+ # Class that represents an *absolute* local or remote path which
4
+ # contains file(s) and/or directories to sync
5
+ #
6
+ class Path2Sync
7
+ #
8
+ # Configures a Path2Sync class
9
+ #
10
+ # @param path [String] local or remote path to sync
11
+ #
12
+ def initialize(path)
13
+ @path = File.expand_path(path)
14
+ end
15
+
16
+ #
17
+ # Syncs all files in path and its subdirectories, ignores symlinks
18
+ #
19
+ # @return lists of synced files, only including those changed
20
+ #
21
+ def sync
22
+ synced = []
23
+ files_to_sync = Find.find(@path).select do |f|
24
+ File.file?(f) && !File.symlink?(f)
25
+ end
26
+ files_to_sync.each { |f| synced.push(f) if File2Sync.new(f).sync }
27
+ synced
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module Kinksync
2
+ # Current gem version
3
+ VERSION = '0.1.0'.freeze
4
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kinksync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pablo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakefs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ description:
70
+ email:
71
+ - pabloguaza@gmail.com
72
+ executables:
73
+ - kinksync
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/kinksync
86
+ - bin/setup
87
+ - kinksync.gemspec
88
+ - lib/kinksync.rb
89
+ - lib/kinksync/configuration.rb
90
+ - lib/kinksync/file_2_sync.rb
91
+ - lib/kinksync/path_2_sync.rb
92
+ - lib/kinksync/version.rb
93
+ homepage: https://github.com/Pizzicato/kinksync
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Sync files all over directory tree with any cloud storage mounted on your
117
+ file system
118
+ test_files: []
119
+ has_rdoc: