Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 461d5824 authored by Cyril Rohr's avatar Cyril Rohr Committed by g5kadmin user
Browse files

Generator now explictly requires bundler to enfore the same dependencies...

Generator now explictly requires bundler to enfore the same dependencies between sites. Refactored JSON generation.
parent 59495341
No related branches found
No related tags found
No related merge requests found
source :rubygems
gem 'json_pure', '~> 1.5'
GEM
remote: http://rubygems.org/
specs:
json_pure (1.5.1)
PLATFORMS
ruby
DEPENDENCIES
json_pure (~> 1.5)
...@@ -8,7 +8,7 @@ The reference data is stored in a Git repository as JSON files, organized into h ...@@ -8,7 +8,7 @@ The reference data is stored in a Git repository as JSON files, organized into h
== Requirements == == Requirements ==
* Ruby >= 1.8.6 * Ruby >= 1.8.6
* JSON (<code>apt-get install libjson-ruby</code> or <code>gem install json</code>) * Bundler (<code>gem install bundler</code>)
* Git * Git
* g5kadmin account * g5kadmin account
...@@ -46,7 +46,11 @@ Finally, these changes are automatically replicated every minute to each API REP ...@@ -46,7 +46,11 @@ Finally, these changes are automatically replicated every minute to each API REP
== Getting started == == Getting started ==
First, clone the remote MASTER REPOSITORY if it is not already done: First, clone the remote MASTER REPOSITORY if it is not already done:
g5kadmin@host:/somewhere/reference-repository$ git clone ssh://g5kadmin@git.grid5000.fr/srv/git/repos/reference-repository.git g5kadmin@host:/somewhere$ git clone ssh://g5kadmin@git.grid5000.fr/srv/git/repos/reference-repository.git
From the newly created reference-repository folder, run the following command to install the required dependencies:
g5kadmin@host:/somewhere/reference-repository$ bundle install
Right now, the easiest way to get started is to look at some existing input files in the "generators/input" directory. There you can see how you can define sites, clusters, nodes and environments programmatically. Right now, the easiest way to get started is to look at some existing input files in the "generators/input" directory. There you can see how you can define sites, clusters, nodes and environments programmatically.
Then you may create a new input file or change an existing one and run it in simulation mode: Then you may create a new input file or change an existing one and run it in simulation mode:
......
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'pp'
require 'rubygems' require 'rubygems'
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue LoadError => e
STDERR.puts e.message
STDERR.puts "Try installing bundler: `gem install bundler`"
exit!
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end
require 'pp'
require 'fileutils' require 'fileutils'
require 'json' require 'json'
require 'yaml' require 'yaml'
......
require 'json/pure'
module JSON
module Pure
module Generator
module GeneratorMethods
module Hash
private
# overwrites json/pure method
def json_transform(state)
delim = ','
delim << state.object_nl
result = '{'
result << state.object_nl
depth = state.depth += 1
first = true
indent = !state.object_nl.empty?
keys.map{|k| k.to_s}.sort.each { |key|
value = self[key] || self[key.to_sym]
result << delim unless first
result << state.indent * depth if indent
result << key.to_s.to_json(state)
result << state.space_before
result << ':'
result << state.space
result << case value
# no idea why this is not handled by json/pure
when Fixnum
value.to_s
else
value.to_json(state)
end
first = false
}
depth = state.depth -= 1
result << state.object_nl
result << state.indent * depth if indent if indent
result << '}'
result
end
end
end
end
end
end
class Numeric class Numeric
def K; self*10**3; end def K; self*10**3; end
def M; self*10**6; end def M; self*10**6; end
def G; self*10**9; end def G; self*10**9; end
def T; self*10**12; end def T; self*10**12; end
{ {
:KiB => 1024, :MiB => 1024**2, :GiB => 1024**3, :TiB => 1024**4, :KiB => 1024, :MiB => 1024**2, :GiB => 1024**3, :TiB => 1024**4,
:KB => 1.K/1.024, :MB => 1.M/1.024**2, :GB => 1.G/1.024**3, :TB => 1.T/1.024**4 :KB => 1.K/1.024, :MB => 1.M/1.024**2, :GB => 1.G/1.024**3, :TB => 1.T/1.024**4
}.each do |method, multiplier| }.each do |method, multiplier|
...@@ -26,68 +74,8 @@ end ...@@ -26,68 +74,8 @@ end
class Hash class Hash
def recursive_merge!(h) def recursive_merge!(h)
self.merge!(h) {|key, _old, _new| if _old.class == Hash then _old.recursive_merge!(_new) else _new end } self.merge!(h) {|key, _old, _new| if _old.class == Hash then _old.recursive_merge!(_new) else _new end }
end
# Returns a JSON string containing a JSON object, that is unparsed from
# this Hash instance.
# _state_ is a JSON::State object, that can also be used to configure the
# produced JSON string output further.
# _depth_ is used to find out nesting depth, to indent accordingly.
#
# Contrary to the original implementation, the keys are *sorted*.
#
def to_json(state = nil, depth = 0, *)
if state
state = JSON.state.from_state(state)
state.check_max_nesting(depth)
json_check_circular(state) { json_transform(state, depth) }
else
json_transform(state, depth)
end
end
private
def json_check_circular(state)
if state and state.check_circular?
state.seen?(self) and raise JSON::CircularDatastructure,
"circular data structures not supported!"
state.remember self
end
yield
ensure
state and state.forget self
end
def json_shift(state, depth)
state and not state.object_nl.empty? or return ''
state.indent * depth
end end
def json_transform(state, depth)
tmp_hash = {}
self.each do |key, value|
tmp_hash[key.to_s] = value
end
delim = ','
delim << state.object_nl if state
result = '{'
result << state.object_nl if state
result << tmp_hash.sort.map { |(key,value)|
s = json_shift(state, depth + 1)
s << key.to_s.to_json(state, depth + 1)
s << state.space_before if state
s << ':'
s << state.space if state
s << value.to_json(state, depth + 1)
}.join(delim)
result << state.object_nl if state
result << json_shift(state, depth)
result << '}'
result
end
end end
...@@ -105,5 +93,5 @@ module Enumerable ...@@ -105,5 +93,5 @@ module Enumerable
r = Hash.new r = Hash.new
each{ |e| (r[yield(e)] ||= []) << e } each{ |e| (r[yield(e)] ||= []) << e }
r r
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment