csd 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gemspec.homepage = "http://github.com/csd/csd"
13
13
  gemspec.authors = ["Technology Transfer Alliance Team"]
14
14
  gemspec.add_dependency "term-ansicolor", ">= 0"
15
- gemspec.add_dependency "activesupport", ">= 0"
15
+ gemspec.add_dependency "active_support", ">= 0"
16
16
  gemspec.add_dependency "builder", ">= 0"
17
17
  gemspec.executables = ["csd"]
18
18
  gemspec.post_install_message = %q{
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
data/bin/csd CHANGED
@@ -5,4 +5,4 @@ require 'rubygems' # As a side note: Rubygems is already included for Ruby >= 1.
5
5
 
6
6
  require File.join(File.dirname(__FILE__), '..', 'lib', 'csd')
7
7
 
8
- CSD::Init.new
8
+ Csd::Init.new
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{csd}
8
- s.version = "0.0.13"
8
+ s.version = "0.0.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Technology Transfer Alliance Team"]
12
- s.date = %q{2010-06-14}
12
+ s.date = %q{2010-06-22}
13
13
  s.default_executable = %q{csd}
14
14
  s.description = %q{CSD stands for Communication Systems Design and is a project of the Telecommunication Systems Laboratory (TSLab) of the Royal Institute of Technology in Stockholm, Sweden. Within CSD many software tools are used to build up various networks and services. This gem is supposed to automate processes to handle the compilation and installation of these software tools. Technology Transfer Alliance (TTA) is the project team, which maintains this code.}
15
15
  s.email = %q{mtoday11@gmail.com}
@@ -29,18 +29,24 @@ Gem::Specification.new do |s|
29
29
  "csd.gemspec",
30
30
  "lib/csd.rb",
31
31
  "lib/csd/applications/base.rb",
32
- "lib/csd/applications/minisip/darwin/minisip_darwin.rb",
32
+ "lib/csd/applications/minisip/base.rb",
33
33
  "lib/csd/applications/minisip/init.rb",
34
- "lib/csd/applications/minisip/linux/minisip_linux.rb",
35
- "lib/csd/applications/minisip/minisip.rb",
34
+ "lib/csd/applications/minisip/unix/base.rb",
35
+ "lib/csd/commands.rb",
36
36
  "lib/csd/init.rb",
37
37
  "lib/csd/options.rb",
38
- "lib/csd/path_struct.rb",
39
- "lib/extensions/array.rb",
40
- "lib/extensions/string.rb",
38
+ "lib/csd/path_container.rb",
39
+ "lib/extensions/core/array.rb",
40
+ "lib/extensions/core/file.rb",
41
+ "lib/extensions/core/object.rb",
42
+ "lib/extensions/core/pathname.rb",
43
+ "lib/extensions/core/string.rb",
44
+ "lib/extensions/gem/platform.rb",
41
45
  "publish",
46
+ "test/functional/test_commands.rb",
42
47
  "test/helper.rb",
43
- "test/test_csd.rb"
48
+ "test/unit/test_pathname.rb",
49
+ "test/unit/test_string.rb"
44
50
  ]
