mortar 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,7 +65,7 @@ class Mortar::Command::Jobs < Mortar::Command::Base
65
65
  #
66
66
  #Examples:
67
67
  #
68
- # $ mortar jobs:run --clustersize 3 geenrate_regression_model_coefficients
68
+ # $ mortar jobs:run --clustersize 3 generate_regression_model_coefficients
69
69
  #
70
70
  #Taking code snapshot... done
71
71
  #Sending code snapshot to Mortar... done
@@ -22,36 +22,60 @@ module Mortar
22
22
  def generate_project(project_name, options)
23
23
 
24
24
  set_script_binding(project_name, options)
25
- mkdir project_name, :verbose => false
26
- @dest_path = File.join(@dest_path, project_name)
27
-
28
- copy_file "README.md", "README.md"
29
- copy_file "gitignore", ".gitignore"
30
- copy_file "Gemfile", "Gemfile"
31
-
32
- mkdir "pigscripts"
33
-
34
- inside "pigscripts" do
35
- generate_file "pigscript.pig", "#{project_name}.pig"
36
- end
37
-
38
- mkdir "macros"
39
-
40
- inside "macros" do
41
- copy_file "gitkeep", ".gitkeep"
42
- end
43
-
44
- mkdir "udfs"
45
-
46
- inside "udfs" do
47
- mkdir "python"
48
- inside "python" do
49
- copy_file "python_udf.py", "#{project_name}.py"
25
+ #TODO: This needs refactoring. Too many side effects and unnecessary
26
+ #complexity. Just manage the directory structure explicitly.
27
+ project_path = File.join(@dest_path, project_name)
28
+ project_already_existed = File.exists?(project_path)
29
+ begin
30
+ mkdir project_name, :verbose => false
31
+ @dest_path = File.join(@dest_path, project_name)
32
+
33
+ copy_file "README.md", "README.md"
34
+ copy_file "gitignore", ".gitignore"
35
+ copy_file "Gemfile", "Gemfile"
36
+
37
+ mkdir "pigscripts"
38
+
39
+ inside "pigscripts" do
40
+ generate_file "pigscript.pig", "#{project_name}.pig"
41
+ end
42
+
43
+ mkdir "macros"
44
+
45
+ inside "macros" do
46
+ copy_file "gitkeep", ".gitkeep"
47
+ end
48
+
49
+ mkdir "udfs"
50
+
51
+ inside "udfs" do
52
+ mkdir "python"
53
+ inside "python" do
54
+ copy_file "python_udf.py", "#{project_name}.py"
55
+ end
56
+ end
57
+
58
+ display_run("bundle install")
59
+ #First verify that we can cd into the project dir.
60
+ #The directory change isn't persisted outside of this system command.
61
+ output = `cd #{project_name}`
62
+ unless $?.exitstatus == 0
63
+ raise Mortar::Command::CommandFailed, output
64
+ end
65
+
66
+ output = `cd #{project_name} && bundle install`
67
+ unless $?.exitstatus == 0
68
+ raise Mortar::Command::CommandFailed, output
69
+ end
70
+ rescue => e
71
+ #If we can't set up the project correctly and the project folder
72
+ #didn't exist before - remove it.
73
+ unless project_already_existed or not File.exists?(project_path)
74
+ display("\nProject creation failed. Removing generated files.\n")
75
+ FileUtils.remove_dir project_path
50
76
  end
77
+ raise e
51
78
  end
52
-
53
- display_run("bundle install")
54
- `cd #{project_name} && bundle install && cd ..`
55
79
 
56
80
  end
57
81
 
@@ -29,8 +29,26 @@ module Mortar
29
29
  #
30
30
 
31
31
  def has_git?
