csd 0.1.5 → 0.1.6

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.
Files changed (258) hide show
  1. data/COPYING +1 -2
  2. data/README.rdoc +7 -1
  3. data/Rakefile +7 -2
  4. data/VERSION +1 -1
  5. data/csd.gemspec +18 -216
  6. data/lib/csd.rb +6 -16
  7. data/lib/csd/application.rb +2 -2
  8. data/lib/csd/application/default.rb +15 -14
  9. data/lib/csd/application/default/base.rb +1 -1
  10. data/lib/csd/application/minisip.rb +43 -11
  11. data/lib/csd/application/minisip/about.yml +5 -5
  12. data/lib/csd/application/minisip/base.rb +82 -70
  13. data/lib/csd/application/minisip/error.rb +1 -1
  14. data/lib/csd/application/minisip/options/common.rb +1 -1
  15. data/lib/csd/application/minisip/options/compile.rb +1 -1
  16. data/lib/csd/application/minisip/options/package.rb +1 -1
  17. data/lib/csd/application/minisip/unix.rb +40 -27
  18. data/lib/csd/application/minisip/unix/darwin.rb +12 -0
  19. data/lib/csd/application/minisip/unix/linux.rb +1 -11
  20. data/lib/csd/application/minisip/unix/linux/debian.rb +14 -25
  21. data/lib/csd/application/minisip/unix/linux/debian/ubuntu10.rb +12 -13
  22. data/lib/csd/applications.rb +5 -5
  23. data/lib/csd/commands.rb +164 -89
  24. data/lib/csd/container.rb +61 -0
  25. data/lib/csd/error.rb +10 -1
  26. data/lib/csd/extensions.rb +3 -2
  27. data/lib/csd/extensions/core/array.rb +29 -1
  28. data/lib/csd/extensions/core/dir.rb +15 -24
  29. data/lib/csd/extensions/core/object.rb +10 -2
  30. data/lib/csd/extensions/core/option_parser.rb +22 -3
  31. data/lib/csd/extensions/core/pathname.rb +30 -2
  32. data/lib/csd/extensions/core/string.rb +51 -4
  33. data/lib/csd/extensions/gem/platform.rb +18 -3
  34. data/lib/csd/{options.rb → options_parser.rb} +16 -20
  35. data/lib/csd/path_container.rb +24 -0
  36. data/lib/csd/user_interface.rb +2 -0
  37. data/lib/csd/user_interface/base.rb +26 -0
  38. data/lib/csd/user_interface/cli.rb +37 -0
  39. data/lib/csd/vendor/active_support/MIT-LICENSE +20 -0
  40. data/lib/csd/vendor/active_support/inflector.rb +155 -0
  41. data/lib/csd/vendor/term/GPL2-LICENSE +339 -0
  42. data/lib/csd/vendor/term/ansicolor.rb +113 -0
  43. data/lib/csd/version.rb +13 -4
  44. data/test/application/test_minisip.rb +45 -0
  45. data/test/functional/test_applications.rb +10 -16
  46. data/test/functional/test_commands.rb +260 -23
  47. data/test/unit/test_string.rb +1 -1
  48. metadata +18 -216
  49. data/lib/active_support.rb +0 -75
  50. data/lib/active_support/all.rb +0 -3
  51. data/lib/active_support/backtrace_cleaner.rb +0 -94
  52. data/lib/active_support/base64.rb +0 -42
  53. data/lib/active_support/basic_object.rb +0 -21
  54. data/lib/active_support/benchmarkable.rb +0 -60
  55. data/lib/active_support/buffered_logger.rb +0 -132
  56. data/lib/active_support/builder.rb +0 -6
  57. data/lib/active_support/cache.rb +0 -626
  58. data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
  59. data/lib/active_support/cache/file_store.rb +0 -188
  60. data/lib/active_support/cache/mem_cache_store.rb +0 -191
  61. data/lib/active_support/cache/memory_store.rb +0 -159
  62. data/lib/active_support/cache/strategy/local_cache.rb +0 -164
  63. data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
  64. data/lib/active_support/callbacks.rb +0 -600
  65. data/lib/active_support/concern.rb +0 -29
  66. data/lib/active_support/configurable.rb +0 -36
  67. data/lib/active_support/core_ext.rb +0 -3
  68. data/lib/active_support/core_ext/array.rb +0 -7
  69. data/lib/active_support/core_ext/array/access.rb +0 -46
  70. data/lib/active_support/core_ext/array/conversions.rb +0 -164
  71. data/lib/active_support/core_ext/array/extract_options.rb +0 -29
  72. data/lib/active_support/core_ext/array/grouping.rb +0 -100
  73. data/lib/active_support/core_ext/array/random_access.rb +0 -20
  74. data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
  75. data/lib/active_support/core_ext/array/wrap.rb +0 -22
  76. data/lib/active_support/core_ext/benchmark.rb +0 -7
  77. data/lib/active_support/core_ext/big_decimal.rb +0 -1
  78. data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -27
  79. data/lib/active_support/core_ext/cgi.rb +0 -1
  80. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
  81. data/lib/active_support/core_ext/class.rb +0 -4
  82. data/lib/active_support/core_ext/class/attribute.rb +0 -67
  83. data/lib/active_support/core_ext/class/attribute_accessors.rb +0 -63
  84. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
  85. data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -232
  86. data/lib/active_support/core_ext/class/subclasses.rb +0 -55
  87. data/lib/active_support/core_ext/date/acts_like.rb +0 -8
  88. data/lib/active_support/core_ext/date/calculations.rb +0 -240
  89. data/lib/active_support/core_ext/date/conversions.rb +0 -99
  90. data/lib/active_support/core_ext/date/freeze.rb +0 -31
  91. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -13
  92. data/lib/active_support/core_ext/date_time/calculations.rb +0 -113
  93. data/lib/active_support/core_ext/date_time/conversions.rb +0 -102
  94. data/lib/active_support/core_ext/date_time/zones.rb +0 -17
  95. data/lib/active_support/core_ext/enumerable.rb +0 -119
  96. data/lib/active_support/core_ext/exception.rb +0 -3
  97. data/lib/active_support/core_ext/file.rb +0 -2
  98. data/lib/active_support/core_ext/file/atomic.rb +0 -41
  99. data/lib/active_support/core_ext/file/path.rb +0 -5
  100. data/lib/active_support/core_ext/float.rb +0 -1
  101. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  102. data/lib/active_support/core_ext/hash.rb +0 -8
  103. data/lib/active_support/core_ext/hash/conversions.rb +0 -150
  104. data/lib/active_support/core_ext/hash/deep_merge.rb +0 -16
  105. data/lib/active_support/core_ext/hash/diff.rb +0 -13
  106. data/lib/active_support/core_ext/hash/except.rb +0 -24
  107. data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -14
  108. data/lib/active_support/core_ext/hash/keys.rb +0 -45
  109. data/lib/active_support/core_ext/hash/reverse_merge.rb +0 -28
  110. data/lib/active_support/core_ext/hash/slice.rb +0 -38
  111. data/lib/active_support/core_ext/integer.rb +0 -3
  112. data/lib/active_support/core_ext/integer/inflections.rb +0 -14
  113. data/lib/active_support/core_ext/integer/multiple.rb +0 -6
  114. data/lib/active_support/core_ext/integer/time.rb +0 -39
  115. data/lib/active_support/core_ext/kernel.rb +0 -5
  116. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  117. data/lib/active_support/core_ext/kernel/debugger.rb +0 -16
  118. data/lib/active_support/core_ext/kernel/reporting.rb +0 -62
  119. data/lib/active_support/core_ext/kernel/requires.rb +0 -26
  120. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
  121. data/lib/active_support/core_ext/load_error.rb +0 -23
  122. data/lib/active_support/core_ext/logger.rb +0 -146
  123. data/lib/active_support/core_ext/module.rb +0 -12
  124. data/lib/active_support/core_ext/module/aliasing.rb +0 -70
  125. data/lib/active_support/core_ext/module/anonymous.rb +0 -24
  126. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
  127. data/lib/active_support/core_ext/module/attr_internal.rb +0 -32
  128. data/lib/active_support/core_ext/module/attribute_accessors.rb +0 -66
  129. data/lib/active_support/core_ext/module/delegation.rb +0 -146
  130. data/lib/active_support/core_ext/module/deprecation.rb +0 -9
  131. data/lib/active_support/core_ext/module/introspection.rb +0 -88
  132. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  133. data/lib/active_support/core_ext/module/reachable.rb +0 -10
  134. data/lib/active_support/core_ext/module/remove_method.rb +0 -6
  135. data/lib/active_support/core_ext/module/synchronization.rb +0 -42
  136. data/lib/active_support/core_ext/name_error.rb +0 -18
  137. data/lib/active_support/core_ext/numeric.rb +0 -2
  138. data/lib/active_support/core_ext/numeric/bytes.rb +0 -44
  139. data/lib/active_support/core_ext/numeric/time.rb +0 -77
  140. data/lib/active_support/core_ext/object.rb +0 -14
  141. data/lib/active_support/core_ext/object/acts_like.rb +0 -10
  142. data/lib/active_support/core_ext/object/blank.rb +0 -76
  143. data/lib/active_support/core_ext/object/conversions.rb +0 -4
  144. data/lib/active_support/core_ext/object/duplicable.rb +0 -65
  145. data/lib/active_support/core_ext/object/extending.rb +0 -11
  146. data/lib/active_support/core_ext/object/instance_variables.rb +0 -67
  147. data/lib/active_support/core_ext/object/misc.rb +0 -2
  148. data/lib/active_support/core_ext/object/returning.rb +0 -42
  149. data/lib/active_support/core_ext/object/to_param.rb +0 -49
  150. data/lib/active_support/core_ext/object/to_query.rb +0 -27
  151. data/lib/active_support/core_ext/object/try.rb +0 -36
  152. data/lib/active_support/core_ext/object/with_options.rb +0 -26
  153. data/lib/active_support/core_ext/proc.rb +0 -14
  154. data/lib/active_support/core_ext/process.rb +0 -1
  155. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  156. data/lib/active_support/core_ext/range.rb +0 -4
  157. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  158. data/lib/active_support/core_ext/range/conversions.rb +0 -21
  159. data/lib/active_support/core_ext/range/include_range.rb +0 -21
  160. data/lib/active_support/core_ext/range/overlaps.rb +0 -8
  161. data/lib/active_support/core_ext/regexp.rb +0 -5
  162. data/lib/active_support/core_ext/rexml.rb +0 -46
  163. data/lib/active_support/core_ext/string.rb +0 -12
  164. data/lib/active_support/core_ext/string/access.rb +0 -99
  165. data/lib/active_support/core_ext/string/behavior.rb +0 -7
  166. data/lib/active_support/core_ext/string/conversions.rb +0 -61
  167. data/lib/active_support/core_ext/string/encoding.rb +0 -11
  168. data/lib/active_support/core_ext/string/exclude.rb +0 -6
  169. data/lib/active_support/core_ext/string/filters.rb +0 -49
  170. data/lib/active_support/core_ext/string/inflections.rb +0 -149
  171. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  172. data/lib/active_support/core_ext/string/multibyte.rb +0 -72
  173. data/lib/active_support/core_ext/string/output_safety.rb +0 -109
  174. data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -4
  175. data/lib/active_support/core_ext/string/xchar.rb +0 -18
  176. data/lib/active_support/core_ext/time/acts_like.rb +0 -8
  177. data/lib/active_support/core_ext/time/calculations.rb +0 -282
  178. data/lib/active_support/core_ext/time/conversions.rb +0 -85
  179. data/lib/active_support/core_ext/time/marshal.rb +0 -56
  180. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  181. data/lib/active_support/core_ext/time/zones.rb +0 -78
  182. data/lib/active_support/core_ext/uri.rb +0 -22
  183. data/lib/active_support/dependencies.rb +0 -628
  184. data/lib/active_support/dependencies/autoload.rb +0 -50
  185. data/lib/active_support/deprecation.rb +0 -18
  186. data/lib/active_support/deprecation/behaviors.rb +0 -38
  187. data/lib/active_support/deprecation/method_wrappers.rb +0 -29
  188. data/lib/active_support/deprecation/proxy_wrappers.rb +0 -74
  189. data/lib/active_support/deprecation/reporting.rb +0 -56
  190. data/lib/active_support/duration.rb +0 -105
  191. data/lib/active_support/gzip.rb +0 -25
  192. data/lib/active_support/hash_with_indifferent_access.rb +0 -145
  193. data/lib/active_support/i18n.rb +0 -8
  194. data/lib/active_support/inflections.rb +0 -56
  195. data/lib/active_support/inflector.rb +0 -7
  196. data/lib/active_support/inflector/inflections.rb +0 -211
  197. data/lib/active_support/inflector/methods.rb +0 -141
  198. data/lib/active_support/inflector/transliterate.rb +0 -97
  199. data/lib/active_support/json.rb +0 -2
  200. data/lib/active_support/json/backends/jsongem.rb +0 -43
  201. data/lib/active_support/json/backends/yajl.rb +0 -40
  202. data/lib/active_support/json/backends/yaml.rb +0 -90
  203. data/lib/active_support/json/decoding.rb +0 -51
  204. data/lib/active_support/json/encoding.rb +0 -254
  205. data/lib/active_support/json/variable.rb +0 -11
  206. data/lib/active_support/lazy_load_hooks.rb +0 -27
  207. data/lib/active_support/locale/en.yml +0 -36
  208. data/lib/active_support/memoizable.rb +0 -103
  209. data/lib/active_support/message_encryptor.rb +0 -71
  210. data/lib/active_support/message_verifier.rb +0 -62
  211. data/lib/active_support/multibyte.rb +0 -44
  212. data/lib/active_support/multibyte/chars.rb +0 -480
  213. data/lib/active_support/multibyte/exceptions.rb +0 -8
  214. data/lib/active_support/multibyte/unicode.rb +0 -393
  215. data/lib/active_support/multibyte/utils.rb +0 -60
  216. data/lib/active_support/notifications.rb +0 -81
  217. data/lib/active_support/notifications/fanout.rb +0 -93
  218. data/lib/active_support/notifications/instrumenter.rb +0 -56
  219. data/lib/active_support/option_merger.rb +0 -25
  220. data/lib/active_support/ordered_hash.rb +0 -158
  221. data/lib/active_support/ordered_options.rb +0 -27
  222. data/lib/active_support/railtie.rb +0 -100
  223. data/lib/active_support/rescuable.rb +0 -114
  224. data/lib/active_support/ruby/shim.rb +0 -22
  225. data/lib/active_support/secure_random.rb +0 -199
  226. data/lib/active_support/string_inquirer.rb +0 -21
  227. data/lib/active_support/test_case.rb +0 -42
  228. data/lib/active_support/testing/assertions.rb +0 -82
  229. data/lib/active_support/testing/declarative.rb +0 -40
  230. data/lib/active_support/testing/default.rb +0 -9
  231. data/lib/active_support/testing/deprecation.rb +0 -55
  232. data/lib/active_support/testing/isolation.rb +0 -154
  233. data/lib/active_support/testing/pending.rb +0 -48
  234. data/lib/active_support/testing/performance.rb +0 -455
  235. data/lib/active_support/testing/setup_and_teardown.rb +0 -111
  236. data/lib/active_support/time.rb +0 -34
  237. data/lib/active_support/time/autoload.rb +0 -5
  238. data/lib/active_support/time_with_zone.rb +0 -341
  239. data/lib/active_support/values/time_zone.rb +0 -377
  240. data/lib/active_support/values/unicode_tables.dat +0 -0
  241. data/lib/active_support/version.rb +0 -10
  242. data/lib/active_support/whiny_nil.rb +0 -60
  243. data/lib/active_support/xml_mini.rb +0 -158
  244. data/lib/active_support/xml_mini/jdom.rb +0 -168
  245. data/lib/active_support/xml_mini/libxml.rb +0 -80
  246. data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
  247. data/lib/active_support/xml_mini/nokogiri.rb +0 -78
  248. data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
  249. data/lib/active_support/xml_mini/rexml.rb +0 -129
  250. data/lib/csd/extensions/core/file.rb +0 -14
  251. data/lib/csd/global_open_struct.rb +0 -19
  252. data/lib/csd/path.rb +0 -32
  253. data/lib/csd/ui.rb +0 -2
  254. data/lib/csd/ui/cli.rb +0 -8
  255. data/lib/csd/ui/ui.rb +0 -45
  256. data/lib/term/ansicolor.rb +0 -102
  257. data/lib/term/ansicolor/.keep +0 -0
  258. data/lib/term/ansicolor/version.rb +0 -10
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
2
  require File.join(File.dirname(__FILE__), '..', 'unix')
