csd 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,9 @@
1
1
  # -*- encoding: UTF-8 -*-
2
- # This file gets eval'ed by the global options parser in lib/csd/rb
3
- # TODO: There must be a nicer solution for this.
2
+ # This file gets eval'ed by the global options parser in lib/csd/options_parser
4
3
 
5
- self.temp = false
6
- opts.on("-t", "--temp",
7
- "Use a subdirectory in the system's temporary directory",
8
- "to download files and not the current directory") do |value|
9
- self.temp = value
10
- end
11
-
12
- self.path = nil
13
- opts.on("--path [PATH]",
14
- "Defines the working directory manually.",
15
- "(This will override the --temp option)") do |value|
16
- self.path = value
4
+ self.apt_get = true
5
+ opts.on("--no-apt-get","Don't run any apt-get commands") do |value|
6
+ self.apt_get = value
17
7
  end
18
8
 
19
9
  #self.owner = nil
@@ -25,11 +15,6 @@ end
25
15
  # end
26
16
  #end
27
17
 
28
- #self.debug_minisip = false
29
- #opts.on("--debug-minisip","Compile MiniSIP using the --enable-debug flag.") do |value|
30
- # self.debug_minisip = value
31
- #end
32
-
33
18
  self.only_fix_giomm = false
34
19
  opts.on("--only-fix-giomm","Forces the AI to do nothing except trying to bugfix the Ubuntu 10.04 giomm") do |value|
35
20
  self.only_fix_giomm = value
