ohajiki 0.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/bin/ohajiki +16 -0
- data/lib/ohajiki.rb +8 -0
- data/lib/ohajiki/config.rb +27 -0
- data/lib/ohajiki/controller.rb +62 -0
- data/lib/ohajiki/repo.rb +108 -0
- data/lib/ohajiki/version.rb +3 -0
- data/ohajiki.conf.sample +3 -0
- data/ohajiki.gemspec +22 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Keisuke KITA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Ohajiki
|
2
|
+
|
3
|
+
Minimum Dropbox clone using Ruby and Git
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install ohajiki
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
Write config file
|
11
|
+
```
|
12
|
+
REMOTE_REPO_URL = 'https://github.com/kitak/ohajiki.git' # Your remote repository url (necessary entry)
|
13
|
+
SYNC_DIR_PATH = '/Users/kitak/.ohajiki' # Sync target (necessary entry)
|
14
|
+
SYNC_INTERVAL_SEC = 5 # Polling Interval (optional entry. default 10)
|
15
|
+
LOGPATH = '/tmp/ohajiki.log' # Logfile location (optional entry)
|
16
|
+
```
|
17
|
+
|
18
|
+
start
|
19
|
+
```
|
20
|
+
ohajiki start -- -c ohajiki.conf
|
21
|
+
```
|
22
|
+
|
23
|
+
stop
|
24
|
+
```
|
25
|
+
ohajiki stop
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/ohajiki
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'daemons'
|
4
|
+
require 'ohajiki'
|
5
|
+
|
6
|
+
if __FILE__ == $0
|
7
|
+
if ARGV.size == 4 && ARGV[1] == "--" && (ARGV[2] == "--config" || ARGV[2] == "-c")
|
8
|
+
Ohajiki::Config.load(File.expand_path(ARGV[3]))
|
9
|
+
end
|
10
|
+
|
11
|
+
pid_dir = File.expand_path('../../tmp', `gem which ohajiki`)
|
12
|
+
Daemons.run_proc('ohajiki', {:dir => pid_dir}) do
|
13
|
+
controller = Ohajiki::Controller.new
|
14
|
+
controller.start
|
15
|
+
end
|
16
|
+
end
|
data/lib/ohajiki.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require "ohajiki/version"
|
2
|
+
require File.expand_path('../ohajiki/config', __FILE__)
|
3
|
+
require File.expand_path('../ohajiki/controller', __FILE__)
|
4
|
+
require File.expand_path('../ohajiki/repo', __FILE__)
|
5
|
+
|
6
|
+
module Ohajiki
|
7
|
+
class ConfigNotFound < StandardError; end
|
8
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Ohajiki
|
4
|
+
module Config
|
5
|
+
def self.load(path)
|
6
|
+
conf = File.read(path)
|
7
|
+
proc {
|
8
|
+
conf = "$SAFE = 2;"+conf
|
9
|
+
self.module_eval conf
|
10
|
+
}.call
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.const_missing(id)
|
14
|
+
# Default settings
|
15
|
+
case id
|
16
|
+
when :LOG_PATH
|
17
|
+
File.expand_path('../../tmp/ohajiki.log', `gem which ohajiki`)
|
18
|
+
when :REMOTE_REPO_URL
|
19
|
+
raise ConfigNotFound, "require REMOTE_REPO_URL in config file"
|
20
|
+
when :SYNC_DIR_PATH
|
21
|
+
raise ConfigNotFound, "require SYNC_DIR_PATH in config file"
|
22
|
+
when :SYNC_INTERVAL_SEC
|
23
|
+
10
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require File.expand_path('../../ohajiki', __FILE__)
|
5
|
+
require File.expand_path('../config', __FILE__)
|
6
|
+
require File.expand_path('../repo', __FILE__)
|
7
|
+
|
8
|
+
module Ohajiki
|
9
|
+
class Controller
|
10
|
+
def initialize
|
11
|
+
@log = Logger.new(File.expand_path(Config::LOG_PATH))
|
12
|
+
@interval_sec = Config::SYNC_INTERVAL_SEC
|
13
|
+
dir_path = File.expand_path(Config::SYNC_DIR_PATH)
|
14
|
+
|
15
|
+
@repo =
|
16
|
+
unless Repo.exist? dir_path
|
17
|
+
Repo.init(dir_path) do
|
18
|
+
remote_add('origin', Config::REMOTE_REPO_URL)
|
19
|
+
pull!
|
20
|
+
end
|
21
|
+
else
|
22
|
+
Repo.new dir_path
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
@log.error "start: #{e.message}" if @log
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
@log.info "start service"
|
30
|
+
loop do
|
31
|
+
sync
|
32
|
+
update
|
33
|
+
sleep @interval_sec
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def sync
|
38
|
+
unless @repo.latest?
|
39
|
+
@log.info "pull #{@repo.remote_head_id}"
|
40
|
+
@repo.reset_hard_head!
|
41
|
+
@repo.pull!
|
42
|
+
else
|
43
|
+
@log.info "repository latest"
|
44
|
+
end
|
45
|
+
rescue => e
|
46
|
+
@log.error "sync: #{e.message}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
if @repo.file_changed?
|
51
|
+
@log.info "push #{@repo.changed_count} files"
|
52
|
+
@repo.add_stage! if @repo.file_added?
|
53
|
+
@repo.commit_all!
|
54
|
+
@repo.push!
|
55
|
+
else
|
56
|
+
@log.info "no changed"
|
57
|
+
end
|
58
|
+
rescue => e
|
59
|
+
@log.error "update: #{e.message}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/ohajiki/repo.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'grit'
|
3
|
+
|
4
|
+
module Ohajiki
|
5
|
+
class Repo
|
6
|
+
class << self
|
7
|
+
def exist?(dir_path)
|
8
|
+
File.exist? File.join(dir_path, '.git')
|
9
|
+
end
|
10
|
+
|
11
|
+
def init(dir_path, &block)
|
12
|
+
Grit::Repo.init(dir_path)
|
13
|
+
repo = self.new dir_path
|
14
|
+
repo.instance_eval &block
|
15
|
+
repo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(dir_path)
|
20
|
+
@dir_path = dir_path
|
21
|
+
in_dir do
|
22
|
+
@repo = Grit::Repo.new('.')
|
23
|
+
@git = Grit::Git.new('./.git')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def in_dir(&block)
|
28
|
+
Dir.chdir(File.expand_path(@dir_path, __FILE__)) do
|
29
|
+
block.call
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def remote_add(name, url)
|
34
|
+
@repo.remote_add(name, url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def latest?
|
38
|
+
remote_head_id == local_head_id
|
39
|
+
end
|
40
|
+
|
41
|
+
def pull!
|
42
|
+
in_dir do
|
43
|
+
@git.native('pull', {}, 'origin', 'master')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def reset_hard_head!
|
48
|
+
in_dir do
|
49
|
+
@git.native('reset', {:hard => true}, 'HEAD')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def remote_head_id
|
54
|
+
in_dir do
|
55
|
+
h = @git.native('ls-remote', {}, 'origin', 'HEAD')
|
56
|
+
h.empty? ? '' : h.split("\t")[0].strip
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def local_head_id
|
61
|
+
in_dir do
|
62
|
+
@git.native('rev-parse', {}, 'HEAD').strip
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def push!
|
67
|
+
in_dir do
|
68
|
+
@git.native('push', {:raise => true}, 'origin', 'master')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_stage!
|
73
|
+
in_dir do
|
74
|
+
@repo.add('.')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def commit_all!
|
79
|
+
in_dir do
|
80
|
+
@repo.commit_all("#{changed_count} files updated")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def file_changed?
|
85
|
+
changed_count > 0
|
86
|
+
end
|
87
|
+
|
88
|
+
def file_added?
|
89
|
+
added_count > 0
|
90
|
+
end
|
91
|
+
|
92
|
+
def changed_count
|
93
|
+
in_dir do
|
94
|
+
@repo.status.select { |file|
|
95
|
+
file.untracked || ['A', 'M', 'D'].include?(file.type)
|
96
|
+
}.size
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def added_count
|
101
|
+
in_dir do
|
102
|
+
@repo.status.select { |file|
|
103
|
+
file.untracked
|
104
|
+
}.size
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/ohajiki.conf.sample
ADDED
data/ohajiki.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ohajiki/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ohajiki"
|
8
|
+
gem.version = Ohajiki::VERSION
|
9
|
+
gem.authors = ["Keisuke KITA"]
|
10
|
+
gem.email = ["kei.kita2501@gmail.com"]
|
11
|
+
gem.description = %q{minimum dropbox clone}
|
12
|
+
gem.summary = %q{minimum dropbox clone}
|
13
|
+
gem.homepage = "https://github.com/kitak/ohajiki"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'grit'
|
21
|
+
gem.add_runtime_dependency 'daemons'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ohajiki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keisuke KITA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: grit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: daemons
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: minimum dropbox clone
|
47
|
+
email:
|
48
|
+
- kei.kita2501@gmail.com
|
49
|
+
executables:
|
50
|
+
- ohajiki
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/ohajiki
|
60
|
+
- lib/ohajiki.rb
|
61
|
+
- lib/ohajiki/config.rb
|
62
|
+
- lib/ohajiki/controller.rb
|
63
|
+
- lib/ohajiki/repo.rb
|
64
|
+
- lib/ohajiki/version.rb
|
65
|
+
- ohajiki.conf.sample
|
66
|
+
- ohajiki.gemspec
|
67
|
+
homepage: https://github.com/kitak/ohajiki
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: minimum dropbox clone
|
91
|
+
test_files: []
|
92
|
+
has_rdoc:
|