3
3
 
4
4
  module CSD
@@ -6,16 +6,6 @@ module CSD
6
6
  module Minisip
7
7
  class Linux < Unix
8
8
 
9
- def compile!
10
- before_compile
11
- Cmd.mkdir Path.work
12
- make_hdviper if checkout_hdviper or Options.dry
13
- checkout_minisip
14
- checkout_plugins
15
- make_minisip
16
- after_compile
17
- end
18
-
19
9
  end
20
10
  end
21
11
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', 'linux')
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'csd/application/minisip/unix/linux'
3
3
 
4
4
  module CSD
5
5
  module Application
@@ -8,15 +8,16 @@ module CSD
8
8
 
9
9
  # A list of apt-get packages that are required by this application.
10
10
  #
11
- DEBIAN_DEPENDENCIES = %w{ libssl-dev libgtkmm-2.4-dev libglademm-2.4-dev libsdl-dev git-core subversion automake libtool libltdl3-dev build-essential libavcodec-dev libswscale-dev libasound2-dev libsdl-ttf2.0-dev nasm yasm ffmpeg }
11
+ DEBIAN_DEPENDENCIES = %w{ libxv-dev libssl-dev libgtkmm-2.4-dev libglademm-2.4-dev libsdl-dev git-core subversion automake libtool libltdl3-dev build-essential libavcodec-dev libswscale-dev libasound2-dev libsdl-ttf2.0-dev nasm yasm ffmpeg }
12
12
 