45
51
  s.homepage = %q{http://github.com/csd/csd}
46
52
  s.post_install_message = %q{
@@ -63,8 +69,10 @@ Gem::Specification.new do |s|
63
69
  s.rubygems_version = %q{1.3.7}
64
70
  s.summary = %q{Installation and compilation handler for software used in CSD projects.}
65
71
  s.test_files = [
66
- "test/helper.rb",
67
- "test/test_csd.rb"
72
+ "test/functional/test_commands.rb",
73
+ "test/helper.rb",
74
+ "test/unit/test_pathname.rb",
75
+ "test/unit/test_string.rb"
68
76
  ]
69
77
 
70
78
  if s.respond_to? :specification_version then
@@ -73,16 +81,16 @@ Gem::Specification.new do |s|
73
81
 
74
82
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
83
  s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
76
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
84
+ s.add_runtime_dependency(%q<active_support>, [">= 0"])
77
85
  s.add_runtime_dependency(%q<builder>, [">= 0"])
78
86
  else
79
87
  s.add_dependency(%q<term-ansicolor>, [">= 0"])
80
- s.add_dependency(%q<activesupport>, [">= 0"])
88
+ s.add_dependency(%q<active_support>, [">= 0"])
81
89
  s.add_dependency(%q<builder>, [">= 0"])
82
90
  end
83
91
  else
84
92
  s.add_dependency(%q<term-ansicolor>, [">= 0"])
85
- s.add_dependency(%q<activesupport>, [">= 0"])
93
+ s.add_dependency(%q<active_support>, [">= 0"])
86
94
  s.add_dependency(%q<builder>, [">= 0"])
87
95
  end
88
96
  end
data/lib/csd.rb CHANGED
@@ -1,2 +1,2 @@
1
- Dir.glob(File.join(File.dirname(__FILE__), 'extensions', '*.rb')) { |file| require file }
1
+ Dir.glob(File.join(File.dirname(__FILE__), 'extensions', '**', '*.rb')) { |file| require file }
2
2
  require File.join(File.dirname(__FILE__), 'csd', 'init')
@@ -1,15 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'commands')
1
2
  require 'rbconfig'
2
3
 
3
- module CSD
4
+ module Csd
4
5
  module Application
5
6
 
6
- # This is the root parent of all Applications
7
+ # This is the class root parent of all Applications
7
8
  #
8
9
  class Base
9
10
 
11
+ include Commands
10
12
  include Gem::UserInteraction
11
13
 
12
14
  attr_reader :gem_version, :options
15
+ attr_reader :after_build, :before_build # Dummies to be overwritten by methods
13
16
  attr_accessor :path
14
17
 
15
18
  def initialize(options={})
@@ -20,34 +23,10 @@ module CSD
20
23
  end
21
24
 
22
25
  def introduction
23
- say "CSD Gem Version: #{gem_version}"
24
- say
25
- say "The working directory is:"
26
- say path.root
26
+ say "CSD Version: #{gem_version}".blue
27
27
  end
28
28
 
29
- def test_command(*args)
30
- say "Testing command for success: #{args.join(' ')}".cyan
31
- system(*args)
32
- end
33
-
34
- def run_command(cmd)
35
- log "Running command: #{cmd} in #{Dir.pwd}".magenta
36
- ret = ''
37
- unless options.dry
38
- IO.popen(cmd) do |stdout|
39
- stdout.each do |line|
40
- say line
41
- ret << line
42
- end
43
- end
44
- end
45
- ret
46
- end
47
29
 
48
- def log(msg="")
49
- say msg.yellow unless options.silent
50
- end
51
30
 
52
31
  end
53
32
  end
@@ -0,0 +1,125 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'base')
2
+
3
+ module Csd
4
+ module Application
5
+ module Minisip
6
+ class Base < Csd::Application::Base
7
+
8
+ def introduction
9
+ super
10
+ define_paths
11
+ say " Working directory: ".green + path.work.to_s.yellow
12
+ say " Your Platform: ".green + Gem::Platform.local.humanize.to_s.yellow
13
+ say " Application module: ".green + self.class.name.to_s.yellow
14
+ say
15
+ unless options.yes
16
+ exit unless ask_yes_no("Continue?".red.bold, true)
17
+ end
18
+ say
19
+ build!
20
+ end
21
+
22
+ def build!
23
+ before_build
24
+ mkdir path.work
25
+ make_hdviper if checkout_hdviper or options.dry
26
+ checkout_minisip
27
+ make_minisip
28
+ after_build
29
+ end
30
+
31
+ def define_paths
32
+ path.work = Pathname.new(File.join(path.root, 'minisip'))
33
+ path.repository = Pathname.new(File.join(path.work, 'repository'))
34
+ path.open_gl_display = Pathname.new(File.join(path.repository, 'libminisip', 'source', 'subsystem_media', 'video', 'display', 'OpenGLDisplay.cxx'))
35
+ path.hdviper = Pathname.new(File.join(path.work, 'hdviper'))
36
+ path.hdviper_x264 = Pathname.new(File.join(path.hdviper, 'x264'))
37
+ path.hdviper_x264_test_x264api = Pathname.new(File.join(path.hdviper_x264, 'test', 'x264API'))
38
+ path.build = Pathname.new(File.join(path.work, 'build'))
39
+ path.build_include = Pathname.new(File.join(path.build, 'include'))
40
+ path.build_lib = Pathname.new(File.join(path.build, 'lib'))
41
+ path.build_lib_pkg_config = Pathname.new(File.join(path.build_lib, 'pkgconfig'))
42
+ path.build_share = Pathname.new(File.join(path.build, 'share'))
43
+ path.build_share_aclocal = Pathname.new(File.join(path.build_share, 'aclocal'))
44
+ end
45
+
46
+ def checkout_hdviper
47
+ if path.hdviper.directory?
48
+ say "Skipping hdviper, because the directory already exists: #{path.hdviper}".green.bold
49
+ else
50
+ if path.hdviper.parent.writable? or options.dry
51
+ say "Downloading hdviper to: #{path.hdviper}".green.bold
52
+ run_command("svn co --quiet svn://hdviper.org/hdviper/wp3/src #{path.hdviper}")
53
+ return true
54
+ else
55
+ say "Could not download hdviper (no permission): #{path.hdviper}".red
56
+ end
57
+ end
58
+ end
59
+
60
+ def make_hdviper
61
+ cd path.hdviper_x264
62
+ run_command('./configure')
63
+ run_command('make')
64
+ cd path.hdviper_x264_test_x264api
65
+ run_command('make')
66
+ end
67
+
68
+ def checkout_minisip # TODO: Refactor because redudancy with checkout_hdviper
69
+ if path.repository.directory?
70
+ say "Skipping repository download, because the directory already exists: #{path.repository}".green.bold
71
+ else
72
+ if path.repository.parent.writable? or options.dry
73
+ say "Downloading minisip repository to: #{path.repository}".green.bold
74
+ run_command("git clone http://github.com/csd/minisip.git #{path.repository}")
75
+ # Fixing hard-coded stuff
76
+ new_file_content = File.read(path.open_gl_display).gsub('/home/erik', path.build)
77
+ File.open(path.open_gl_display, 'w+') { |file| file << new_file_content }
78
+ return true
79
+ else
80
+ say "Could not download minisip repository (no permission): #{path.hdviper}".red
81
+ end
82
+ end
83
+ end
84
+
85
+ def make_minisip
86
+ [path.build, path.build_include, path.build_lib, path.build_share, path.build_share_aclocal].each { |target| mkdir target }
87
+ ['libmutil', 'libmnetutil', 'libmcrypto', 'libmikey', 'libmsip', 'libmstun', 'libminisip', 'minisip'].each do |library|
88
+ directory = Pathname.new(File.join(path.repository, library))
89
+ next if options.only and !options.only.include?(library)
90
+ if cd(directory) or options.dry
91
+ if options.bootstrap
92
+ say "Bootstrapping #{library}".green.bold
93
+ run_command("./bootstrap -I #{path.build_share_aclocal.enquote}")
94
+ end
95
+ if options.configure
96
+ say "Configuring #{library}".green.bold
97
+ individual_options = case library
98
+ when 'libminisip'
99
+ %Q{--enable-debug --enable-video --disable-mil --disable-decklink --enable-opengl --disable-sdl CPPFLAGS="-I#{path.hdviper_x264_test_x264api} -I#{path.hdviper_x264}" LDFLAGS="#{File.join(path.hdviper_x264_test_x264api, 'libx264api.a')} #{File.join(path.hdviper_x264, 'libtidx264.a')} -lpthread -lrt"}
100
+ #%Q{--enable-debug --enable-video --disable-mil --disable-decklink --enable-opengl --disable-sdl CPPFLAGS="-I#{path.hdviper_x264}" LDFLAGS="#{File.join(path.hdviper_x264, 'libx264.a')} -lpthread -lrt"}
101
+ when 'minisip'
102
+ %Q{--enable-debug --enable-video --enable-textui --enable-opengl}
103
+ else
104
+ ''
105
+ end
106
+ run_command(%Q{./configure #{individual_options} --prefix=#{path.build.enquote} PKG_CONFIG_PATH=#{path.build_lib_pkg_config.enquote} ACLOCAL_FLAGS=#{path.build_share_aclocal} LD_LIBRARY_PATH=#{path.build_lib.enquote} --silent})
107
+ end
108
+ if options.make
109
+ say "Make #{library}".green.bold
110
+ run_command("make")
111
+ end
112
+ if options.make_install
113
+ say "Make install #{library}".green.bold
114
+ run_command("make install")
115
+ end
116
+ else
117
+ say "Skipping minisip library #{library} because it not be found: #{directory}".green.bold
118
+ end
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+ end
125
+ end
@@ -1,19 +1,16 @@
1
- require File.join(File.dirname(__FILE__), 'minisip')
2
1
  Dir.glob(File.join(File.dirname(__FILE__), '**', '*.rb')) { |file| require file }
3
2
 
4
- module CSD
3
+ module Csd
5
4
  module Application
6
5
  module Minisip
7
6
  class Init
8
7
 
9
8
  def self.application(*args)
10
- case Gem::Platform.local
9
+ case Gem::Platform.local.os
11
10
  when 'linux'
12
- MinisipLinux.new(*args)
13
- when 'darwin'
14
- MinisipDarwin.new(*args)
11
+ Unix::Base.new(*args)
15
12
  else
16
- Minisip.new(*args)
13
+ Base.new(*args)
17
14
  end
18
15
  end
19
16
 
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'base')
2
+
3
+ module Csd
4
+ module Application
5
+ module Minisip
6
+ module Unix
7
+ class Base < Csd::Application::Minisip::Base
8
+
9
+ # A list of apt-get packages that are required by this application.
10
+ #
11
+ DEBIAN_DEPENDENCIES = %w{ libssl-dev libglademm-2.4-dev libsdl-dev git-core subversion automake libtool libltdl3-dev build-essential libavcodec-dev libswscale-dev nasm yasm libasound2-dev libsdl-ttf2.0-dev }
12
+
13
+ def before_build
14
+ fix_aclocal_dirlist
15
+ install_aptitude_dependencies
16
+ end
17
+
18
+ def after_build
19
+ ldconfig_and_gtkgui
20
+ end
21
+
22
+ def install_aptitude_dependencies
23
+ DEBIAN_DEPENDENCIES.each do |apt|
24
+ run_command("sudo apt-get --yes install #{apt}")
25
+ end if options.apt_get
26
+ end
27
+
28
+ def fix_aclocal_dirlist
29
+ return
30
+ content = '/usr/local/share/aclocal'
31
+ target = Pathname.new('/usr/share/aclocal/dirlist')
32
+ unless target.exist? and File.new(target).read == content # TODO: replace with File.read
33
+ begin
34
+ File.new(target, 'w').write(content).close
35
+ rescue Errno::EACCES => e
36
+ say "Please run the following commands with the right permissions.".red.bold
37
+ say " sudo rm /usr/share/aclocal/dirlist".green.bold
38
+ say " sudo touch /usr/share/aclocal/dirlist".green.bold
39
+ say " sudo echo /usr/local/share/aclocal >> /usr/share/aclocal/dirlist".green.bold
40
+ exit
41
+ end
42
+ end
43
+ end
44
+
45
+ def ldconfig_and_gtkgui
46
+ run_command("ldconfig /usr/local/lib/libminisip.so.0")
47
+ run_command("minisip_gtkgui")
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,171 @@
1
+ require 'pathname'
2
+ require 'ostruct'
3
+ require 'active_support'
4
+
5
+ module Csd
6
+ # This module contains wrapper methods for standard file system commands. They are meant to be
7
+ # a little bit more robust (e.g. raising no exceptions) and return elaborate feedback on their operation.
8
+ #
9
+ module Commands
10
+
11
+ # The Process module is a collection of methods used to manipulate processes.
12
+ # We use it to check whether we run as sudo or not by evaluating the uid of ths user (if it's 0 it's root)
13
+ include Process
14
+
15
+ # Objects of this class can be returned by Commands. Since it is an OpenStruct object,
16
+ # it can contain an arbritary number of values.
17
+ #
18
+ class CommandResult < OpenStruct
19
+
20
+ # This creates an convenient, read-only accessor for the OpenStruct object values.
21
+ # It simply maps methods that end with a <tt>?</tt> to the same method without <tt>?</tt>.
22
+ #
23
+ # ==== Examples
24
+ #
25
+ # command_result.something? # => command_result.something
26
+ #
27
+ def method_missing(meth, *args, &block)
28
+ meth.to_s.ends_with?('?') ? self.send(meth.to_s.chop.to_sym, *args, &block) : super
29
+ end
30
+
31
+ end
32
+
33
+ # Creates a directory recursively.
34
+ #
35
+ # ==== Returns
36
+ #
37
+ # This method returns a CommandResult object with the following values:
38
+ #
39
+ # [+success?+] +true+ if the directory exists after the operation, +nil+ if not.
40
+ # [+already_existed?+] +true+ if the directory existed before the operation, +nil+ if not.
41
+ # [+writable?+] +true+ if the directory is writable, +false+ if not, +nil+ if the directory doesn't exist.
42
+ #
43
+ # ==== Examples
44
+ #
45
+ # result = mkdir('foo') # => #<CommandResult...>
46
+ # result.success? # => true
47
+ # result.already_existed? # => false
48
+ #
49
+ # puts "I created a directory" if mkdir('bar').success?
50
+ #
51
+ # mkdir('i/can/create/directories/recursively')
52
+ #
53
+ def mkdir(target)
54
+ target = target.pathnamify
55
+ result = CommandResult.new
56
+ if target.directory?
57
+ # Don't say anything if the directory already exists
58
+ result.already_existed = true
59
+ else
60
+ begin
61
+ say "Creating directory: #{target}".cyan unless options.quiet
62
+ # Try to create the directory
63
+ target.mkpath unless options.dry
64
+ rescue Errno::EACCES => e
65
+ say "Cannot create directory (no permission): #{target}".red unless options.quiet
66
+ return result
67
+ end
68
+ end
69
+ result.success = (target.directory? or options.dry)
70
+ result.writable = (target.writable? or options.dry)
71
+ result
72
+ end
73
+
74
+ # Changes the current directory.
75
+ #
76
+ # ==== Returns
77
+ #
78
+ # This method returns a CommandResult object with the following values:
79
+ #
80
+ # [+success?+] +true+ if pwd is where it was requested to be after the operation, +nil+ if not.
81
+ #
82
+ def cd(target)
83
+ target = target.pathnamify
84
+ result = CommandResult.new
85
+ if target.directory? or options.dry
86
+ say "cd #{target}".yellow
87
+ Dir.chdir(target)
88
+ elsif target.exist?
89
+ say "Cannot change to directory because it exists but is not a directory: #{target}".red
90
+ end
91
+ result.success = (target.current_path? or options.dry)
92
+ result
93
+ end
94
+
95
+ # Runs a command on the system.
96
+ #
97
+ # ==== Returns
98
+ #
99
+ # The command's output as an +Array+. Note that the exit code can be accessed via the global variable <tt>$?</tt>
100
+ #
101
+ # ==== Options
102
+ #
103
+ # The following options can be passed as a hash.
104
+ #
105
+ # [+:exit_on_failure+] If the exit code of the command was not 0, exit the CSD application.
106
+ #
107
+ #
108
+ def sh(cmd, params={})
109
+ default_params = { :exit_on_failure => true }
110
+ params = default_params.merge(params)
111
+ say "Running command in #{Dir.pwd}".yellow unless options.silent
112
+ say cmd.cyan
113
+ ret = ''
114
+ unless options.dry
115
+ IO.popen(cmd) do |stdout|
116
+ stdout.each do |line|
117
+ say " #{line}" if options.verbose
118
+ ret << line
119
+ end
120
+ end
121
+ end
122
+ exit_if_last_command_had_errors if params[:exit_on_failure]
123
+ ret
124
+ end
125
+
126
+
127
+ def test_command(*args)
128
+ say "Testing command for success: #{args.join(' ')}".yellow
129
+ system(*args)
130
+ end
131
+
132
+ def run_command(cmd, params={})
133
+ default_params = { :exit_on_failure => true }
134
+ params = default_params.merge(params)
135
+ say "Running command in #{Dir.pwd}".yellow unless options.quiet
136
+ say cmd.cyan
137
+ ret = ''
138
+ unless options.dry
139
+ IO.popen(cmd) do |stdout|
140
+ stdout.each do |line|
141
+ say " #{line}"
142
+ ret << line
143
+ end
144
+ end
145
+ end
146
+ exit_if_last_command_had_errors if params[:exit_on_failure]
147
+ ret
148
+ end
149
+
150
+ def exit_if_last_command_had_errors
151
+ unless $?.try(:success?) or options.dry
152
+ say "The last command was unsuccessful.".red unless options.quiet
153
+ exit
154
+ end
155
+ end
156
+
157
+
158
+ def say(something='')
159
+ end
160
+
161
+ def log(msg="")
162
+ say msg.yellow unless options.silent
163
+ end
164
+
165
+ # Dummy to be overwritten by real options
166
+ def options
167
+ OpenStruct.new
168
+ end
169
+
170
+ end
171
+ end
@@ -6,7 +6,12 @@ require 'ostruct'
6
6
  require 'tmpdir'
7
7
  require 'active_support/core_ext'
8
8
 
9
- module CSD
9
+ # This namespace is given to the entire CSD gem.
10
+ #
11
+ module Csd
12
+ # On initialization, this class bootstraps and runs the CSD gem.
13
+ # The initialization is most likely be done by the `csd´ executable.
14
+ #
10
15
  class Init
11
16
 
12
17
  include Gem::UserInteraction
@@ -16,7 +21,7 @@ module CSD
16
21
  def initialize
17
22
  @options = Options.parse
18
23
  @path = path_struct
19
- @gem_version = File.new(File.join(path.gem_root, 'VERSION')).read
24
+ @gem_version = File.read(File.join(path.gem_root, 'VERSION'))
20
25
  validate_arguments
21
26
  @application = initialize_application
22
27
  @application.introduction
@@ -24,7 +29,7 @@ module CSD
24
29
  end
25
30
 
26
31
  def path_struct
27
- path = PathStruct.new
32
+ path = PathContainer.new
28
33
  if options.path
29
34
  if File.directory?(options.path)
30
35
  path.root = File.expand_path(options.path)
@@ -53,7 +58,7 @@ module CSD
53
58
  directory_name = ARGV.second.underscore
54
59
  begin
55
60
  require File.join(File.join(path.applications, "#{directory_name}"), 'init.rb')
56
- "CSD::Application::#{directory_name.camelize}::Init".constantize.application(:gem_version => @gem_version, :options => @options, :path => @path)
61
+ "Csd::Application::#{directory_name.camelize}::Init".constantize.application(:gem_version => @gem_version, :options => @options, :path => @path)
57
62
  rescue LoadError
58
63
  say "Unknown application: #{directory_name}"
59
64
  exit
@@ -2,7 +2,7 @@ require 'optparse'
2
2
  require 'optparse/time'
3
3
  require 'ostruct'
4
4
 
5
- module CSD
5
+ module Csd
6
6
  class Options
7
7
 
8
8
  #
@@ -10,14 +10,17 @@ module CSD
10
10
  #
11
11
  def self.parse
12
12
  # Default options
13
- options = OpenStruct.new
14
- options.temp = false
15
- options.silent = false
16
- options.dry = false
13
+ options = OpenStruct.new
14
+ options.temp = false
15
+ options.silent = false
16
+ options.dry = false
17
17
  options.bootstrap = true
18
18
  options.configure = true
19
19
  options.make = true
20
20
  options.make_install = true
21
+ options.owner = nil
22
+ options.apt_get = true
23
+ options.yes = false
21
24
 
22
25
  # Parse the command line options
23
26
  OptionParser.new do |opts|
@@ -41,28 +44,53 @@ module CSD
41
44
  options.dry = value
42
45
  end
43
46
 
44
- opts.on("-d", "--no-bootstrap","Don't run the bootstrap command") do |value|
47
+ opts.on("-y", "--yes","Answering all questions with 'yes'") do |value|
48
+ options.yes = value
49
+ end
50
+
51
+ opts.on("-na", "--no-apt-get","Don't run any apt-get commands") do |value|
52
+ options.apt_get = value
53
+ end
54
+
55
+ opts.on("-nb", "--no-bootstrap","Don't run any bootstrap commands") do |value|
45
56
  options.bootstrap = value
46
57
  end
47
58
 
48
- opts.on("-d", "--no-configure","Don't run the configure command") do |value|
59
+ opts.on("-nc", "--no-configure","Don't run any configure commands") do |value|
49
60
  options.configure = value
50
61
  end
51
62
 
52
- opts.on("-d", "--no-make","Don't run the make command") do |value|
63
+ opts.on("-nm", "--no-make","Don't run any make commands") do |value|
53
64
  options.make = value
54
65
  end
55
66
 
56
- opts.on("-d", "--no-make-install","Don't run the make install command") do |value|
67
+ opts.on("-nmi", "--no-make-install","Don't run any make install commands") do |value|
57
68
  options.make_install = value
58
69
  end
59
70
 
71
+ opts.on("--only libmcrypto,libmnetuli,etc.", Array, "Include only these libraries") do |list|
72
+ options.only = list
73
+ end
74
+
75
+ opts.on("-o", "--owner [OWNER]","Specify OWNER:GROUP for this operation") do |value|
76
+ options.owner = value
77
+ end
78
+
60
79
  opts.on("-p", "--path [PATH]",
61
80
  "Defines the working directory manually.",
62
81
  "(This will override the --temp option)") do |value|
63
82
  options.path = value
64
83
  end
65
84
 
85
+
86
+ opts.on("-d", "--debug","Show debugging information") do |value|
87
+ options.quiet = value
88
+ end
89
+
90
+ opts.on("--verbose","Show elaborate output") do |value|
91
+ options.quiet = value
92
+ end
93
+
66
94
  opts.on("-s", "--silent","Don't show any output") do |value|
67
95
  options.silent = value
68
96
  end
@@ -73,10 +101,19 @@ module CSD
73
101
  end
74
102
 
75
103
  opts.on_tail("-v", "--version", "Show version") do
76
- puts "CSD Gem Version: #{CSD::Init::GEM_VERSION}"
104
+ puts "CSD Gem Version: #{File.read(File.join(PathContainer.new.gem_root, 'VERSION'))}"
77
105
  exit
78
106
  end
79
- end.parse!
107
+ end
108
+
109
+ #.parse!
110
+
111
+ if options.owner
112
+ chmod = options.owner.split(':')
113
+ options.owner = chmod.first
114
+ options.group = chmod.last
115
+ end
116
+
80
117
  options
81
118
  end
82
119
 
@@ -1,7 +1,7 @@
1
1
  require 'ostruct'
2
2
 
3
- module CSD
4
- class PathStruct < OpenStruct
3
+ module Csd
4
+ class PathContainer < OpenStruct
5
5
 
6
6
  def gem_root
7
7
  File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
@@ -0,0 +1,13 @@
1
+ module Csd
2
+ module Extensions
3
+ module Core
4
+ module Array
5
+
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ class Array #:nodoc:
12
+ include Csd::Extensions::Core::Array
13
+ end
@@ -0,0 +1,13 @@
1
+ module Csd
2
+ module Extensions
3
+ module Core
4
+ module File
5
+
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ class File #:nodoc:
12
+ extend Csd::Extensions::Core::File
13
+ end
@@ -0,0 +1,22 @@
1
+ module Csd
2
+ module Extensions
3
+ module Core
4
+ module Object
5
+
6
+ # Creates a Pathname object from the current object. Preferrably from Strings and Hashes.
7
+ #
8
+ def pathnamify
9
+ case self
10
+ when ::Pathname then self
11
+ else ::Pathname.new(self)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Object #:nodoc:
21
+ include Csd::Extensions::Core::Object
22
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'string')
2
+
3
+ module Csd
4
+ module Extensions
5
+ module Core
6
+ module Pathname
7
+
8
+ def enquote
9
+ to_s.enquote
10
+ end
11
+
12
+ def current_path?
13
+ self.exist? and self.realpath == self.class.getwd.realpath
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ class Pathname #:nodoc:
22
+ include Csd::Extensions::Core::Pathname
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'term/ansicolor'
2
+
3
+ module Csd
4
+ module Extensions
5
+ module Core
6
+ module String
7
+
8
+ def enquote
9
+ %Q{"#{self}"}
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class String #:nodoc:
18
+ include Term::ANSIColor
19
+ include Csd::Extensions::Core::String
20
+ end
@@ -0,0 +1,20 @@
1
+ module Csd
2
+ module Extensions
3
+ module Gem
4
+ module Platform
5
+
6
+ def humanize
7
+ version_string = version ? ", version #{version}" : ''
8
+ "#{os} (CPU: #{cpu}#{version_string})"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ module Gem
17
+ class Platform #:nodoc:
18
+ include Csd::Extensions::Gem::Platform
19
+ end
20
+ end
@@ -0,0 +1,98 @@
1
+ require 'helper'
2
+ require 'ostruct'
3
+
4
+ class Cmd
5
+ include Csd::Commands
6
+ attr_accessor :options
7
+ def initialize
8
+ @options = OpenStruct.new({ :silent => true, :quiet => true, :dry => false })
9
+ end
10
+ end
11
+
12
+ class TestCommands < Test::Unit::TestCase
13
+
14
+ context "As a directory function" do
15
+
16
+ setup do
17
+ @cmd = Cmd.new
18
+ @tmp = Dir.mktmpdir
19
+ @dir = Pathname.new File.join(@tmp, 'folder')
20
+ @subdir = Pathname.new File.join(@dir, 'subfolder')
21
+ end
22
+
23
+ teardown do
24
+ FileUtils.rm_r(@tmp)
25
+ end
26
+
27
+ context "mkdir" do
28
+
29
+ should "return the proper CommandResult if the directory already existed" do
30
+ ensure_mkdir(@dir)
31
+ assert_kind_of(Cmd::CommandResult, result = @cmd.mkdir(@dir))
32
+ assert result.success?
33
+ assert result.already_existed?
34
+ assert result.writable?
35
+ end
36
+
37
+ should "return the proper CommandResult if the directory already existed in dry mode" do
38
+ @cmd.options.dry = true
39
+ ensure_mkdir(@dir)
40
+ assert_kind_of(Cmd::CommandResult, result = @cmd.mkdir(@dir))
41
+ assert result.success?
42
+ assert result.already_existed?
43
+ assert result.writable?
44
+ end
45
+
46
+ should "create the directory if it doesn't exist yet" do
47
+ assert_kind_of(Cmd::CommandResult, result = @cmd.mkdir(@dir))
48
+ assert result.success?
49
+ assert !result.already_existed?
50
+ assert result.writable?
51
+ end
52
+
53
+ should "create the directory if it doesn't exist yet in dry mode" do
54
+ @cmd.options.dry = true
55
+ assert_kind_of(Cmd::CommandResult, result = @cmd.mkdir(@dir))
56
+ assert result.success?
57
+ assert !result.already_existed?
58
+ assert result.writable?
59
+ end
60
+
61
+ should "notify if there is no permission to create the directory" do
62
+ ensure_mkdir(@dir)
63
+ @dir.chmod(0000)
64
+ assert_kind_of(Cmd::CommandResult, result = @cmd.mkdir(@dir))
65
+ assert result.success?
66
+ assert result.already_existed?
67
+ assert !result.writable?
68
+ Pathname.new(@dir).chmod(0777) # Cleanup
69
+ end
70
+
71
+ end # context "mkdir"
72
+
73
+ context "cd" do
74
+
75
+ should "return a CommanResult with success? if the directory was changed successfully" do
76
+ assert_kind_of(Cmd::CommandResult, result = @cmd.cd('/'))
77
+ assert result.success?
78
+ assert_kind_of(Cmd::CommandResult, result = @cmd.cd(@tmp))
79
+ assert result.success?
80
+ end
81
+
82
+ should "realize when the target is not a directory, but a file or something" do
83
+ testfile_path = File.join(@tmp, 'testfile')
84
+ File.new(testfile_path, 'w')
85
+ assert_kind_of(Cmd::CommandResult, result = @cmd.cd(testfile_path))
86
+ assert !result.success?
87
+ end
88
+
89
+ should "realize when the target doesn't exist" do
90
+ assert_kind_of(Cmd::CommandResult, result = @cmd.cd('/i/for/sure/dont/exist'))
91
+ assert !result.success?
92
+ end
93
+
94
+ end # context "cd"
95
+
96
+ end # context "As a directory function"
97
+
98
+ end
@@ -1,10 +1,20 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'tmpdir'
5
+ require 'redgreen'
4
6
 
