nodes 0.1.7 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nodes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eugene Markine
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 CHANGED
@@ -0,0 +1,29 @@
1
+ # Nodes
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'nodes'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nodes
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 point.
9
- # point add "{ name: 'test point', tag: test, zero, one: 1, two: [1,2] }"
8
+ # This command create new nodes in current directory:
9
+ # nodes init
10
10
  #
11
11
  # Other examples:
12
- # point find "{ name, tag, zero }"
13
- # point del "{ name, tag, zero, one, two }"
12
+ # nodes put
13
+ # nodes del
14
14
  #
15
15
  # == Usage
16
- # point [options] json_text/file.yml
16
+ # nodes [options]
17
17
  #
18
- # For help use: point -h
18
+ # For help use: nodes -h
19
19
  #
20
20
  # == Options
21
21
  # -h, --help Displays help message
@@ -26,7 +26,7 @@
26
26
  # Eugene Markine
27
27
  #
28
28
  # == Copyright
29
- # Copyright (c) 2010 EugeneLab. Licensed under the GNU General Public License (GPL), Version 2:
29
+ # Copyright (c) 2013 EugeneLab. Licensed under the GNU General Public License (GPL), Version 2:
30
30
  # http://www.opensource.org/licenses/gpl-2.0.php
31
31
 
32
32
  # TO DO - change license if necessary
@@ -37,15 +37,15 @@
37
37
  require "#{File.dirname(__FILE__)}/../lib/nodes"
38
38
 
39
39
  commands_help = "Commands:\n" \
40
- " init Init new point\n" \
41
- " del Delete point \n" \
42
- " clone Clone point from server\n" \
43
- " put Put changes to server\n" \
40
+ " init Init new nodes\n" \
41
+ " list List of nodes on the nodes\n" \
42
+ " del Delete the nodes \n" \
44
43
  " get Get changes from server\n" \
45
- " size Size of point\n" \
44
+ " put Put changes to server\n" \
45
+ " size Size of the nodes\n" \
46
46
  "\n"
47
- # " country <ip> Extract a country name from IP address\n"
48
- usage_help = "usage: point command [arguments...] [options...]\n\n" + commands_help
47
+
48
+ usage_help = "usage: nodes command [arguments...] [options...]\n\n" + commands_help
49
49
 
50
50
  unless ARGV.first
51
51
  puts "Nodes #{Nodes::VERSION}"
@@ -54,8 +54,8 @@ unless ARGV.first
54
54
  end
55
55
 
56
56
  command = ARGV.shift
57
- dir = ARGV.first
58
- dir = Dir.pwd unless dir
57
+ #dir = ARGV.first
58
+ #dir = Dir.pwd unless dir
59
59
 
60
60
  #puts "find: #{ARGV.find "-h"}"
61
61
 
@@ -64,26 +64,17 @@ case command
64
64
  when 'version'
65
65
  puts "Nodes #{Nodes::VERSION}"
66
66
  when 'init'
67
- Nodes.init dir
68
- Nodes.put dir
69
- when 'clone'
70
- name = ARGV.first
71
- unless name
72
- puts "You must specify a name to clone.\n\n"
73
- puts "usage: point clone <name>\n\n"
74
- exit
75
- end
76
- Nodes.clone name
67
+ Nodes.init
68
+ when 'list'
69
+ Nodes.list
77
70
  when 'put'
78
- Nodes.put dir
71
+ Nodes.put
79
72
  when 'get'
80
- Nodes.get dir
73
+ Nodes.get
81
74
  when 'del'
82
- Nodes.del dir
75
+ Nodes.del
83
76
  when 'size'
84
- Nodes.size dir
85
- when 'country'
86
- Nodes.country(ARGV.shift)
77
+ Nodes.size
87
78
  else
88
79
  puts "Unknown command: #{command}\n"
89
80
  puts commands_help
