evm 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ data.tar.gz: 8fb0ab152c90381b5c75dc3e838ba90c8921cfe1
4
+ metadata.gz: cac1bab75598acb21fabc23f70efa34126e21b1d
5
+ SHA512:
6
+ data.tar.gz: e2a1929f41aeb72569cb4030ab32beebc9b332ca402a881f9a5bf556c66f17e343d2875dfb83b2af2a49da0c7c146ff3a6126dc9ecab6085a8044c10c81558f7
7
+ metadata.gz: 202ac5cde3e3e33fee21999a2ffb9951ab4535c2d708e77b9eae43c4b1ef9d744e6729ee33f644950d66deff8bb00ae28184ce3957bcd4d0a81fab5d54229941
data/bin/emacs ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'evm'
6
+
7
+ package = Evm::Package.current
8
+
9
+ system = Evm::System.new(package.bin.to_s)
10
+ system.run(ARGV)
data/bin/evm ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'evm'
6
+
7
+ Evm::Cli.parse(ARGV)
@@ -0,0 +1,83 @@
1
+ require 'open3'
2
+ require 'fileutils'
3
+
4
+ module Evm
5
+ class Builder
6
+ class Dsl
7
+ def initialize
8
+ @options = []
9
+ end
10
+
11
+ def recipe(name, &block)
12
+ @name = name
13
+
14
+ yield
15
+ end
16
+
17
+ def tar_gz(name)
18
+ tar_file = Evm::TarFile.new(name)
19
+ tar_file.download!
20
+ tar_file.extract!
21
+ end
22
+
23
+ def osx(&block)
24
+ yield if Evm::Os.osx?
25
+ end
26
+
27
+ def linux(&block)
28
+ yield if Evm::Os.linux?
29
+ end
30
+
31
+ def option(name, value = nil)
32
+ @options << name
33
+ @options << value if value
34
+ end
35
+
36
+ def install(&block)
37
+ yield
38
+ end
39
+
40
+ def configure
41
+ run_command './configure', *@options
42
+ end
43
+
44
+ def make(target)
45
+ run_command 'make', target
46
+ end
47
+
48
+ def build_path
49
+ Evm.local.join('tmp', @name)
50
+ end
51
+
52
+ def installation_path
53
+ Evm.local.join(@name)
54
+ end
55
+
56
+ def platform_name
57
+ Evm::Os.platform_name
58
+ end
59
+
60
+ def copy(from, to)
61
+ FileUtils.cp_r(from, to)
62
+ end
63
+
64
+ private
65
+
66
+ def run_command(command, *args)
67
+ Dir.chdir(build_path) do
68
+ system = Evm::System.new(command)
69
+ system.run(args)
70
+ end
71
+ end
72
+ end
73
+
74
+ def initialize(recipe)
75
+ @recipe = recipe
76
+ end
77
+
78
+ def build!
79
+ dsl = Dsl.new
80
+ dsl.instance_eval(@recipe.read)
81
+ end
82
+ end
83
+ end
data/lib/evm/cli.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Evm
2
+ module Cli
3
+ def self.parse(argv)
4
+ options = {}
5
+
6
+ if argv.include?('--force')
7
+ options[:force] = !!argv.delete('--force')
8
+ end
9
+
10
+ if argv.include?('--help') || argv.include?('-h')
11
+ Evm.print_usage_and_die
12
+ end
13
+
14
+ command, argument = argv
15
+
16
+ begin
17
+ const = Evm::Command.const_get(command.capitalize)
18
+ const.new(argument, options)
19
+ rescue NameError
20
+ Evm.die "No such command: #{command}"
21
+ rescue Evm::Exception => exception
22
+ Evm.die exception.message
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module Evm
2
+ module Command
3
+ class Bin
4
+ def initialize(package_name = nil, options = {})
5
+ if package_name
6
+ package = Evm::Package.find(package_name)
7
+ else
8
+ package = Evm::Package.current
9
+ end
10
+
11
+ if package
12
+ STDOUT.puts package.bin
13
+ else
14
+ raise Evm::Exception.new('No current selected')
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Evm
2
+ module Command
3
+ class Install
4
+ def initialize(package_name, options = {})
5
+ unless package_name
6
+ raise Evm::Exception.new('The install command requires an argument')
7
+ end
8
+
9
+ package = Evm::Package.find(package_name)
10
+
11
+ if options[:force]
12
+ package.uninstall!
13
+ end
14
+
15
+ if package.installed?
16
+ raise Evm::Exception.new("Already installed #{package_name}")
17
+ else
18
+ package.install!
19
+
20
+ STDOUT.puts "Successfully installed #{package_name}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module Evm
2
+ module Command
3
+ class List
4
+ def initialize(*args)
5
+ packages = Evm::Package.all
6
+ packages.each do |package|
7
+ if package.current?
8
+ STDOUT.print '* '
9
+ end
10
+
11
+ STDOUT.print package
12
+
13
+ if package.installed?
14
+ STDOUT.print ' [I]'
15
+ end
16
+
17
+ STDOUT.puts
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Evm
2
+ module Command
3
+ class Uninstall
4
+ def initialize(package_name, options = {})
5
+ unless package_name
6
+ raise Evm::Exception.new('The uninstall command requires an argument')
7
+ end
8
+
9
+ package = Evm::Package.find(package_name)
10
+
11
+ if package.installed?
12
+ package.uninstall!
13
+
14
+ STDOUT.puts "Successfully uninstalled #{package_name}"
15
+ else
16
+ raise Evm::Exception.new("Not installed #{package_name}")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Evm
2
+ module Command
3
+ class Use
4
+ def initialize(package_name, options = {})
5
+ unless package_name
6
+ raise Evm::Exception.new('The use command requires an argument')
7
+ end
8
+
9
+ package = Evm::Package.find(package_name)
10
+
11
+ if package.installed?
12
+ package.use!
13
+ else
14
+ raise Evm::Exception.new("Package not installed: #{package_name}")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module Evm
2
+ module Command
3
+ end
4
+ end
5
+
6
+ require 'evm/command/install'
7
+ require 'evm/command/uninstall'
8
+ require 'evm/command/use'
9
+ require 'evm/command/list'
10
+ require 'evm/command/bin'
@@ -0,0 +1,4 @@
1
+ module Evm
2
+ class Exception < StandardError
3
+ end
4
+ end
data/lib/evm/os.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Evm
2
+ module Os
3
+ def self.osx?
4
+ RUBY_PLATFORM.downcase.include?('darwin')
5
+ end
6
+
7
+ def self.linux?
8
+ RUBY_PLATFORM.downcase.include?('linux')
9
+ end
10
+
11
+ def self.platform_name
12
+ if osx?
13
+ :osx
14
+ elsif linux?
15
+ :linux
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,83 @@
1
+ module Evm
2
+ class Package
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def current?
10
+ Package.current && Package.current.name == @name
11
+ end
12
+
13
+ def installed?
14
+ path.exist?
15
+ end
16
+
17
+ def path
18
+ Evm.local.join(@name)
19
+ end
20
+
21
+ def bin
22
+ if Evm::Os.osx? && path.join('Emacs.app').exist?
23
+ path.join('Emacs.app', 'Contents', 'MacOS', 'Emacs')
24
+ else
25
+ path.join('bin', 'emacs')
26
+ end
27
+ end
28
+
29
+ def use!
30
+ File.open(Package.current_file, 'w') do |file|
31
+ file.write(@name)
32
+ end
33
+ end
34
+
35
+ def install!
36
+ Evm::Builder.new(recipe).build!
37
+ end
38
+
39
+ def uninstall!
40
+ path.rmtree
41
+
42
+ if current?
43
+ Package.current_file.delete
44
+ end
45
+ end
46
+
47
+ def to_s
48
+ @name
49
+ end
50
+
51
+ def recipe
52
+ Evm::Recipe.find(@name)
53
+ end
54
+
55
+ class << self
56
+ def current_file
57
+ Evm.local.join('current')
58
+ end
59
+
60
+ def current
61
+ if current_file.exist?
62
+ find(current_file.read)
63
+ end
64
+ end
65
+
66
+ def find(package_name)
67
+ recipe = Evm::Recipe.find(package_name)
68
+ if recipe
69
+ Package.new(package_name)
70
+ else
71
+ raise Evm::Exception.new("No such package: #{package_name}")
72
+ end
73
+ end
74
+
75
+ def all
76
+ recipes = Evm::Recipe.all
77
+ recipes.map do |recipe|
78
+ Package.new(recipe.name)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
data/lib/evm/recipe.rb ADDED
@@ -0,0 +1,40 @@
1
+ module Evm
2
+ class Recipe
3
+ RECIPE_PATH = Evm.root.join('recipes')
4
+
5
+ attr_reader :name
6
+
7
+ class Dsl
8
+ attr_reader :name
9
+
10
+ def recipe(name, &block)
11
+ @name = name
12
+ end
13
+ end
14
+
15
+ def initialize(recipe_file)
16
+ @recipe_file = recipe_file
17
+
18
+ dsl = Dsl.new
19
+ dsl.instance_eval(read)
20
+
21
+ @name = dsl.name
22
+ end
23
+
24
+ def read
25
+ File.read(@recipe_file)
26
+ end
27
+
28
+ class << self
29
+ def find(name)
30
+ all.find { |recipe| recipe.name == name }
31
+ end
32
+
33
+ def all
34
+ Dir.glob(RECIPE_PATH.join('*.rb')).map do |recipe_file|
35
+ Recipe.new(recipe_file)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/evm/system.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Evm
2
+ class System
3
+ def initialize(executable)
4
+ @executable = executable
5
+ end
6
+
7
+ def run(*args)
8
+ command = build_command(args)
9
+ unless Kernel.system(command)
10
+ raise Evm::Exception.new("An error occurred running command: #{command}")
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def build_command(args)
17
+ ([@executable] + args).join(' ')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,51 @@
1
+ require 'open-uri'
2
+
3
+ module Evm
4
+ class TarFile
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def download!
10
+ unless tars_path.exist?
11
+ tars_path.mkdir
12
+ end
13
+
14
+ unless tar_path.exist?
15
+ File.open(tar_path, 'wb') do |write_file|
16
+ open(url, 'rb') do |read_file|
17
+ write_file.write(read_file.read)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def extract!
24
+ unless builds_path.exist?
25
+ builds_path.mkdir
26
+ end
27
+
28
+ system = Evm::System.new('tar')
29
+ system.run('-xzf', tar_path.to_s, '-C', builds_path.to_s)
30
+ end
31
+
32
+
33
+ private
34
+
35
+ def url
36
+ "https://s3.amazonaws.com/emacs-evm/#{@name}"
37
+ end
38
+
39
+ def tars_path
40
+ Evm.local.join('tars')
41
+ end
42
+
43
+ def tar_path
44
+ tars_path.join(@name)
45
+ end
46
+
47
+ def builds_path
48
+ Evm.local.join('tmp')
49
+ end
50
+ end
51
+ end
data/lib/evm.rb CHANGED
@@ -0,0 +1,49 @@
1
+ require 'pathname'
2
+
3
+ module Evm
4
+ def self.root
5
+ Pathname.new(__FILE__).parent.parent.expand_path
6
+ end
7
+
8
+ def self.local
9
+ Pathname.new('/').join('usr', 'local', 'evm')
10
+ end
11
+
12
+ def self.die(*args)
13
+ args.each do |arg|
14
+ STDERR.print(arg)
15
+ STDERR.puts
16
+ end
17
+
18
+ exit 1
19
+ end
20
+
21
+ def self.print_usage_and_die
22
+ die <<-EOS
23
+ USAGE: evm COMMAND [OPTIONS]
24
+
25
+ Emacs Version Manager
26
+
27
+ COMMANDS:
28
+ install <name> Install package name
29
+ uninstall <name> Uninstall package name
30
+ bin [name] Show path to Emacs binary for package name
31
+ list List all available packages
32
+ use <name> Select name as current package
33
+
34
+ OPTIONS:
35
+ --force Force install even when already installed
36
+ --help, -h Display this help message
37
+ EOS
38
+ end
39
+ end
40
+
41
+ require 'evm/os'
42
+ require 'evm/cli'
43
+ require 'evm/recipe'
44
+ require 'evm/package'
45
+ require 'evm/command'
46
+ require 'evm/exception'
47
+ require 'evm/builder'
48
+ require 'evm/tar_file'
49
+ require 'evm/system'
metadata CHANGED
@@ -1,47 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: evm
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Johan Andersson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-30 00:00:00.000000000 Z
11
+
12
+ date: 2013-12-01 00:00:00 Z
13
13
  dependencies: []