32
- %x{ git --version }
33
- $?.success?
32
+ # Needs to have git version 1.7.7 or greater. Earlier versions lack
33
+ # the necessary untracked option for stash.
34
+ git_version_output, has_git = run_cmd("git --version")
35
+ if has_git
36
+ git_version = git_version_output.split(" ")[2]
37
+ versions = git_version.split(".")
38
+ is_ok_version = versions[0].to_i >= 1 &&
39
+ versions[1].to_i >= 7 &&
40
+ versions[2].to_i >= 7
41
+ end
42
+ has_git && is_ok_version
43
+ end
44
+
45
+ def run_cmd(cmd)
46
+ begin
47
+ output = %x{#{cmd}}
48
+ rescue Exception => e
49
+ output = ""
50
+ end
51
+ return [output, $?.success?]
34
52
  end
35
53
 
36
54
  def has_dot_git?
@@ -39,7 +57,7 @@ module Mortar
39
57
 
40
58
  def git(args, check_success=true, check_git_directory=true)
41
59
  unless has_git?
42
- raise GitError, "git must be installed"
60
+ raise GitError, "git 1.7.7 or higher must be installed"
43
61
  end
44
62
 
45
63
  if check_git_directory && !has_dot_git?
@@ -483,6 +483,5 @@ module Mortar
483
483
  create_display_method("exists", "1;34")
484
484
  create_display_method("identical", "1;34")
485
485
  create_display_method("conflict", "1;31")
486
-
487
486
  end
488
487
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
  module Mortar
18
18
  # see http://semver.org/
19
- VERSION = "0.2.1"
19
+ VERSION = "0.3.0"
20
20
  end
@@ -15,6 +15,7 @@
15
15
  #
16
16
 
17
17
  require "spec_helper"
18
+ require "mortar/generators/generator_base"
18
19
  require "mortar/command/generate"
19
20
  require "fileutils"
20
21
  require "tmpdir"
@@ -42,6 +43,7 @@ describe Mortar::Command::Generate do
42
43
 
43
44
  File.read("Test/pigscripts/Test.pig").each_line { |line| line.match(/<%.*%>/).should be_nil }
44
45
  end
46
+
45
47
  it "error when name isn't provided" do
46
48
  stderr, stdout = execute("generate:project")
47
49
  stderr.should == <<-STDERR
@@ -49,6 +51,31 @@ describe Mortar::Command::Generate do
49
51
  ! Must specify PROJECTNAME.
50
52
  STDERR
51
53
  end
54
+
55
+ it 'removes project directory when generate:project fails' do
56
+ any_instance_of(Mortar::Generators::Base) do |base|
57
+ stub(base).copy_file { raise Mortar::Command::CommandFailed, 'Bad Copy'}
58
+ end
59
+ begin
60
+ stderr, stdout = execute("generate:project Test")
61
+ rescue => e
62
+ e.message.should == 'Bad Copy'
63
+ end
64
+ File.exists?("Test").should be_false
65
+ end
66
+
67
+ it 'does not remove pre-existing project directory when generate:project fails' do
68
+ FileUtils.mkdir("Test")
69
+ any_instance_of(Mortar::Generators::Base) do |base|
70
+ stub(base).copy_file { raise Mortar::Command::CommandFailed, 'Bad Copy'}
71
+ end
72
+ begin
73
+ stderr, stdout = execute("generate:project Test")
74
+ rescue => e
75
+ e.message.should == 'Bad Copy'
76
+ end
77
+ File.exists?("Test").should be_true
78
+ end
52
79
  end
53
80
 
54
81
  describe "new" do
@@ -24,6 +24,22 @@ module Mortar
24
24
  @git = Mortar::Git::Git.new
25
25
  end
26
26
 
27
+ context "has_git?" do
28
+ it "returns false with no git installed" do
29
+ mock(@git).run_cmd("git --version").returns("-bash: git: command not found")
30
+ @git.has_git?.should be_false
31
+ end
32
+
33
+ it "returns false with unsupported git version" do
34
+ mock(@git).run_cmd("git --version").returns("git version 1.7.6")
35
+ @git.has_git?.should be_false
36
+ end
37
+
38
+ it "returns false with unsupported git version" do
39
+ @git.has_git?.should be_true
40
+ end
41
+
42
+ end
27
43
 
28
44
  context "has_any_commits" do
29
45
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mortar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mortar Data
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-31 00:00:00 Z
18
+ date: 2012-09-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: mortar-api-ruby
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 23
28
+ hash: 19
29
29
  segments:
30
30
  - 0
31
- - 2
31
+ - 3
32
32
  - 0
33
- version: 0.2.0
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency