clenver 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e85aeffdfd4c41bcd5e0619efd95f1a01376b88
4
- data.tar.gz: b653a128a39b2df1fe746bfb0cfc9264f824edf1
3
+ metadata.gz: 2d4880cba20de7af9933abb25142c153e468b682
4
+ data.tar.gz: 5e7717f8eea907de21682dfe872def8a1de8c625
5
5
  SHA512:
6
- metadata.gz: e17ec53f716c370021a4dedef70d670d52bb4584827e0c94ea140747ca85acd1c77751d6bc6860ef9f54fcb2f82a62454138fa074b7401bb95ada298f6d74abe
7
- data.tar.gz: bbb1da9489a957ba1d706a04cb5d622cd0c73a3ebb51e48195bf893897b19bf2b50d233a533e7bbec753aa5f057fe49a001e3a8106294a3ec393dff421da6b2e
6
+ metadata.gz: de94cf713faa45c10334d5c3d4363c5c9849ae39dbe9b575194af95b2a8bc3490d9a2a46f929ae57a3752223ee08431dc1592d57bc82bbb1662dda5e4091700b
7
+ data.tar.gz: 57adedcb97c0567459a5f7248b1d6f021a19ad6b9158b0c06ac3b25af6f4f73a1189ba7b46fbb9f21f54703b321c4b74135ccdb337db83c56555260f4bdf583c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clenver (0.1.13)
4
+ clenver (0.1.14)
5
5
  git (= 1.2.6)
6
6
  gli (= 2.8.0)
7
7
  thor (= 0.18.1)
data/Rakefile CHANGED
@@ -20,6 +20,7 @@ desc 'Run features'
20
20
  Cucumber::Rake::Task.new(:features) do |t|
21
21
  opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
22
  opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ opts += " --tags ~@sudo"
23
24
  t.cucumber_opts = opts
24
25
  t.fork = false
25
26
  end
@@ -32,8 +33,17 @@ Cucumber::Rake::Task.new('features:wip') do |t|
32
33
  t.fork = false
33
34
  end
34
35
 
36
+ desc 'Run features tagged as sudo (@sudo)'
37
+ Cucumber::Rake::Task.new('features:sudo') do |t|
38
+ tag_opts = ' --tags ~@pending'
39
+ tag_opts = ' --tags @sudo'
40
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
41
+ t.fork = false
42
+ end
43
+
35
44
  task :cucumber => :features
36
45
  task 'cucumber:wip' => 'features:wip'
46
+ task 'cucumber:sudo' => 'features:sudo'
37
47
  task :wip => 'features:wip'
38
48
  require 'rake/testtask'
39
49
  Rake::TestTask.new do |t|
