scout-essentials 1.0.0

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 (107) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.vimproject +78 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +18 -0
  7. data/Rakefile +47 -0
  8. data/VERSION +1 -0
  9. data/lib/scout/cmd.rb +348 -0
  10. data/lib/scout/concurrent_stream.rb +284 -0
  11. data/lib/scout/config.rb +168 -0
  12. data/lib/scout/exceptions.rb +77 -0
  13. data/lib/scout/indiferent_hash/case_insensitive.rb +30 -0
  14. data/lib/scout/indiferent_hash/options.rb +115 -0
  15. data/lib/scout/indiferent_hash.rb +96 -0
  16. data/lib/scout/log/color.rb +224 -0
  17. data/lib/scout/log/color_class.rb +269 -0
  18. data/lib/scout/log/fingerprint.rb +69 -0
  19. data/lib/scout/log/progress/report.rb +244 -0
  20. data/lib/scout/log/progress/util.rb +173 -0
  21. data/lib/scout/log/progress.rb +106 -0
  22. data/lib/scout/log/trap.rb +107 -0
  23. data/lib/scout/log.rb +441 -0
  24. data/lib/scout/meta_extension.rb +100 -0
  25. data/lib/scout/misc/digest.rb +63 -0
  26. data/lib/scout/misc/filesystem.rb +25 -0
  27. data/lib/scout/misc/format.rb +255 -0
  28. data/lib/scout/misc/helper.rb +31 -0
  29. data/lib/scout/misc/insist.rb +56 -0
  30. data/lib/scout/misc/monitor.rb +66 -0
  31. data/lib/scout/misc/system.rb +73 -0
  32. data/lib/scout/misc.rb +10 -0
  33. data/lib/scout/named_array.rb +138 -0
  34. data/lib/scout/open/lock/lockfile.rb +587 -0
  35. data/lib/scout/open/lock.rb +68 -0
  36. data/lib/scout/open/remote.rb +135 -0
  37. data/lib/scout/open/stream.rb +491 -0
  38. data/lib/scout/open/util.rb +244 -0
  39. data/lib/scout/open.rb +170 -0
  40. data/lib/scout/path/find.rb +204 -0
  41. data/lib/scout/path/tmpfile.rb +8 -0
  42. data/lib/scout/path/util.rb +127 -0
  43. data/lib/scout/path.rb +51 -0
  44. data/lib/scout/persist/open.rb +17 -0
  45. data/lib/scout/persist/path.rb +15 -0
  46. data/lib/scout/persist/serialize.rb +157 -0
  47. data/lib/scout/persist.rb +104 -0
  48. data/lib/scout/resource/open.rb +8 -0
  49. data/lib/scout/resource/path.rb +80 -0
  50. data/lib/scout/resource/produce/rake.rb +69 -0
  51. data/lib/scout/resource/produce.rb +151 -0
  52. data/lib/scout/resource/scout.rb +3 -0
  53. data/lib/scout/resource/software.rb +178 -0
  54. data/lib/scout/resource/util.rb +59 -0
  55. data/lib/scout/resource.rb +40 -0
  56. data/lib/scout/simple_opt/accessor.rb +54 -0
  57. data/lib/scout/simple_opt/doc.rb +126 -0
  58. data/lib/scout/simple_opt/get.rb +57 -0
  59. data/lib/scout/simple_opt/parse.rb +67 -0
  60. data/lib/scout/simple_opt/setup.rb +26 -0
  61. data/lib/scout/simple_opt.rb +5 -0
  62. data/lib/scout/tmpfile.rb +129 -0
  63. data/lib/scout-essentials.rb +10 -0
  64. data/scout-essentials.gemspec +143 -0
  65. data/share/color/color_names +507 -0
  66. data/share/color/diverging_colors.hex +12 -0
  67. data/share/software/install_helpers +523 -0
  68. data/test/scout/indiferent_hash/test_case_insensitive.rb +16 -0
  69. data/test/scout/indiferent_hash/test_options.rb +46 -0
  70. data/test/scout/log/test_color.rb +0 -0
  71. data/test/scout/log/test_progress.rb +108 -0
  72. data/test/scout/misc/test_digest.rb +30 -0
  73. data/test/scout/misc/test_filesystem.rb +30 -0
  74. data/test/scout/misc/test_insist.rb +13 -0
  75. data/test/scout/misc/test_system.rb +21 -0
  76. data/test/scout/open/test_lock.rb +52 -0
  77. data/test/scout/open/test_remote.rb +25 -0
  78. data/test/scout/open/test_stream.rb +676 -0
  79. data/test/scout/open/test_util.rb +73 -0
  80. data/test/scout/path/test_find.rb +110 -0
  81. data/test/scout/path/test_util.rb +22 -0
  82. data/test/scout/persist/test_open.rb +37 -0
  83. data/test/scout/persist/test_path.rb +37 -0
  84. data/test/scout/persist/test_serialize.rb +114 -0
  85. data/test/scout/resource/test_path.rb +58 -0
  86. data/test/scout/resource/test_produce.rb +94 -0
  87. data/test/scout/resource/test_software.rb +24 -0
  88. data/test/scout/resource/test_util.rb +38 -0
  89. data/test/scout/simple_opt/test_doc.rb +16 -0
  90. data/test/scout/simple_opt/test_get.rb +11 -0
  91. data/test/scout/simple_opt/test_parse.rb +10 -0
  92. data/test/scout/simple_opt/test_setup.rb +77 -0
  93. data/test/scout/test_cmd.rb +85 -0
  94. data/test/scout/test_concurrent_stream.rb +29 -0
  95. data/test/scout/test_config.rb +66 -0
  96. data/test/scout/test_indiferent_hash.rb +26 -0
  97. data/test/scout/test_log.rb +32 -0
  98. data/test/scout/test_meta_extension.rb +80 -0
  99. data/test/scout/test_misc.rb +6 -0
  100. data/test/scout/test_named_array.rb +43 -0
  101. data/test/scout/test_open.rb +146 -0
  102. data/test/scout/test_path.rb +54 -0
  103. data/test/scout/test_persist.rb +186 -0
  104. data/test/scout/test_resource.rb +26 -0
  105. data/test/scout/test_tmpfile.rb +53 -0
  106. data/test/test_helper.rb +50 -0
  107. metadata +247 -0