5
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
9
  require 'csd'
8
10
 
9
11
  class Test::Unit::TestCase
10
- end
12
+
13
+ def ensure_mkdir(target)
14
+ target = Pathname.new(target) unless target.is_a?(Pathname)
15
+ target.mkpath
16
+ assert target.directory?
17
+ target
18
+ end
19
+
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ class TestPathname < Test::Unit::TestCase
4
+
5
+ context "A normal Pathname object" do
6
+
7
+ should "be enquotable" do
8
+ assert_equal '"/"', Pathname.new('/').enquote
9
+ end
10
+
11
+ should "know if its the current pwd or not (regardless of the requested directory actually existing)" do
12
+ Dir.chdir('/tmp')
13
+ assert Pathname.new('/tmp').current_path?
14
+ assert !Pathname.new('/i/do/not/exist').current_path?
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ class TestString < Test::Unit::TestCase
4
+
5
+ context "A normal String object" do
6
+
7
+ should "be enquotable" do
8
+ assert_equal '"wow it works"', 'wow it works'.enquote
9
+ end
10
+
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 13
10
- version: 0.0.13
9
+ - 14
10
+ version: 0.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Technology Transfer Alliance Team
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-14 00:00:00 +02:00
18
+ date: 2010-06-22 00:00:00 +02:00
19
19
  default_executable: csd
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: activesupport
36
+ name: active_support
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -80,18 +80,24 @@ files:
80
80
  - csd.gemspec