13
- def before_compile
14
- #fix_aclocal_dirlist
13
+ def compile!
15
14
  install_aptitude_dependencies if Options.apt_get
15
+ super
16
16
  end
17
17
 
18
- def after_compile
19
- ldconfig_and_gtkgui
18
+ def package!
19
+ modify_libminisip_rules
20
+ super
20
21
  end
21
22
 
22
23
  def install_aptitude_dependencies
@@ -26,27 +27,15 @@ module CSD
26
27
  end
27
28
  end
28
29
 
29
- def fix_aclocal_dirlist
30
- return
31
- content = '/usr/local/share/aclocal'
32
- target = Pathname.new('/usr/share/aclocal/dirlist')
33
- unless target.exist? and File.new(target).read == content # TODO: replace with File.read
34
- begin
35
- File.new(target, 'w').write(content).close
36
- rescue Errno::EACCES => e
37
- say "Please run the following commands with the right permissions.".red.bold
38
- say " sudo rm /usr/share/aclocal/dirlist".green.bold
39
- say " sudo touch /usr/share/aclocal/dirlist".green.bold
40
- say " sudo echo /usr/local/share/aclocal >> /usr/share/aclocal/dirlist".green.bold
41
- exit
42
- end
30
+ def modify_libminisip_rules
31
+ if File.exist? Path.repository_libminisip_rules_backup
32
+ UI.warn "The libminisip rules seem to be fixed already, I won't touch them now. Delete #{Path.repository_libminisip_rules_backup.enquote} to enforce it."
33
+ else
34
+ Cmd.copy Path.repository_libminisip_rules, Path.repository_libminisip_rules_backup
35
+ Cmd.replace Path.repository_libminisip_rules, 'AUTOMATED_INSTALLER_PLACEHOLDER=""', [cpp_flags, ld_flags].join(' ')
43
36
  end
