bozo-scripts 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,24 @@
1
- module Bozo::Packagers
2
-
3
- # Specifies gem packager.
4
- #
5
- # Builds any '*.gemspec' file in the root directory
6
- class Rubygems
7
-
8
- def execute
9
- dist_dir = File.expand_path(File.join('dist', 'gem'))
10
- FileUtils.mkdir_p dist_dir
11
-
12
- Dir['*.gemspec'].each { |spec| build_gem spec }
13
- Dir['*.gem'].each { |file| FileUtils.mv file, File.join(dist_dir, file) }
14
- end
15
-
16
- private
17
-
18
- def build_gem(spec)
19
- execute_command :rubygems, ['gem', 'build', spec]
20
- end
21
-
22
- end
23
-
1
+ module Bozo::Packagers
2
+
3
+ # Specifies gem packager.
4
+ #
5
+ # Builds any '*.gemspec' file in the root directory
6
+ class Rubygems
7
+
8
+ def execute
9
+ dist_dir = File.expand_path(File.join('dist', 'gem'))
10
+ FileUtils.mkdir_p dist_dir
11
+
12
+ Dir['*.gemspec'].each { |spec| build_gem spec }
13
+ Dir['*.gem'].each { |file| FileUtils.mv file, File.join(dist_dir, file) }
14
+ end
15
+
16
+ private
17
+
18
+ def build_gem(spec)
19
+ execute_command :rubygems, ['gem', 'build', spec]
20
+ end
21
+
22
+ end
23
+
24
24
  end
