dropgit 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.
- checksums.yaml +15 -0
- data/bin/dropgit +18 -0
- data/lib/dropgit/daemon.rb +62 -0
- data/lib/dropgit/repository.rb +79 -0
- data/lib/dropgit/settings.rb +55 -0
- data/lib/dropgit.rb +82 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
ZjA4ZjMwNzM4ZTIxNThmYzkwMDJlNDkwNDMwNWQxNzg1ODI4ZWJkYg==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
NWNlZDM2ZTA2YjlhNWE2M2M3ZDJhOWRlMTkzODcxZGUyMTVlOTk2Zg==
|
|
7
|
+
!binary "U0hBNTEy":
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
MjJjYzE4ZDUzZGMyNWQ4NjJhMmJlMDU4ZTgxY2Q4NjJhNzM0OTFiZmEwNzQz
|
|
10
|
+
YzlhZjQ4ZTEzNzQ0MTdiNTFjYTkxNmZiMDYzMDNlNDAwMzQ1YmRmMDMyNzll
|
|
11
|
+
NDRmNzkxMTBhMTQzM2UxMGQzZjBjZWYyOTE0M2YwOGQ4NGZmNDE=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
ZjY5OGVlMTRkYjBiNGYzYzczMWIwODAxODE1ZDdlOTAyZWE0ZmFmOWEyZjI0
|
|
14
|
+
MWRjMzRhZmFjY2NmNGQ1ZWRmOTM5NmI3NWRkMDBjMjRiZjUwMWE3ZDUwZDQ2
|
|
15
|
+
MGY5NDc2YWE5MWMxMDBlNzVjMTc4YzU3NzAxNjM3ZGQzNjllYzQ=
|
data/bin/dropgit
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'dropgit'
|
|
4
|
+
|
|
5
|
+
app = DropGit::App.new
|
|
6
|
+
|
|
7
|
+
if ARGV.length > 0 && app.respond_to?(ARGV[0])
|
|
8
|
+
begin
|
|
9
|
+
app.method(ARGV[0]).call(*ARGV.drop(1))
|
|
10
|
+
rescue Exception => e
|
|
11
|
+
if e.class != SystemExit
|
|
12
|
+
puts "Error: #{e.message}"
|
|
13
|
+
app.help
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
app.help
|
|
18
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'daemons'
|
|
2
|
+
require 'dropgit/repository.rb'
|
|
3
|
+
require 'dropgit/settings.rb'
|
|
4
|
+
|
|
5
|
+
module DropGit
|
|
6
|
+
class Daemon
|
|
7
|
+
def initialize
|
|
8
|
+
@repositories = []
|
|
9
|
+
DropGit.settings.repositories.each do |data|
|
|
10
|
+
@repositories << Repository.new(data)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# run
|
|
15
|
+
def run
|
|
16
|
+
loop do
|
|
17
|
+
@repositories.each { |r| r.update }
|
|
18
|
+
sleep 1
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# start daemon
|
|
23
|
+
def start
|
|
24
|
+
raise "DropGit daemon already started" if is_running
|
|
25
|
+
Daemons.daemonize({
|
|
26
|
+
:app_name => 'dropgit',
|
|
27
|
+
:dir_mode => :normal,
|
|
28
|
+
:dir => DropGit.settings.daemon_dir,
|
|
29
|
+
:log_output => true
|
|
30
|
+
})
|
|
31
|
+
run
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def stop
|
|
35
|
+
raise "DropGit daemon is already stopped" unless File.exists?(pid_file)
|
|
36
|
+
Process.kill("INT", pid)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# -- private ---
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def pid_file
|
|
43
|
+
"#{DropGit.settings.daemon_dir}/dropgit.pid"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def pid
|
|
47
|
+
`cat #{pid_file}`.to_i
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def is_running
|
|
51
|
+
return false unless File.exists?(pid_file)
|
|
52
|
+
begin
|
|
53
|
+
Process.kill(0, pid)
|
|
54
|
+
return true
|
|
55
|
+
rescue Exception => e
|
|
56
|
+
p "PID: #{e.message}"
|
|
57
|
+
return false
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module DropGit
|
|
2
|
+
class Repository
|
|
3
|
+
def self.create(path, remote)
|
|
4
|
+
data = {
|
|
5
|
+
'name' => File.basename(path),
|
|
6
|
+
'path' => path
|
|
7
|
+
}
|
|
8
|
+
new_repo = Repository.new(data)
|
|
9
|
+
new_repo.git_init(remote)
|
|
10
|
+
new_repo
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(data)
|
|
14
|
+
@name = data['name']
|
|
15
|
+
@path = data['path']
|
|
16
|
+
@git_dir = File.join(DropGit.settings.git_base, @name)
|
|
17
|
+
@git_cmd = "git --git-dir=#{@git_dir} --work-tree=#{@path}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update
|
|
21
|
+
if need_sync?
|
|
22
|
+
git_commit
|
|
23
|
+
git_push
|
|
24
|
+
puts "#{@name} remote was out of sync, pushed"
|
|
25
|
+
end
|
|
26
|
+
if git_pull
|
|
27
|
+
puts "#{@name} local was out of sync, pulled"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def git_init(remote)
|
|
32
|
+
@remote = remote
|
|
33
|
+
raise "Repository '#{@name}' already exists in '#{@git_dir}'" if File.exists?(@git_dir)
|
|
34
|
+
puts "Initializing git repository in #{@git_dir} from data in #{@path}"
|
|
35
|
+
puts git "init"
|
|
36
|
+
puts git "add ."
|
|
37
|
+
puts git "commit -m 'DropGit initial commit'"
|
|
38
|
+
puts git "remote add origin #{@remote}"
|
|
39
|
+
puts git "push -u origin master"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def data
|
|
43
|
+
{
|
|
44
|
+
'name' => @name,
|
|
45
|
+
'path' => @path,
|
|
46
|
+
'remote' => @remote
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# -- private --
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# check if need sycronization
|
|
54
|
+
def need_sync?
|
|
55
|
+
out = git "status"
|
|
56
|
+
!out.include?("nothing to commit")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def git_commit
|
|
60
|
+
message = "Dropgit: #{Time.new.to_s}"
|
|
61
|
+
git "add . -A"
|
|
62
|
+
git "commit -m '#{message}'"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def git_push
|
|
66
|
+
git "push"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def git_pull
|
|
70
|
+
out = git "pull"
|
|
71
|
+
out != "Already up-to-date.\n"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# call git
|
|
75
|
+
def git(params)
|
|
76
|
+
`#{@git_cmd} #{params}`
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
module DropGit
|
|
4
|
+
# Manage DropGit settings
|
|
5
|
+
class Settings
|
|
6
|
+
attr_accessor :repositories, :git_base, :daemon_dir
|
|
7
|
+
@@directory = File.join(Dir.home, ".dropgit")
|
|
8
|
+
@@filename = File.join(@@directory, "settings")
|
|
9
|
+
# Constructor
|
|
10
|
+
def initialize
|
|
11
|
+
Dir.mkdir(@@directory) unless Dir.exists?(@@directory)
|
|
12
|
+
load
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_repo(repository)
|
|
16
|
+
@repositories << repository.data
|
|
17
|
+
save
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# --- private ---
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# load
|
|
24
|
+
def load
|
|
25
|
+
if File.readable?(@@filename)
|
|
26
|
+
data = YAML::load(File.read(@@filename))
|
|
27
|
+
data.each do |key, val|
|
|
28
|
+
instance_variable_set("@#{key}", val)
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
populate_default
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# save
|
|
36
|
+
def save
|
|
37
|
+
data = {}
|
|
38
|
+
instance_variables.each {|var| data[var.to_s.delete("@")] = instance_variable_get(var) }
|
|
39
|
+
file = File.open(@@filename, 'w')
|
|
40
|
+
YAML::dump(data, file)
|
|
41
|
+
file.close
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def populate_default
|
|
45
|
+
puts "Initializing #{@@filename} with default settings"
|
|
46
|
+
@git_base = File.join(Dir.home, ".dropgit", "repositories") unless @git_base
|
|
47
|
+
Dir.mkdir(@git_base) unless Dir.exists?(@git_base)
|
|
48
|
+
@daemon_dir = "#{@@directory}/daemon"
|
|
49
|
+
Dir.mkdir(@daemon_dir) unless Dir.exists?(@daemon_dir)
|
|
50
|
+
@repositories = [] unless @repositories
|
|
51
|
+
save
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/dropgit.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'dropgit/settings'
|
|
2
|
+
require 'dropgit/repository'
|
|
3
|
+
require 'dropgit/daemon'
|
|
4
|
+
|
|
5
|
+
module DropGit
|
|
6
|
+
def self.settings=(settings)
|
|
7
|
+
@settings = settings
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.settings
|
|
11
|
+
@settings
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class App
|
|
15
|
+
# -- public --
|
|
16
|
+
public
|
|
17
|
+
# Constructor
|
|
18
|
+
def initialize
|
|
19
|
+
DropGit.settings = Settings.new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Show usage
|
|
23
|
+
def help
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Initialize repository for current directory
|
|
27
|
+
def init(remote)
|
|
28
|
+
raise "Specify a remote repository" unless remote
|
|
29
|
+
new_repo = Repository.create(Dir.pwd, remote)
|
|
30
|
+
DropGit.settings.add_repo new_repo
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def git(name)
|
|
34
|
+
repo = DropGit.settings.repositories.select { |data| data['name'] == name }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def list
|
|
38
|
+
repos = DropGit.settings.repositories
|
|
39
|
+
length = {}
|
|
40
|
+
repos.each do |repo|
|
|
41
|
+
repo.each do |key, val|
|
|
42
|
+
if length[key]
|
|
43
|
+
if val.length > length[key]
|
|
44
|
+
length[key] = val.length
|
|
45
|
+
end
|
|
46
|
+
else
|
|
47
|
+
length[key] = val.length
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
head = "|"
|
|
52
|
+
length.each do |key, val|
|
|
53
|
+
head << " " << key.ljust(val + 2) << "|"
|
|
54
|
+
end
|
|
55
|
+
puts "-" * head.length
|
|
56
|
+
puts head
|
|
57
|
+
puts "-" * head.length
|
|
58
|
+
repos.each do |repo|
|
|
59
|
+
line = "|"
|
|
60
|
+
repo.each do |key, val|
|
|
61
|
+
line << " " << val.ljust(length[key] + 2) << "|"
|
|
62
|
+
end
|
|
63
|
+
puts line
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# start daemon
|
|
68
|
+
def start
|
|
69
|
+
Daemon.new.start
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# debug daemon
|
|
73
|
+
def run
|
|
74
|
+
Daemon.new.run
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def stop
|
|
78
|
+
Daemon.new.stop
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dropgit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alessandro Pezzato
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Automagically put on git version control system a Dropbox folder
|
|
14
|
+
email: alessandro@pezzato.net
|
|
15
|
+
executables:
|
|
16
|
+
- dropgit
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/dropgit.rb
|
|
21
|
+
- lib/dropgit/daemon.rb
|
|
22
|
+
- lib/dropgit/repository.rb
|
|
23
|
+
- lib/dropgit/settings.rb
|
|
24
|
+
- bin/dropgit
|
|
25
|
+
homepage: http://pezzato.net/projects/dropgit.html
|
|
26
|
+
licenses: []
|
|
27
|
+
metadata: {}
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ! '>='
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ! '>='
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
requirements: []
|
|
43
|
+
rubyforge_project:
|
|
44
|
+
rubygems_version: 2.0.3
|
|
45
|
+
signing_key:
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Drop Git
|
|
48
|
+
test_files: []
|