@@ -0,0 +1,53 @@
1
+ Feature: Initialization basics
2
+ In order to save time and money
3
+ User should be able to bootstrap project environment ASAP
4
+
5
+ Scenario: Given config file doesn't exist
6
+ When I run `clenver init no_name.yml`
7
+ Then the exit status should be 2
8
+
9
+ Scenario: Valid config file given
10
+ Given The default aruba timeout is 10 seconds
11
+ Given a file named "valid.yml" with:
12
+ """
13
+ https://github.com/pietrushnic/dummy.git:
14
+ links:
15
+ dummy/foobar.txt:
16
+ - foobar_link
17
+ dummy/foobar:
18
+ - foobar_dir_link
19
+ """
20
+ When I run `clenver init valid.yml`
21
+ Then the exit status should be 0
22
+
23
+ Scenario: Invalid config file given
24
+ Given a file named "invalid.yml" with:
25
+ """
26
+ Lorem:{]}
27
+ ipsum:
28
+ dolor: sit amet,
29
+ consectetur adipisicing elit, sed: do eiusmod tempor
30
+ incididunt: ut
31
+ labore et dolore: magna aliqua.
32
+ """
33
+ When I run `clenver init invalid.yml`
34
+ Then the exit status should be 1
35
+
36
+ Scenario: Init simple project (repo w/ colon)
37
+ Given The default aruba timeout is 10 seconds
38
+ Given a file named "test_repo.yml" with:
39
+ """
40
+ https://github.com/pietrushnic/dummy.git:
41
+ """
42
+ When I run `clenver init test_repo.yml`
43
+ Then the following files should exist:
44
+ | dummy/README.md |
45
+
46
+ Scenario: Init simple project (repo w/o colon)
47
+ Given The default aruba timeout is 10 seconds
48
+ Given a file named "test_repo.yml" with:
49
+ """
50
+ https://github.com/pietrushnic/dummy.git
51
+ """
52
+ When I run `clenver init test_repo.yml`
53
+ Then the exit status should be 2
@@ -0,0 +1,17 @@
1
+ Feature: Initialization repository
2
+ In order to save time and money
3
+ User should be able to bootstrap project environment ASAP
4
+
5
+ Scenario: run simple command
6
+ Given The default aruba timeout is 10 seconds
7
+ Given a file named "test_repo.yml" with:
8
+ """
9
+ https://github.com/pietrushnic/dummy.git:
10
+ run:
11
+ - echo "success!!!!"
12
+ - echo "succes1s!!!!"
13
+ """
14
+ When I run `clenver init test_repo.yml some_tmp`
15
+ Then the output should contain "success!!!!\n"
16
+ Then the output should contain "succes1s!!!!\n"
17
+
@@ -0,0 +1,15 @@
1
+ Feature: Initialization
2
+ In order to save time and money
3
+ User should be able to bootstrap project environment ASAP
4
+
5
+ Scenario: Init simple project to given directory
6
+ Given The default aruba timeout is 10 seconds
7
+ Given a file named "test_repo.yml" with:
8
+ """
9
+ https://github.com/pietrushnic/dummy.git:
10
+ """
11
+ When I run `clenver init test_repo.yml`
12
+ Then the following files should exist:
13
+ | dummy/README.md |
14
+
15
+
@@ -0,0 +1,59 @@
1
+ Feature: Initialization links
2
+ In order to save time and money
3
+ User should be able to bootstrap project environment ASAP
4
+
5
+ Scenario: Init project with symbolic links
6
+ Given The default aruba timeout is 10 seconds
7
+ Given a file named "test_repo.yml" with:
8
+ """
9
+ https://github.com/pietrushnic/dummy.git:
10
+ dst:
11
+ - src/dummy
12
+ links:
13
+ src/dummy/foobar.txt:
14
+ - src/dummy/foobar_link
15
+ src/dummy/foobar:
16
+ - src/dummy/foobar_dir_link
17
+ """
18
+ When I run `clenver init test_repo.yml`
19
+ Then the following links should exist:
20
+ | src/dummy/foobar_link |
21
+ | src/dummy/foobar_dir_link |
22
+
23
+ @announce
24
+ Scenario: files backup verification
25
+ Given The default aruba timeout is 10 seconds
26
+ Given a file named "test_repo.yml" with:
27
+ """
28
+ https://github.com/pietrushnic/dummy.git:
29
+ links:
30
+ dummy/foobar.txt:
31
+ - foobar_link
32
+ - foobar_link
33
+ dummy/foobar:
34
+ - foobar_dir_link
35
+ """
36
+ When I run `clenver init test_repo.yml`
37
+ When I run `tree`
38
+ Then the following links should exist:
39
+ | foobar_link |
40
+ | foobar_link_old |
41
+ | foobar_dir_link |
42
+
43
+ Scenario: use system variable in path
44
+ Given The default aruba timeout is 10 seconds
45
+ Given a file named "test_repo.yml" with:
46
+ """
47
+ https://github.com/pietrushnic/dummy.git:
48
+ links:
49
+ $HOME/foobar.txt:
50
+ - $HOME/foobar_link
51
+ """
52
+ When I run `clenver init test_repo.yml some_tmp`
53
+ Then the following links should exist:
54
+ | $HOME/foobar_link |
55
+
56
+ @wip
57
+ Scenario: destination already exist
58
+ Scenario: destination not exist
59
+ Scenario: access denied
@@ -0,0 +1,64 @@
1
+ Feature: Initialization repository
2
+ In order to save time and money
3
+ User should be able to bootstrap project environment ASAP
4
+
5
+ @sudo
6
+ Scenario: apt: check if package installed
7
+ Given The default aruba timeout is 10 seconds
8
+ Given a file named "test_repo.yml" with:
9
+ """
10
+ apt:
11
+ - vim
12
+ """
13
+ When I run `clenver init test_repo.yml some_tmp`
14
+ Then the output should contain "vim is already the newest version.\n"
15
+
16
+ @sudo
17
+ Scenario: package installed and simple command run
18
+ Given The default aruba timeout is 10 seconds
19
+ Given a file named "test_repo.yml" with:
20
+ """
21
+ apt:
22
+ - vim
23
+ https://github.com/pietrushnic/dummy.git:
24
+ run:
25
+ - echo "success!!!!"
26
+ """
27
+ When I run `clenver init test_repo.yml some_tmp`
28
+ Then the output should contain "vim is already the newest version.\n"
29
+ Then the output should contain "success!!!!\n"
30
+
31
+ Scenario: install gem
32
+ Given The default aruba timeout is 120 seconds
33
+ Given a file named "test_repo.yml" with:
34
+ """
35
+ gem:
36
+ - tmuxinator
37
+ https://github.com/pietrushnic/dummy.git:
38
+ run:
39
+ - echo "success!!!!"
40
+ """
41
+ When I run `clenver init test_repo.yml some_tmp`
42
+ Then the output should contain "installed\n"
43
+ Then the output should contain "success!!!!\n"
44
+
45
+ @sudo
46
+ Scenario: install gems and packages
47
+ Given The default aruba timeout is 120 seconds
48
+ Given a file named "test_repo.yml" with:
49
+ """
50
+ apt:
51
+ - vim
52
+ - mutt
53
+ gem:
54
+ - tmuxinator
55
+ - git
56
+ https://github.com/pietrushnic/dummy.git:
57
+ run:
58
+ - echo "success!!!!"
59
+ """
60
+ When I run `clenver init test_repo.yml some_tmp`
61
+ Then the output should contain "gems installed\n"
62
+ Then the output should contain "vim is already the newest version.\n"
63
+ Then the output should contain "mutt is already the newest version.\n"
64
+ Then the output should contain "success!!!!\n"
@@ -0,0 +1,58 @@
1
+ Feature: Initialization repository
2
+ In order to save time and money
3
+ User should be able to bootstrap project environment ASAP
4
+
5
+ @announce
6
+ Scenario: Connect remote and check uri
7
+ Given The default aruba timeout is 25 seconds
8
+ Given a file named "test_repo.yml" with:
9
+ """
10
+ https://github.com/pietrushnic/spf13-vim.git:
11
+ remotes:
12
+ upstream:
13
+ - https://github.com/spf13/spf13-vim.git
14
+ """
15
+ When I run `clenver init test_repo.yml`
16
+ Then the following remote uris should be connected in "spf13-vim":
17
+ | https://github.com/spf13/spf13-vim.git |
18
+
19
+ Scenario: Connect remote and check its name
20
+ Given The default aruba timeout is 25 seconds
21
+ Given a file named "test_repo.yml" with:
22
+ """
23
+ https://github.com/pietrushnic/spf13-vim.git:
24
+ remotes:
25
+ upstream:
26
+ - https://github.com/spf13/spf13-vim.git
27
+ """
28
+ When I run `clenver init test_repo.yml`
29
+ Then the following remote branches should be connected in "spf13-vim":
30
+ | upstream |
31
+
32
+ Scenario: Clone repo and verify its destination
33
+ Given The default aruba timeout is 25 seconds
34
+ Given a file named "test_repo.yml" with:
35
+ """
36
+ https://github.com/pietrushnic/spf13-vim.git:
37
+ dst:
38
+ - $HOME/abs_path_test/spf13-vim
39
+ """
40
+ When I run `clenver init test_repo.yml`
41
+ Then the following absolute path should exist: "$HOME/abs_path_test/spf13-vim"
42
+
43
+ @wip
44
+ Scenario: destination already exist
45
+ Scenario: destination not exist
46
+ Scenario: access denied
47
+ Scenario: multiple destinations
48
+ Given The default aruba timeout is 25 seconds
49
+ Given a file named "test_repo.yml" with:
50
+ """
51
+ https://github.com/pietrushnic/spf13-vim.git:
52
+ dst:
53
+ - $HOME/abs_path_test/spf13-vim
54
+ dst:
55
+ - $HOME/abs_path_test/spf13-vim-1
56
+ """
57
+ When I run `clenver init test_repo.yml`
58
+ Then the following absolute path should exist: "$HOME/abs_path_test/spf13-vim"
@@ -34,3 +34,8 @@ Then(/^the output should contain correct version$/) do
34
34
  assert_partial_output(Clenver::VERSION, all_output)