@@ -0,0 +1,37 @@
1
+ require "./node"
2
+ require 'digest/sha2'
3
+
4
+
5
+ class FileNode < Node
6
+
7
+ def initialize(file=nil)
8
+ super
9
+ file = __FILE__ unless file
10
+ file = File.expand_path(file)
11
+ if File.stat(file).file?
12
+ @keys['name'] = File.basename(file)
13
+ #@keys['path'] = File.dirname(file)
14
+ @keys['size'] = File.size(file)
15
+ sha2 = Digest::SHA2.new
16
+ File.open(file, 'r') do |fh|
17
+ while buffer = fh.read(1024)
18
+ sha2 << buffer
19
+ end
20
+ end
21
+ @keys['hash'] = sha2.hexdigest
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ #
28
+ #node = FileNode.new
29
+ #puts "yaml:"
30
+ #puts node.to_yaml
31
+ #puts
32
+ #puts "marshal:"
33
+ #puts Marshal.dump(node)
34
+ #p node.name
35
+ #p node.path
36
+ #p node.size
37
+ #p node.hash
data/lib/nodes/node.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ class Node
4
+
5
+ attr_accessor :keys
6
+
7
+ #
8
+ #attr_accessor :up, :down
9
+ #attr_accessor :left, :right
10
+ #attr_accessor :front, :back
11
+ #attr_accessor :previous, :next
12
+ #
13
+ #attr_accessor :store # directory where this node stored
14
+
15
+ def initialize(name=nil)
16
+ @keys = {}
17
+ @keys['name'] = name
18
+ end
19
+
20
+ def hash
21
+ @keys['hash']
22
+ end
23
+
24
+ def name=(name)
25
+ @keys['name'] = name
26
+ end
27
+
28
+ def tags=(tags)
29
+ @keys['tags'] = tags
30
+ end
31
+
32
+ def method_missing(name, *args, &block)
33
+ if @keys.key?(name.to_s)
34
+ @keys[name.to_s]
35
+ else
36
+ super
37
+ end
38
+ end
39
+
40
+ def ==(other)
41
+ return self.size == other.size && self.hash == other.hash
42
+ end
43
+
44
+ def dump(filename=nil)
45
+ filename = ".#{self.class.name}.yml" unless filename
46
+ File.open(filename, "w") do |file|
47
+ file.write self.to_yaml
48
+ end
49
+ end
50
+
51
+ def self.load(filename=nil)
52
+ filename = ".#{self.name}.yml" unless filename
53
+ YAML::load_file(filename)
54
+ end
55
+
56
+ end
57
+
58
+
59
+
60
+ #node = Node.new("ирбиш")
61
+ #node = Node.new("irbish")
62
+ #p node.name
63
+ #p node.keys
@@ -0,0 +1,57 @@
1
+ require "./node"
2
+ require "./file_node"
3
+
4
+ class Point < Node
5
+
6
+ def initialize(path=nil)
7
+ super
8
+ path = File.dirname(__FILE__) unless path
9
+ @keys['name'] = File.basename(path)
10
+ @keys['path'] = path
11
+ files = []
12
+ Dir.glob("**/*").each do |filename|
13
+ filepath = "#{path}/#{filename}"
14
+ if File.stat(filepath).file?
15
+ file = FileNode.new(filepath)
16
+ tags = File.dirname(filename).split(File::SEPARATOR)
17
+ file.tags = tags if tags[0] != "."
18
+ files << file
19
+ end
20
+ end
21
+ @keys['size'] = files.inject(0){|sum,file| sum + file.size }
22
+ sha2 = Digest::SHA2.new
23
+ files.each do |file|
24
+ sha2 << file.hash
25
+ end
26
+ @keys['hash'] = sha2.hexdigest
27
+ @keys['list'] = files
28
+ end
29
+
30
+
31
+ end
32
+
33
+ #node = Point.new
34
+ #p node.list
35
+
36
+
37
+ #
38
+ #node = Point.new
39
+ #node.dump
40
+ #p node.size
41
+ #puts node.hash
42
+ #node = Point.load
43
+ #p node.size
44
+ #puts node.hash
45
+
46
+
47
+ #node.files.each do |file|
48
+ # p file
49
+ #end
50
+ #p node.size
51
+ #p node.hash
52
+ #
53
+ #puts "yaml:"
54
+ #puts node.to_yaml
55
+ #puts
56
+ #puts "marshal:"
57
+ #puts Marshal.dump(node)
@@ -0,0 +1,3 @@
1
+ module Nodes
2
+ VERSION = "0.2.1"
3
+ end
data/lib/nodes.rb CHANGED
@@ -1,75 +1,35 @@
1
- require 'find'
2
-
1
+ require "nodes/version"
3
2
 
4
3
  module Nodes
5
- VERSION = "0.1.7"
6
-
7
4
 
8
- def self.init(dir)
9
- puts "Init new point '#{File.basename(dir)}' in #{dir}"
10
- src = "#{File.dirname(__FILE__)}/../.point"
11
- system("cp -r #{src} #{dir}")
5
+ def self.init
6
+ puts "init new nodes in the file system"
12
7
  end
13
8
 
