nodes 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/command.rb +25 -16
  2. data/bin/{node → point} +25 -16
  3. data/lib/nodes.rb +38 -14
  4. metadata +5 -5
data/bin/command.rb CHANGED
@@ -5,17 +5,17 @@
5
5
  # Users can add, delete, edit nodes, manage access rights, etc.
6
6
  #
7
7
  # == Examples
8
- # This command add new node.
9
- # node add "{ name: 'test node', tag: test, zero, one: 1, two: [1,2] }"
8
+ # This command add new point.
9
+ # point add "{ name: 'test point', tag: test, zero, one: 1, two: [1,2] }"
10
10
  #
11
11
  # Other examples:
12
- # node find "{ name, tag, zero }"
13
- # node del "{ name, tag, zero, one, two }"
12
+ # point find "{ name, tag, zero }"
13
+ # point del "{ name, tag, zero, one, two }"
14
14
  #
15
15
  # == Usage
16
- # node [options] json_text/file.yml
16
+ # point [options] json_text/file.yml
17
17
  #
18
- # For help use: node -h
18
+ # For help use: point -h
19
19
  #
20
20
  # == Options
21
21
  # -h, --help Displays help message
@@ -31,8 +31,10 @@
31
31
 
32
32
  # TO DO - change license if necessary
33
33
 
34
- require 'rubygems'
35
- require "nodes"
34
+ #require 'rubygems'
35
+ #require "nodes"
36
+
37
+ require "#{File.dirname(__FILE__)}/../lib/nodes"
36
38
 
37
39
  commands_help = "Commands:\n" \
38
40
  " init Init new point\n" \
@@ -40,9 +42,10 @@ commands_help = "Commands:\n" \
40
42
  " clone Clone point from server\n" \
41
43
  " put Put changes to server\n" \
42
44
  " get Get changes from server\n" \
43
- "\n"
45
+ " size Size of point\n" \
46
+ "\n"
44
47
  # " country <ip> Extract a country name from IP address\n"
45
- usage_help = "usage: node command [arguments...] [options...]\n\n" + commands_help
48
+ usage_help = "usage: point command [arguments...] [options...]\n\n" + commands_help
46
49
 
47
50
  unless ARGV.first
48
51
  puts "Nodes #{Nodes::VERSION}"
@@ -51,28 +54,34 @@ unless ARGV.first
51
54
  end
52
55
 
53
56
  command = ARGV.shift
57
+ dir = ARGV.first
58
+ dir = Dir.pwd unless dir
59
+
60
+ #puts "find: #{ARGV.find "-h"}"
61
+
54
62
 
55
63
  case command
56
64
  when 'version'
57
65
  puts "Nodes #{Nodes::VERSION}"
58
66
  when 'init'
59
- dir = ARGV.shift
60
67
  Nodes.init dir
61
68
  Nodes.put dir
62
69
  when 'clone'
63
- name = ARGV.shift
70
+ name = ARGV.first
64
71
  unless name
65
72
  puts "You must specify a name to clone.\n\n"
66
- puts "usage: node clone <name>\n\n"
73
+ puts "usage: point clone <name>\n\n"
67
74
  exit
68
75
  end
69
76
  Nodes.clone name
70
77
  when 'put'
71
- Nodes.put ARGV.shift
78
+ Nodes.put dir
72
79
  when 'get'
73
- Nodes.get ARGV.shift
80
+ Nodes.get dir
74
81
  when 'del'
75
- Nodes.del ARGV.shift
82
+ Nodes.del dir
83
+ when 'size'
84
+ Nodes.size dir
76
85
  when 'country'
77
86
  Nodes.country(ARGV.shift)
78
87
  else
data/bin/{node → point} RENAMED
@@ -5,17 +5,17 @@
5
5
  # Users can add, delete, edit nodes, manage access rights, etc.
6
6
  #
7
7
  # == Examples
8
- # This command add new node.
9
- # node add "{ name: 'test node', tag: test, zero, one: 1, two: [1,2] }"
8
+ # This command add new point.
9
+ # point add "{ name: 'test point', tag: test, zero, one: 1, two: [1,2] }"
10
10
  #
11
11
  # Other examples:
12
- # node find "{ name, tag, zero }"
13
- # node del "{ name, tag, zero, one, two }"
12
+ # point find "{ name, tag, zero }"
13
+ # point del "{ name, tag, zero, one, two }"
14
14
  #
15
15
  # == Usage
16
- # node [options] json_text/file.yml
16
+ # point [options] json_text/file.yml
17
17
  #
18
- # For help use: node -h
18
+ # For help use: point -h
19
19
  #
20
20
  # == Options
21
21
  # -h, --help Displays help message
@@ -31,8 +31,10 @@
31
31
 
32
32
  # TO DO - change license if necessary
33
33
 
34
- require 'rubygems'
35
- require "nodes"
34
+ #require 'rubygems'
35
+ #require "nodes"
36
+
37
+ require "#{File.dirname(__FILE__)}/../lib/nodes"
36
38
 
37
39
  commands_help = "Commands:\n" \
38
40
  " init Init new point\n" \
@@ -40,9 +42,10 @@ commands_help = "Commands:\n" \
40
42
  " clone Clone point from server\n" \
41
43
  " put Put changes to server\n" \