44
37
  end
45
38
 
46
- def ldconfig_and_gtkgui
47
- Cmd.run(Path.build_gtkgui)
48
- end
49
-
50
39
  end
51
40
  end
52
41
  end
@@ -1,33 +1,32 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', 'debian')
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'csd/application/minisip/unix/linux/debian'
3
3
 
4
4
  module CSD
5
5
  module Application
6
6
  module Minisip
7
7
  class Ubuntu10 < Debian
8
-
9
- def before_compile
10
- super
8
+
9
+ def compile!
11
10
  fix_ubuntu_10_04
12
11
  exit if Options.only_fix_giomm
12
+ super
13
13
  end
14
14
 
15
15
  def fix_ubuntu_10_04
16
- # TODO put backup file in Path.xxx
17
- if File.exist?("#{Path.giomm_header}.ai-backup")
18
- UI.warn "giomm-2.4 seems to be fixed already, I won't touch it. Delete `#{"#{Path.giomm_header}.ai-backup"}´ to enforce it."
16
+ if File.exist? Path.giomm_header_backup
17
+ UI.warn "giomm-2.4 seems to be fixed already, I won't touch it now. Delete #{Path.giomm_header_backup.enquote} to enforce it."
19
18
  else
20
19
  Path.new_giomm_header = File.join(Dir.mktmpdir, 'giomm.h')