@@ -0,0 +1,523 @@
1
+ #vim: ft=sh
2
+
3
+ [[ -z $SOFTWARE_DIR ]] && SOFTWARE_DIR="$HOME/software"
4
+ OPT_DIR="$SOFTWARE_DIR/opt"; [ -d $OPT_SRC_DIR ] || mkdir -p $OPT_SRC_DIR
5
+ OPT_BIN_DIR="$OPT_DIR/bin"; [ -d $OPT_BIN_DIR ] || mkdir -p $OPT_BIN_DIR
6
+ OPT_SRC_DIR="$SOFTWARE_DIR/src"; [ -d $OPT_SRC_DIR ] || mkdir -p $OPT_SRC_DIR
7
+ OPT_SCM_DIR="$SOFTWARE_DIR/scm"; [ -d $OPT_SCM_DIR ] || mkdir -p $OPT_SCM_DIR
8
+ OPT_JAR_DIR="$OPT_DIR/jars"; [ -d $OPT_JAR_DIR ] || mkdir -p $OPT_JAR_DIR
9
+ OPT_BUILD_DIR="$SOFTWARE_DIR/.build"; [ -d $OPT_BUILD_DIR ] || mkdir -p $OPT_BUILD_DIR
10
+
11
+ if (false && command -v realpath && realpath --help | grep relative) > /dev/null; then
12
+ function relative_path(){
13
+ local basedir=$1
14
+ local path=$2
15
+ echo $(realpath --relative-to="$basedir" "$path")
16
+ }
17
+ else
18
+ realpath(){
19
+ OURPWD=$PWD
20
+ cd "$(dirname "$1")"
21
+ LINK=$(readlink "$(basename "$1")")
22
+ while [ "$LINK" ]; do
23
+ cd "$(dirname "$LINK")" 2> /dev/null
24
+ LINK=$(readlink "$(basename "$1")")
25
+ done
26
+ REALPATH="$PWD/$(basename "$1")"
27
+ cd "$OURPWD"
28
+ echo "$REALPATH"
29
+ }
30
+
31
+ function relative_path(){
32
+ local basedir="$(realpath $1)"
33
+ local path="$(realpath "$2")"
34
+ local pre=""
35
+ basedir=${basedir%.}
36
+ while [[ ! $path = $basedir* ]]; do
37
+ pre=${pre}../
38
+ basedir=$(dirname $basedir)
39
+ done
40
+ echo ${pre}${path/$basedir\/} |tr -s '/' '/'
41
+ }
42
+ fi
43
+
44
+ function link(){
45
+ local source="$1"
46
+ local target="$2"
47
+ local rel_source=$(relative_path "$(dirname $target)" "$source")
48
+
49
+ [ -h "$target" ] && rm "$target"
50
+ [ -h "$target" ] || ln -s "$rel_source" "$target"
51
+ }
52
+
53
+ function expand_path(){
54
+ name=$(basename $1)
55
+ dir=$(dirname $1)
56
+
57
+ echo "$(cd $dir && pwd)/$name"
58
+ }
59
+
60
+ function add2file(){
61
+ file=$1
62
+ line=$2
63
+
64
+ local rel=$(relative_path "$OPT_DIR" "$line")
65
+ grep "$rel" "$file" || echo "$rel" >> "$file"
66
+ }
67
+
68
+ #{{{ GET PKG OPT_BUILD_DIR
69
+
70
+ # From SRC
71
+ get_pkg(){
72
+ local name="$1"
73
+ local url="$2"
74
+
75
+ if [ ! -f "$OPT_SRC_DIR/$name.pkg" ]; then
76
+ wget "$url" -O "$OPT_SRC_DIR/$name.pkg" || wget "$url" -O "$OPT_SRC_DIR/$name.pkg" --no-check-certificate || (rm -f "$OPT_SRC_DIR/$name.pkg"; echo "Error downloading"; exit -1)
77
+ fi
78
+ }
79
+
80
+ uncompress_pkg(){
81
+ local name="$1"
82
+ local pkg="$OPT_SRC_DIR/$name.pkg"
83
+
84
+ local old_pwd="`expand_path $(pwd)`"
85
+ clean_build
86
+
87
+ mkdir -p "$OPT_BUILD_DIR"
88
+ cd "$OPT_BUILD_DIR"
89
+
90
+ (tar xvfz $pkg || tar xvfJ $pkg || tar xvfj $pkg || unzip $pkg || (echo "Error decompressing" & cd & exit -1 ) ) 2> /dev/null
91
+
92
+ cd "$old_pwd"
93
+ }
94
+
95
+ get_src(){
96
+ local name="$1"
97
+ local url="$2"
98
+
99
+ get_pkg "$name" "$url"
100
+ uncompress_pkg "$name"
101
+ }
102
+
103
+ # From SNV
104
+ get_svn(){
105
+ local name="$1"
106
+ local url="$2"
107
+
108
+ local old_pwd="`expand_path $(pwd)`"
109
+
110
+ cd $OPT_SCM_DIR
111
+ if [ -d "$name" ]; then
112
+ cd "$name"
113
+ svn update
114
+ else
115
+ echo svn checkout "$url" "$name"
116
+ svn checkout "$url" "$name"
117
+ fi
118
+
119
+ clean_build
120
+
121
+ cd $OPT_BUILD_DIR
122
+ link "$OPT_SCM_DIR/$name" "$name"
123
+
124
+ cd "$old_pwd"
125
+
126
+ }
127
+
128
+ # From GIT
129
+ get_git(){
130
+ local name="$1"
131
+ local url="$2"
132
+
133
+ if [[ "$url" == *" "* ]]; then
134
+ version="${url/* /}"
135
+ url="${url/ */}"
136
+ echo "Using version $version of repo $url"
137
+ else
138
+ version='none'
139
+ fi
140
+
141
+ local old_pwd="`expand_path $(pwd)`"
142
+
143
+ cd $OPT_SCM_DIR
144
+ if [ -d "$name" ]; then
145
+ cd "$name"
146
+
147
+ if [ ! "$NOWEB" == "true" -a $version == 'none' ]; then
148
+ git stash
149
+ git pull origin master
150
+ git rebase master
151
+ git stash apply
152
+ git submodule init
153
+ git submodule update
154
+ fi
155
+ else
156
+ if [ $version == 'none' ];then
157
+ git clone --recursive "$url" "$name"
158
+ else
159
+ git clone --recursive "$url" "$name" -b $version
160
+ fi
161
+
162
+ cd "$name"
163
+ git submodule init
164
+ git submodule update
165
+ fi
166
+
167
+ clean_build
168
+
169
+ cd $OPT_BUILD_DIR
170
+ link "$OPT_SCM_DIR/$name" "$name"
171
+
172
+ cd "$old_pwd"
173
+ }
174
+
175
+
176
+ #{{{ BUILD PKG in OPT_BUILD_DIR
177
+
178
+ clean_build(){
179
+ rm -Rf $OPT_BUILD_DIR/*
180
+ }
181
+
182
+ build_dir(){
183
+ echo $OPT_BUILD_DIR/$(ls $OPT_BUILD_DIR |head -n 1)
184
+ }
185
+
186
+ compile(){
187
+ local name=$1; shift
188
+ local extra="$@"
189
+
190
+ if [ -f bootstrap ]; then
191
+ ./bootstrap
192
+ fi
193
+
194
+ if [ -f Makefile -o -f makefile ]; then
195
+ make -j 4 || exit -1
196
+ make install || echo "No install"
197
+ fi
198
+
199
+ [ -f build.xml ] && (ant || exit -1)
200
+
201
+ [ -f setup.rb ] && (ruby -Ilib/ setup.rb --prefix="$(opt_dir "$name")" $extra || exit -1)
202
+
203
+ [ -f install.rb ] && ruby -Ilib/ install.rb config --prefix="$(opt_dir "$name")" $extra && ruby -Ilib/ install.rb install
204
+
205
+ if [ -f setup.py ]; then
206
+ python setup.py build && python setup.py install --user || exit -1
207
+ clean_build
208
+ fi
209
+ }
210
+
211
+ prepare_make(){
212
+ local name=$1; shift
213
+ local extra="$@"
214
+
215
+ local old_pwd="`expand_path $(pwd)`"
216
+
217
+ cd "`build_dir`"
218
+
219
+ [ -f bootstrap ] && (./bootstrap || exit -1)
220
+
221
+ [ -d src -a ! -e CMakeLists.txt -a ! -e Makefile -a ! -e configure ] && cd src
222
+
223
+ [ -f bootstrap ] && (./bootstrap || exit -1)
224
+
225
+ if [ -f config/m4 ]; then
226
+ libtoolize --force
227
+ aclocal
228
+ autoheader
229
+ fi
230
+
231
+ if [ -f Makefile.am -a ! -f configure ]; then
232
+ autoreconf
233
+ fi
234
+
235
+ if [ -f aclocal.m4 ]; then
236
+ autoconf
237
+ fi
238
+
239
+ if [ -f autogen.sh ]; then
240
+ ./autogen.sh
241
+ fi
242
+
243
+ if [ -f aclocal.m4 ]; then
244
+ autoreconf -i
245
+ autoconf
246
+ automake --add-missing
247
+ else
248
+ autoconf
249
+ automake --add-missing
250
+ fi
251
+
252
+ if [ -f config ]; then
253
+ ln -s config configure
254
+ fi
255
+
256
+ cd "$old_pwd"
257
+ }
258
+
259
+ build_make(){
260
+ local name=$1; shift
261
+ local extra="$@"
262
+
263
+ local old_pwd="`expand_path $(pwd)`"
264
+ cd "`build_dir`"
265
+ echo PWD: `pwd`
266
+ ls
267
+
268
+
269
+ [ -d src -a ! -e CMakeLists.txt -a ! -e Makefile -a ! -e configure ] && cd src
270
+ [ -d source -a ! -e CMakeLists.txt -a ! -e Makefile -a ! -e configure ] && cd source
271
+
272
+ echo "Building with configure $name"
273
+ if [ "x$extra" != "x" ]; then
274
+ echo "Extra params: $extra"
275
+ fi
276
+
277
+ if [ ! -f configure ]; then
278
+ prepare_make $name
279
+ fi
280
+
281
+ if [ -f configure ]; then
282
+ ./configure --prefix="$(opt_dir "$name")" $extra
283
+ compile "$name" $extra
284
+ [ -d "$(opt_dir "$name")" ] || move_opt "$name"
285
+ setup "$name"
286
+ clean_build
287
+ else
288
+ compile "$name" $extra
289
+ move_opt "$name"
290
+ setup "$name"
291
+ clean_build
292
+ fi
293
+
294
+ cd "$old_pwd"
295
+ }
296
+
297
+ buid_cmake(){
298
+ local name=$1; shift
299
+ local extra="$@"
300
+
301
+ local old_pwd="`expand_path $(pwd)`"
302
+ cd "`build_dir`"
303
+ echo PWD: `pwd`
304
+ ls
305
+
306
+
307
+ [ -d src -a ! -e CMakeLists.txt -a ! -e Makefile -a ! -e configure ] && cd src
308
+ [ -d source -a ! -e CMakeLists.txt -a ! -e Makefile -a ! -e configure ] && cd source
309
+
310
+ echo "Building with cmake $name"
311
+ if [ "x$extra" != "x" ]; then
312
+ echo "Extra params: $extra"
313
+ fi
314
+
315
+ echo "Using cmake"
316
+ [ -d build ] || mkdir build
317
+
318
+ cd build
319
+ cmake -DMAKE_INSTALL_PREFIX=/ $extra ..
320
+ if [ ! -f Makefile -a -f ../configure ]; then
321
+ ../configure --prefix="$(opt_dir "$name")" $extra
322
+ make -j 4
323
+ make install || (cd .. ; mv build "$(opt_dir "$name")")
324
+ else
325
+ make DESTDIR="$(opt_dir "$name")" -j 4 && make DESTDIR="$(opt_dir "$name")" install
326
+ fi
327
+ cd ..
328
+
329
+ if [ ! -d "$(opt_dir "$name")" ]; then
330
+ mkdir -p "$(opt_dir "$name")"
331
+ for subd in bin lib lib64 include pkgdir; do
332
+ [ -d $subd ] && mv $subd "$(opt_dir "$name")"/$subd
333
+ done
334
+ fi
335
+
336
+ setup "$name"
337
+ clean_build
338
+
339
+ cd "$old_pwd"
340
+ }
341
+
342
+ build(){
343
+ local name=$1; shift
344
+ local extra="$@"
345
+
346
+ echo "Building $name"
347
+ if [ "x$extra" != "x" ]; then
348
+ echo "Extra params: $extra"
349
+ fi
350
+
351
+ local old_pwd="`expand_path $(pwd)`"
352
+ cd "`build_dir`"
353
+
354
+ [ -d src -a ! -e CMakeLists.txt -a ! -e Makefile -a ! -e configure ] && cd src
355
+
356
+ if [ -f CMakeLists.txt ]; then
357
+ buid_cmake "$name" $extra
358
+ else
359
+ build_make "$name" $extra
360
+ fi
361
+
362
+ cd "$old_pwd"
363
+ }
364
+
365
+ #{{{ SETUP
366
+
367
+ is_versioned(){
368
+ local name="$1"
369
+ [[ $name =~ : ]]
370
+ }
371
+
372
+ opt_dir(){
373
+ local name="$1"
374
+ if is_versioned "$name"; then
375
+ local real_name=`echo $1 | sed 's/:.*//'`
376
+ local version=`echo $1 | sed 's/.*://'`
377
+ echo "$OPT_DIR/$real_name/$version"
378
+ else
379
+ echo "$OPT_DIR/$name"
380
+ fi
381
+ }
382
+
383
+ move_opt(){
384
+ local name="$1"
385
+ local pkg_dir=$(opt_dir "$name")
386
+ local source=$(build_dir)
387
+
388
+ mkdir -p $(dirname "$pkg_dir")
389
+ if [ -h "$source" ]; then
390
+ local real_source=$(realpath "$source")
391
+ echo link "$real_source" "$pkg_dir"
392
+ link "$real_source" "$pkg_dir"
393
+ else
394
+ mv "$source" "$pkg_dir"
395
+ fi
396
+ }
397
+
398
+ setup(){
399
+ local name="$1"
400
+ local pkg_dir="`opt_dir \"$name\"`"
401
+
402
+ if is_versioned "$name"; then
403
+ rm -f "$(dirname $pkg_dir)/current"
404
+ link "$pkg_dir" "$(dirname $pkg_dir)/current"
405
+ pkg_dir="$(dirname $pkg_dir)/current"
406
+ fi
407
+
408
+ if [ -d "$pkg_dir/bin/" -o -d "$pkg_dir/usr/local/bin/" ]; then
409
+
410
+ for exe in ` find "$pkg_dir/bin/" -maxdepth 1 -type f -executable`; do
411
+ exe=$(basename $exe)
412
+ rm -f "$OPT_DIR/bin/$exe"
413
+ link "$pkg_dir/bin/$exe" "$OPT_DIR/bin/$exe" 2>/dev/null
414
+ done
415
+
416
+ for exe in ` find "$pkg_dir/usr/local/bin/" -maxdepth 1 -type f -executable`; do
417
+ exe=$(basename $exe)
418
+ rm -f "$OPT_DIR/usr/local/bin/$exe"
419
+ link "$pkg_dir/usr/local/bin/$exe" "$OPT_DIR/bin/$exe" 2>/dev/null
420
+ done
421
+
422
+
423
+ else
424
+ local old_pwd="`expand_path $(pwd)`"
425
+
426
+ for exe in ` find "$pkg_dir/" "$pkg_dir/build" "$pkg_dir/source/" "$pkg_dir/src/" -maxdepth 1 -type f -executable`; do
427
+ orig=$exe
428
+ exe=$(basename $exe)
429
+ echo "EXE $exe"
430
+ rm -f "$OPT_DIR/bin/$exe"
431
+ link "$orig" "$OPT_DIR/bin/$exe" 2>/dev/null
432
+ done
433
+ fi
434
+
435
+ ([ -d "$pkg_dir/include" ] && add2file "$OPT_DIR/.c-paths" "$pkg_dir/include")
436
+ ([ -d "$pkg_dir/lib" ] && add2file "$OPT_DIR/.ld-paths" "$pkg_dir/lib")
437
+ ([ -d "$pkg_dir/lib64" ] && add2file "$OPT_DIR/.ld-paths" "$pkg_dir/lib64")
438
+ ([ -d "$pkg_dir/lib/pkgconfig" ] && add2file "$OPT_DIR/.pkgconfig-paths" "$pkg_dir/lib/pkgconfig")
439
+ echo $name setup
440
+ }
441
+
442
+ #{{{ HELPERS
443
+
444
+ prepare_pkg(){
445
+ local name="$1"
446
+ local url="$2"
447
+ shift;shift;
448
+
449
+ get_pkg "$name" "$url"
450
+ uncompress_pkg "$name"
451
+ }
452
+
453
+ install_src(){
454
+ local name="$1"
455
+ local url="$2"
456
+ shift;shift;
457
+ local extra="$@"
458
+
459
+ prepare_pkg "$name" "$url"
460
+ build "$name" "$extra"
461
+ }
462
+
463
+ install_svn(){
464
+ local name="$1"
465
+ local url="$2"
466
+ shift;shift;
467
+ local extra="$@"
468
+
469
+ get_svn "$name" "$url"
470
+ build "$name" $extra
471
+ }
472
+
473
+ custom_build(){
474
+ local name="$1"
475
+ shift;
476
+ local cmd="$@"
477
+
478
+ echo "Building $name"
479
+
480
+ local old_pwd="`expand_path $(pwd)`"
481
+ cd "`build_dir`"
482
+ echo `pwd`
483
+ ls
484
+
485
+ eval $cmd
486
+
487
+ move_opt "$name"
488
+ setup "$name"
489
+ clean_build
490
+
491
+ cd "$old_pwd"
492
+ }
493
+
494
+ install_git(){
495
+ local name="$1"
496
+ local url="$2"
497
+ shift;shift;
498
+ local extra="$@"
499
+
500
+ get_git "$name" "$url"
501
+ build "$name" $extra
502
+ }
503
+
504
+ install_jar(){
505
+ local name="$1"
506
+ local url="$2"
507
+
508
+ [ -d "$OPT_DIR/$name/" ] || mkdir -p "$OPT_DIR/$name/"
509
+ wget "$url" -O "$OPT_DIR/$name/$name.jar" || wget "$url" -O "$OPT_DIR/$name/$name.jar" --no-check-certificate || (rm "$OPT_DIR/$name/$name.jar"; exit -1)
510
+ link "$OPT_DIR/$name/$name.jar" "$OPT_JAR_DIR/$name.jar"
511
+ }
512
+
513
+ jar2bin(){
514
+ local name="$1";shift
515
+ local extra="$@"
516
+
517
+ echo "#!/bin/bash" > $OPT_DIR/bin/$name
518
+ echo "java $extra -jar '$OPT_JAR_DIR/$name.jar'" >> $OPT_DIR/bin/$name
519
+
520
+ chmod +x $OPT_DIR/bin/$name
521
+ }
522
+
523
+ # vim: ft=sh
@@ -0,0 +1,16 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestCaseInsensitiveHash < Test::Unit::TestCase
5
+ def test_case_insensitive_hash
6
+ a = {:a => 1, "b" => 2}
7
+ a.extend CaseInsensitiveHash
8
+
9
+ assert_equal 1, a[:a]
10
+ assert_equal 1, a["A"]
11
+ assert_equal 1, a[:A]
12
+ assert_equal 2, a["B"]
13
+ assert_equal 2, a[:b]
14
+ end
15
+ end
16
+
@@ -0,0 +1,46 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestOptions < Test::Unit::TestCase
5
+
6
+
7
+ def test_add_defaults
8
+ options = {:a => 1, "b" => 2}
9
+ assert_equal 2, IndiferentHash.add_defaults(options, :b => 3)["b"]
10
+ assert_equal 2, IndiferentHash.add_defaults(options, "b" => 3)["b"]
11
+ assert_equal 3, IndiferentHash.add_defaults(options, :c => 3)["c"]
12
+ assert_equal 3, IndiferentHash.add_defaults(options, "c" => 4)[:c]
13
+ assert_equal 3, IndiferentHash.add_defaults(options, "c" => 4)["c"]
14
+ end
15
+
16
+ def test_positions2hash
17
+ inputs = IndiferentHash.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
18
+ assert_equal 1, inputs[:one]
19
+ assert_equal 2, inputs[:two]
20
+ assert_equal nil, inputs[:three]
21
+ assert_equal nil, inputs[:four]
22
+ end
23
+
24
+ def test_process_to_hash
25
+ list = [1,2,3,4]
26
+ assert_equal 4, IndiferentHash.process_to_hash(list){|l| l.collect{|e| e * 2 } }[2]
27
+ end
28
+
29
+ def test_hash2string
30
+ hash = {}
31
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
32
+
33
+ hash = {:a => 1}
34
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
35
+
36
+ hash = {:a => true}
37
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
38
+
39
+ hash = {:a => :b}
40
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
41
+
42
+ hash = {:a => /test/}
43
+ assert_equal({}, IndiferentHash.string2hash(IndiferentHash.hash2string(hash)))
44
+ end
45
+ end
46
+
File without changes
@@ -0,0 +1,108 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestProgress < Test::Unit::TestCase
5
+ SLEEP_TIME=0.0001
6
+ def test_bar
7
+ t1 = Thread.new do
8
+ Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
9
+ 20.times do
10
+ bar.tick
11
+ sleep SLEEP_TIME
12
+ end
13
+ Log.debug "Done progress"
14
+ assert_equal 100, bar.percent
15
+ end
16
+ end
17
+
18
+ t2 = Thread.new do
19
+ Log::ProgressBar.with_bar(20, :desc => "Bar 2") do |bar|
20
+ 20.times do
21
+ bar.tick
22
+ sleep SLEEP_TIME
23
+ end
24
+ Log.debug "Done progress"
25
+ assert_equal 100, bar.percent
26
+ end
27
+ end
28
+ t1.join
29
+ t2.join
30
+ end
31
+
32
+ def test_bar_no_size
33
+ t1 = Thread.new do
34
+ Log::ProgressBar.with_bar(nil, :desc => "Bar 1", :frequency => 0) do |bar|
35
+ 20.times do
36
+ bar.tick
37
+ sleep SLEEP_TIME
38
+ end
39
+ assert bar.history.length > 0
40
+ end
41
+ end
42
+
43
+ t2 = Thread.new do
44
+ Log::ProgressBar.with_bar(nil, :desc => "Bar 2", :frequency => 0) do |bar|
45
+ 20.times do
46
+ bar.tick
47
+ sleep SLEEP_TIME
48
+ end
49
+ assert bar.history.length > 0
50
+ end
51
+ end
52
+ t1.join
53
+ t2.join
54
+ end
55
+
56
+ def test_bar_nested
57
+ Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
58
+ bar.init
59
+ 20.times do
60
+ Log::ProgressBar.with_bar(5, :desc => "Bar 2") do |bar|
61
+ 5.times do
62
+ bar.tick
63
+ sleep SLEEP_TIME
64
+ end
65
+ end
66
+ bar.tick
67
+ sleep SLEEP_TIME
68
+ end
69
+ end
70
+ end
71
+
72
+ def test_pos
73
+ size = 10000
74
+
75
+ Log::ProgressBar.with_bar(size, :desc => "Bar 1") do |bar|
76
+ bar.init
77
+ nums = []
78
+ 100.times do
79
+ nums << rand(size)
80
+ end
81
+ nums.sort.each do |num|
82
+ bar.pos num
83
+ sleep SLEEP_TIME
84
+ end
85
+ bar.tick
86
+ end
87
+ end
88
+
89
+ def test_file
90
+ size = 10000
91
+
92
+ TmpFile.with_file do |file|
93
+
94
+ Log::ProgressBar.with_bar(size, :desc => "Bar 1", :file => file) do |bar|
95
+ bar.init
96
+ nums = []
97
+ 100.times do
98
+ nums << rand(size)
99
+ end
100
+ nums.sort.each do |num|
101
+ bar.pos num
102
+ sleep SLEEP_TIME
103
+ end
104
+ bar.tick
105
+ end
106
+ end
107
+ end
108
+ end