81
81
  - lib/csd.rb
82
82
  - lib/csd/applications/base.rb
83
- - lib/csd/applications/minisip/darwin/minisip_darwin.rb
83
+ - lib/csd/applications/minisip/base.rb
84
84
  - lib/csd/applications/minisip/init.rb
85
- - lib/csd/applications/minisip/linux/minisip_linux.rb
86
- - lib/csd/applications/minisip/minisip.rb
85
+ - lib/csd/applications/minisip/unix/base.rb
86
+ - lib/csd/commands.rb
87
87
  - lib/csd/init.rb
88
88
  - lib/csd/options.rb
89
- - lib/csd/path_struct.rb
90
- - lib/extensions/array.rb
91
- - lib/extensions/string.rb
89
+ - lib/csd/path_container.rb
90
+ - lib/extensions/core/array.rb
91
+ - lib/extensions/core/file.rb
92
+ - lib/extensions/core/object.rb
93
+ - lib/extensions/core/pathname.rb
94
+ - lib/extensions/core/string.rb
95
+ - lib/extensions/gem/platform.rb
92
96
  - publish
97
+ - test/functional/test_commands.rb
93
98
  - test/helper.rb
94
- - test/test_csd.rb
99
+ - test/unit/test_pathname.rb
100
+ - test/unit/test_string.rb
95
101
  has_rdoc: true