21
20
  Cmd.copy(Path.giomm_header, Path.new_giomm_header)
22
- Cmd.replace(Path.new_giomm_header, '#include <giomm/socket.h>', "/* ----- AI COMMENTING OUT START ----- \n#include <giomm/socket.h>")
23
- Cmd.replace(Path.new_giomm_header, '#include <giomm/tcpconnection.h>', "#include <giomm/tcpconnection.h>\n ----- AI COMMENTING OUT END ----- */")
24
- Cmd.replace(Path.new_giomm_header, '# include <giomm/unixconnection.h>', "// #include <giomm/unixconnection.h> // COMMENTED OUT BY AI")
25
- Cmd.run("sudo cp #{Path.giomm_header} #{Path.giomm_header}.ai-backup")
21
+ Cmd.replace Path.new_giomm_header do |r|
22
+ r.replace '#include <giomm/socket.h>', "/* ----- AI COMMENTING OUT START ----- \n#include <giomm/socket.h>"
23
+ r.replace '#include <giomm/tcpconnection.h>', "#include <giomm/tcpconnection.h>\n ----- AI COMMENTING OUT END ----- */"
24
+ end
25
+ Cmd.run("sudo cp #{Path.giomm_header} #{Path.giomm_header_backup}")
26
26
  Cmd.run("sudo cp #{Path.new_giomm_header} #{Path.giomm_header}")
27
27
  end
28
28
  end
29
29
 
30
-
31
30
  end
32
31
  end
33
32
  end
@@ -1,7 +1,6 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
2
  require 'ostruct'
3
- require 'active_support/inflector'
4
- require 'active_support/core_ext/string/inflections'
3
+ require 'csd/extensions/core/string'
5
4
 
6
5
  module CSD
7
6
 
@@ -9,14 +8,15 @@ module CSD
9
8
  #
10
9
  class Applications
11
10
 
12
- # Returns nil if application could not be found
11
+ # Returns the application module instance of +app_name+. Returns +nil+ if the application could not be found or loaded.
13
12
  #
14
13
  def self.find(app_name)
14
+ return nil if app_name.to_s.empty?
15
15
  begin
16
16
  UI.debug "Applications.find: Attempting to require `#{File.join(Path.applications, app_name.to_s)}´."
17
17
  require File.join(Path.applications, app_name.to_s)
18
18
  UI.debug "Applications.find: Attempting to load `#{app_name}´."