42
44
  " get Get changes from server\n" \
43
- "\n"
45
+ " size Size of point\n" \
46
+ "\n"
44
47
  # " country <ip> Extract a country name from IP address\n"
45
- usage_help = "usage: node command [arguments...] [options...]\n\n" + commands_help
48
+ usage_help = "usage: point command [arguments...] [options...]\n\n" + commands_help
46
49
 
47
50
  unless ARGV.first
48
51
  puts "Nodes #{Nodes::VERSION}"
@@ -51,28 +54,34 @@ unless ARGV.first
51
54
  end
52
55
 
53
56
  command = ARGV.shift
57
+ dir = ARGV.first
58
+ dir = Dir.pwd unless dir
59
+
60
+ #puts "find: #{ARGV.find "-h"}"
61
+
54
62
 
55
63
  case command
56
64
  when 'version'
57
65
  puts "Nodes #{Nodes::VERSION}"
58
66
  when 'init'
59
- dir = ARGV.shift
60
67
  Nodes.init dir
61
68
  Nodes.put dir
62
69
  when 'clone'
63
- name = ARGV.shift
70
+ name = ARGV.first
64
71
  unless name
65
72
  puts "You must specify a name to clone.\n\n"
66
- puts "usage: node clone <name>\n\n"
73
+ puts "usage: point clone <name>\n\n"
67
74
  exit
68
75
  end
69
76
  Nodes.clone name
70
77
  when 'put'
71
- Nodes.put ARGV.shift
78
+ Nodes.put dir
72
79
  when 'get'
73
- Nodes.get ARGV.shift
80
+ Nodes.get dir
74
81
  when 'del'
75
- Nodes.del ARGV.shift
82
+ Nodes.del dir
83
+ when 'size'
84
+ Nodes.size dir
76
85
  when 'country'
77
86
  Nodes.country(ARGV.shift)
78
87
  else
data/lib/nodes.rb CHANGED
@@ -1,11 +1,12 @@
1
+ require 'find'
2
+
1
3
  module Nodes
2
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
3
5
 
4
6
 
5
- def self.init(dir=nil)
6
- dir = Dir.pwd unless dir
7
+ def self.init(dir)
7
8
  puts "Init new point '#{File.basename(dir)}' in #{dir}"
8
- src = "#{File.dirname(__FILE__)}/../.node"
9
+ src = "#{File.dirname(__FILE__)}/../.point"
9
10
  system("cp -r #{src} #{dir}")
10
11
  end
11
12
 
@@ -17,20 +18,43 @@ module Nodes
17
18
  get dir
18
19
  end
19
20
 
20
- def self.put(dir=nil)
21
- dir = Dir.pwd unless dir
22
- system("cd #{dir} && #{dir}/.node/put")
21
+ def self.put(dir)
22
+ system("cd #{dir} && #{dir}/.point/put")
23
+ end
24
+
25
+ def self.get(dir)
26
+ system("cd #{dir} && #{dir}/.point/get")
23
27
  end
24
28
 
25
- def self.get(dir=nil)
26
- dir = Dir.pwd unless dir
27
- system("cd #{dir} && #{dir}/.node/get")
29
+ def self.del(dir)
30
+ return unless system("cd #{dir} && #{dir}/.point/del")
31
+ system("cd #{dir} && rm -rf #{dir}/.point")
28
32
  end
29
33
 
30
- def self.del(dir=nil)
31
- dir = Dir.pwd unless dir
32
- return unless system("cd #{dir} && #{dir}/.node/del")
33
- system("cd #{dir} && rm -rf #{dir}/.node")
34
+ def self.size(dir, hidden = false)
35
+ total_size = 0
36
+ total_files = 0
37
+ total_directories = 0
38
+ Find.find(dir) do |path|
39
+ if FileTest.directory?(path)
40
+ total_directories += 1
41
+ if File.basename(path)[0] == ?.
42
+ Find.prune # Don't look any further into this directory.
43
+ else
44
+ next
45
+ end
46
+ else
47
+ if hidden || File.basename(path)[0] != ?.
48
+ total_files += 1
49
+ total_size += FileTest.size(path)
50
+ # print path+" -> "
51
+ # puts FileTest.size(path)
52
+ end
53
+ end
54
+ end
55
+ puts "size: #{total_size}"
56
+ puts "directories: #{total_directories}"
57
+ puts "files: #{total_files}"
34
58
  end
35
59
 
36
60
  def self.country ip
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eugene Markine
@@ -34,14 +34,14 @@ description: Nodes is a data warehouse in the form of meta tags, which may have
34
34
  email:
35
35
  - emarkine@gmail.com
36
36
  executables:
37
- - node
37
+ - point
38
38
  extensions: []
39
39
 
40
40
  extra_rdoc_files: []
41
41
 
42
42
  files:
43
43
  - bin/command.rb
44
- - bin/node
44
+ - bin/point
45
45
  - lib/nodes.rb
46
46
  - LICENSE
47
47
  - README.md
@@ -80,6 +80,6 @@ rubyforge_project: nodes
80
80
  rubygems_version: 1.3.7
81
81
  signing_key:
82
82
  specification_version: 3
83
- summary: Nodes Spin
83
+ summary: Nodes is data management system based on OS files system
84
84
  test_files: []
85
85