Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove rarely used session functionality

  • Loading branch information...
commit e075fabc2c432934734672011f29445480e144fc 1 parent 0b7ef2b
Rich Lane authored
View
25 bin/rvc
@@ -57,34 +57,15 @@ end
$interactive = $opts[:script].nil? and $stdin.tty?
-session = if ENV['RVC_SESSION'] and not ENV['RVC_SESSION'].empty?
- RVC::FilesystemSession.new ENV['RVC_SESSION']
-else
- RVC::MemorySession.new
-end
-
# TODO remove $shell when all references are gone
-$shell = shell = RVC::Shell.new(session)
+$shell = shell = RVC::Shell.new
shell.reload_modules false
# Prompt for hostname if none given. Useful on win32.
-if shell.session.connections.empty? and ARGV.empty? and $interactive
+if ARGV.empty? and $interactive
ARGV << Readline.readline("Host to connect to (user@host): ")
end
-# TODO update or remove
-shell.session.connections.each do |key|
- conn = shell.session.get_connection(key) or fail "no such connection #{key.inspect}"
- uri = "#{conn['username']}@#{conn['host']}"
- begin
- puts "Connecting to #{conn['host']}..."
- shell.cmds.vim.connect uri, {}
- rescue RVC::Util::UserError
- puts "Failed to connect to #{conn['host']}: #{$!.message}"
- exit 1
- end
-end
-
# TODO cookies, cert digests
ARGV.each do |str|
begin
@@ -95,7 +76,7 @@ ARGV.each do |str|
end
begin
- puts "Connecting to #{uri.host}..." if (ARGV+shell.session.connections).size > 1
+ puts "Connecting to #{uri.host}..." if ARGV.size > 1
scheme = uri.scheme || 'vim'
scheme_handler = RVC::SCHEMES[scheme] or RVC::Util.err "invalid scheme #{scheme.inspect}"
scheme_handler[uri]
View
2  lib/rvc.rb
@@ -30,5 +30,3 @@ module RVC
require 'rvc/completion'
require 'rvc/option_parser'
require 'rvc/shell'
-require 'rvc/memory_session'
-require 'rvc/filesystem_session'
View
2  lib/rvc/completion.rb
@@ -175,7 +175,7 @@ def child_candidates word
def mark_candidates word
return [] unless word.empty? || word[0..0] == '~'
prefix_regex = /^#{Regexp.escape(word[1..-1] || '')}/
- @shell.session.marks.grep(prefix_regex).sort.
+ @shell.fs.marks.keys.grep(prefix_regex).sort.
map { |x| ["~#{x}", '/'] }
end
end
View
101 lib/rvc/filesystem_session.rb
@@ -1,101 +0,0 @@
-# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-module RVC
-
-class FilesystemSession
- def initialize name
- fail "invalid session name" unless name =~ /^[\w-]+$/
- @dir = File.join(ENV['HOME'], '.rvc', 'sessions', name)
- prev_umask = File.umask 077
- FileUtils.mkdir_p @dir
- FileUtils.mkdir_p mark_dir
- FileUtils.mkdir_p connection_dir
- File.umask prev_umask
- @priv = {}
- end
-
- def marks
- Dir.entries(mark_dir).reject { |x| x == '.' || x == '..' } + @priv.keys
- end
-
- def get_mark key
- if is_private_mark? key
- @priv[key]
- else
- return nil unless File.exists? mark_fn(key)
- File.readlines(mark_fn(key)).
- map { |path| $shell.fs.lookup(path.chomp) }.
- inject([], &:+)
- end
- end
-
- def set_mark key, objs
- if is_private_mark? key
- if objs == nil
- @priv.delete key
- else
- @priv[key] = objs
- end
- else
- if objs == nil
- File.unlink mark_fn(key)
- else
- File.open(mark_fn(key), 'w') do |io|
- objs.each { |obj| io.puts obj.rvc_path_str }
- end
- end
- end
- end
-
- def connections
- Dir.entries(connection_dir).reject { |x| x == '.' || x == '..' }
- end
-
- def get_connection key
- return nil unless File.exists? connection_fn(key)
- File.open(connection_fn(key)) { |io| YAML.load io }
- end
-
- def set_connection key, conn
- if conn == nil
- File.unlink(connection_fn(key))
- else
- File.open(connection_fn(key), 'w') { |io| YAML.dump conn, io }
- end
- end
-
- private
-
- def is_private_mark? key
- return key == '' ||
- key == '~' ||
- key == '@' ||
- key =~ /^\d+$/
- end
-
- def mark_dir; File.join(@dir, 'marks') end
- def mark_fn(key); File.join(mark_dir, key) end
- def connection_dir; File.join(@dir, 'connections') end
- def connection_fn(key); File.join(connection_dir, key) end
-end
-
-end
-
View
16 lib/rvc/fs.rb
@@ -21,17 +21,17 @@
module RVC
class FS
- attr_reader :root, :cur
+ attr_reader :root, :cur, :marks
MARK_PATTERN = /^~(?:([\d\w]*|~|@))$/
REGEX_PATTERN = /^%/
GLOB_PATTERN = /\*/
- def initialize root, session
+ def initialize root
fail unless root.is_a? RVC::InventoryObject
@root = root
@cur = root
- @session = session
+ @marks = {}
end
def display_path
@@ -40,7 +40,7 @@ def display_path
def cd dst
fail unless dst.is_a? RVC::InventoryObject
- @session.set_mark '~', [@cur]
+ @marks['~'] = [@cur]
@cur = dst
end
@@ -71,7 +71,7 @@ def traverse_one cur, arc, first
# XXX shouldnt be nil
[(cur.respond_to?(:parent) && cur.parent) ? cur.parent : (cur.rvc_parent || cur)]
when MARK_PATTERN
- if first and objs = @session.get_mark($1)
+ if first and objs = @marks[$1]
objs
else
[]
@@ -84,7 +84,7 @@ def traverse_one cur, arc, first
cur.children.select { |k,v| k =~ regex }.map { |k,v| v.rvc_link(cur, k); v }
else
# XXX check for ambiguous child
- if first and arc =~ /^\d+$/ and objs = @session.get_mark(arc)
+ if first and arc =~ /^\d+$/ and objs = @marks[arc]
objs
else
if child = cur.traverse_one(arc)
@@ -97,6 +97,10 @@ def traverse_one cur, arc, first
end
end
+ def delete_numeric_marks
+ @marks.reject! { |k,v| k =~ /^\d+$/ }
+ end
+
# Utility methods
def lookup_single path
View
59 lib/rvc/memory_session.rb
@@ -1,59 +0,0 @@
-# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-module RVC
-
-class MemorySession
- def initialize
- @marks = {}
- @connections = {}
- end
-
- def marks
- @marks.keys
- end
-
- def get_mark key
- @marks[key]
- end
-
- def set_mark key, objs
- if objs == nil
- @marks.delete key
- else
- fail "not an array" unless objs.is_a? Array
- @marks[key] = objs
- end
- end
-
- def connections
- @connections.keys
- end
-
- def get_connection key
- @connections[key]
- end
-
- def set_connection key, conn
- @connections[key] = conn
- end
-end
-
-end
View
7 lib/rvc/modules/basic.rb
@@ -123,9 +123,9 @@ def debug
def cd obj
shell.fs.cd(obj)
- shell.session.set_mark '', [find_ancestor(RbVmomi::VIM::Datacenter)].compact
- shell.session.set_mark '@', [find_ancestor(RbVmomi::VIM)].compact
- shell.delete_numeric_marks
+ shell.fs.marks[''] = [find_ancestor(RbVmomi::VIM::Datacenter)].compact
+ shell.fs.marks['@'] = [find_ancestor(RbVmomi::VIM)].compact
+ shell.fs.delete_numeric_marks
end
def find_ancestor klass
@@ -348,7 +348,6 @@ def rename obj, name
def disconnect connection
k, = shell.connections.find { |k,v| v == connection }
shell.connections.delete k
- shell.session.set_connection k, nil
end
View
6 lib/rvc/modules/mark.rb
@@ -31,7 +31,7 @@
def mark key, objs
err "invalid mark name" unless key =~ /^\w+$/
- shell.session.set_mark key, objs
+ shell.fs.marks[key] = objs
end
@@ -44,7 +44,7 @@ def mark key, objs
def edit key
editor = ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
- objs = shell.session.get_mark(key) or err "no such mark #{key.inspect}"
+ objs = shell.fs.marks[key] or err "no such mark #{key.inspect}"
filename = File.join(Dir.tmpdir, "rvc.#{Time.now.to_i}.#{rand(65536)}")
File.open(filename, 'w') { |io| objs.each { |obj| io.puts(obj.rvc_path_str) } }
begin
@@ -63,5 +63,5 @@ def edit key
end
def list
- shell.session.marks.each { |x| puts x }
+ shell.fs.marks.each { |k,v| puts k }
end
View
4 lib/rvc/modules/vim.rb
@@ -141,10 +141,6 @@ def connect uri, opts
conn_name.succ! while shell.connections.member? conn_name
shell.connections[conn_name] = vim
- shell.session.set_connection conn_name,
- 'host' => host,
- 'username' => username,
- 'rev' => opts[:rev]
end
def prompt_password
View
2  lib/rvc/ruby_evaluator.rb
@@ -62,7 +62,7 @@ def method_missing sym, *a
if a.empty?
if @shell.cmds.namespaces.member? sym
@shell.cmds.namespaces[sym]
- elsif sym.to_s =~ /_?([\w\d]+)(!?)/ && objs = @shell.session.get_mark($1)
+ elsif sym.to_s =~ /_?([\w\d]+)(!?)/ && objs = @shell.fs.marks[$1]
if $2 == '!'
objs
else
View
11 lib/rvc/shell.rb
@@ -25,14 +25,13 @@
module RVC
class Shell
- attr_reader :fs, :completion, :session
+ attr_reader :fs, :completion, :marks
attr_reader :connections, :aliases
attr_accessor :debug, :cmds
- def initialize session
- @session = session
+ def initialize
@persist_ruby = false
- @fs = RVC::FS.new RVC::RootNode.new(self), session
+ @fs = RVC::FS.new RVC::RootNode.new(self)
@ruby_evaluator = RVC::RubyEvaluator.new self
@completion = RVC::Completion.new self
@connections = {}
@@ -234,10 +233,6 @@ def introspect_class klass
end
end
- def delete_numeric_marks
- @session.marks.grep(/^\d+$/).each { |x| @session.set_mark x, nil }
- end
-
BULTIN_MODULE_PATH = [File.expand_path(File.join(File.dirname(__FILE__), 'modules')),
File.join(ENV['HOME'], ".rvc")]
ENV_MODULE_PATH = (ENV['RVC_MODULE_PATH'] || '').split ':'
View
3  test/test_completion.rb
@@ -2,8 +2,7 @@
class CompletionTest < Test::Unit::TestCase
def setup
- session = RVC::MemorySession.new
- @shell = RVC::Shell.new(session)
+ @shell = RVC::Shell.new
@shell.reload_modules false
end
View
15 test/test_fs.rb
@@ -16,9 +16,8 @@ class FSTest < Test::Unit::TestCase
Root.rvc_link nil, ''
def setup
- session = RVC::MemorySession.new
- @context = RVC::FS.new Root, session
- @shell = RVC::Shell.new session
+ @context = RVC::FS.new Root
+ @shell = RVC::Shell.new
@shell.instance_variable_set :@fs, @context
end
@@ -30,7 +29,7 @@ def teardown
def test_new
assert_equal Root, @context.cur
assert_equal "", @context.display_path
- assert_equal 0, @shell.session.marks.size
+ assert_equal 0, @shell.fs.marks.size
assert_equal [['', Root]], @context.cur.rvc_path
end
@@ -96,20 +95,20 @@ def test_lookup_mark
assert_equal nil, obj
['foo', '~', '7', ''].each do |mark|
- @shell.session.set_mark mark, [b_obj]
+ @shell.fs.marks[mark] = [b_obj]
obj = @context.lookup("~#{mark}")[0]
assert_equal [['', Root], ['a', NodeA], ['b', NodeB]], obj.rvc_path
- @shell.session.set_mark mark, []
+ @shell.fs.marks[mark] = []
obj = @context.lookup("~#{mark}")[0]
assert_equal nil, obj
end
- @shell.session.set_mark '7', [b_obj]
+ @shell.fs.marks['7'] = [b_obj]
obj = @context.lookup("7")[0]
assert_equal [['', Root], ['a', NodeA], ['b', NodeB]], obj.rvc_path
- @shell.session.set_mark '7', []
+ @shell.fs.marks['7'] = []
obj = @context.lookup("7")[0]
assert_equal nil, obj
end
View
3  test/test_help.rb
@@ -2,8 +2,7 @@
class HelpTest < Test::Unit::TestCase
def setup
- session = RVC::MemorySession.new
- @shell = RVC::Shell.new(session)
+ @shell = RVC::Shell.new
@shell.reload_modules false
end
View
3  test/test_modules.rb
@@ -4,8 +4,7 @@
class ModulesTest < Test::Unit::TestCase
def setup
- session = RVC::MemorySession.new
- @shell = RVC::Shell.new(session)
+ @shell = RVC::Shell.new
@shell.cmds = RVC::Namespace.new 'root', @shell, nil
@shell.load_module_dir MODULES_DIR, @shell.cmds, false
end
View
3  test/test_shell.rb
@@ -35,8 +35,7 @@ def redirect
class ShellTest < Test::Unit::TestCase
def setup
- session = RVC::MemorySession.new
- @shell = RVC::Shell.new(session)
+ @shell = RVC::Shell.new
@shell.cmds = RVC::Namespace.new 'root', @shell, nil
@shell.cmds.child_namespace(:foo).load_code FOO_MODULE, 'inline'
@shell.cmds.child_namespace(:foo).child_namespace(:bar).load_code FOO_BAR_MODULE, 'inline'
Please sign in to comment.
Something went wrong with that request. Please try again.