19
- ActiveSupport::Inflector.constantize "CSD::Application::#{app_name.camelize}"
19
+ "CSD::Application::#{app_name.to_s.camelize}".constantize
20
20
  rescue LoadError => e
21
21
  UI.debug "Applications.find: The Application `#{app_name}´ could not be loaded properly."
22
22
  UI.debug " Reason: #{e}"
@@ -1,36 +1,18 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
2
  require 'pathname'
3
3
  require 'ostruct'
4
4
 
5
5
  module CSD
6
- # This module contains wrapper methods for standard file system operations. They are meant to be
6
+ # This class contains wrapper methods for standard file system operations. They are meant to be
7
7
  # a little bit more robust (e.g. raising no exceptions) and return elaborate feedback on their operation.
8
8
  # All of these methods, except for the +run+ method, are platform independent.
9
9
  #
10
- module Commands
10
+ class Commands
11
11
 
12
12
  # The Process module is a collection of methods used to manipulate processes.
13
13
  # 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)
14
14
  include Process
15
15
 
16
- # Objects of this class can be returned by Commands. Since it is an OpenStruct object,
17
- # it can contain an arbritary number of values.
18
- #
19
- class CommandResult < OpenStruct
20
-
21
- # This creates an convenient, read-only accessor for the OpenStruct object values.
22
- # It simply maps methods that end with a <tt>?</tt> to the same method without <tt>?</tt>.
23
- #
24
- # ==== Examples
25
- #
26
- # command_result.something? # => command_result.something
27
- #
28
- def method_missing(meth, *args, &block)
29
- meth.to_s.ends_with?('?') ? self.send(meth.to_s.chop.to_sym, *args, &block) : super
30
- end
31
-
32
- end
33
-
34
16
  # Creates a directory recursively.
35
17
  #
36
18
  # ==== Returns
@@ -51,7 +33,9 @@ module CSD
51
33
  #
52
34
  # mkdir('i/can/create/directories/recursively')
53
35
  #
54
- def mkdir(target)
36
+ def mkdir(target, params={})
37
+ default_params = { :die_on_failure => true, :show_output => false }
38
+ params = default_params.merge(params)
55
39
  target = target.pathnamify
56
40
  result = CommandResult.new
57
41
  if target.directory?
@@ -61,10 +45,10 @@ module CSD
61
45
  begin
62
46
  UI.info "Creating directory: #{target}".cyan
63
47
  # Try to create the directory
64
- target.mkpath unless (Options.dry or Options.reveal)
48
+ target.mkpath unless Options.reveal
65
49
  rescue Errno::EACCES => e
66
- UI.error "Cannot create directory (no permission): #{target}"
67
- return result
50
+ result.reason = "Cannot create directory (no permission): #{target}"
51
+ params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
68
52
  end
69
53
  end
70
54
  result.success = (target.directory? or Options.reveal)
@@ -80,67 +64,103 @@ module CSD
80
64
  #
81
65
  # [+success?+] +true+ if pwd is where it was requested to be after the operation, +nil+ if not.
82
66
  #
83
- def cd(target)
67
+ def cd(target, params={})
68
+ default_params = { :die_on_failure => true, :show_output => false }
69
+ params = default_params.merge(params)
84
70
  target = target.pathnamify
85
71
  result = CommandResult.new
86
- if target.directory? or Options.reveal
87
- UI.info "cd #{target}".yellow
88
- if Options.reveal
89
- @pwd = target.to_s
90
- else
72
+ UI.info "cd #{target}".yellow
73
+ if Options.reveal
74
+ # We need to fake changing the directory in reveal mode.
75
+ @pwd = target.to_s
76
+ result.success = true
77
+ else
78
+ begin
91
79
  Dir.chdir(target)
80
+ result.success = target.current_path?
81
+ rescue Exception => e
82
+ result.reason = "Cannot change to directory `#{target}´. Reason: #{e.message}"
83
+ params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
92
84
  end
93
- elsif target.exist?
94
- UI.error "Cannot change to directory because it exists but is not a directory: #{target}".red
95
85
  end
96
- result.success = (target.current_path? or Options.reveal)
97
86
  result
98
87
  end
99
88
 
100
89
  # Copies one or several files to the destination
101
90
  #
102
- def copy(src, dest)
103
- UI.info "Copying `#{src to `#{dest}´".cyan
104
- FileUtils.cp(src, dest) unless (Options.dry or Options.reveal)
91
+ def copy(src, dest, params={})
92
+ transfer(:copy, src, dest, params)
105
93
  end
106
94
 
107
95
  # Moves one or several files to the destination
108
96
  #
109
- def move(src, dest)
110
- UI.info "Moving `#{src to `#{dest}´".cyan
111
- FileUtils.mv(src, dest) unless (Options.dry or Options.reveal)
97
+ def move(src, dest, params={})
98
+ transfer(:move, src, dest, params)
112
99
  end