@@ -40,36 +25,30 @@ opts.on("--ffmpeg-first","Compile FFmpeg before compiling MiniSIP. Default is fi
40
25
  self.ffmpeg_first = value
41
26
  end
42
27
 
43
- self.apt_get = true
44
- opts.on("--no-apt-get","Don't run any apt-get commands") do |value|
45
- self.apt_get = value
46
- end
28
+
29
+
30
+ opts.headline 'MINISIP LIBRARY OPTIONS'.green.bold
47
31
 
48
32
  self.bootstrap = true
49
- opts.on("--no-bootstrap","Don't run any bootstrap commands") do |value|
33
+ opts.on("--no-bootstrap","Don't run the bootstrap command on any MiniSIP library") do |value|
50
34
  self.bootstrap = value
51
35
  end
52
36
 
53
37
  self.configure = true
54
- opts.on("--no-configure","Don't run any configure commands") do |value|
38
+ opts.on("--no-configure","Don't run the configure command on any MiniSIP library") do |value|
55
39
  self.configure = value
56
40
  end
57
41
 
58
42
  self.make = true
59
- opts.on("--no-make","Don't run any make commands") do |value|
43
+ opts.on("--no-make","Don't run the make command on any MiniSIP library") do |value|
60
44
  self.make = value
61
45
  end
62
46
 
63
47
  self.make_install = true
64
- opts.on("--no-make-install","Don't run any make install commands") do |value|
48
+ opts.on("--no-make-install","Don't run the make install command on any MiniSIP library") do |value|
65
49
  self.make_install = value
66
50
  end
67
51
 
68
- self.make_dist = false
69
- opts.on("--make-dist","Use `make dist´ instead of `make install´") do |value|
70
- self.make_dist = value
71
- end
72
-
73
- opts.on("--only libmcrypto,libmnetuli,etc.", Array, "Process only these libraries") do |list|
52
+ opts.on("--only libmutil,libmsip,etc.", Array, "Process only these libraries") do |list|
74
53
  self.only = list
75
54
  end
@@ -100,7 +100,7 @@ module CSD
100
100
  UI.info "Creating plugin target directory".green.bold
101
101
  # result = Path.plugins_destination.parent.directory? ? Cmd.run("sudo mkdir #{Path.plugins_destination}") : CommandResult.new
102
102
  # TODO: This will maybe need sudo rights in the future
103
- Cmd.copy(Dir[File.join('Path.plugins', '*.{l,la,so}')], Path.plugins_destination) if Path.plugins_destination.directory?
103
+ Cmd.copy(Dir[File.join(Path.plugins, '*.{l,la,so}')], Path.plugins_destination) if Path.plugins_destination.directory?
104
104
  end
105
105
 
106
106
  # Iteratively configures and compiles the internal MiniSIP libraries.
@@ -132,9 +132,8 @@ module CSD
132
132
  Cmd.run("make")
133
133
  end
134
134
  if Options.make_install
135
- maker_command = Options.make_dist ? 'dist' : 'install'
136
- UI.info "Make #{maker_command} #{library}".green.bold
137
- Cmd.run("make #{maker_command}")
135
+ UI.info "Make install #{library}".green.bold
136
+ Cmd.run("make install")
138
137
  end
139
138
  else
140
139
  UI.warn "Skipping minisip library #{library} because it not be found: #{directory}".green.bold
@@ -186,7 +185,7 @@ module CSD
186
185
  UI.error "Could not enter #{directory}."
187
186
  end
188
187
  end
189
- Cmd.cd Path.root
188
+ Cmd.cd '/'
190
189
  Cmd.run('minisip_gtk_gui')
191
190
  end
192
191
 
data/lib/csd/commands.rb CHANGED
@@ -49,7 +49,7 @@ module CSD
49
49
  target.mkpath unless Options.reveal
50
50
  rescue Errno::EACCES => e
51
51
  result.reason = "Cannot create directory (no permission): #{target}"
52
- params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
52
+ params[:die_on_failure] ? raise(CSD::Error::Command::MkdirFailed, result.reason) : UI.error(result.reason)
53
53
  end
54
54
  end
55
55
  result.success = (target.directory? or Options.reveal)
@@ -81,7 +81,7 @@ module CSD
81
81
  result.success = target.current_path?
82
82
  rescue Exception => e
83
83
  result.reason = "Cannot change to directory `#{target}´. Reason: #{e.message}"
84
- params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
84
+ params[:die_on_failure] ? raise(CSD::Error::Command::CdFailed, result.reason) : UI.error(result.reason)
85
85
  end
86
86
  end
87
87
  result
@@ -165,7 +165,7 @@ module CSD
165
165
  end
166
166
  result.success = false
167
167
  result.reason = "Could not perform replace operation! #{e.message}"
168
- params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
168
+ params[:die_on_failure] ? raise(CSD::Error::Command::ReplaceFailed, result.reason) : UI.error(result.reason)
169
169
  end
170
170
  result
171
171
  end
@@ -190,7 +190,7 @@ module CSD
190
190
  # [+output?+] The command's output as a +String+ (with newline delimiters). Note that the exit code can be accessed via the global variable <tt>$?</tt>
191
191
  #
192
192
  def run(cmd, params={})
193
- default_params = { :die_on_failure => true, :announce_pwd => true, :verbose => Options.verbose, :internal => Options.testmode }
193
+ default_params = { :die_on_failure => true, :announce_pwd => true, :verbose => Options.verbose, :internal => false }
194
194
  params = default_params.merge(params)
195
195
  result = CommandResult.new
196
196
  cmd = cmd.to_s
@@ -211,12 +211,12 @@ module CSD
211
211
  result.output << line
212
212
  end
213
213
  end
214
- UI.separator unless params[:verbose] or params[:internal] or Options.testmode # i.e. if dots are concatenated in the same line, we should create a new line after them
214
+ UI.separator unless params[:verbose] or params[:internal] # i.e. if dots are concatenated in the same line, we should create a new line after them
215
215
  result.status = $?
216
216
  result.success = $?.success?
217
217
  if params[:die_on_failure] and !result.success
218
218
  UI.info result.output unless params[:verbose] # In verbose mode, we don't need to repeat the unsuccessful command's output
219
- UI.die "The last command was unsuccessful."
219
+ raise CSD::Error::Command::RunFailed, "The last command was unsuccessful."
220
220
  end
221
221
  result
222
222
  end
@@ -236,7 +236,14 @@ module CSD
236
236
  rescue Exception => e
237
237
  result.success = false
238
238
  result.reason = "Could not perform #{action} operation! #{e.message}"
239
- params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
239
+ if params[:die_on_failure]
240
+ case action
241
+ when :copy then raise CSD::Error::Command::CopyFailed, result.reason
242
+ when :move then raise CSD::Error::Command::MoveFailed, result.reason
243
+ end
244
+ else
245
+ UI.error result.reason
246
+ end
240
247
  end
241
248
  result
242
249
  end
@@ -262,7 +269,7 @@ module CSD
262
269
  end
263
270
  UI.info "Downloading #{name} to #{destination.enquote}".green.bold
264
271
  # We will simply return the CommandResult of the run-method.
265
- Cmd.run("git clone #{repository} #{destination}", :announce_pwd => false, :verbose => true)
272
+ Cmd.run("git clone #{repository} #{destination}", :announce_pwd => false)
266
273
  end
267
274
 
268
275
  end
data/lib/csd/container.rb CHANGED
@@ -2,10 +2,24 @@
2
2
 
3
3
  module CSD
4
4
  class << self
5
- # This method chooses and holds the user interface instance.
5
+
6
+ # This method holds the user interface instance.
6
7
  #
7
8
  def ui
8
- @@ui ||= UserInterface::CLI.new
9
+ # In testmode we don't want to perform caching
10
+ return choose_ui if Options.testmode
11
+ # Otherwise we choose and cache the UI here
12
+ @@ui ||= choose_ui
13
+ end
14
+
15
+ # This method chooses an user interface instance according to the Options and returns a new instance of it.
16
+ #
17
+ def choose_ui
18
+ if Options.silent
19
+ UserInterface::Silent.new
20
+ else
21
+ UserInterface::CLI.new
22
+ end
9
23
  end
10
24
 
11
25
  # This method chooses and holds the command execution instance.
@@ -54,6 +68,11 @@ module CSD
54
68
  # A wrapper for the Options class to be able to run all methods as class methods.
55
69
  #
56
70
  class Options
71
+ # Because the Options class will respond to clear, we must pass it on explicitly to the OptionsParser instance residing in CSD.options
72
+ #
73
+ def self.clear
74
+ ::CSD.options.clear
75
+ end
57
76
  def self.method_missing(meth, *args, &block)
58
77
  ::CSD.options.send(meth, *args, &block)
59
78
  end
data/lib/csd/error.rb CHANGED
@@ -23,18 +23,25 @@ module CSD
23
23
  module Argument
24
24
  class NoApplication < CSDError; status_code(11); end
25
25
  class NoAction < CSDError; status_code(12); end
26
+ class InvalidOption < CSDError; status_code(50); end
26
27
  end
27
28
 
28
- # Errors in this module are related to the Application Module Framework
29
+ # Errors in this module are raised by the Command module
29
30
  #
30
- module Application
31
- class OptionsSyntax < CSDError; status_code(200); end
31
+ module Command
32
+ class RunFailed < CSDError; status_code(60); end
33
+ class CdFailed < CSDError; status_code(61); end
34
+ class CopyFailed < CSDError; status_code(62); end
35
+ class MoveFailed < CSDError; status_code(63); end
36
+ class ReplaceFailed < CSDError; status_code(64); end
37
+ class MkdirFailed < CSDError; status_code(65); end
32
38
  end
33
39
 
34
- # Errors in this module are raised by the User Interface
35
- # TODO: This has to go :)
36
- module UI
37
- class Die < CSDError; status_code(1000); end
40
+ # Errors in this module are related to the Application Module Framework
41
+ #
42
+ module Application
43
+ class OptionsSyntax < CSDError; status_code(100); end
44
+ class NoInstanceMethod < CSDError; status_code(101); end
38
45
  end
39
46
 
40
47
  end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ module CSD
4
+ module Extensions
5
+ module Core
6
+ # This module comprises extensions to the Kernel module
7
+ #
8
+ module Kernel
9
+
10
+ # Checks whether the AI was executed with superuser rights (a.k.a. +sudo+). Returns +true+ or +false+.
11
+ #
12
+ def superuser?
13
+ Process.uid == 0
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module Kernel #:nodoc:
22
+ include CSD::Extensions::Core::Kernel
23
+ end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: UTF-8 -*-
2
+ require 'csd/vendor/active_support/object_extensions'
2
3
 
3
4
  module CSD
4
5
  module Extensions
@@ -0,0 +1,26 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'ostruct'
3
+
4
+ module CSD
5
+ module Extensions
6
+ module Core
7
+ # This module comprises extensions to OpenStruct.
8
+ #
9
+ module OpenStruct
10
+
11
+ # Deletes all attributes of this OpenStruct instance.
12
+ #
13
+ def clear
14
+ testmode = self.testmode # This is the only thing we would not like to overwrite. It indicates whether we are running our Test Suite or not.
15
+ @table = {}
16
+ self.testmode = testmode
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ class Object #:nodoc:
25
+ include CSD::Extensions::Core::OpenStruct
26
+ end
@@ -35,6 +35,8 @@ module CSD
35
35
  end
36
36
 
37
37
  def clear
38
+ # Resetting all attributes to nil (because e.g. an application instance might have modified or added some).
39
+ super
38
40
  # First we define all valid actions and scopes
39
41
  self.actions = []
40
42
  self.scopes = []
@@ -83,18 +85,9 @@ module CSD
83
85
  #
84
86
  def parse_options
85
87
  OptionParser.new do |opts|
86
- self.banner = Applications.current ? "ADVANCED HELP FOR #{Applications.current.name}" : "Usage: ".bold + "ai [help] [TASK] APPLICATION [OPTIONS]"
88
+ self.banner = Applications.current ? 'OPTIONS' : "Usage: ".bold + "#{CSD.executable} [help] [TASK] APPLICATION [OPTIONS]"
87
89
  opts.banner = self.banner.magenta.bold
88
90
 
89
- unless Applications.current
90
- opts.headline "EXAMPLE COMMANDS".green.bold
91
- opts.list_item 'ai', 'Lists all available applications'
92
- opts.list_item 'ai minisip', 'Lists available tasks for the application MiniSIP'
93
- opts.list_item 'ai minisip --developer', 'Lists advanced AI tasks for the application MiniSIP'
94
- opts.list_item 'ai compile minisip', 'Downloads MiniSIP and compiles it'
95
- opts.list_item 'ai help compile minisip', 'Shows more details about the different compiling options'
96
- end
97
-
98
91
  # Here we load application-specific options file.
99
92
  # TODO: There must be a better way for this in general than to eval the raw ruby code
100
93
  begin
@@ -117,30 +110,32 @@ module CSD
117
110
  #opts.on("-l", "--local","Assume that there is no uplink to the Internet") do |value|
118
111
  # self.online = !value
119
112
  #end
120
- opts.on("-r", "--reveal","List all commands that normally would be executed in this operation") do |value|
113
+ opts.on("-r", "--reveal","List all commands that normally would be executed in this operation (preview-mode)") do |value|
121
114
  self.reveal = value
122
115
  end
123
116
  opts.on("-e", "--verbose","Show more elaborate output") do |value|
124
117
  self.verbose = value
125
118
  end
126
- opts.on("-d", "--debug","Show more elaborate output and debugging information") do |value|
119
+ opts.on("-d", "--debug","Show more elaborate output and debugging information about the AI") do |value|
127
120
  self.debug = value
128
121
  end
129
122
  opts.on("-s", "--silent","Don't show any output") do |value|
130
123
  self.silent = value
131
124
  end
132
- opts.on_tail("-a", "--developer", "Activating advanced AI functionality (developers only)") do |value|
133
- self.developer = value
134
- end
125
+ #opts.on_tail("-a", "--developer", "Activating advanced AI functionality (developers only)") do |value|
126
+ # self.developer = value
127
+ #end
135
128
  opts.on_tail("-h", "--help", "Show detailed help (regarding the given ACTION and APPLICATION)") do |value|
136
129
  self.help = value
137
130
  end
138
- opts.on_tail("-v", "--version", "Show version") do
131
+ opts.on_tail("-v", "--version", "Show the version of this AI") do
139
132
  puts "CSD Gem Version: #{CSD::Version}".blue
140
133
  exit
141
134
  end
142
135
  self.helptext = opts.help
143
136
  end.parse!
137
+ rescue OptionParser::InvalidOption => e
138
+ raise Error::Argument::InvalidOption, e.message.gsub('invalid option: ', 'This option argument seems to be incorrect: ')
144
139
  end
145
140
 
146
141
  end
@@ -1,10 +1,18 @@
1
1
  # -*- encoding: UTF-8 -*-
2
+
2
3
  module CSD
4
+ # User Interaction is performed within this namespace.
5
+ #
3
6
  module UserInterface
7
+ # This is the parent class of all user interfaces.
8
+ #
4
9
  class Base
5
-
10
+
6
11
  def separator
7
12
  end
13
+
14
+ def indicate_activity
15
+ end
8
16
 
9
17
  def debug(message)
10
18
  end
@@ -17,9 +25,6 @@ module CSD
17
25
 
18
26
  def error(message)
19
27
  end
20
-
21
- def die(message)
22
- end
23
28
 
24
29
  end
25
30
  end
@@ -6,35 +6,30 @@ module CSD
6
6
  class CLI < Base
7
7
 
8
8
  include Gem::UserInteraction
9
-
9
+
10
10
  def separator
11
- say
11
+ $stdout.puts
12
12
  end
13
13
 
14
14
  def indicate_activity
15
15
  $stdout.putc '.'
16
16
  $stdout.flush
17
17
  end
18
-
18
+
19
19
  def debug(message)
20
- say "DEBUG: #{message}".magenta if Options.debug and !Options.silent
20
+ $stdout.puts "DEBUG: #{message}".magenta if Options.debug
21
21
  end
22
-
22
+
23
23
  def info(message)
24
- say message if !Options.silent
24
+ $stdout.puts message
25
25
  end
26
-
26
+
27
27
  def warn(message)
28
- say 'NOTE: '.red + message.red if !Options.silent
28
+ $stdout.puts 'NOTE: '.red + message.red
29
29
  end
30
-
30
+
31
31
  def error(message)
32
- say('ERROR: '.red.blink + message.red) if !Options.silent
33
- end
34
-
35
- def die(message)
36
- say('ERROR: '.red.blink + message.red) if !Options.silent
37
- raise Error::UI::Die
32
+ $stderr.puts('ERROR: '.red.blink + message.red)
38
33
  end
39
34
 
40
35
  end