mortar 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mortar/command/jobs.rb +1 -1
- data/lib/mortar/generators/project_generator.rb +52 -28
- data/lib/mortar/git.rb +21 -3
- data/lib/mortar/helpers.rb +0 -1
- data/lib/mortar/version.rb +1 -1
- data/spec/mortar/command/generate_spec.rb +27 -0
- data/spec/mortar/git_spec.rb +16 -0
- metadata +8 -8
data/lib/mortar/command/jobs.rb
CHANGED
@@ -65,7 +65,7 @@ class Mortar::Command::Jobs < Mortar::Command::Base
|
|
65
65
|
#
|
66
66
|
#Examples:
|
67
67
|
#
|
68
|
-
# $ mortar jobs:run --clustersize 3
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
|
data/lib/mortar/git.rb
CHANGED
@@ -29,8 +29,26 @@ module Mortar
|
|
29
29
|
#
|
30
30
|
|
31
31
|
def has_git?
|
32
|
-
|
33
|
-
|
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?
|
data/lib/mortar/helpers.rb
CHANGED
data/lib/mortar/version.rb
CHANGED
@@ -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
|
data/spec/mortar/git_spec.rb
CHANGED
@@ -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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
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-
|
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:
|
28
|
+
hash: 19
|
29
29
|
segments:
|
30
30
|
- 0
|
31
|
-
-
|
31
|
+
- 3
|
32
32
|
- 0
|
33
|
-
version: 0.
|
33
|
+
version: 0.3.0
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|