113
100
 
114
101
  # This returns the current pwd. However, it will return a fake result if we are in reveal-commands-mode.
115
102
  #
116
103
  def pwd
117
- if Options.reveal
118
- @pwd ||= Dir.pwd
119
- else
120
- Dir.pwd
104
+ begin
105
+ if Options.reveal
106
+ @pwd ||= Dir.pwd
107
+ else
108
+ Dir.pwd
109
+ end
110
+ rescue Errno::ENOENT => e
111
+ UI.debug "The current pwd could not be located. Was the directory removed?"
112
+ nil
121
113
  end
122
114
  end
123
115
 
124
- # Replaces all occurences of a pattern in a file
125
- #
126
- # ==== Returns
116
+ # Replaces all occurences of a pattern in a file.
117
+ # In a block, it yields the Replacer class.
118
+ # Otherwise it calls the replace function in the Replacer class.
127
119
  #
128
- # This method returns a CommandResult object with the following values:
129
- #
130
- # [+success?+] +true+ if the replacement was successful, +nil+ if not.
120
+ def replace(filepath, pattern='', substitution='', params={}, &block)
121
+ params = pattern if pattern.is_a?(Hash)
122
+ default_params = { :die_on_failure => true }
123
+ params = default_params.merge(params)
124
+ UI.info "Modifying contents of `#{filepath}´ as follows:".cyan
125
+ Replacer.filepath = filepath
126
+ if block_given?
127
+ yield Replacer
128
+ else
129
+ Replacer.replace(pattern, substitution, params)
130
+ end
131
+ end
132
+
133
+ # This class is yielded by the replace function in a block
131
134
  #
132
- def replace(filepath, pattern, substitution)
133
- result = CommandResult.new
134
- begin
135
- UI.info "Modifying contents of `#{filepath}´ as follows:".blue
136
- UI.info " (Replacing all occurences of `#{pattern}´ with `#{substitution}´)".blue
137
- new_file_content = File.read(filepath).gsub(pattern, substitution)
138
- File.open(filepath, 'w+') { |file| file << new_file_content } unless (Options.dry or Options.reveal)
139
- rescue Errno::ENOENT => e
140
- result.success = false
135
+ class Replacer
136
+ class << self
137
+ attr_accessor :filepath
138
+ end
139
+
140
+ # Replaces all occurences of a pattern in a file
141
+ #
142
+ # ==== Returns
143
+ #
144
+ # This method returns a CommandResult object with the following values:
145
+ #
146
+ # [+success?+] +true+ if the replacement was successful, +nil+ if not.
147
+ #
148
+ def self.replace(pattern, substitution, params={})
149
+ result = CommandResult.new
150
+ default_params = { :die_on_failure => true }
151
+ params = default_params.merge(params)
152
+ begin
153
+ UI.info " `#{pattern}´ => `#{substitution}´".blue
154
+ new_file_content = File.read(self.filepath).gsub(pattern.to_s, substitution.to_s)
155
+ File.open(self.filepath, 'w+') { |file| file << new_file_content } unless Options.reveal
156
+ result.success = true
157
+ rescue Errno::ENOENT => e
158
+ result.success = false
159
+ result.reason = "Could not perform replace operation! #{e.message}"
160
+ params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
161
+ end
162
+ result
141
163
  end
142
- result.success = true if Options.reveal
143
- result
144
164
  end
145
165
 
146
166
  # Runs a command on the system.
@@ -153,52 +173,107 @@ module CSD
153
173
  #
154
174
  # The following options can be passed as a hash.
155
175
  #
156
- # [+:exit_on_failure+] If the exit code of the command was not 0, exit the CSD application.
176
+ # [+:exit_on_failure+] If the exit code of the command was not 0, exit the CSD application (default: +true+).
177
+ # [+:silent+] Don't show the command's output prints by any means (default: +false+).
178
+ # [+:announce_pwd+] Before running the command, say in which path the command will be executed (default: +true+).
179
+ # [+:verbose+] Instead of printing just one `.´ per command output line, print the original command output lines (default: +false+).
157
180
  #
158
181
  def run(cmd, params={})
159
- cmd = cmd.to_s
160
- default_params = { :die_on_failure => true, :silent => false }
182
+ default_params = { :die_on_failure => true, :silent => false, :announce_pwd => true, :verbose => false }
183
+ params[:verbose] = true if Options.verbose
161
184
  params = default_params.merge(params)
162
- unless params[:silent]
163
- UI.info "Running command in #{pwd}".yellow
164
- UI.info cmd.cyan
185
+ result = CommandResult.new
186
+ cmd = cmd.to_s
187
+ UI.error "The current working directory (aka 'pwd') could not be identified. It was probably deleted." and return unless pwd
188
+ UI.info "Running command in #{pwd}".yellow unless (!params[:announce_pwd] or params[:silent])
189
+ UI.info cmd.cyan unless params[:silent]
190
+ if Options.reveal
191
+ result.success = true
192
+ return result
165
193
  end