@@ -1,34 +1,34 @@
1
- module Bozo::Preparers
2
-
3
- class CommonAssemblyInfo
4
-
5
- def company_name(name)
6
- @company_name = name
7
- end
8
-
9
- def execute
10
- log_info 'Generating common assembly info'
11
-
12
- git_hash = env['GIT_HASH_FULL']
13
- computer_name = env['COMPUTERNAME']
14
- trademark = computer_name ? "#{computer_name} #{git_hash}" : git_hash
15
- path = File.expand_path(File.join('build', 'CommonAssemblyInfo.cs'))
16
-
17
- log_debug "Version: #{version}"
18
- log_debug "Commit hash: #{git_hash}"
19
- log_debug "Computer name: #{computer_name}" if computer_name
20
- log_debug "Path: #{path}"
21
-
22
- File.open(path, 'w+') do |f|
23
- f << "using System.Reflection;\n"
24
- f << "\n"
25
- f << "[assembly: AssemblyCompany(\"#{@company_name}\")]\n"
26
- f << "[assembly: AssemblyVersion(\"#{version}\")]\n"
27
- f << "[assembly: AssemblyFileVersion(\"#{version}\")]\n"
28
- f << "[assembly: AssemblyTrademark(\"#{trademark}\")]"
29
- end
30
- end
31
-
32
- end
33
-
34
- end
1
+ module Bozo::Preparers
2
+
3
+ class CommonAssemblyInfo
4
+
5
+ def company_name(name)
6
+ @company_name = name
7
+ end
8
+
9
+ def execute
10
+ log_info 'Generating common assembly info'
11
+
12
+ git_hash = env['GIT_HASH_FULL']
13
+ computer_name = env['COMPUTERNAME']
14
+ trademark = computer_name ? "#{computer_name} #{git_hash}" : git_hash
15
+ path = File.expand_path(File.join('build', 'CommonAssemblyInfo.cs'))
16
+
17
+ log_debug "Version: #{version}"
18
+ log_debug "Commit hash: #{git_hash}"
19
+ log_debug "Computer name: #{computer_name}" if computer_name
20
+ log_debug "Path: #{path}"
21
+
22
+ File.open(path, 'w+') do |f|
23
+ f << "using System.Reflection;\n"
24
+ f << "\n"
25
+ f << "[assembly: AssemblyCompany(\"#{@company_name}\")]\n"
26
+ f << "[assembly: AssemblyVersion(\"#{version}\")]\n"
27
+ f << "[assembly: AssemblyFileVersion(\"#{version}\")]\n"
28
+ f << "[assembly: AssemblyTrademark(\"#{trademark}\")]"
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -1,152 +1,152 @@
1
- module Bozo::Preparers
2
-
3
- # Preparer for creating files based upon configuration files and ERB-style
4
- # templates before any compilation occurs.
5
- #
6
- # == Overview
7
- #
8
- # This preparer is primarily intended for generating config files with shared
9
- # values but it is capable of generating whatever files you want. Each
10
- # instance of the preparer is isolated from the anothers so you could specify
11
- # multiple preparers to work with different configurations and templates if
12
- # you wished.
13
- #
14
- # By default the preparer will load <tt>default.rb</tt> followed by
15
- # <tt>[environment].rb</tt> followed by <tt>[machine_name].rb</tt> from the
16
- # configured config_path if the file exists. It will then load any files
17
- # explicitly required through the config_file method.
18
- #
19
- # == Hook configuration
20
- #
21
- # prepare :file_templating do |t|
22
- # t.config_path 'somewhere' # defaults to 'config' if not specified
23
- # t.config_file 'my/specific/file.rb' # must be a specific file
24
- # t.template_files 'src/**/*.config.template' # can use glob format
25
- # end
26
- #
27
- # Source files are expected to have an additional extension compared to the
28
- # target file. For example, a source file of
29
- # <tt>src/csharp/Project/Project.config.template</tt> will generate the file
30
- # <tt>src/csharp/Project/Project.config</tt>.
31
- #
32
- # == Configuration files
33
- #
34
- # Configuration files specify a hash of hashes in a more readable format.
35
- # For example:
36
- #
37
- # group :example do
38
- # set :one, 'foo'
39
- # set :two, 'bar'
40
- # end
41
- #
42
- # Internally creates a hash like:
43
- #
44
- # {:example => {:one => 'foo', :two => 'bar'}}
45
- #
46
- # A configuration file can overwrite the values specified by a preceding one
47
- # without error. Groups can be opened and closed as desired and nesting
48
- # groups is possible.
49
- #
50
- # == Template files
51
- #
52
- # To use a value within an ERB template you specify the hash hierarchy as if
53
- # they were method names rather than having to use the full hash syntax.
54
- #
55
- # Therefore, this is valid:
56
- #
57
- # Foo is <%= example.one %>
58
- #
59
- # Whilst this is *not* valid:
60
- #
61
- # Foo is <%= self[:example][:one] %>
62
- #
63
- # If a template uses a value that is not specified within the configuration
64
- # then the preparer will raise an error and halt the build.
65
- class FileTemplating
66
-
67
- # Creates a new instance.
68
- def initialize
69
- @config_path = 'config'
70
- @template_globs = []
71
- @config_files = []
72
- end
73
-
74
- # Sets the path of the directory within which the preparer should look for
75
- # the default configuration files.
76
- #
77
- # @param [String] path
78
- # The path to the directory containing the default configuration files.
79
- def config_path(path)
80
- @config_path = path
81
- end
82
-
83
- # Adds a specific file to load configuration from.
84
- #
85
- # @param [String] path
86
- # The path to a configuration file.
87
- def config_file(path)
88
- @config_files << path
89
- end
90
-
91
- # Adds a set of templates files from which to generate files.
92
- #
93
- # @param [String] glob
94
- # A glob that points to a set of files that should pass through the
95
- # templating engine.
96
- def template_files(glob)
97
- @template_globs << glob
98
- end
99
-
100
- # Generate all the files matching the configuration.
101
- def execute
102
- log_info '' # formatting
103
- log_info 'Generating files'
104
-
105
- get_coordinator.generate_files do |template, target|
106
- log_debug "Generating #{target} from #{template}"
107
- end
108
- end
109
-
110
- private
111
-
112
- # Creates a new templating coordinator based upon the current
113
- # configuration.
114
- def get_coordinator
115
- coordinator = Bozo::ErubisTemplatingCoordinator.new
116
-
117
- add_config coordinator
118
- add_templates coordinator
119
-
120
- coordinator
121
- end
122
-
123
- # Adds the configuration to the templating coordinator.
124
- def add_config(coordinator)
125
- add_default_config_files coordinator
126
- @config_files.each {|f| coordinator.required_config_file f}
127
- end
128
-
129
- # Adds the default configuration from the configuration directory to the
130
- # templating coordinator.
131
- #
132
- # @param [ErubisTemplatingCoordinator] coordinator
133
- # The template coordinator to add the configuration to.
134
- def add_default_config_files(coordinator)
135
- default_files = ['default.rb', "#{environment}.rb"]
136
- default_files << "#{env['MACHINENAME']}.rb" if env['MACHINENAME']
137
-
138
- default_files.each do |file|
139
- coordinator.config_file File.join(@config_path, file)
140
- end
141
- end
142
-
143
- # Adds the templates to the templating coordinator.
144
- def add_templates(coordinator)
145
- @template_globs.each do |glob|
146
- coordinator.template_files glob
147
- end
148
- end
149
-
150
- end
151
-
152
- end
1
+ module Bozo::Preparers
2
+
3
+ # Preparer for creating files based upon configuration files and ERB-style
4
+ # templates before any compilation occurs.
5
+ #
6
+ # == Overview
7
+ #
8
+ # This preparer is primarily intended for generating config files with shared
9
+ # values but it is capable of generating whatever files you want. Each
10
+ # instance of the preparer is isolated from the anothers so you could specify
11
+ # multiple preparers to work with different configurations and templates if
12
+ # you wished.
13
+ #
14
+ # By default the preparer will load <tt>default.rb</tt> followed by
15
+ # <tt>[environment].rb</tt> followed by <tt>[machine_name].rb</tt> from the
16
+ # configured config_path if the file exists. It will then load any files
17
+ # explicitly required through the config_file method.
18
+ #
19
+ # == Hook configuration
20
+ #
21
+ # prepare :file_templating do |t|
22
+ # t.config_path 'somewhere' # defaults to 'config' if not specified
23
+ # t.config_file 'my/specific/file.rb' # must be a specific file
24
+ # t.template_files 'src/**/*.config.template' # can use glob format
25
+ # end
26
+ #
27
+ # Source files are expected to have an additional extension compared to the
28
+ # target file. For example, a source file of
29
+ # <tt>src/csharp/Project/Project.config.template</tt> will generate the file
30
+ # <tt>src/csharp/Project/Project.config</tt>.
31
+ #
32
+ # == Configuration files
33
+ #
34
+ # Configuration files specify a hash of hashes in a more readable format.
35
+ # For example:
36
+ #
37
+ # group :example do
38
+ # set :one, 'foo'
39
+ # set :two, 'bar'
40
+ # end
41
+ #
42
+ # Internally creates a hash like:
43
+ #
44
+ # {:example => {:one => 'foo', :two => 'bar'}}
45
+ #
46
+ # A configuration file can overwrite the values specified by a preceding one
47
+ # without error. Groups can be opened and closed as desired and nesting
48
+ # groups is possible.
49
+ #
50
+ # == Template files
51
+ #
52
+ # To use a value within an ERB template you specify the hash hierarchy as if
53
+ # they were method names rather than having to use the full hash syntax.
54
+ #
55
+ # Therefore, this is valid:
56
+ #
57
+ # Foo is <%= example.one %>
58
+ #
59
+ # Whilst this is *not* valid:
60
+ #
61
+ # Foo is <%= self[:example][:one] %>
62
+ #
63
+ # If a template uses a value that is not specified within the configuration
64
+ # then the preparer will raise an error and halt the build.
65
+ class FileTemplating
66
+
67
+ # Creates a new instance.
68
+ def initialize
69
+ @config_path = 'config'
70
+ @template_globs = []
71
+ @config_files = []
72
+ end
73
+
74
+ # Sets the path of the directory within which the preparer should look for
75
+ # the default configuration files.
76
+ #
77
+ # @param [String] path
78
+ # The path to the directory containing the default configuration files.
79
+ def config_path(path)
80
+ @config_path = path
81
+ end
82
+
83
+ # Adds a specific file to load configuration from.
84
+ #
85
+ # @param [String] path
86
+ # The path to a configuration file.
87
+ def config_file(path)
88
+ @config_files << path
89
+ end
90
+
91
+ # Adds a set of templates files from which to generate files.
92
+ #
93
+ # @param [String] glob
94
+ # A glob that points to a set of files that should pass through the
95
+ # templating engine.
96
+ def template_files(glob)
97
+ @template_globs << glob
98
+ end
99
+
100
+ # Generate all the files matching the configuration.
101
+ def execute
102
+ log_info '' # formatting
103
+ log_info 'Generating files'
104
+
105
+ get_coordinator.generate_files do |template, target|
106
+ log_debug "Generating #{target} from #{template}"
107
+ end
108
+ end
109
+
110
+ private
111
+
112
+ # Creates a new templating coordinator based upon the current
113
+ # configuration.
114
+ def get_coordinator
115
+ coordinator = Bozo::ErubisTemplatingCoordinator.new
116
+
117
+ add_config coordinator
118
+ add_templates coordinator
119
+
120
+ coordinator
121
+ end
122
+
123
+ # Adds the configuration to the templating coordinator.
124
+ def add_config(coordinator)
125
+ add_default_config_files coordinator
126
+ @config_files.each {|f| coordinator.required_config_file f}
127
+ end
128
+
129
+ # Adds the default configuration from the configuration directory to the
130
+ # templating coordinator.
131
+ #
132
+ # @param [ErubisTemplatingCoordinator] coordinator
133
+ # The template coordinator to add the configuration to.
134
+ def add_default_config_files(coordinator)
135
+ default_files = ['default.rb', "#{environment}.rb"]
136
+ default_files << "#{env['MACHINENAME']}.rb" if env['MACHINENAME']
137
+
138
+ default_files.each do |file|
139
+ coordinator.config_file File.join(@config_path, file)
140
+ end
141
+ end
142
+
143
+ # Adds the templates to the templating coordinator.
144
+ def add_templates(coordinator)
145
+ @template_globs.each do |glob|
146
+ coordinator.template_files glob
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+ end
@@ -1,83 +1,83 @@
1
- require 'fileutils'
2
-
3
- module Bozo::Publishers
4
-
5
- # Publisher that copies files from one location to another.
6
- class FileCopy
7
-
8
- # Creates a new instance.
9
- def initialize
10
- @directories = []
11
- end
12
-
13
- # Adds a source directory of files copy.
14
- #
15
- # Must be relative to the project root. All files within the directory and
16
- # its subdirectories will be copied to the destination directory,
17
- # maintaining the file structure.
18
- #
19
- # @params [Array] args
20
- # Path to a directory relative to the project root.
21
- def directory(*args)
22
- @directories << args
23
- end
24
-
25
- # Set the destination directory of the file copy.
26
- #
27
- # Must be an absolute path.
28
- #
29
- # @params [String] destination
30
- # The absolution path the source files should be copied to.
31
- def destination(destination)
32
- @destination = destination
33
- end
34
-
35
- def execute
36
- if @directories.empty? or @destination.nil?
37
- raise Bozo::ConfigurationError.new 'You must specify at least one source file or directory AND a destination directory'
38
- end
39
-
40
- ensure_no_clashing_files
41
-
42
- copy_pairs do |source, target|
43
- FileUtils.mkdir_p File.dirname(target)
44
- log_debug "Publishing \"#{File.basename(source)}\" to \"#{target}\""
45
- FileUtils.cp source, target
46
- end
47
- end
48
-
49
- private
50
-
51
- # Checks the destination does not contain files that will be overwritten by
52
- # the source files.
53
- def ensure_no_clashing_files
54
- existing_files = []
55
-
56
- copy_pairs do |source, target|
57
- existing_files << target if File.exist? target
58
- end
59
-
60
- raise Bozo::ConfigurationError.new "Target files already exist - #{existing_files}" unless existing_files.empty?
61
- end
62
-
63
- # Returns the source-destination file pairs specified by the source
64
- # directories and destination directory.
65
- def copy_pairs # :yields: source_path, destination_path
66
- destination = File.join @destination
67
-
68
- @directories.each do |dir|
69
- relative_source_dir = File.join(dir)
70
- source_dir = File.expand_path relative_source_dir
71
- source_dir_path = Pathname.new source_dir
72
-
73
- Dir[File.join(source_dir, '**', '*')].each do |source_file|
74
- rel_path = Pathname.new(source_file).relative_path_from(source_dir_path).to_s
75
- target_file = File.join(destination, rel_path)
76
- yield source_file, target_file
77
- end
78
- end
79
- end
80
-
81
- end
82
-
1
+ require 'fileutils'
2
+
3
+ module Bozo::Publishers
4
+
5
+ # Publisher that copies files from one location to another.
6
+ class FileCopy
7
+
8
+ # Creates a new instance.
9
+ def initialize
10
+ @directories = []
11
+ end
12
+
13
+ # Adds a source directory of files copy.
14
+ #
15
+ # Must be relative to the project root. All files within the directory and
16
+ # its subdirectories will be copied to the destination directory,
17
+ # maintaining the file structure.
18
+ #
19
+ # @params [Array] args
20
+ # Path to a directory relative to the project root.
21
+ def directory(*args)
22
+ @directories << args
23
+ end
24
+
25
+ # Set the destination directory of the file copy.
26
+ #
27
+ # Must be an absolute path.
28
+ #
29
+ # @params [String] destination
30
+ # The absolution path the source files should be copied to.
31
+ def destination(destination)
32
+ @destination = destination
33
+ end
34
+
35
+ def execute
36
+ if @directories.empty? or @destination.nil?
37
+ raise Bozo::ConfigurationError.new 'You must specify at least one source file or directory AND a destination directory'
38
+ end
39
+
40
+ ensure_no_clashing_files
41
+
42
+ copy_pairs do |source, target|
43
+ FileUtils.mkdir_p File.dirname(target)
44
+ log_debug "Publishing \"#{File.basename(source)}\" to \"#{target}\""
45
+ FileUtils.cp source, target
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ # Checks the destination does not contain files that will be overwritten by
52
+ # the source files.
53
+ def ensure_no_clashing_files
54
+ existing_files = []
55
+
56
+ copy_pairs do |source, target|
57
+ existing_files << target if File.exist? target
58
+ end
59
+
60
+ raise Bozo::ConfigurationError.new "Target files already exist - #{existing_files}" unless existing_files.empty?
61
+ end
62
+
63
+ # Returns the source-destination file pairs specified by the source
64
+ # directories and destination directory.
65
+ def copy_pairs # :yields: source_path, destination_path
66
+ destination = File.join @destination
67
+
68
+ @directories.each do |dir|
69
+ relative_source_dir = File.join(dir)
70
+ source_dir = File.expand_path relative_source_dir
71
+ source_dir_path = Pathname.new source_dir
72
+
73
+ Dir[File.join(source_dir, '**', '*')].each do |source_file|
74
+ rel_path = Pathname.new(source_file).relative_path_from(source_dir_path).to_s
75
+ target_file = File.join(destination, rel_path)
76
+ yield source_file, target_file
77
+ end
78
+ end
79
+ end
80
+
81
+ end
82
+
83
83
  end