35
35
  end
36
36
 
37
+ Then(/^the following absolute path should exist: "(.*?)"$/) do |arg1|
38
+ out = %x[echo #{arg1}].strip
39
+ File.should be_directory(out)
40
+ end
41
+
data/lib/clenver/cli.rb CHANGED
@@ -10,10 +10,6 @@ module Clenver
10
10
  include Logging
11
11
  def self.start(*)
12
12
  super
13
- # logger.debug("args: #{args}")
14
- # path = args[0]
15
- # dst_dist = args[1]
16
- # Clenver::Runner.new(path, dst_dist).start
17
13
  end
18
14
 
19
15
  def initialize(*)
@@ -0,0 +1,14 @@
1
+ require 'clenver/logging'
2
+
3
+ class CommandExecutor
4
+ include Logging
5
+ attr_accessor :cmd
6
+ def initialize(cmd)
7
+ @cmd = cmd
8
+ end
9
+
10
+ def execute
11
+ logger.info(%x[#{cmd}])
12
+ end
13
+ end
14
+
data/lib/clenver/link.rb CHANGED
@@ -1,36 +1,33 @@
1
1
  require 'fileutils'
2
+ require 'clenver/logging'
2
3
 
3
4
  class Link
5
+ include Logging
4
6
  MAX_REPEAT = 3
7
+ attr_accessor :src, :dst
5
8
  def initialize(src,dst)
6
9
  @src = src
7
- @dst = expand_dst(dst)
10
+ @dst = dst
8
11
  end
12
+
9
13
  def create
10
14
  puts "Link.create"
11
- puts @dst
12
- @dst.each do |d|
13
- puts "src:#{@src}"
14
- puts "d:#{d} "
15
+ dst.each do |d|
15
16
  i = 0
17
+ d = d.to_s.gsub(/\$\w+/) {|m| ENV[m[1..-1]]}
18
+ logger.debug("d:#{d}")
19
+ logger.debug("src:#{src.gsub(/\$\w+/) {|n| ENV[n[1..-1]]}}")
16
20
  while i < MAX_REPEAT do
17
21
  begin
18
- File.symlink(@src, d.to_s)
22
+ File.symlink(src.gsub(/\$\w+/) {|n| ENV[n[1..-1]]}, d)
19
23
  rescue SystemCallError
20
- FileUtils.mv(d.to_s, d.to_s + "_old")
24
+ FileUtils.mv(d, d + "_old")
21
25
  else
26
+ logge.debug("else")
22
27
  break
23
28
  end
24
29
  i += 1
25
30
  end
26
31
  end
27
32
  end
28
- def expand_dst(dst)
29
- ret = Array.new()
30
- dst.each do |d|
31
- path = %x[ echo #{d}]
32
- ret.push(path.strip)
33
- end
34
- return ret
35
- end
36
33
  end
@@ -1,4 +1,5 @@
1
1
  class PackageManger
2
+ attr_accessor :pkgs
2
3
  def initialize(name, pkgs)
3
4
  @name = name
4
5
  @pkgs = pkgs
@@ -7,9 +8,9 @@ class PackageManger
7
8
  def install()
8
9
  case @name
9
10
  when 'apt'
10
- out = %x[sudo apt-get -y install #{@pkgs}]
11
+ out = %x[sudo apt-get -y install #{pkgs}]
11
12
  when 'gem'
12
- out = %x[gem install #{@pkgs}]
13
+ out = %x[gem install #{pkgs}]
13
14
  end
14
15
  puts out
15
16
  end
@@ -4,10 +4,14 @@ require 'clenver/logging'
4
4
 
5
5
  class Project
6
6
  include Logging
7
- attr_accessor :name, :repos, :dst, :abs_path
8
- def initialize(name, repos, dst)
7
+ attr_accessor :name, :repos, :dst, :abs_path, :pkg_mgr, :yaml, :links, :cmd_exec
8
+ def initialize(name, yaml, dst)
9
9
  @name = name
10
- @repos = repos
10
+ @yaml = yaml
11
+ @repos = []
12
+ @pkg_mgr = []
13
+ @links = []
14
+ @cmd_exec = []
11
15
  @dst = dst
12
16
  @abs_path = Dir::pwd + "/" + @name
13
17
  end
@@ -23,45 +27,37 @@ class Project
23
27
  Dir::chdir(path)
24
28
  end
25
29
 
26
- def create_repos(dst=nil)
27
- logger.debug("create_repos:")
28
- goto_dst
29
- case @repos
30
- when Hash
31
- @repos.each do |uri, content|
32
- #TODO: verify if r is a supported repo
33
- if uri == 'apt' or uri == 'gem'
34
- next
35
- end
36
- begin
37
- r = Repository.new(uri, dst)
38
- r.clone
39
- @repos[uri]['object'] = r
40
- rescue Exception => msg
41
- puts msg
42
- end
43
- end
44
- when String
45
- begin
46
- repo = Repository.new(@repos, dst)
47
- repo.clone
48
- rescue Exception => msg
49
- puts msg
50
- end
30
+ def init
31
+ for r in repos do
32
+ logger.debug("clone repo:#{r.repo_uri}")
33
+ r.clone
34
+ r.add_remotes
35
+ end
36
+ for p in pkg_mgr do
37
+ logger.debug("install packages: #{p.pkgs}")
38
+ p.install
39
+ end
40
+ for l in links do
41
+ logger.debug("create link src: #{l.src} dst:#{l.dst}")
42
+ l.create
43
+ end
44
+ for c in cmd_exec do
45
+ logger.debug("execute: #{c.cmd}")
46
+ c.execute
51
47
  end
52
48
  end
53
49
 
54
50
  def init_project
55
51
  logger.debug("init_project:")
56
- case @repos
52
+ case @yaml
57
53
  when Hash
58
54
  init_links
59
55
  init_repos
60
56
  init_runs
61
57
  when String
62
58
  begin
63
- unless @repos.nil?
64
- @repos['links'].each do |s,d|
59
+ unless @yaml.nil?
60
+ @yaml['links'].each do |s,d|
65
61
  Link.new(s,d).create
66
62
  end
67
63
  end
@@ -72,61 +68,49 @@ class Project
72
68
  end
73
69
 
74
70
  def init_links
75
- @repos.each do |uri, content|
76
- begin
77
- unless content.nil?
78
- #links
79
- unless content['links'].nil?
80
- content['links'].each do |s,d|
81
- if /\$\w+/.match(s)
82
- #TODO: this is ugly and should be fixed
83
- buf = Array.new().push(s)
84
- s_path = Link.new(s,d).expand_dst(buf)[0]
85
- elsif
86
- s_path = content['object'].get_abs_path + "/" + s
87
- end
88
- Link.new(s_path,d).create
89
- end
71
+ logger.debug("init_links")
72
+ @yaml.each do |uri, content|
73
+ if content.is_a?(Hash)
74
+ #links
75
+ unless content['links'].nil?
76
+ content['links'].each do |s,d|
77
+ #TODO: this is ugly and should be fixed
78
+ buf = Array.new().push(s)
79
+ s_path = Link.new(s,d).expand_dst(buf)[0]
80
+ Link.new(s_path,d).create
90
81
  end
91
82
  end
92
- rescue Exception => msg
93
- puts msg
94
83
  end
95
84
  end
96
85
  end
97
86
 
98
87
  def init_repos
99
- @repos.each do |uri, content|
100
- begin
101
- unless content.nil?
102
- #remotes
103
- unless content['remotes'].nil?
104
- content['remotes'].each do |name, uri|
105
- Dir::chdir(content['object'].get_abs_path)
106
- content['object'].add_remote(name, uri)
107
- end
88
+ logger.debug("init_yaml")
89
+ repos.each do |r|
90
+ logger.debug("r:#{r}")
91
+ if r.content.is_a?(Hash)
92
+ #remotes
93
+ logger.debug("content:#{r.content}")
94
+ unless r.content['remotes'].nil?
95
+ logger.debug("r.content:#{r.content['remotes']}")
96
+ r.content['remotes'].each do |name, uri|
97
+ r.add_remote(name, uri)
108
98
  end
109
99
  end
110
- rescue Exception => msg
111
- puts msg
112
100
  end
113
101
  end
114
102
  end
115
103
 
116
104
  def init_runs
117
- @repos.each do |uri, content|
118
- begin
119
- unless content.nil?
120
- #run
121
- unless content['run'].nil?
122
- content['run'].each do |cmd|
123
- Dir::chdir(content['object'].get_abs_path)
124
- puts %x[#{cmd}]
125
- end
105
+ logger.debug("init_runs")
106
+ @yaml.each do |uri, content|
107
+ if content.is_a?(Hash)
108
+ #run
109
+ unless content['run'].nil?
110
+ content['run'].each do |cmd|
111
+ puts %x[#{cmd}]
126
112
  end
127
113
  end
128
- rescue Exception => msg
129
- puts msg
130
114
  end
131
115
  end
132
116
  end
@@ -1,23 +1,51 @@
1
1
  require 'git'
2
+ require 'clenver/logging'
2
3
 
3
4
  class Repository
4
- def initialize(repo, dst)
5
- @repo_uri = repo
6
- @dst = dst
5
+ include Logging
6
+ attr_accessor :repo_uri, :config, :repo, :dst, :remotes
7
+ #TODO: think about better way to handle dst from URI
8
+ def initialize(uri, config = nil)
9
+ @repo_uri = uri
10
+ @dst = get_dst(config)
11
+ @remotes = get_remotes(config)
7
12
  @abs_path = nil
8
13
  @repo = nil
9
14
  end
10
15
 
16
+ def get_remotes(config)
17
+ unless config.nil?
18
+ if config.has_key?('remotes')
19
+ config['remotes']
20
+ end
21
+ end
22
+ end
23
+
24
+ def get_dst(config)
25
+ unless config.nil?
26
+ if config.has_key?('dst')
27
+ return config['dst'][0]
28
+ end
29
+ end
30
+ logger.debug("dst:#{Dir::pwd + "/" + File.basename(repo_uri, '.git')}")
31
+ Dir::pwd + "/" + File.basename(repo_uri, '.git')
32
+ end
33
+
11
34
  def clone
12
- repo_basename = File.basename("#{@repo_uri}",".git")
13
- @repo = Git.clone(@repo_uri, repo_basename)
14
- @abs_path = Dir::pwd + "/" + repo_basename
35
+ repo = Git.clone(repo_uri, dst)
36
+ logger.debug("clone:#{repo}")
15
37
  end
16
38
 
17
39
  def get_abs_path
18
40
  @abs_path
19
41
  end
20
- def add_remote(name, uri)
21
- @repo.add_remote(name, uri)
42
+
43
+ def add_remotes
44
+ logger.debug("self.inspect:#{self.inspect}")
45
+ unless remotes.nil?
46
+ for name, uri in remotes do
47
+ Git.open(dst).add_remote(name, uri)
48
+ end
49
+ end
22
50
  end
23
51
  end
@@ -1,51 +1,85 @@
1
- require 'gli'
1
+ require 'psych'
2
2
  require 'clenver'
3
3
  require 'clenver/project'
4
4
  require 'clenver/logging'
5
5
  require 'clenver/package_manager'
6
+ require 'clenver/command_executor'
6
7
 
7
8
  module Clenver
8
9
  class Runner
9
10
  include Logging
10
11
 
12
+ attr_accessor :path, :dst, :yaml
11
13
  def initialize(path, dst)
12
14
  @path = path
13
15
  @dst = dst
16
+ @yaml = parse_config
17
+ end
18
+
19
+ def parse_config
20
+ begin
21
+ Psych.load_file("#{path}")
22
+ rescue Psych::SyntaxError => ex
23
+ logger.error("#{path}: syntax error : #{ex.message}")
24
+ exit 1
25
+ end
26
+ end
27
+
28
+ def create_package_manager(type)
29
+ PackageManger.new(type, yaml[type].join(' '))
30
+ end
31
+
32
+ def create_repository(uri)
33
+ logger.debug("content:#{yaml[uri]}")
34
+ if yaml[uri].is_a?(Hash)
35
+ Repository.new(uri, yaml[uri])
36
+ else
37
+ Repository.new(uri)
38
+ end
39
+ end
40
+
41
+ def create_links
42
+ l = []
43
+ for src, links in yaml['links']
44
+ l << Link.new(src, links)
45
+ end
46
+ return l
47
+ end
48
+
49
+ def create_cmd_exec
50
+ e = []
51
+ for c in yaml['run']
52
+ e << CommandExecutor.new(c)
53
+ end
54
+ return e
14
55
  end
15
56
 
16
57
  def start
17
- if File.exist?(@path)
18
- begin
19
- yaml = Psych.load_file("#{@path}")
20
- logger.debug("yaml: #{yaml}")
21
- #TODO: create test and fix this place with check for empty file
22
- p = Project.new(File.basename("#{@path}", ".yml"), yaml, @dst)
23
- pkgs = ""
24
- unless yaml['apt'].nil?
25
- for pkg in yaml['apt'] do
26
- pkgs = pkgs + " " + pkg + " "
27
- end
28
- puts pkgs
29
- p_mgr = PackageManger.new('apt', pkgs)
30
- p_mgr.install()
58
+ #TODO: create test and fix this place with check for empty file
59
+ p = Project.new(File.basename("#{path}", ".yml"), yaml, dst)
60
+ if yaml.is_a?(Hash)
61
+ for k,v in yaml do
62
+ logger.info("key:#{k}")
63
+ logger.info("value:#{v}")
64
+ if k == 'apt' or k == 'gem'
65
+ p.pkg_mgr << create_package_manager(k)
66
+ end
67
+ if k.match /(http|https|git).+/
68
+ p.repos << create_repository(k)
69
+ end
70
+ if k == 'links'
71
+ p.links = create_links
31
72
  end
32
- pkgs = ""
33
- unless yaml['gem'].nil?
34
- for pkg in yaml['gem'] do
35
- pkgs = pkgs + " " + pkg + " "
36
- end
37
- puts pkgs
38
- p_mgr = PackageManger.new('gem', pkgs)
39
- p_mgr.install()
73
+ if k == 'run'
74
+ p.cmd_exec = create_cmd_exec
40
75
  end
41
- p.create_repos
42
- p.init_project
43
- rescue Psych::SyntaxError => ex
44
- exit_now!("#{@path}: syntax error : #{ex.message}", 1)
45
76
  end
46
77
  else
47
- exit_now!("#{@path} no such file or directory", 2)
78
+ logger.error("#{path} is not a valid clenver configuration")
79
+ exit 2
48
80
  end
81
+ p.init
82
+ #p.init_project
49
83
  end
50
84
  end
51
85
  end
@@ -1,3 +1,3 @@
1
1
  module Clenver
2
- VERSION = '0.1.13'
2
+ VERSION = '0.1.14'
3
3
  end
@@ -86,8 +86,15 @@ init_custom () {
86
86
  echo "nd_pt: $nd_pt"
87
87
  fi
88
88
  bash_cmd "$home_v$nd_pt"
89
- ssh_cmd "git clone https://github.com/pietrushnic/clenver_projects.git src/clenver_projects"
89
+ ssh_cmd "source ~/.bash_profile; git clone https://github.com/pietrushnic/clenver_projects.git src/clenver_projects"
90
90
  bash_cmd "clenver init $home_v/src/clenver_projects/general.yml"
91
91
  }
92
92
 
93
+ init_file () {
94
+ # assume that vm is running
95
+ scp_cmd $1 /home/user
96
+ home_v='$HOME'
97
+ nd_pt="/${1##*/}"
98
+ bash_cmd "clenver init $home_v$nd_pt"
99
+ }
93
100
  eval "$@"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clenver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Król
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-17 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -131,13 +131,19 @@ files:
131
131
  - clenver.gemspec
132
132
  - clenver.rdoc
133
133
  - features/clenver.feature
134
- - features/clenver_init.feature
135
134
  - features/clenver_version.feature
135
+ - features/init/basic.feature
136
+ - features/init/exec_cmd.feature
137
+ - features/init/init.feature
138
+ - features/init/links.feature
139
+ - features/init/pkg_manager.feature
140
+ - features/init/repository.feature
136
141
  - features/step_definitions/clenver_steps.rb
137
142
  - features/support/env.rb
138
143
  - lib/clenver.rb
139
144
  - lib/clenver/assets/sample.yml
140
145
  - lib/clenver/cli.rb
146
+ - lib/clenver/command_executor.rb
141
147
  - lib/clenver/link.rb
142
148
  - lib/clenver/logging.rb
143
149
  - lib/clenver/package_manager.rb
@@ -174,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
180
  version: '0'
175
181
  requirements: []
176
182
  rubyforge_project:
177
- rubygems_version: 2.1.5
183
+ rubygems_version: 2.1.10
178
184
  signing_key:
179
185
  specification_version: 4
180
186
  summary: Command line home directory manager
@@ -1,209 +0,0 @@
1
- Feature: Initialization
2
- In order to save time and money
3
- User should be able to bootstrap project environment ASAP
4
-
5
- Scenario: Given config file doesn't exist
6
- When I run `clenver init no_name.yml`
7
- Then the exit status should be 2
8
-
9
- Scenario: Valid config file given
10
- Given The default aruba timeout is 10 seconds
11
- Given a file named "valid.yml" with:
12
- """
13
- https://github.com/pietrushnic/dummy.git:
14
- links:
15
- foobar.txt:
16
- - foobar_link
17
- foobar:
18
- - foobar_dir_link
19
- """
20
- When I run `clenver init valid.yml`
21
- Then the exit status should be 0
22
-
23
- Scenario: Invalid config file given
24
- Given a file named "invalid.yml" with:
25
- """
26
- Lorem:{]}
27
- ipsum:
28
- dolor: sit amet,
29
- consectetur adipisicing elit, sed: do eiusmod tempor
30
- incididunt: ut
31
- labore et dolore: magna aliqua.
32
- """
33
- When I run `clenver init invalid.yml`
34
- Then the exit status should be 1
35
-
36
- Scenario: Init simple project (repo w/ colon)
37
- Given The default aruba timeout is 10 seconds
38
- Given a file named "test_repo.yml" with:
39
- """
40
- https://github.com/pietrushnic/dummy.git:
41
- """
42
- When I run `clenver init test_repo.yml`
43
- Then the following files should exist:
44
- | test_repo/dummy/README.md |
45
-
46
- Scenario: Init simple project (repo w/o colon)
47
- Given The default aruba timeout is 10 seconds
48
- Given a file named "test_repo.yml" with:
49
- """
50
- https://github.com/pietrushnic/dummy.git
51
- """
52
- When I run `clenver init test_repo.yml`
53
- Then the following files should exist:
54
- | test_repo/dummy/README.md |
55
-
56
- Scenario: Init simple project to given directory
57
- Given The default aruba timeout is 10 seconds
58
- Given a file named "test_repo.yml" with:
59
- """
60
- https://github.com/pietrushnic/dummy.git:
61
- """
62
- When I run `clenver init test_repo.yml some_tmp`
63
- Then the following files should exist:
64
- | some_tmp/test_repo/dummy/README.md |
65
-
66
- Scenario: Init project with symbolic links
67
- Given The default aruba timeout is 10 seconds
68
- Given a file named "test_repo.yml" with:
69
- """
70
- https://github.com/pietrushnic/dummy.git:
71
- links:
72
- foobar.txt:
73
- - foobar_link
74
- foobar:
75
- - foobar_dir_link
76
- """
77
- When I run `clenver init test_repo.yml some_tmp`
78
- Then the following links should exist:
79
- | some_tmp/test_repo/foobar_link |
80
- | some_tmp/test_repo/foobar_dir_link |
81
-
82
- Scenario: files backup verification
83
- Given The default aruba timeout is 10 seconds
84
- Given a file named "test_repo.yml" with:
85
- """
86
- https://github.com/pietrushnic/dummy.git:
87
- links:
88
- foobar.txt:
89
- - foobar_link
90
- - foobar_link
91
- foobar:
92
- - foobar_dir_link
93
- """
94
- When I run `clenver init test_repo.yml some_tmp`
95
- Then the following links should exist:
96
- | some_tmp/test_repo/foobar_link |
97
- | some_tmp/test_repo/foobar_link_old |
98
- | some_tmp/test_repo/foobar_dir_link |
99
-
100
- Scenario: use system variable in path
101
- Given The default aruba timeout is 10 seconds
102
- Given a file named "test_repo.yml" with:
103
- """
104
- https://github.com/pietrushnic/dummy.git:
105
- links:
106
- $HOME/foobar.txt:
107
- - $HOME/foobar_link
108
- """
109
- When I run `clenver init test_repo.yml some_tmp`
110
- Then the following links should exist:
111
- | $HOME/foobar_link |
112
-
113
- Scenario: Connect remote and check uri
114
- Given The default aruba timeout is 25 seconds
115
- Given a file named "test_repo.yml" with:
116
- """
117
- https://github.com/pietrushnic/spf13-vim.git:
118
- remotes:
119
- upstream:
120
- - https://github.com/spf13/spf13-vim.git
121
- """
122
- When I run `clenver init test_repo.yml some_tmp`
123
- Then the following remote uris should be connected in "some_tmp/test_repo/spf13-vim":
124
- | https://github.com/spf13/spf13-vim.git |
125
-
126
- Scenario: Connect remote and check its name
127
- Given The default aruba timeout is 25 seconds
128
- Given a file named "test_repo.yml" with:
129
- """
130
- https://github.com/pietrushnic/spf13-vim.git:
131
- remotes:
132
- upstream:
133
- - https://github.com/spf13/spf13-vim.git
134
- """
135
- When I run `clenver init test_repo.yml some_tmp`
136
- Then the following remote branches should be connected in "some_tmp/test_repo/spf13-vim":
137
- | upstream |
138
-
139
- Scenario: run simple command
140
- Given The default aruba timeout is 10 seconds
141
- Given a file named "test_repo.yml" with:
142
- """
143
- https://github.com/pietrushnic/dummy.git:
144
- run:
145
- - echo "success!!!!"
146
- """
147
- When I run `clenver init test_repo.yml some_tmp`
148
- Then the output should contain "success!!!!\n"
149
-
150
- @ignore
151
- Scenario: apt: check if package installed
152
- Given The default aruba timeout is 10 seconds
153
- Given a file named "test_repo.yml" with:
154
- """
155
- apt:
156
- - vim
157
- """
158
- When I run `clenver init test_repo.yml some_tmp`
159
- Then the output should contain "vim is already the newest version.\n"
160
-
161
- @ignore
162
- Scenario: package installed and simple command run
163
- Given The default aruba timeout is 10 seconds
164
- Given a file named "test_repo.yml" with:
165
- """
166
- apt:
167
- - vim
168
- https://github.com/pietrushnic/dummy.git:
169
- run:
170
- - echo "success!!!!"
171
- """
172
- When I run `clenver init test_repo.yml some_tmp`
173
- Then the output should contain "vim is already the newest version.\n"
174
- Then the output should contain "success!!!!\n"
175
-
176
- Scenario: install gem
177
- Given The default aruba timeout is 120 seconds
178
- Given a file named "test_repo.yml" with:
179
- """
180
- gem:
181
- - tmuxinator
182
- https://github.com/pietrushnic/dummy.git:
183
- run:
184
- - echo "success!!!!"
185
- """
186
- When I run `clenver init test_repo.yml some_tmp`
187
- Then the output should contain "installed\n"
188
- Then the output should contain "success!!!!\n"
189
-
190
- @ignore
191
- Scenario: install gems and packages
192
- Given The default aruba timeout is 120 seconds
193
- Given a file named "test_repo.yml" with:
194
- """
195
- apt:
196
- - vim
197
- - mutt
198
- gem:
199
- - tmuxinator
200
- - git
201
- https://github.com/pietrushnic/dummy.git:
202
- run:
203
- - echo "success!!!!"
204
- """
205
- When I run `clenver init test_repo.yml some_tmp`
206
- Then the output should contain "gems installed\n"
207
- Then the output should contain "vim is already the newest version.\n"
208
- Then the output should contain "mutt is already the newest version.\n"
209
- Then the output should contain "success!!!!\n"