166
- return '' if Options.reveal or Options.dry
167
- ret = ''
194
+ result.output = ''
195
+ $stderr.reopen '/dev/null' if params[:silent] # This prevents even output of error messages from the executed commands
168
196
  IO.popen(cmd) do |stdout|
169
197
  stdout.each do |line|
170
- UI.info " #{line}" unless params[:silent]
171
- ret << line
198
+ if params[:verbose]
199
+ UI.info " #{line}" unless params[:silent]
200
+ else
201
+ $stdout.putc '.' unless params[:silent]
202
+ $stdout.flush
203
+ end
204
+ result.output << line
172
205
  end
173
206
  end
174
- die_if_last_command_had_errors if params[:die_on_failure]
175
- ret
207
+ UI.separator if (!params[:silent] and !params[:verbose]) # i.e. if dots are outputted, we should create a new line after them
208
+ result.success = $?.success?
209
+ if params[:die_on_failure] and !result.success
210
+ UI.info result.output unless params[:verbose] # In verbose mode, we don't need to repeat the unsuccessful command's output
211
+ UI.die "The last command was unsuccessful."
212
+ end
213
+ result
214
+ end
215
+
216
+ private
217
+
218
+ # The common backend for copy and move operations.
219
+ #
220
+ def transfer(action, src, dest, params={})
221
+ default_params = { :die_on_failure => true }
222
+ params = default_params.merge(params)
223
+ result = CommandResult.new
224
+ UI.info "#{action == :copy ? 'Copying' : 'Moving'} `#{src}´ to `#{dest}´".cyan
225
+ begin
226
+ FileUtils.send(action, src, dest) unless Options.reveal
227
+ result.success = true
228
+ rescue Exception => e
229
+ result.success = false
230
+ result.reason = "Could not perform #{action} operation! #{e.message}"
231
+ params[:die_on_failure] ? UI.die(result.reason) : UI.error(result.reason)
232
+ end
233
+ result
176
234
  end
177
235
 
178
- def die_if_last_command_had_errors
179
- UI.die "The last command was unsuccessful." unless $?.success?
236
+ # Clones the master branch of a repository using +git+. +name+ is a +String+ used for UI outputs,
237
+ # +repository+ is the URL/path to the repository, +destination+ is an absolute or relative
238
+ # path to where the repository should be downloaded to.
239
+ #
240
+ # This command will not do anything if the destination already exists.
241
+ #
242
+ def git_clone(name, repository, destination, params={})
243
+ default_params = { :announce_pwd => false, :silent => true }
244
+ params = default_params.merge(params)
245
+ result = CommandResult.new
246
+ destination = destination.pathnamify
247
+ # At this point we break off if the destination already exists, but in reveal-mode we want to continue.
248
+ UI.warn "Skipping #{name} download, because the directory already exists: #{destination.enquote}" and return if (destination.directory? and !Options.reveal)
249
+ if destination.parent.writable? or Options.reveal
250
+ UI.info "Downloading #{name} to #{destination.enquote}".green.bold
251
+ result.success = Cmd.run("git clone #{repository} #{destination} #{('--quiet' if params[:silent])}", params.merge({:die_on_failure => false})).success?
252
+ else
253
+ UI.error "Could not download #{name} (no permission): #{destination.enquote}"
254
+ result.success = false
255
+ end
256
+ result
180
257
  end
181
258
 
182
259
  end
183
260
 
184
- # Having a class to include all command modules
261
+ # Objects of this class can be returned by Commands. Since it is an OpenStruct object,
262
+ # it can contain an arbritary number of values.
185
263
  #
186
- class CommandsInstance
187
- include Commands
188
- end
189
-
190
- # Wrapping the CommandsInstance class
191
- #
192
- class Cmd
193
- COMMANDS = %w{ mkdir cd run replace copy move } unless defined?(COMMANDS)
264
+ class CommandResult < OpenStruct
194
265
 
195
- def self.instance
196
- @@instance ||= CommandsInstance.new
266
+ # This creates an convenient, read-only accessor for the OpenStruct object values.
267
+ # It simply maps methods that end with a <tt>?</tt> to the same method without <tt>?</tt>.
268
+ #
269
+ # ==== Examples
270
+ #
271
+ # command_result.something? # => command_result.something
272
+ #
273
+ def method_missing(meth, *args, &block)
274
+ meth.to_s.ends_with?('?') ? self.send(meth.to_s.chop.to_sym, *args, &block) : super
197
275
  end
198
276
 
199
- def self.method_missing(meth, *args, &block)
200
- COMMANDS.include?(meth.to_s) ? instance.send(meth, *args, &block) : super
201
- end
202
277
  end
203
278
 
204
279
  end