birr 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ #
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'megam/core/log'
17
+ require 'mixlib/config'
18
+
19
+ class Megam
20
+ class Config
21
+ extend(Mixlib::Config)
22
+ def self.inspect
23
+ configuration.inspect
24
+ end
25
+
26
+ def self.add_formatter(name, file_path=nil)
27
+ formatters << [name, file_path]
28
+ end
29
+
30
+ def self.formatters
31
+ @formatters ||= []
32
+ end
33
+
34
+
35
+ # Valid log_levels are:
36
+ # * :debug
37
+ # * :info
38
+ # * :warn
39
+ # * :fatal
40
+ # These work as you'd expect. There is also a special `:auto` setting.
41
+ # When set to :auto, Birr will auto adjust the log verbosity based on
42
+ # context. When a tty is available (usually becase the user is running meggy
43
+ # in a console), the log level is set to :warn, and output formatters are
44
+ # used as the primary mode of output. When a tty is not available, the
45
+ # logger is the primary mode of output, and the log level is set to :info
46
+ log_level :auto
47
+ log_location STDOUT
48
+ # toggle info level log items that can create a lot of output
49
+ verbose_logging true
50
+
51
+ install_file nil
52
+
53
+
54
+
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ class Megam
15
+ # == Megam::Exceptions
16
+ # Megam's custom exceptions are all contained within the Megam::Exceptions
17
+ # namespace.
18
+ class Exceptions
19
+
20
+ class Application < RuntimeError; end
21
+
22
+ class FileNotFound < RuntimeError; end
23
+
24
+ class WorkAreaNotFound < RuntimeError; end
25
+
26
+ class UnsupportedAction < RuntimeError; end
27
+
28
+ class MissingLibrary < RuntimeError; end
29
+
30
+
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'fileutils'
2
+
3
+ class Megam::FileCache
4
+ def store
5
+ file_path_array = File.split(path)
6
+ file_name = file_path_array.pop
7
+ cache_path = create_cache_path(File.join(file_path_array))
8
+ File.open(File.join(cache_path, file_name), "w", perm) do |io|
9
+ io.print(contents)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'logger'
17
+ require 'mixlib/log'
18
+
19
+ class Megam
20
+ class Log
21
+ extend Mixlib::Log
22
+
23
+ # Force initialization of the primary log device (@logger)
24
+ init
25
+
26
+
27
+ class Formatter
28
+ def self.show_time=(*args)
29
+ Mixlib::Log::Formatter.show_time = *args
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,121 @@
1
+ #
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ require 'rubygems'
16
+
17
+ class Megam
18
+ class Text
19
+
20
+ attr_reader :stdout
21
+ attr_reader :stderr
22
+ attr_reader :stdin
23
+ attr_reader :config
24
+
25
+ def initialize(stdout, stderr, stdin, config)
26
+ @stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config
27
+ end
28
+
29
+ def highline
30
+ @highline ||= begin
31
+ require 'highline'
32
+ HighLine.new
33
+ end
34
+ end
35
+
36
+ # Prints a message to stdout. Aliased as +info+ for compatibility with
37
+ # the logger API.
38
+
39
+ def msg(message)
40
+ stdout.puts message
41
+ end
42
+
43
+ alias :info :msg
44
+
45
+ # Prints a msg to stderr. Used for warn, error, and fatal.
46
+ def err(message)
47
+ stderr.puts message
48
+ end
49
+
50
+ # Print a warning message
51
+ def warn(message)
52
+ err("#{color('WARNING:', :yellow, :bold)} #{message}")
53
+ end
54
+
55
+ # Print an error message
56
+ def error(message)
57
+ err("#{color('ERROR:', :red, :bold)} #{message}")
58
+ end
59
+
60
+ # Print a message describing a fatal error.
61
+ def fatal(message)
62
+ err("#{color('FATAL:', :red, :bold)} #{message}")
63
+ end
64
+
65
+ def color(string, *colors)
66
+ if color?
67
+ highline.color(string, *colors)
68
+ else
69
+ string
70
+ end
71
+ end
72
+
73
+ # Should colored output be used? For output to a terminal, this is
74
+ # determined by the value of `config[:color]`. When output is not to a
75
+ # terminal, colored output is never used
76
+ def color?
77
+ ##Chef::Config[:color] && stdout.tty? && !Chef::Platform.windows?
78
+ :red
79
+ end
80
+
81
+ def agree(*args, &block)
82
+ highline.agree(*args, &block)
83
+ end
84
+
85
+ def ask(*args, &block)
86
+ highline.ask(*args, &block)
87
+ end
88
+
89
+ def list(*args)
90
+ highline.list(*args)
91
+ end
92
+
93
+ # Formats +data+ using the configured presenter and outputs the result
94
+ # via +msg+. Formatting can be customized by configuring a different
95
+ # presenter. See +use_presenter+
96
+ def output(data)
97
+ msg @presenter.format(data)
98
+ end
99
+
100
+ def ask_question(question, opts={})
101
+ question = question + "[#{opts[:default]}] " if opts[:default]
102
+
103
+ if opts[:default] and config[:defaults]
104
+ opts[:default]
105
+ else
106
+ stdout.print question
107
+ a = stdin.readline.strip
108
+
109
+ if opts[:default]
110
+ a.empty? ? opts[:default] : a
111
+ else
112
+ a
113
+ end
114
+ end
115
+ end
116
+
117
+ def pretty_print(data)
118
+ stdout.puts data
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,125 @@
1
+ require "mixlib/shellout"
2
+ require "megam/birr_options"
3
+ require "megam/core/text"
4
+ require "megam/birr"
5
+ require "megam/workarea"
6
+ require "megam/transferarea"
7
+ require "megam/cmd_verb"
8
+ require "ruby-progressbar"
9
+
10
+ class Megam
11
+ module Install
12
+
13
+ Birr.text.info(Birr.text.color(" |***|", :yellow, :bold))
14
+ Birr.text.info(Birr.text.color(" Birr |* *| "+::Megam::VERSION, :red))
15
+ Birr.text.info(Birr.text.color(" |===|", :green, :bold))
16
+ def self.included(receiver)
17
+ receiver.extend(Megam::Install::ClassMethods)
18
+ end
19
+
20
+ WORKAREA_PRECONFIG_DIRS = %w[package dump tarball]
21
+
22
+ def self.workarea_loader
23
+ @workarea_loader ||= Megam::WorkAreaLoader.new(WORKAREA_PRECONFIG_DIRS)
24
+ end
25
+
26
+ module ClassMethods
27
+ #default parms del_if_exists is false
28
+ #message prints a dump directory string
29
+ def dump(options = {},&block)
30
+ if block_given?
31
+ birr_opts = BirrOptions.new(&block)
32
+ options[:method_name] = __method__.to_s
33
+ copy(options,birr_opts)
34
+ end
35
+ end
36
+
37
+ def script(options = {},&block)
38
+ if block_given?
39
+ birr_opts = BirrOptions.new(&block)
40
+ cmd = Megam::WorkArea.new(options)
41
+ options[:method_name] = "package"
42
+ key = Megam::Install.workarea_loader[(File.join(options[:method_name],cmd.directory))]
43
+ birr_opts.command(cmd.find_package_script(options[:method_name]+'.'+cmd.directory, birr_opts.commands).fetch(key))
44
+ shelly(options,birr_opts)
45
+ end
46
+ end
47
+
48
+ def install(options = {},&block)
49
+ if block_given?
50
+ birr_opts = BirrOptions.new(&block)
51
+ cmd = Megam::WorkArea.new(options)
52
+ options[:method_name] = __method__.to_s
53
+ shelly(options,birr_opts)
54
+ end
55
+ end
56
+
57
+ def tarball(options = {},&block)
58
+ if block_given?
59
+ birr_opts = BirrOptions.new(&block)
60
+ cmd = Megam::WorkArea.new(options)
61
+ options[:method_name] = __method__.to_s
62
+ tar_dir = Megam::Install.workarea_loader[(File.join(options[:method_name],cmd.directory.gsub(".", File::SEPARATOR)))]
63
+
64
+ tmp_opts = {:tar_file => File.join(tar_dir,birr_opts.tarball_file), :to_dir => Megam::TransferArea.convert_to_transferarea_dir(cmd.directory) }
65
+ birr_opts.command(Megam::CmdVerb.untar(tmp_opts))
66
+ shelly(options, birr_opts)
67
+ end
68
+ end
69
+
70
+ #now run the stuff in parsed block.
71
+ #eg.pull out the directory and copy it.
72
+ def copy (options, birr_opts)
73
+ cmd = Megam::WorkArea.new(options)
74
+
75
+ Birr.text.info(Birr.text.color("DUMP :", :green, :bold) + "dumping directory " + "#{cmd.directory}")
76
+
77
+ if cmd.directory_avail?
78
+ from_dir = Megam::Install.workarea_loader[(File.join(options[:method_name],cmd.directory))]
79
+ to_dir = Megam::TransferArea.convert_to_transferarea_dir(cmd.directory)
80
+
81
+ goahead_copy = Birr.text.agree("Do you wish to copy files from #{from_dir}\n to #{to_dir} [y/n]?")
82
+
83
+ if Dir.exists?(from_dir) && goahead_copy
84
+ #formulate the shell cp command, and returns it. now feed it to shelly and execute it.
85
+ cp_opts = { :from_dir => from_dir,
86
+ :to_dir => to_dir,
87
+ :sudo => birr_opts.sudo?,
88
+ :recursive => true,
89
+ :copy_on_new => true}
90
+ birr_opts.command(Megam::CmdVerb.cp(cp_opts))
91
+ options[:message] = ''
92
+ shelly(options,birr_opts)
93
+ else
94
+ unless goahead_copy
95
+ then
96
+ Birr.text.warn "Skip : OK."
97
+ else
98
+ Birr.text.fatal "Skip : You need to specify an existing #{from_dir}\n in the :directory option to dump"
99
+
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ #now run the stuff in parsed block.
106
+ #eg.pull out the command and run it.
107
+ def shelly (options ={},birr_opts)
108
+ msg = ''
109
+ msg = options[:message] if options[:message]
110
+ Birr.text.info(Birr.text.color("INSTALL :", :green, :bold) + msg.to_s) unless !msg.strip
111
+ command ||= birr_opts.commands
112
+ unless !BirrOptions.method_defined?(:command)
113
+ command.each do |scmd|
114
+ Birr.text.info(Birr.text.color("SHELL :", :cyan, :bold) + scmd.to_s)
115
+ find = Mixlib::ShellOut.new(scmd.strip)
116
+ find.run_command
117
+ Birr.text.info find.stdout
118
+ find.error!
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ require "megam/core/text"
16
+ require "megam/birr"
17
+
18
+ # class responsible for converting "you", "root" to the correct directories.
19
+ # This is not a good way to do so.
20
+ class Megam::TransferArea
21
+
22
+ def self.convert_to_transferarea_dir(transferarea_name)
23
+ temp_transferarea_name = transferarea_name.dup
24
+ temp_transferarea_name = temp_transferarea_name.gsub("you", transfer_you_dir) if temp_transferarea_name.match("you")
25
+
26
+ temp_transferarea_name = temp_transferarea_name.gsub("root", transfer_root_dir) if temp_transferarea_name.match("root")
27
+ temp_transferarea_name = temp_transferarea_name.gsub(".", File::SEPARATOR)
28
+ temp_transferarea_name
29
+ end
30
+
31
+ #the root directory. its stubbed out now to ~/Desktop/tmp/root
32
+ def self.transfer_root_dir
33
+ File.join(File::SEPARATOR)
34
+ end
35
+
36
+ #the home directory. its stubbed out now to ~/Desktop/tmp
37
+ def self.transfer_you_dir
38
+ File.join(ENV['HOME']) || Dir.pwd
39
+ end
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ class Megam
2
+ ## expands the current directory of where the dew file executes and figures out the expanded
3
+ ## directory
4
+ BIRR_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
5
+ VERSION = '0.1'
6
+ end
@@ -0,0 +1,96 @@
1
+ #
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ require "megam/core/text"
16
+ require "megam/birr"
17
+ require "megam/workarea_loader"
18
+
19
+ # a class which manages the work area, ie find the files in workarea, packaging script in it.
20
+ class Megam::WorkArea
21
+
22
+ attr_accessor :del_if_exists
23
+ attr_accessor :directory
24
+ attr_accessor :msg
25
+ attr_accessor :dir_glob_files
26
+ def initialize (options)
27
+ @del_if_exists = false
28
+ @directory = options[:directory] if options[:directory]
29
+ @del_if_exists = options[:del_if_exists] if options[:del_if_exists]
30
+ @msg = options[:message] if options[:message]
31
+ end
32
+
33
+ def directory_avail?
34
+ directory
35
+ end
36
+
37
+ #Lists all the files under the workarea_installer/<directory>
38
+ #using a helper
39
+ def list_directory(i_dir)
40
+ @dir_glob_files = {}
41
+ @dir_glob_files ||= (find_files_via_dirglob(i_dir).values).flatten
42
+ end
43
+
44
+ #Lists all the files under the dir
45
+ def find_files_via_dirglob(i_dir)
46
+ dir_files = {}
47
+ Megam::Birr.text.info(Megam::Birr.text.color("GLOB :", :green, :bold) + "#{i_dir}")
48
+ if Dir.exists?(i_dir)
49
+ dir_files[i_dir] = Dir.glob("#{i_dir}/**/*")
50
+ end
51
+ dir_files
52
+ end
53
+
54
+ def self.workarea_install_directory
55
+ File.dirname(Megam::Config[:install_file])
56
+ end
57
+
58
+ def workarea_install(i_dir)
59
+ unless workarea_install_not_found!(i_dir)
60
+ File.join(workarea_install_directory,i_dir)
61
+ end
62
+ end
63
+
64
+ # :nodoc:
65
+ # Error out and print usage. probably becuase the arguments given by the
66
+ # user could not be resolved to a subcommand.
67
+ def workarea_install_not_found!(i_dir)
68
+ missing_install_dir = nil
69
+
70
+ if missing_install_dir = !(WORKAREA_PRECONFIG_DIRS.find {|wai| wai == i_dir} )
71
+ Megam::Birr.text.fatal("Cannot find workarea install dir for: '#{i_dir}'")
72
+ exit 10
73
+ end
74
+ missing_install_dir
75
+ end
76
+
77
+ def find_package_script(dir,package_words)
78
+ adir = dir.dup
79
+ adir = adir.gsub(".", File.path("/"))
80
+ package_script_files = {}
81
+ matching_dir = nil
82
+
83
+ while ( package_script_files.empty? ) && ( !package_words.empty? )
84
+ if (!matching_dir) && (!package_words.empty?)
85
+ package_script ||= package_words.pop
86
+ matching_dir ||= Megam::Install.workarea_loader[File.join(adir.strip)]
87
+ package_script_files[matching_dir] = Dir.glob("#{matching_dir}/**"+ package_script)
88
+ end
89
+ end
90
+ package_script_files
91
+ end
92
+
93
+ def to_s
94
+ "workarea[:directory =>"+directory+"]"
95
+ end
96
+ end