packc 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.
- checksums.yaml +7 -0
- data/bin/pack +69 -0
- data/lib/app.rb +36 -0
- data/lib/tasks/api.rb +40 -0
- data/lib/tasks/watch.rb +9 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 805e2e43e71aa5f56709ece66e1ee98a78faef23
|
4
|
+
data.tar.gz: 679353a43406cf7c856602a5e81c903a26805c87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92c12ed52e56a274872fade9378f96bf9ee2d7b6e5dc06a916532275e0e8114f4d2c5447170bb7d151eebaacca5a8e99398c9195f80884af58c5c8d7817b16dd
|
7
|
+
data.tar.gz: 001a96b38c26addd8f55cfdf2b1761d04f092d0923e6d7df7b2b6d9eec7e9782e8a5aa3150361e8e3c4d9f155c44eccdc84f4209a7bd7076345de318e4babcd6
|
data/bin/pack
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'daemons'
|
5
|
+
require_relative '../lib/app'
|
6
|
+
|
7
|
+
# Default configurations
|
8
|
+
$DEFAULT_CONFIG = '{
|
9
|
+
"server": "http://localhost:3000",
|
10
|
+
"email": "",
|
11
|
+
"pass": ""
|
12
|
+
}'
|
13
|
+
|
14
|
+
# CLI class
|
15
|
+
class CommandLine < Thor
|
16
|
+
desc 'upload', 'Upload file(s) to server'
|
17
|
+
method_option :replace, :aliases => '-r', :desc => 'Replace remote files with duplicate names', :type => :boolean
|
18
|
+
def upload(*paths)
|
19
|
+
expand_paths paths
|
20
|
+
paths.each do |path|
|
21
|
+
App.api.post_file path, options[:replace]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'watch', 'Watch for changes and sync files, replaces files by default'
|
26
|
+
method_option :no_replace, :desc => 'Do not replace files but upload a new instance with each change', :type => :boolean, :default => false
|
27
|
+
def watch(*paths)
|
28
|
+
threads = []
|
29
|
+
expand_paths paths
|
30
|
+
|
31
|
+
replace = !options[:no_replace]
|
32
|
+
|
33
|
+
paths.each do |path|
|
34
|
+
threads << Thread.new do
|
35
|
+
App.watch path do |event|
|
36
|
+
if event == :create or event == :modify
|
37
|
+
App.api.post_file path, replace
|
38
|
+
elsif event == :delete
|
39
|
+
App.api.delete_file path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
threads.each do |t| t.join end
|
46
|
+
end
|
47
|
+
|
48
|
+
no_commands do
|
49
|
+
def expand_paths(paths)
|
50
|
+
paths.each do |path|
|
51
|
+
path = File.expand_path path
|
52
|
+
|
53
|
+
if File.directory? path
|
54
|
+
paths.delete path
|
55
|
+
entries = Dir.glob("#{path}/*").map do |child|
|
56
|
+
File.expand_path child
|
57
|
+
end
|
58
|
+
|
59
|
+
paths = paths.concat entries
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
require_relative '../lib/tasks/api'
|
67
|
+
App.setup
|
68
|
+
|
69
|
+
CommandLine.start
|
data/lib/app.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative './tasks/api'
|
2
|
+
require_relative './tasks/watch'
|
3
|
+
|
4
|
+
module App
|
5
|
+
include API
|
6
|
+
include Watch
|
7
|
+
@config_path = File.join(Dir.home, '.pack')
|
8
|
+
|
9
|
+
def self.setup
|
10
|
+
# Create config file
|
11
|
+
unless File.exists? @config_path
|
12
|
+
new_file = File.open(@config_path, 'w')
|
13
|
+
new_file.write $DEFAULT_CONFIG
|
14
|
+
new_file.close
|
15
|
+
end
|
16
|
+
|
17
|
+
# Read and Parse config file
|
18
|
+
@config_file = File.open(@config_path, 'r')
|
19
|
+
@config = JSON.parse(@config_file.read)
|
20
|
+
|
21
|
+
if @config['email'].empty? or @config['pass'].empty?
|
22
|
+
abort "You have not configured your credentials yet, add them to ~/.pack"
|
23
|
+
end
|
24
|
+
|
25
|
+
@config['username'] = @config['email'][/[^@]*/]
|
26
|
+
|
27
|
+
self.api.setup(@config)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.api
|
31
|
+
HTTP
|
32
|
+
end
|
33
|
+
def self.watch(path, &fn)
|
34
|
+
Watch.watch path, &fn
|
35
|
+
end
|
36
|
+
end
|
data/lib/tasks/api.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'httmultiparty'
|
2
|
+
|
3
|
+
module API
|
4
|
+
# API paths to send requests to
|
5
|
+
API_PATHS = {
|
6
|
+
files: '/files'
|
7
|
+
}
|
8
|
+
|
9
|
+
class HTTP
|
10
|
+
include HTTMultiParty
|
11
|
+
|
12
|
+
def self.setup(config)
|
13
|
+
@config = config
|
14
|
+
base_uri config['server']
|
15
|
+
@auth = {:username => config['email'], :password => config['pass']}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.post_file(path, replace)
|
19
|
+
res = self.post(API_PATHS[:files], :query => {
|
20
|
+
:file => {
|
21
|
+
:file => File.open(path)
|
22
|
+
},
|
23
|
+
:from => 'pack-client',
|
24
|
+
:replace => replace == true ? 'true' : nil
|
25
|
+
}, :detect_mime_type => true,
|
26
|
+
:accept => :json,
|
27
|
+
:basic_auth => @auth)
|
28
|
+
|
29
|
+
puts res.code == 200 ? 'Done.' : 'Error! ' + res.message
|
30
|
+
puts res
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.delete_file(path)
|
34
|
+
url = API_PATHS[:files] + '/' + @config['username'] + '/' + File.basename(path)
|
35
|
+
puts url
|
36
|
+
res = self.delete(url, :accept => :json, :basic_auth => @auth)
|
37
|
+
puts res.code == 200 ? 'Deleted': 'Error! ' + res.message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/tasks/watch.rb
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: packc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mahdi Dibaiee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: mdibaiee@aol.com
|
15
|
+
executables:
|
16
|
+
- pack
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/pack
|
21
|
+
- lib/app.rb
|
22
|
+
- lib/tasks/api.rb
|
23
|
+
- lib/tasks/watch.rb
|
24
|
+
homepage: https://github.com/mdibaiee/pack
|
25
|
+
licenses:
|
26
|
+
- GPUv3
|
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.4.8
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Dead-simple self-hosted cloud storage
|
48
|
+
test_files: []
|