14
- description: EVM is a command-line tool that allows you to install multiple Emacs
15
- versions.
14
+
15
+ description: EVM is a command-line tool that allows you to install multiple Emacs versions.
16
16
  email: johan.rejeep@gmail.com
17
- executables: []
17
+ executables:
18
+ - evm
19
+ - emacs
18
20
  extensions: []
21
+
19
22
  extra_rdoc_files: []
20
- files:
23
+
24
+ files:
25
+ - lib/evm/builder.rb
26
+ - lib/evm/cli.rb
27
+ - lib/evm/command/bin.rb
28
+ - lib/evm/command/install.rb
29
+ - lib/evm/command/list.rb
30
+ - lib/evm/command/uninstall.rb
31
+ - lib/evm/command/use.rb
32
+ - lib/evm/command.rb
33
+ - lib/evm/exception.rb
34
+ - lib/evm/os.rb
35
+ - lib/evm/package.rb
36
+ - lib/evm/recipe.rb
37
+ - lib/evm/system.rb
38
+ - lib/evm/tar_file.rb
21
39
  - lib/evm.rb
40
+ - bin/evm
41
+ - bin/emacs
22
42
  homepage: http://github.com/rejeep/evm
23
- licenses:
43
+ licenses:
24
44
  - MIT
45
+ metadata: {}
46
+
25
47
  post_install_message:
26
48
  rdoc_options: []
27
- require_paths:
49
+
50
+ require_paths:
28
51
  - lib
29
- required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ! '>='
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - &id001
55
+ - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - *id001
41
61
  requirements: []
62
+
42
63
  rubyforge_project:
43
- rubygems_version: 1.8.25
64
+ rubygems_version: 2.0.14
44
65
  signing_key:
45
- specification_version: 3
66
+ specification_version: 4
46
67
  summary: Emacs Version Manager
47
68
  test_files: []
69
+