codestrap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +4 -0
- data/.yardopts +3 -0
- data/BOILERPLATE.md +151 -0
- data/CODESTRAPFILE.md +28 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +13 -0
- data/README.md +69 -0
- data/Rakefile +51 -0
- data/bin/strap +8 -0
- data/bin/upstrap +8 -0
- data/codestrap.gemspec +37 -0
- data/config/projects/codestrap.rb +22 -0
- data/config/software/codestrap.rb +20 -0
- data/config/software/ruby.rb +247 -0
- data/config/software/zlib.rb +86 -0
- data/features/client.feature +99 -0
- data/features/fixtures/client/home/codestrap/bin/.empty +0 -0
- data/features/fixtures/client/home/codestrap/content/bash.erb +3 -0
- data/features/fixtures/client/home/codestrap/content/gem/dir/file +0 -0
- data/features/fixtures/client/home/codestrap/content/gem/dir/template +3 -0
- data/features/fixtures/client/home/codestrap/content/gem/file +1 -0
- data/features/fixtures/client/home/codestrap/content/gem/template +3 -0
- data/features/fixtures/client/home/codestrap/content/local_remote.erb +1 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/dir/file +0 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/dir/template +3 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/file +1 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/template +3 -0
- data/features/fixtures/client/home/codestrap/objects/local.json +3 -0
- data/features/fixtures/client/output/.empty +0 -0
- data/features/fixtures/client/var/lib/codestrap/bin/.empty +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/bashremote.erb +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/dir/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/dir/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local.erb +1 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/dir/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/dir/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/file +1 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote.erb +1 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/dir/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/dir/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/objects/remote.json +3 -0
- data/features/fixtures/logging/home/logging/codestrap/bin/stubdirectory/.empty +0 -0
- data/features/fixtures/logging/home/logging/codestrap/bin/stubnotlink +0 -0
- data/features/fixtures/logging/home/logging/codestrap/content/.empty +0 -0
- data/features/fixtures/logging/home/logging/codestrap/objects/.empty +0 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/address.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/cell.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/email.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/mobile.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/name.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/phone.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/Modulefile +12 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/README +17 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/manifests/init.pp +42 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/spec/spec_helper.rb +18 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/tests/init.pp +13 -0
- data/features/fixtures/server/mixed/var/lib/stub/objects/contact.json +8 -0
- data/features/fixtures/server/mixed/var/lib/stub/objects/shadow/contact.json +8 -0
- data/features/fixtures/strap/projects/etc/.empty +0 -0
- data/features/fixtures/strap/projects/home/user/dir/bin/.empty +0 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/Modulefile +12 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/README +17 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/manifests/:stub:project.name:/subclass.pp +3 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/manifests/init.pp +42 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/spec/spec_helper.rb +18 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/tests/init.pp +13 -0
- data/features/fixtures/strap/projects/home/user/dir/objects/contact.json +8 -0
- data/features/fixtures/strap/projects/home/user/dir/objects/shadow/contact.json +8 -0
- data/features/fixtures/strap/projects/output/.empty +0 -0
- data/features/fixtures/stub/contact/etc/.empty +0 -0
- data/features/fixtures/stub/contact/home/user/dir/bin/.empty +0 -0
- data/features/fixtures/stub/contact/home/user/dir/content/address.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/cell.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/email.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/mobile.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/name.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/phone.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/objects/contact.json +8 -0
- data/features/fixtures/stub/contact/home/user/dir/objects/shadow/contact.json +8 -0
- data/features/fixtures/stub/contact/output/.empty +0 -0
- data/features/fixtures/stub/date/etc/.empty +0 -0
- data/features/fixtures/stub/date/home/user/stub/bin/.empty +0 -0
- data/features/fixtures/stub/date/home/user/stub/content/day.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/hour.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/minute.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/month.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/second.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/year.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/objects/.empty +0 -0
- data/features/fixtures/stub/date/output/.empty +0 -0
- data/features/fixtures/stub/script/etc/.empty +0 -0
- data/features/fixtures/stub/script/home/user/stub/bin/.empty +0 -0
- data/features/fixtures/stub/script/home/user/stub/content/credentials.erb +6 -0
- data/features/fixtures/stub/script/home/user/stub/objects/credentials.rb +11 -0
- data/features/fixtures/stub/script/output/.empty +0 -0
- data/features/logging.feature +39 -0
- data/features/object_scripts.feature +13 -0
- data/features/server.feature +36 -0
- data/features/step_definitions/client_steps.rb +99 -0
- data/features/step_definitions/logging_steps.rb +65 -0
- data/features/step_definitions/object_scripts_steps.rb +26 -0
- data/features/step_definitions/server_steps.rb +112 -0
- data/features/step_definitions/strap_steps.rb +69 -0
- data/features/step_definitions/stub_option_simple_steps.rb +31 -0
- data/features/step_definitions/stub_steps.rb +94 -0
- data/features/strap.feature +34 -0
- data/features/stub.feature +157 -0
- data/features/stub_option_simple.feature +14 -0
- data/features/stub_packages.feature +15 -0
- data/features/support/env.rb +197 -0
- data/lib/codestrap.rb +415 -0
- data/lib/codestrap/cli.rb +76 -0
- data/lib/codestrap/client.rb +179 -0
- data/lib/codestrap/config.rb +199 -0
- data/lib/codestrap/log.rb +56 -0
- data/lib/codestrap/mixin.rb +20 -0
- data/lib/codestrap/namespace.rb +19 -0
- data/lib/codestrap/object/abstract.rb +33 -0
- data/lib/codestrap/object/factory.rb +86 -0
- data/lib/codestrap/object/standard/datetime.rb +24 -0
- data/lib/codestrap/object/standard/files.rb +40 -0
- data/lib/codestrap/object/standard/project.rb +33 -0
- data/lib/codestrap/object/standard/rest.rb +30 -0
- data/lib/codestrap/patch.rb +122 -0
- data/lib/codestrap/server/rest.rb +177 -0
- data/lib/codestrap/server/version.rb +5 -0
- data/lib/codestrap/strap/abstract.rb +135 -0
- data/lib/codestrap/strap/factory.rb +85 -0
- data/lib/codestrap/strap/standard.rb +95 -0
- data/lib/codestrap/stub/abstract.rb +156 -0
- data/lib/codestrap/stub/factory.rb +87 -0
- data/lib/codestrap/stub/standard.rb +23 -0
- data/lib/codestrap/version.rb +3 -0
- data/omnibus.rb +53 -0
- data/package-scripts/codestrap/postinst +25 -0
- data/package-scripts/codestrap/postrm +17 -0
- data/package-scripts/codestrap/preinst +7 -0
- data/package-scripts/codestrap/prerm +15 -0
- data/resources/codestrap/pkg/background.png +0 -0
- data/resources/codestrap/pkg/distribution.xml.erb +22 -0
- data/resources/codestrap/pkg/license.html.erb +202 -0
- data/resources/codestrap/pkg/welcome.html.erb +7 -0
- metadata +466 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'etc'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
require 'tmpdir'
|
6
|
+
require 'tempfile'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
module Codestrap
|
10
|
+
class Client
|
11
|
+
def initialize(url)
|
12
|
+
uri = URI url
|
13
|
+
@url = url
|
14
|
+
@scheme = uri.scheme
|
15
|
+
@host = uri.host
|
16
|
+
@port = uri.port
|
17
|
+
self.capability uri
|
18
|
+
end
|
19
|
+
|
20
|
+
# Cache directory path. Will be created if directory doesn't exist
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
def cache
|
24
|
+
@cache ||= begin
|
25
|
+
cache = File.join(Dir.tmpdir, Etc.getlogin, digest, 'codestrap')
|
26
|
+
FileUtils.mkpath cache unless File.exist? cache
|
27
|
+
@cache = cache
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Content cache directory path. Will be created if directory doesn't exists
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
def cache_content
|
35
|
+
@cache_content ||= begin
|
36
|
+
cache_content = File.join(cache, 'content')
|
37
|
+
FileUtils.mkpath cache_content unless File.exist? cache_content
|
38
|
+
@cache_content = cache_content
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Object cache directory path. Will be created if directory doesn't exists
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
def cache_object
|
46
|
+
@cache_object ||= begin
|
47
|
+
cache_object = File.join(cache, 'objects')
|
48
|
+
FileUtils.mkpath cache_object unless File.exist? cache_object
|
49
|
+
@cache_object = cache_object
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return MD5 hexdigest digest of the capability URL
|
54
|
+
#
|
55
|
+
# @return [String]
|
56
|
+
def digest
|
57
|
+
@digest ||= (Digest::MD5.hexdigest @url)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Sets capability URL. Returns JSON capability document as hash.
|
61
|
+
#
|
62
|
+
# @param [URI] uri
|
63
|
+
# Capability URI
|
64
|
+
# @return [Hash|nil]
|
65
|
+
# JSON document as a Hash
|
66
|
+
def capability(uri=nil)
|
67
|
+
return @capability unless uri
|
68
|
+
begin
|
69
|
+
response = Net::HTTP.get_response URI uri
|
70
|
+
@capability = JSON.parse(response.body)
|
71
|
+
return @capability
|
72
|
+
rescue Errno::ECONNREFUSED
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def stubmetadata(file)
|
78
|
+
return nil unless @capability
|
79
|
+
response = Net::HTTP.get_response URI stubmetadataurl + '?name=' + file
|
80
|
+
JSON.parse(response.body)
|
81
|
+
end
|
82
|
+
|
83
|
+
def stubmetadataurl
|
84
|
+
return nil unless @capability
|
85
|
+
"#{@scheme}://#{@host}:#{@port}#{@capability['urls']['stub']['metadata']}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def stublist
|
89
|
+
return nil unless @capability
|
90
|
+
response = Net::HTTP.get_response URI stubmetadataurl
|
91
|
+
JSON.parse(response.body).keys
|
92
|
+
end
|
93
|
+
|
94
|
+
def stubfileurl
|
95
|
+
return nil unless @capability
|
96
|
+
"#{@scheme}://#{@host}:#{@port}#{@capability['urls']['stub']['file']}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def strapmetadata(project)
|
100
|
+
return nil unless @capability
|
101
|
+
response = Net::HTTP.get_response URI strapmetadataurl + '?name=' + project
|
102
|
+
JSON.parse(response.body)[project]
|
103
|
+
end
|
104
|
+
|
105
|
+
def straplist
|
106
|
+
return nil unless @capability
|
107
|
+
response = Net::HTTP.get_response URI strapmetadataurl
|
108
|
+
JSON.parse(response.body).keys
|
109
|
+
end
|
110
|
+
|
111
|
+
def strapmetadataurl
|
112
|
+
return nil unless @capability
|
113
|
+
"#{@scheme}://#{@host}:#{@port}#{@capability['urls']['strap']['metadata']}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def strapprojecturl
|
117
|
+
return nil unless @capability
|
118
|
+
"#{@scheme}://#{@host}:#{@port}#{@capability['urls']['strap']['project']}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def objecturl
|
122
|
+
return nil unless @capability
|
123
|
+
"#{@scheme}://#{@host}:#{@port}#{@capability['urls']['objects']}"
|
124
|
+
end
|
125
|
+
|
126
|
+
def getobjects(objects=nil)
|
127
|
+
return {} unless @capability
|
128
|
+
response = Net::HTTP.get_response URI objecturl
|
129
|
+
JSON.parse(response.body)
|
130
|
+
end
|
131
|
+
|
132
|
+
def getstub(codestrap)
|
133
|
+
return nil unless @capability
|
134
|
+
path = File.join(cache_content, codestrap + '.erb')
|
135
|
+
|
136
|
+
# Get metadata
|
137
|
+
metadata = stubmetadata codestrap
|
138
|
+
if not metadata or metadata.empty?
|
139
|
+
return nil
|
140
|
+
end
|
141
|
+
|
142
|
+
# create file
|
143
|
+
response = Net::HTTP.get_response URI stubfileurl + "/#{codestrap}"
|
144
|
+
File.open(path, 'w') do |file|
|
145
|
+
file.write response.body
|
146
|
+
end
|
147
|
+
|
148
|
+
path
|
149
|
+
end
|
150
|
+
|
151
|
+
def getstrap(project)
|
152
|
+
return nil unless @capability
|
153
|
+
path = File.join(cache_content, project)
|
154
|
+
|
155
|
+
# Get metadata
|
156
|
+
metadata = strapmetadata project
|
157
|
+
if not metadata or metadata.empty?
|
158
|
+
return nil
|
159
|
+
end
|
160
|
+
|
161
|
+
# Make directories
|
162
|
+
metadata['files'].each do |file|
|
163
|
+
next unless file['ftype'].eql?('directory')
|
164
|
+
FileUtils.mkdir_p File.join(path, file['file'])
|
165
|
+
end
|
166
|
+
|
167
|
+
# Make files
|
168
|
+
metadata['files'].each do |file|
|
169
|
+
next unless file['ftype'].eql?('file')
|
170
|
+
response = Net::HTTP.get_response URI strapprojecturl + "/#{project}/" + file['file']
|
171
|
+
File.open(File.join(path, file['file']), 'w') do |fh|
|
172
|
+
fh.write response.body
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
path
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module Codestrap
|
2
|
+
module Server
|
3
|
+
class Config
|
4
|
+
# Bind IP Address
|
5
|
+
# @return [String]
|
6
|
+
attr_accessor :bind
|
7
|
+
# Port number
|
8
|
+
# @return [Integer]
|
9
|
+
attr_accessor :port
|
10
|
+
# Array of files
|
11
|
+
# @return [Array]
|
12
|
+
attr_accessor :base
|
13
|
+
# Ignore files from project
|
14
|
+
# @return [Array]
|
15
|
+
attr_accessor :ignore
|
16
|
+
|
17
|
+
# List of content directories
|
18
|
+
# @return [Array]
|
19
|
+
def content
|
20
|
+
Array(base).map { |dir| File.join(dir, 'content') }
|
21
|
+
end
|
22
|
+
|
23
|
+
# List of object directories
|
24
|
+
# @return [Array]
|
25
|
+
def objects
|
26
|
+
Array(base).map { |dir| File.join(dir, 'objects') }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
module Local
|
31
|
+
class Config
|
32
|
+
# Array of directories
|
33
|
+
# @return [Array]
|
34
|
+
attr_accessor :base
|
35
|
+
# Array of capability URLs
|
36
|
+
# @return [Array]
|
37
|
+
attr_accessor :urls
|
38
|
+
# List of files to ignore when parsing boiler plates
|
39
|
+
# @return [Array]
|
40
|
+
attr_accessor :ignore
|
41
|
+
# Directory to store links to executable
|
42
|
+
# @return [String]
|
43
|
+
def links
|
44
|
+
links = nil
|
45
|
+
Array(base).each do |dir|
|
46
|
+
path = File.join(dir, 'bin')
|
47
|
+
next unless File.exist? path
|
48
|
+
links = path
|
49
|
+
break
|
50
|
+
end
|
51
|
+
links
|
52
|
+
end
|
53
|
+
|
54
|
+
# List of content directories
|
55
|
+
# @return [Array]
|
56
|
+
def content
|
57
|
+
Array(base).map { |dir| File.join(dir, 'content') }
|
58
|
+
end
|
59
|
+
|
60
|
+
# List of object directories
|
61
|
+
# @return [Array]
|
62
|
+
def objects
|
63
|
+
Array(base).map { |dir| File.join(dir, 'objects') }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Codestrapfile
|
70
|
+
def self.server
|
71
|
+
@@server ||= Codestrap::Server::Config.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.local
|
75
|
+
@@local ||= Codestrap::Local::Config.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def server
|
79
|
+
@@server ||= Codestrap::Server::Config.new
|
80
|
+
|
81
|
+
if block_given?
|
82
|
+
yield @@server
|
83
|
+
else
|
84
|
+
@@server
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def local
|
89
|
+
@@local ||= Codestrap::Local::Config.new
|
90
|
+
|
91
|
+
if block_given?
|
92
|
+
yield @@local
|
93
|
+
else
|
94
|
+
@@local
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.config
|
99
|
+
obj = Codestrapfile.new()
|
100
|
+
yield obj if block_given?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module Codestrap
|
105
|
+
# Loaded variables from Codestrapfile presented as getters
|
106
|
+
class Config
|
107
|
+
def initialize
|
108
|
+
# Setup defaults
|
109
|
+
Codestrapfile.config do |conf|
|
110
|
+
conf.local.base = %W[codestrap .codestrap].map { |d| File.join(ENV['HOME'], d) }
|
111
|
+
conf.local.ignore = []
|
112
|
+
conf.server.bind = '127.0.0.1'
|
113
|
+
conf.server.port = '4567'
|
114
|
+
conf.server.base = conf.local.base
|
115
|
+
conf.server.ignore = conf.local.ignore
|
116
|
+
end
|
117
|
+
|
118
|
+
@@codestrapfile_mtime = Time.new(0)
|
119
|
+
load_codestrapfile
|
120
|
+
end
|
121
|
+
|
122
|
+
def codestrapfile_mtime(codestrapfile)
|
123
|
+
if not codestrapfile and ENV['CODESTRAPFILE'] and File.exist? ENV['CODESTRAPFILE']
|
124
|
+
codestrapfile = ENV['CODESTRAPFILE']
|
125
|
+
end
|
126
|
+
if codestrapfile
|
127
|
+
return File::Stat.new(codestrapfile).mtime
|
128
|
+
else
|
129
|
+
return Time.new(0)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def reload_on_change
|
134
|
+
reload = false
|
135
|
+
mtime = nil
|
136
|
+
codestrapfile = nil
|
137
|
+
if ENV['CODESTRAPFILE'] and !@@codestrapfile
|
138
|
+
reload = true
|
139
|
+
codestrapfile = ENV['CODESTRAPFILE']
|
140
|
+
mtime = codestrapfile_mtime(codestrapfile)
|
141
|
+
elsif ENV['CODESTRAPFILE'] and !ENV['CODESTRAPFILE'].eql?(@@codestrapfile)
|
142
|
+
reload = true
|
143
|
+
codestrapfile = ENV['CODESTRAPFILE']
|
144
|
+
mtime = codestrapfile_mtime(codestrapfile)
|
145
|
+
elsif @@codestrapfile
|
146
|
+
mtime = codestrapfile_mtime(@@codestrapfile)
|
147
|
+
if mtime > @@codestrapfile_mtime
|
148
|
+
reload = true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
if reload
|
152
|
+
load codestrapfile
|
153
|
+
@@codestrapfile = codestrapfile
|
154
|
+
@@codestrapfile_mtime = mtime
|
155
|
+
true
|
156
|
+
end
|
157
|
+
false
|
158
|
+
end
|
159
|
+
|
160
|
+
def load_codestrapfile(codestrapfile=nil)
|
161
|
+
codestrapfile_mtime = nil
|
162
|
+
unless codestrapfile
|
163
|
+
# Load possible codestrapfiles
|
164
|
+
[ENV['CODESTRAPFILE'], File.join(ENV['HOME'], 'codestrap', 'Codestrapfile'), File.join(ENV['HOME'], '.codestrap', 'Codestrapfile')].each do |sf|
|
165
|
+
next unless sf and File.exist?(sf)
|
166
|
+
codestrapfile = sf
|
167
|
+
codestrapfile_mtime = codestrapfile_mtime(sf)
|
168
|
+
break
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
if codestrapfile
|
173
|
+
load codestrapfile
|
174
|
+
@@codestrapfile = codestrapfile
|
175
|
+
@@codestrapfile_mtime = codestrapfile_mtime
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.local
|
180
|
+
@@config ||= Codestrapfile.new
|
181
|
+
@@config.local
|
182
|
+
end
|
183
|
+
|
184
|
+
def local
|
185
|
+
@@config ||= Codestrapfile.new
|
186
|
+
@@config.local
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.server
|
190
|
+
@@config ||= Codestrapfile.new
|
191
|
+
@@config.server
|
192
|
+
end
|
193
|
+
|
194
|
+
def server
|
195
|
+
@@config ||= Codestrapfile.new
|
196
|
+
@@config.server
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Codestrap
|
2
|
+
# Logging with pre set error messages
|
3
|
+
#
|
4
|
+
# The Log class has been designed to keep track of all possible messages the program will generate
|
5
|
+
class Log
|
6
|
+
@@msgs = {
|
7
|
+
STRAPMISSING: Proc.new { |*args| sprintf %q[Could not find project "%s".], *args },
|
8
|
+
STUBMISSING: Proc.new { |*args| sprintf %q[Could not find template "%s".], *args },
|
9
|
+
NOPATH: Proc.new { |*args| sprintf %q[No path to "%s".], *args },
|
10
|
+
LINKTARGET: Proc.new { |*args| sprintf %q[Invalid link target "%s". The link target must be the "%s" command], *args },
|
11
|
+
INVALIDCMD: Proc.new { |*args| sprintf %q[Invalid command "%s".], *args },
|
12
|
+
FILEEXISTS: Proc.new { |*args| sprintf %q[File "%s" exists. Can not overwrite.], *args },
|
13
|
+
GENERATE_NOTLINK: Proc.new { |*args| sprintf %q[File "%s" is not a symlink.], *args },
|
14
|
+
}
|
15
|
+
|
16
|
+
# Log pre set fatal message
|
17
|
+
#
|
18
|
+
# @param [Symbol] msg
|
19
|
+
# @param [Array] args
|
20
|
+
def fatal(msg, *args)
|
21
|
+
puts @@msgs[msg].call(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Log pre set error message
|
25
|
+
#
|
26
|
+
# @param [Symbol] msg
|
27
|
+
# @param [Array] args
|
28
|
+
def error(msg, *args)
|
29
|
+
puts @@msgs[msg].call(*args)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Log pre set error message
|
33
|
+
#
|
34
|
+
# @param [Symbol] msg
|
35
|
+
# @param [Array] args
|
36
|
+
def warn(msg, *args)
|
37
|
+
puts @@msgs[msg].call(*args)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Log pre set error message
|
41
|
+
#
|
42
|
+
# @param [Symbol] msg
|
43
|
+
# @param [Array] args
|
44
|
+
def info(msg, *args)
|
45
|
+
puts @@msgs[msg].call(*args)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Log pre set error message
|
49
|
+
#
|
50
|
+
# @param [Symbol] msg
|
51
|
+
# @param [Array] args
|
52
|
+
def debug(msg, *args)
|
53
|
+
puts @@msgs[msg].call(*args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Codestrap
|
2
|
+
module Mixin
|
3
|
+
module Exceptions
|
4
|
+
module Factory
|
5
|
+
class FactoryException < Exception; end
|
6
|
+
class FactoryAbstractMethod < Exception; end
|
7
|
+
class FactoryNotImplemented < Exception; end
|
8
|
+
class FactoryArgumentError < ArgumentError; end
|
9
|
+
class FactoryMethodEnforcement < ArgumentError; end
|
10
|
+
end
|
11
|
+
module Template
|
12
|
+
class RendererAbstractOnly < Exception; end
|
13
|
+
class RendererRequiredMethod < Exception; end
|
14
|
+
class RendererCannotOverwrite < Exception; end
|
15
|
+
class RendererTypeError < Exception; end
|
16
|
+
class RendererMissingRoot < Exception; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|