96
102
  homepage: http://github.com/csd/csd
97
103
  licenses: []
@@ -127,5 +133,7 @@ signing_key:
127
133
  specification_version: 3
128
134
  summary: Installation and compilation handler for software used in CSD projects.
129
135
  test_files:
136
+ - test/functional/test_commands.rb
130
137
  - test/helper.rb
131
- - test/test_csd.rb
138
+ - test/unit/test_pathname.rb
139
+ - test/unit/test_string.rb
@@ -1,12 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'minisip')
2
-
3
- module CSD
4
- module Application
5
- module Minisip
6
- class MinisipDarwin < Minisip
7
-
8
-
9
- end
10
- end
11
- end
12
- end
@@ -1,36 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'minisip')
2
-
3
- module CSD
4
- module Application
5
- module Minisip
6
- class MinisipLinux < Minisip
7
-
8
- def build!
9
- define_paths
10
- create_working_dir
11
- install_aptitude_dependencies
12
- checkout_repository
13
- make_libraries
14
- fix_aclocal_dirlist
15
- ldconfig_and_gtkgui
16
- end
17
-
18
- def install_aptitude_dependencies
19
- ['git-core', 'subversion', 'automake', 'libssl-dev', 'libtool', 'libglademm-2.4-dev'].each do |apt|
20
- run_command("sudo apt-get --yes install #{apt}")
21
- end
22
- end
23
-
24
- def fix_aclocal_dirlist
25
- run_command "sudo echo /usr/local/share/aclocal >> /usr/share/aclocal/dirlist"
26
- end
27
-
28
- def ldconfig_and_gtkgui
29
- run_command("ldconfig /usr/local/lib/libminisip.so.0")
30
- run_command("minisip_gtkgui")
31
- end
32
-
33
- end
34
- end
35
- end
36
- end
@@ -1,75 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'base')
2
-
3
- module CSD
4
- module Application
5
- module Minisip
6
- class Minisip < CSD::Application::Base
7
-
8
- def introduction
9
- super
10
- log
11
- log "Hello, I'm the application #{self.class.name}"
12
- exit unless ask_yes_no("Continue?", true)
13
- build!
14
- end
15
-
16
- def build!
17
- define_paths
18
- create_working_dir
19
- checkout_repository
20
- make_libraries
21
- end
22
-
23
- def define_paths
24
- path.work = File.expand_path(File.join(path.root, 'minisip_building'))
25
- path.repository = File.expand_path(File.join(path.work, 'repository'))
26
- end
27
-
28
- def create_working_dir
29
- if File.directory?(path.work)
30
- log "Working directory ´#{path.work}´ already exists."
31
- else
32
- log "Creating working directory ´#{path.work}´"
33
- Dir.mkdir(path.work)
34
- end
35
- Dir.chdir(path.work)
36
- end
37
-
38
- def checkout_repository
39
- if File.directory?(path.repository)
40
- log "The minisip repository already exists in ´#{path.repository}´"
41
- else
42
- log "Checking out minisip repository to ´#{path.repository}´"
43
- #run_command("git clone http://github.com/csd/minisip.git repository")
44
- if test_command('svn', 'info', 'svn://minisip.org/minisip/trunk')
45
- run_command("svn co svn://minisip.org/minisip/trunk #{path.repository}")
46
- else
47
- log "Sorry, something is wrong with subversion.".red.bold
48
- exit
49
- end
50
- end
51
- end
52
-
53
- def make_libraries
54
- ['libmutil', 'libmnetutil', 'libmcrypto', 'libmikey', 'libmsip', 'libmstun', 'libminisip'].each do |lib|
55
- lib_dir = File.join(path.repository, lib)
56
- if File.directory?(lib_dir)
57
- Dir.chdir(lib_dir)
58
- log "Bootstrapping #{lib}".green.bold
59
- run_command("./bootstrap")
60
- log "Configuring #{lib}".green.bold
61
- run_command("./configure")
62
- log "Make #{lib}".green.bold
63
- run_command("make")
64
- log "Make install #{lib}".green.bold
65
- run_command("make install")
66
- else
67
- log "Skipping ´#{lib}´ because ´#{lib_dir}´ could not be found".red.bold
68
- end
69
- end
70
- end
71
-
72
- end
73
- end
74
- end
75
- end
@@ -1,7 +0,0 @@
1
- module ArrayExtensions
2
-
3
- end
4
-
5
- class Array #:nodoc:
6
- include ArrayExtensions
7
- end
@@ -1,15 +0,0 @@
1
- require 'term/ansicolor'
2
- #require 'active_support'
3
-
4
- module StringExtensions
5
-
6
- #def constantize
7
- # ActiveSupport::Inflector.constantize(self)
8
- #end
9
-
10
- end
11
-
12
- class String #:nodoc:
13
- include Term::ANSIColor
14
- include StringExtensions
15
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestCsd < Test::Unit::TestCase
4
- should "something important" do
5
- assert true
6
- end
7
- end