14
- def self.clone(name)
15
- puts "Clone from server point '#{name}'"
16
- dir = "#{Dir.pwd}/#{name}"
17
- return unless system("mkdir #{dir}")
18
- init dir
19
- get dir
9
+ def self.put
10
+ puts "put the nodes to server"
20
11
  end
21
12
 
22
- def self.put(dir)
23
- system("cd #{dir} && #{dir}/.point/put")
13
+ def self.get
14
+ puts "get the nodes to server"
24
15
  end
25
16
 
26
- def self.get(dir)
27
- system("cd #{dir} && #{dir}/.point/get")
17
+ def self.del
18
+ puts "delete the nodes from file system"
28
19
  end
29
20
 
30
- def self.del(dir)
31
- return unless system("cd #{dir} && #{dir}/.point/del")
32
- system("cd #{dir} && rm -rf #{dir}/.point")
21
+ def self.list
22
+ puts "list of nodes in the nodes"
33
23
  end
34
24
 
35
- def self.size(dir, hidden = false)
36
- total_size = 0
37
- total_files = 0
38
- total_directories = 0
39
- Find.find(dir) do |path|
40
- if FileTest.directory?(path)
41
- total_directories += 1
42
- if File.basename(path)[0] == ?.
43
- Find.prune # Don't look any further into this directory.
44
- else
45
- next
46
- end
47
- else
48
- if hidden || File.basename(path)[0] != ?.
49
- total_files += 1
50
- total_size += FileTest.size(path)
51
- # print path+" -> "
52
- # puts FileTest.size(path)
53
- end
54
- end
55
- end
56
- puts "size: #{total_size}"
57
- puts "directories: #{total_directories}"
58
- puts "files: #{total_files}"
25
+ def self.size(hidden = false)
26
+ puts "size of the nodes"
59
27
  end
60
28
 
61
- def self.country ip
62
- require 'geoip'
63
- print ip
64
- geoip = GeoIP.new("data/GeoIP.dat")
65
- location = geoip.country(p)
66
- country = location[2] if location != nil
67
- print " - #{country}"
68
- end
69
-
70
- def self.call cmd
71
- successfully = system(cmd)
72
- exit "blach" unless successfully
73
- end
29
+ #
30
+ #def self.call cmd
31
+ # successfully = system(cmd)
32
+ # exit "blach" unless successfully
33
+ #end
74
34
 
75
35
  end
@@ -0,0 +1,16 @@
1
+ class Model < FileNode
2
+
3
+
4
+
5
+ end
6
+
7
+
8
+ #
9
+ #node = Point.new
10
+ #node.dump
11
+ #p node.size
12
+ #puts node.hash
13
+ #node = Point.load
14
+ #p node.size
15
+ #puts node.hash
16
+
data/metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nodes
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 7
9
+ version: 0.1.7
10
+ platform: ruby
11
+ authors:
12
+ - Eugene Markine
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-12 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: Nodes is a data warehouse in the form of meta tags, which may have additional values
34
+ email:
35
+ - emarkine@gmail.com
36
+ executables:
37
+ - point
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - bin/command.rb
44
+ - bin/point
45
+ - lib/nodes.rb
46
+ - LICENSE
47
+ - README.md
48
+ - ROADMAP.md
49
+ - CHANGELOG.md
50
+ has_rdoc: true
51
+ homepage: http://eugenelab.com/nodes
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 3
75
+ - 6
76
+ version: 1.3.6
77
+ requirements: []
78
+
79
+ rubyforge_project: nodes
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Nodes is data management system based on OS files system
84
+ test_files: []
85
+
data/nodes.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nodes/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "nodes"
8
+ gem.version = Nodes::VERSION
9
+ gem.date = Time.now.strftime('%Y-%m-%d')
10
+ gem.summary = "easy manipulator of related nodes"
11
+ gem.description = "Nodes is a system of interconnected nodes through the named connections."
12
+ gem.authors = ["Eugene Markine"]
13
+ gem.email = ["eugene@markine.nl"]
14
+ gem.homepage = "http://eugenelab.com"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
metadata CHANGED
@@ -1,85 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nodes
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 7
9
- version: 0.1.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Eugene Markine
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-11-12 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
31
- type: :development
32
- version_requirements: *id001
33
- description: Nodes is a data warehouse in the form of meta tags, which may have additional values
34
- email:
35
- - emarkine@gmail.com
36
- executables:
37
- - point
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Nodes is a system of interconnected nodes through the named connections.
15
+ email:
16
+ - eugene@markine.nl
17
+ executables:
18
+ - nodes
38
19
  extensions: []
