aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-06-19 17:51:24 -0700
committerelijah <elijah@riseup.net>2013-06-19 17:51:24 -0700
commit23aa42d957294b025a367c543cd99f137c48e289 (patch)
treedba6247f616c72cf9b737d7a47b837498449b685 /lib
parent5675bd54cf7dc11a234bb305c64c801c4eeaea62 (diff)
downloadleap_cli-23aa42d957294b025a367c543cd99f137c48e289.tar.gz
leap_cli-23aa42d957294b025a367c543cd99f137c48e289.tar.bz2
fixed utf8 bug when locale not set, and improved testing for ruby 1.8.
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli.rb2
-rw-r--r--lib/leap_cli/config/manager.rb23
-rw-r--r--lib/leap_cli/config/object.rb4
-rw-r--r--lib/leap_cli/version.rb2
4 files changed, 23 insertions, 8 deletions
diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb
index 259c00f..2f9ffec 100644
--- a/lib/leap_cli.rb
+++ b/lib/leap_cli.rb
@@ -1,5 +1,7 @@
module LeapCli; end
+$ruby_version = RUBY_VERSION.split('.').collect{ |i| i.to_i }.extend(Comparable)
+
require 'leap/platform.rb'
require 'leap_cli/version.rb'
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index d2bc1f3..92cf190 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -1,5 +1,9 @@
require 'json/pure'
+if $ruby_version < [1,9]
+ require 'iconv'
+end
+
module LeapCli
module Config
@@ -218,9 +222,18 @@ module LeapCli
end
end
+ #
+ # force UTF-8
+ #
+ if $ruby_version >= [1,9]
+ string = buffer.string.force_encoding('utf-8')
+ else
+ string = Iconv.conv("UTF-8//IGNORE", "UTF-8", buffer.string)
+ end
+
# parse json
begin
- hash = JSON.parse(buffer.string, :object_class => Hash, :array_class => Array) || {}
+ hash = JSON.parse(string, :object_class => Hash, :array_class => Array) || {}
rescue SyntaxError, JSON::ParserError => exc
log 0, :error, 'in file "%s":' % filename
log 0, exc.to_s, :indent => 1
@@ -293,11 +306,10 @@ module LeapCli
def remove_disabled_nodes
@disabled_nodes = Config::ObjectList.new
- @nodes.select! do |name, node|
- if node.enabled
- true
- else
+ @nodes.each do |name, node|
+ unless node.enabled
log 2, :skipping, "disabled node #{name}."
+ @nodes.delete(name)
@disabled_nodes[name] = node
if node['services']
node['services'].to_a.each do |node_service|
@@ -309,7 +321,6 @@ module LeapCli
@tags[node_tag].node_list.delete(node.name)
end
end
- false
end
end
end
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index b88c7b4..1edef3f 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -1,7 +1,9 @@
require 'erb'
require 'json/pure' # pure ruby implementation is required for our sorted trick to work.
-$KCODE = 'UTF8' unless RUBY_VERSION > "1.9.0"
+if $ruby_version < [1,9]
+ $KCODE = 'UTF8'
+end
require 'ya2yaml' # pure ruby yaml
require 'leap_cli/config/macros'
diff --git a/lib/leap_cli/version.rb b/lib/leap_cli/version.rb
index bbec03a..00df109 100644
--- a/lib/leap_cli/version.rb
+++ b/lib/leap_cli/version.rb
@@ -1,6 +1,6 @@
module LeapCli
unless defined?(LeapCli::VERSION)
- VERSION = '1.1.0'
+ VERSION = '1.1.1'
SUMMARY = 'Command line interface to the LEAP platform'
DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.'
LOAD_PATHS = ['lib', 'vendor/certificate_authority/lib', 'vendor/rsync_command/lib']