39
-
40
20
  extra_rdoc_files: []
41
-
42
- files:
43
- - bin/command.rb
44
- - bin/point
45
- - lib/nodes.rb
46
- - LICENSE
21
+ files:
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - LICENSE.txt
47
25
  - README.md
48
26
  - ROADMAP.md
49
- - CHANGELOG.md
50
- has_rdoc: true
51
- homepage: http://eugenelab.com/nodes
27
+ - Rakefile
28
+ - bin/nodes
29
+ - lib/nodes.rb
30
+ - lib/nodes/file_node.rb
31
+ - lib/nodes/node.rb
32
+ - lib/nodes/point.rb
33
+ - lib/nodes/version.rb
34
+ - lib/rails/model.rb
35
+ - metadata
36
+ - nodes.gemspec
37
+ homepage: http://eugenelab.com
52
38
  licenses: []
53
-
54
39
  post_install_message:
55
40
  rdoc_options: []
56
-
57
- require_paths:
41
+ require_paths:
58
42
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
43
+ required_ruby_version: !ruby/object:Gem::Requirement
60
44
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- segments:
65
- - 0
66
- version: "0"
67
- required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
50
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 1
74
- - 3
75
- - 6
76
- version: 1.3.6
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
77
55
  requirements: []
78
-
79
- rubyforge_project: nodes
80
- rubygems_version: 1.3.7
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.24
81
58
  signing_key:
82
59
  specification_version: 3
83
- summary: Nodes is data management system based on OS files system
60
+ summary: easy manipulator of related nodes
84
61
  test_files: []
85
-
data/LICENSE DELETED
File without changes
data/bin/point DELETED
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # == Synopsis
4
- # Nodes is a data warehouse in the form of meta tags, which may have additional values.
5
- # Users can add, delete, edit nodes, manage access rights, etc.
6
- #
7
- # == Examples
8
- # This command add new point.
9
- # point add "{ name: 'test point', tag: test, zero, one: 1, two: [1,2] }"
10
- #
11
- # Other examples:
12
- # point find "{ name, tag, zero }"
13
- # point del "{ name, tag, zero, one, two }"
14
- #
15
- # == Usage
16
- # point [options] json_text/file.yml
17
- #
18
- # For help use: point -h
19
- #
20
- # == Options
21
- # -h, --help Displays help message
22
- # -v, --version Display the version, then exit
23
- # TO DO - add additional options
24
- #
25
- # == Author
26
- # Eugene Markine
27
- #
28
- # == Copyright
29
- # Copyright (c) 2010 EugeneLab. Licensed under the GNU General Public License (GPL), Version 2:
30
- # http://www.opensource.org/licenses/gpl-2.0.php
31
-
32
- # TO DO - change license if necessary
33
-
34
- #require 'rubygems'
35
- #require "nodes"
36
-
37
- require "#{File.dirname(__FILE__)}/../lib/nodes"
38
-
39
- commands_help = "Commands:\n" \
40
- " init Init new point\n" \
41
- " del Delete point \n" \
42
- " clone Clone point from server\n" \
43
- " put Put changes to server\n" \
44
- " get Get changes from server\n" \
45
- " size Size of point\n" \
46
- "\n"
47
- # " country <ip> Extract a country name from IP address\n"
48
- usage_help = "usage: point command [arguments...] [options...]\n\n" + commands_help
49
-
50
- unless ARGV.first
51
- puts "Nodes #{Nodes::VERSION}"
52
- puts usage_help
53
- exit
54
- end
55
-
56
- command = ARGV.shift
57
- dir = ARGV.first
58
- dir = Dir.pwd unless dir
59
-
60
- #puts "find: #{ARGV.find "-h"}"
61
-
62
-
63
- case command
64
- when 'version'
65
- puts "Nodes #{Nodes::VERSION}"
66
- when 'init'
67
- Nodes.init dir
68
- Nodes.put dir
69
- when 'clone'
70
- name = ARGV.first
71
- unless name
72
- puts "You must specify a name to clone.\n\n"
73
- puts "usage: point clone <name>\n\n"
74
- exit
75
- end
76
- Nodes.clone name
77
- when 'put'
78
- Nodes.put dir
79
- when 'get'
80
- Nodes.get dir
81
- when 'del'
82
- Nodes.del dir
83
- when 'size'
84
- Nodes.size dir
85
- when 'country'
86
- Nodes.country(ARGV.shift)
87
- else
88
- puts "Unknown command: #{command}\n"
89
- puts commands_help
90
- end