sprout 0.7.246 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/CHANGELOG.md +10 -0
- data/Gemfile +28 -0
- data/MIT-LICENSE +3 -2
- data/POSTINSTALL.rdoc +28 -0
- data/README.textile +152 -0
- data/bin/sprout +1 -131
- data/bin/sprout-generator +10 -0
- data/bin/sprout-library +11 -0
- data/bin/sprout-tool +10 -0
- data/lib/sprout.rb +4 -500
- data/lib/sprout/archive_unpacker.rb +122 -206
- data/lib/sprout/base.rb +90 -0
- data/lib/sprout/concern.rb +30 -0
- data/lib/sprout/dir.rb +23 -0
- data/lib/sprout/errors.rb +94 -0
- data/lib/sprout/executable.rb +496 -0
- data/lib/sprout/executable/boolean.rb +35 -0
- data/lib/sprout/executable/collection_param.rb +53 -0
- data/lib/sprout/executable/file_param.rb +53 -0
- data/lib/sprout/executable/files.rb +26 -0
- data/lib/sprout/executable/number.rb +10 -0
- data/lib/sprout/executable/param.rb +222 -0
- data/lib/sprout/executable/parameter_factory.rb +28 -0
- data/lib/sprout/executable/path.rb +21 -0
- data/lib/sprout/executable/paths.rb +21 -0
- data/lib/sprout/executable/string_param.rb +15 -0
- data/lib/sprout/executable/strings.rb +11 -0
- data/lib/sprout/executable/url.rb +10 -0
- data/lib/sprout/executable/urls.rb +10 -0
- data/lib/sprout/file_target.rb +76 -0
- data/lib/sprout/generator/base.rb +233 -0
- data/lib/sprout/generator/command.rb +67 -0
- data/lib/sprout/generator/directory_manifest.rb +49 -0
- data/lib/sprout/generator/file_manifest.rb +55 -0
- data/lib/sprout/generator/manifest.rb +13 -0
- data/lib/sprout/generator/template_manifest.rb +13 -0
- data/lib/sprout/generators/generator/generator_generator.rb +48 -0
- data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
- data/lib/sprout/generators/generator/templates/generator_executable +9 -0
- data/lib/sprout/generators/generator/templates/generator_template +1 -0
- data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
- data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
- data/lib/sprout/generators/library/library_generator.rb +20 -0
- data/lib/sprout/generators/library/templates/library.gemspec +19 -0
- data/lib/sprout/generators/library/templates/library.rb +15 -0
- data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
- data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
- data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
- data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
- data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
- data/lib/sprout/generators/tool/templates/Gemfile +4 -0
- data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
- data/lib/sprout/generators/tool/templates/tool.rb +38 -0
- data/lib/sprout/generators/tool/tool_generator.rb +36 -0
- data/lib/sprout/library.rb +111 -0
- data/lib/sprout/log.rb +1 -0
- data/lib/sprout/platform.rb +71 -0
- data/lib/sprout/process_runner.rb +80 -40
- data/lib/sprout/progress_bar.rb +341 -0
- data/lib/sprout/rdoc_parser.rb +91 -0
- data/lib/sprout/remote_file_loader.rb +72 -50
- data/lib/sprout/remote_file_target.rb +44 -152
- data/lib/sprout/ruby_feature.rb +167 -0
- data/lib/sprout/specification.rb +197 -0
- data/lib/sprout/string.rb +19 -0
- data/lib/sprout/system.rb +35 -0
- data/lib/sprout/system/base_system.rb +225 -0
- data/lib/sprout/system/java_system.rb +9 -0
- data/lib/sprout/system/osx_system.rb +26 -0
- data/lib/sprout/system/unix_system.rb +72 -0
- data/lib/sprout/system/vista_system.rb +16 -0
- data/lib/sprout/system/win_nix_system.rb +41 -0
- data/lib/sprout/system/win_system.rb +76 -0
- data/lib/sprout/test/sprout_test_case.rb +211 -0
- data/lib/sprout/version.rb +9 -4
- data/rakefile.rb +85 -144
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/sprout.gemspec +26 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
- data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
- data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
- data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
- data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
- data/test/fixtures/examples/app_generator.rb +127 -0
- data/test/fixtures/examples/echo_inputs.rb +151 -0
- data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
- data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
- data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
- data/test/fixtures/executable/mxmlc.rb +805 -0
- data/test/fixtures/executable/params/input.as +0 -0
- data/test/fixtures/executable/params/input2.as +0 -0
- data/test/fixtures/executable/params/input3.as +0 -0
- data/test/fixtures/executable/params/mxmlc +5 -0
- data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
- data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
- data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
- data/test/fixtures/executable/paths/folder1/file1 +0 -0
- data/test/fixtures/executable/paths/folder1/file2 +0 -0
- data/test/fixtures/executable/paths/folder1/file3 +0 -0
- data/test/fixtures/executable/paths/folder2/file4 +0 -0
- data/test/fixtures/executable/paths/folder2/file5 +0 -0
- data/test/fixtures/executable/paths/folder3/file6 +0 -0
- data/test/fixtures/executable/src/Main.as +0 -0
- data/test/fixtures/executable/windows_line_endings +47 -0
- data/test/fixtures/generators/song_generator.rb +11 -0
- data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
- data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
- data/test/fixtures/generators/temp_generator.rb +24 -0
- data/test/fixtures/generators/templates/Main.as +9 -0
- data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
- data/test/fixtures/generators/templates/SomeFile +1 -0
- data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
- data/test/fixtures/generators/templates/Song.txt +3 -0
- data/test/fixtures/generators/templates/destroy +0 -0
- data/test/fixtures/generators/templates/generate +0 -0
- data/test/fixtures/library/archive/Archive.swc +0 -0
- data/test/fixtures/library/sources/lib/a/A.as +0 -0
- data/test/fixtures/library/sources/lib/b/B.as +0 -0
- data/test/fixtures/library/sources/src/Source.as +0 -0
- data/test/fixtures/process_runner/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/failure +5 -0
- data/test/fixtures/process_runner/success +4 -0
- data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
- data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
- data/test/fixtures/remote_file_target/bin/echochamber +3 -0
- data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
- data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
- data/test/fixtures/specification/asunit4.rb +25 -0
- data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
- data/test/fixtures/specification/flashplayer.rb +30 -0
- data/test/fixtures/specification/flex4sdk.rb +72 -0
- data/test/fixtures/specification/flexunit4.sproutspec +17 -0
- data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
- data/test/fixtures/specification/src/AsUnit.as +0 -0
- data/test/fixtures/user/mxmlc_crlf +3 -0
- data/test/unit/archive_unpacker_test.rb +108 -0
- data/test/unit/boolean_param_test.rb +38 -0
- data/test/unit/executable_option_parser_test.rb +142 -0
- data/test/unit/executable_param_test.rb +76 -0
- data/test/unit/executable_test.rb +237 -0
- data/test/unit/fake_executable_task.rb +22 -0
- data/test/unit/fake_other_executable.rb +20 -0
- data/test/unit/fake_process_runner.rb +29 -0
- data/test/unit/file_param_test.rb +61 -0
- data/test/unit/file_target_test.rb +42 -0
- data/test/unit/files_param_test.rb +72 -0
- data/test/unit/generator_generator_test.rb +85 -0
- data/test/unit/generator_test.rb +333 -0
- data/test/unit/library_generator_test.rb +41 -0
- data/test/unit/library_test.rb +88 -0
- data/test/unit/osx_system_test.rb +20 -0
- data/test/unit/path_param_test.rb +43 -0
- data/test/unit/paths_param_test.rb +53 -0
- data/test/unit/platform_test.rb +76 -0
- data/test/unit/process_runner_test.rb +104 -0
- data/test/unit/rdoc_parser_test.rb +15 -0
- data/test/unit/remote_file_loader_test.rb +34 -0
- data/test/unit/remote_file_target_test.rb +105 -0
- data/test/unit/ruby_feature_test.rb +108 -0
- data/test/unit/ruby_generator_test.rb +70 -0
- data/test/unit/specification_test.rb +73 -0
- data/test/unit/sprout_test.rb +170 -0
- data/test/unit/sprout_test_helper.rb +18 -0
- data/test/unit/string_param_test.rb +19 -0
- data/test/unit/string_test.rb +20 -0
- data/test/unit/strings_param_test.rb +27 -0
- data/test/unit/test_helper.rb +1 -0
- data/test/unit/tool_generator_test.rb +43 -0
- data/test/unit/unix_system_test.rb +52 -0
- data/test/unit/user_test.rb +147 -0
- data/test/unit/vista_system_test.rb +40 -0
- data/test/unit/win_nix_system_test.rb +26 -0
- data/test/unit/win_system_test.rb +61 -0
- metadata +318 -113
- data/doc/Bundle +0 -14
- data/doc/Generator +0 -35
- data/doc/Library +0 -63
- data/doc/Task +0 -21
- data/doc/Tool +0 -20
- data/lib/platform.rb +0 -113
- data/lib/progress_bar.rb +0 -354
- data/lib/sprout/builder.rb +0 -51
- data/lib/sprout/bundle_resolver.rb +0 -349
- data/lib/sprout/commands/generate.rb +0 -9
- data/lib/sprout/dynamic_accessors.rb +0 -40
- data/lib/sprout/general_tasks.rb +0 -6
- data/lib/sprout/generator.rb +0 -7
- data/lib/sprout/generator/base_mixins.rb +0 -186
- data/lib/sprout/generator/named_base.rb +0 -227
- data/lib/sprout/project_model.rb +0 -278
- data/lib/sprout/simple_resolver.rb +0 -88
- data/lib/sprout/tasks/erb_resolver.rb +0 -118
- data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
- data/lib/sprout/tasks/git_task.rb +0 -134
- data/lib/sprout/tasks/library_task.rb +0 -118
- data/lib/sprout/tasks/sftp_task.rb +0 -248
- data/lib/sprout/tasks/ssh_task.rb +0 -153
- data/lib/sprout/tasks/tool_task.rb +0 -836
- data/lib/sprout/tasks/zip_task.rb +0 -158
- data/lib/sprout/tool_task_model.rb +0 -19
- data/lib/sprout/user.rb +0 -415
- data/lib/sprout/version_file.rb +0 -89
- data/lib/sprout/zip_util.rb +0 -61
- data/samples/gem_wrap/rakefile.rb +0 -17
data/doc/Bundle
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
|
2
|
-
A Sprout Bundle is a collection of Ruby code that supports a particular interest or technology. At the time of this writing, we have two bundles available.
|
3
|
-
|
4
|
-
* ActionScript 2 Bundle (link[link:files/bundles/as2/README.html]) which supports ActionScript 2.0 development
|
5
|
-
* ActionScript 3 Bundle (link[link:files/bundles/as3/README.html]) which supports ActionScript 3.0, MXML and AIR development
|
6
|
-
|
7
|
-
Bundles are the named entry point that the +sprout+ shell tool uses to find project generators[link:files/doc/Generator.html].
|
8
|
-
|
9
|
-
Bundles should be packaged and published to the RubyForge gem repository with very specific names as follows:
|
10
|
-
|
11
|
-
sprout-#{bundle_name}-bundle where ${bundle_name} is what will be given to the -n parameter of the +sprout+ gem.
|
12
|
-
|
13
|
-
The as3 bundle is released as sprout-as3-bundle on RubyForge, but we can simply enter the short name when creating new as3 projects.
|
14
|
-
|
data/doc/Generator
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
A SproutGenerator is a set of specifically configured folders and files that have been placed in a particular, expected location on disk.
|
2
|
-
The Sprout generator feature is a minor modification to the standard Rubigen generators.
|
3
|
-
|
4
|
-
Sprouts modifies the underlying Rubigen Generator implementation in that we need support for multiple languages or technologies while Rubigen is able to simply expect that it's generating Ruby code.
|
5
|
-
|
6
|
-
Generators can exist in multiple different locations on disk, to learn how to create a new generator, see the Rubigen documentation[http://rubigen.rubyforge.org/].
|
7
|
-
|
8
|
-
To use a new or existing generator, simply enter it's name from within a project after calling
|
9
|
-
script/generate
|
10
|
-
|
11
|
-
When a string is passed to the generate command, sprouts will look in the following locations in the following order with 'name' being the generator name that you have requested:
|
12
|
-
* #{project_path}/generators/#{name}
|
13
|
-
* #{project_path}/script/generators/#{name}
|
14
|
-
* #{project_path}/vendor/generators/#{name}
|
15
|
-
* #{Sprout::Sprout.sprout_cache}/generators/#{Sprout::ProjectModel.language}/#{name}
|
16
|
-
* All Rubygems with a name ending with '-bundle' and with contents that match '/lib/sprout/**/generators/[name]'
|
17
|
-
|
18
|
-
This means that when you have a new project and enter:
|
19
|
-
script/generate foo
|
20
|
-
|
21
|
-
We will first look in your project for, 'generators/foo', 'script/generators/foo' and 'vendor/generators/foo'.
|
22
|
-
|
23
|
-
Assuming no viable generator is found in your project, we will then look in your Sprout::Sprout sprout_cache for a folder named 'generators/foo'.
|
24
|
-
|
25
|
-
Assuming no viable generator is found in your system wide path, we will begin looking inside of installed Ruby Gems. The expected gem will have a file at:
|
26
|
-
|
27
|
-
lib/sprout/**/generators/foo/foo_generator.rb
|
28
|
-
|
29
|
-
If no named generator is found in any of these places an exception will be encountered.
|
30
|
-
|
31
|
-
Sprouts generators can be initiated from one of two places, either from a project directory with script/generate or directly from the Sprout gem.
|
32
|
-
|
33
|
-
When executing generators directly from the Sprout gem, you must send in a bundle base name and know that only 'project' generators found in that bundle will be executed.
|
34
|
-
|
35
|
-
When executing generators from a project, the Sprout::ProjectModel language parameter is used to determine the bundle (if necessary), and then the Generator name is used to execute any found generator.
|
data/doc/Library
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
|
2
|
-
A Library is simply shared code. Some libraries are distributed with only source, others are only pre-compiled binaries (SWC for ActionScript libraries), and still others are made available in both forms.
|
3
|
-
|
4
|
-
The Sprout::LibraryTask will download and copy a remote library sprout gem.
|
5
|
-
The remote archive can include (or reference) either source or a pre-compiled
|
6
|
-
file. For ActionScript libraries, this would be a SWC file.
|
7
|
-
|
8
|
-
This task is integrated with some of the compiler tasks in such
|
9
|
-
a way that if an Sprout::MXMLCTask has any number of library tasks in
|
10
|
-
it's prerequisites list, each of those libraries will be added
|
11
|
-
to the compiler directive appropriately.
|
12
|
-
|
13
|
-
Following is a simple example of a library task. Using only
|
14
|
-
this simple task definition, the Adobe corelib library sprout gem
|
15
|
-
will be downloaded, installed and copied to your Sprout::ProjectModel +lib_dir+.
|
16
|
-
|
17
|
-
library :corelib
|
18
|
-
|
19
|
-
By adding this named task as a prerequisite to your compilation task,
|
20
|
-
that SWC will also be added to the Sprout::MXMLCTask +library_path+ parameter.
|
21
|
-
|
22
|
-
mxmlc 'bin/SomeProject.swf' => :corelib
|
23
|
-
|
24
|
-
You can also specify a particular library gem version if the library
|
25
|
-
has changed since your project began.
|
26
|
-
|
27
|
-
library :asunit3 do |t|
|
28
|
-
t.version = '3.0.1'
|
29
|
-
end
|
30
|
-
|
31
|
-
This will ensure that only that particular library version is used for this project.
|
32
|
-
|
33
|
-
You may want to refer to a library using a particular task name, but have it
|
34
|
-
use a different library sprout gem. This can be done using the gem_name parameter
|
35
|
-
as follows:
|
36
|
-
|
37
|
-
library :asunit do |t|
|
38
|
-
t.gem_name = 'sprout-asunit3-library'
|
39
|
-
end
|
40
|
-
|
41
|
-
This may be useful because now the AsUnit[http://www.asunit.org] sources will be installed to:
|
42
|
-
lib/asunit
|
43
|
-
instead of:
|
44
|
-
lib/asunit3
|
45
|
-
and you can now depend on this library as simply +:asunit+ in your compiler tasks.
|
46
|
-
|
47
|
-
You can easily create your own library gems using the Sprout::GemWrapTask and then
|
48
|
-
refer to them by gem name.
|
49
|
-
|
50
|
-
In order to share your library tasks, you will need to
|
51
|
-
do one of the following:
|
52
|
-
|
53
|
-
* Tell interested developers to manually install your library gem
|
54
|
-
* Upload your gem to any Rubyforge[http://www.rubyforge.org] project file releases area.
|
55
|
-
If your gem name begins with 'sprout-' and ends with '-library', you (and others) can refer to it by only
|
56
|
-
the string in between that prefix and suffix. Otherwise, you (and others) will always have
|
57
|
-
to set the gem_name parameter to the full name of your custom library.
|
58
|
-
* Submit your library for inclusion from the ProjectSprouts[http://www.projectsprouts.org] project.
|
59
|
-
* Add your gem to your own custom gem_server[http://rambleon.org/2007/04/19/creating-your-own-gem-server/], and set up your rakefiles to pull from that server
|
60
|
-
|
61
|
-
You can search for all available libraries as follows:
|
62
|
-
gem search -r sprout-*library
|
63
|
-
Only results that begin with 'sprout-' are known, valid libraries.
|
data/doc/Task
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
In Sprouts, a Task is referring to a Rake[http://rake.rubyforge.org/] Task.
|
2
|
-
|
3
|
-
Rake is the automated build to written in Ruby. This tool is similar to Ant[http://ant.apache.org/] and Make[http://www.gnu.org/software/make/] if you're familiar with those technologies.
|
4
|
-
|
5
|
-
The main thing that differentiates Rake from it's competitors is the fact that Rake tasks are defined and configured in Ruby code rather than XML or C. This lets us more easily avoid repetition throughout a rakefile, and we gain the full power of the Ruby language to apply to our build scripts.
|
6
|
-
|
7
|
-
Essentially, Rake allows us to write and maintain much smaller, more digestible build scripts.
|
8
|
-
|
9
|
-
To learn more about Rake, check out Martin Fowler's seminal article[http://martinfowler.com/articles/rake.html] on the subject.
|
10
|
-
|
11
|
-
At the time of this writing, Sprouts makes the following Rake tasks available:
|
12
|
-
* Core Sprout::SFTPTask
|
13
|
-
* Core Sprout::ZipTask
|
14
|
-
* Core Sprout::LibraryTask
|
15
|
-
* As3Bundle Sprout::AsDocTask
|
16
|
-
* As3Bundle Sprout::AsUnitTask
|
17
|
-
* As3Bundle Sprout::COMPCTask
|
18
|
-
* As3Bundle Sprout::MXMLCTask
|
19
|
-
* As2Bundle Sprout::MTASCTask
|
20
|
-
* As2Bundle Sprout::SWFMillTask
|
21
|
-
|
data/doc/Tool
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
A Tool is a Ruby Gem that usually refers to an executable or binary application.
|
3
|
-
These applications are either natively cross platform, or the Ruby Gem should include a
|
4
|
-
YAML document that tells Sprouts where to go in order to get the appropriate binary for
|
5
|
-
which platform the user is currently running.
|
6
|
-
|
7
|
-
CLI Tools are usually referenced by subclasses of Sprout::ToolTask.
|
8
|
-
|
9
|
-
Once installed, many Tool Sprouts are made available from your path. For example
|
10
|
-
if you install the sprout-mtasc-tool gem, from that point forward you can execute mtasc
|
11
|
-
from the terminal as follows:
|
12
|
-
|
13
|
-
mtasc -help # Should throw an error
|
14
|
-
sudo gem install sprout-mtasc-tool
|
15
|
-
mtasc -help # Should download and execute mtasc
|
16
|
-
|
17
|
-
Using just Sprout tools by themselves, we now have have the ability to install and manage
|
18
|
-
requisite executables across platforms with zero configuration.
|
19
|
-
|
20
|
-
In reality, 'Tool Sprouts' are actually nothing more than a naming convention and expected gem configuration, but once those requirements are met, the core Sprout::Sprout can do some important work with them.
|
data/lib/platform.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# platform.rb: naive platform detection for Ruby
|
3
|
-
# author: Matt Mower
|
4
|
-
#
|
5
|
-
# == Platform
|
6
|
-
#
|
7
|
-
# Platform is a simple module which parses the Ruby constant
|
8
|
-
# RUBY_PLATFORM and works out the OS, it's implementation,
|
9
|
-
# and the architecture it's running on.
|
10
|
-
#
|
11
|
-
# The motivation for writing this was coming across a case where
|
12
|
-
#
|
13
|
-
# +if RUBY_PLATFORM =~ /win/+
|
14
|
-
#
|
15
|
-
# didn't behave as expected (i.e. on powerpc-darwin-8.1.0)
|
16
|
-
#
|
17
|
-
# It is hoped that providing a library for parsing the platform
|
18
|
-
# means that we can cover all the cases and have something which
|
19
|
-
# works reliably 99% of the time.
|
20
|
-
#
|
21
|
-
# Please report any anomalies or new combinations to the author(s).
|
22
|
-
#
|
23
|
-
# == Use
|
24
|
-
#
|
25
|
-
# require "platform"
|
26
|
-
#
|
27
|
-
# defines
|
28
|
-
#
|
29
|
-
# Platform::OS (:unix,:win32,:vms,:os2)
|
30
|
-
# Platform::impl (:macosx,:linux,:mswin)
|
31
|
-
# Platform::arch (:powerpc,:x86,:alpha)
|
32
|
-
#
|
33
|
-
# if an unknown configuration is encountered any (or all) of
|
34
|
-
# these constant may have the value :unknown.
|
35
|
-
#
|
36
|
-
# To display the combination for your setup run
|
37
|
-
#
|
38
|
-
# ruby platform.rb
|
39
|
-
#
|
40
|
-
module Platform #:nodoc:
|
41
|
-
os = nil
|
42
|
-
impl = nil
|
43
|
-
arch = nil
|
44
|
-
|
45
|
-
if RUBY_PLATFORM =~ /darwin/i
|
46
|
-
os = :unix
|
47
|
-
impl = :macosx
|
48
|
-
elsif RUBY_PLATFORM =~ /linux/i
|
49
|
-
os = :unix
|
50
|
-
impl = :linux
|
51
|
-
elsif RUBY_PLATFORM =~ /freebsd/i
|
52
|
-
os = :unix
|
53
|
-
impl = :freebsd
|
54
|
-
elsif RUBY_PLATFORM =~ /netbsd/i
|
55
|
-
os = :unix
|
56
|
-
impl = :netbsd
|
57
|
-
elsif RUBY_PLATFORM =~ /solaris/i
|
58
|
-
os = :unix
|
59
|
-
impl = :linux # Our platform checks currently examine 'impl' instead of 'os'
|
60
|
-
elsif RUBY_PLATFORM =~ /vista/i
|
61
|
-
os = :win32
|
62
|
-
impl = :vista
|
63
|
-
elsif RUBY_PLATFORM =~ /mswin/i
|
64
|
-
os = :win32
|
65
|
-
impl = :mswin
|
66
|
-
elsif RUBY_PLATFORM =~ /cygwin/i
|
67
|
-
os = :win32
|
68
|
-
impl = :cygwin
|
69
|
-
elsif RUBY_PLATFORM =~ /mingw/i
|
70
|
-
os = :win32
|
71
|
-
impl = :mingw
|
72
|
-
elsif RUBY_PLATFORM =~ /bccwin/i
|
73
|
-
os = :win32
|
74
|
-
impl = :bccwin
|
75
|
-
elsif RUBY_PLATFORM =~ /wince/i
|
76
|
-
os = :win32
|
77
|
-
impl = :wince
|
78
|
-
elsif RUBY_PLATFORM =~ /vms/i
|
79
|
-
os = :vms
|
80
|
-
impl = :vms
|
81
|
-
elsif RUBY_PLATFORM =~ /os2/i
|
82
|
-
os = :os2
|
83
|
-
impl = :os2 # maybe there is some better choice here?
|
84
|
-
else
|
85
|
-
os = :unknown
|
86
|
-
impl = :unknown
|
87
|
-
end
|
88
|
-
|
89
|
-
# whither AIX, SOLARIS, and the other unixen?
|
90
|
-
# i386-solaris2.11
|
91
|
-
|
92
|
-
if RUBY_PLATFORM =~ /(i\d86)/i
|
93
|
-
arch = :x86
|
94
|
-
elsif RUBY_PLATFORM =~ /ia64/i
|
95
|
-
arch = :ia64
|
96
|
-
elsif RUBY_PLATFORM =~ /powerpc/i
|
97
|
-
arch = :powerpc
|
98
|
-
elsif RUBY_PLATFORM =~ /alpha/i
|
99
|
-
arch = :alpha
|
100
|
-
else
|
101
|
-
arch = :unknown
|
102
|
-
end
|
103
|
-
|
104
|
-
OS = os
|
105
|
-
IMPL = impl
|
106
|
-
ARCH = arch
|
107
|
-
# What about AMD, Turion, Motorola, etc..?
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
if __FILE__ == $0
|
112
|
-
puts "Platform OS=#{Platform::OS}, impl=#{Platform::IMPL}, arch=#{Platform::ARCH}"
|
113
|
-
end
|
data/lib/progress_bar.rb
DELETED
@@ -1,354 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ruby/ProgressBar - a text progress bar library
|
3
|
-
#
|
4
|
-
# Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
|
5
|
-
# All rights reserved.
|
6
|
-
# This is free software with ABSOLUTELY NO WARRANTY.
|
7
|
-
#
|
8
|
-
# You can redistribute it and/or modify it under the terms
|
9
|
-
# of Ruby's license.
|
10
|
-
#
|
11
|
-
# Modified by Luke Bayes to support progress display on
|
12
|
-
# multiple simultaneous connections
|
13
|
-
|
14
|
-
require 'singleton'
|
15
|
-
|
16
|
-
class ProgressBar # :nodoc:[all]
|
17
|
-
VERSION = "0.9"
|
18
|
-
@@debug = false
|
19
|
-
@@outio = $stderr
|
20
|
-
|
21
|
-
def self.new(title, total)
|
22
|
-
return ProgressBarManager.instance.add(title, total)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.debug?
|
26
|
-
@@debug
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.debug=(debug)
|
30
|
-
@@debug = debug
|
31
|
-
if(debug)
|
32
|
-
@@outio = StringIO.new
|
33
|
-
else
|
34
|
-
@@outio = $stderr
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.outio
|
39
|
-
@@outio
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class ProgressBarImpl # :nodoc:[all]
|
45
|
-
|
46
|
-
def initialize (title, total, out = STDERR)
|
47
|
-
@title = title
|
48
|
-
@total = total
|
49
|
-
@out = out
|
50
|
-
@terminal_width = 80
|
51
|
-
@bar_mark = "."
|
52
|
-
@current = 0
|
53
|
-
@previous = 0
|
54
|
-
@finished_p = false
|
55
|
-
@start_time = Time.now
|
56
|
-
@previous_time = @start_time
|
57
|
-
@title_width = 18
|
58
|
-
@format = "%-#{@title_width}s %3d%% %s %s"
|
59
|
-
@format_arguments = [:title, :percentage, :bar, :stat]
|
60
|
-
clear
|
61
|
-
show
|
62
|
-
end
|
63
|
-
attr_reader :title
|
64
|
-
attr_reader :current
|
65
|
-
attr_reader :total
|
66
|
-
attr_accessor :start_time,
|
67
|
-
:title_width,
|
68
|
-
:bar_mark
|
69
|
-
|
70
|
-
def fmt_bar
|
71
|
-
bar_width = do_percentage * @terminal_width / 100
|
72
|
-
sprintf("|%s%s|",
|
73
|
-
@bar_mark * bar_width,
|
74
|
-
" " * (@terminal_width - bar_width))
|
75
|
-
end
|
76
|
-
|
77
|
-
def fmt_percentage
|
78
|
-
do_percentage
|
79
|
-
end
|
80
|
-
|
81
|
-
def fmt_stat
|
82
|
-
if @finished_p then elapsed else eta end
|
83
|
-
end
|
84
|
-
|
85
|
-
def fmt_stat_for_file_transfer
|
86
|
-
if @finished_p then
|
87
|
-
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
88
|
-
else
|
89
|
-
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def fmt_title
|
94
|
-
@title[0,(@title_width - 1)] + ":"
|
95
|
-
end
|
96
|
-
|
97
|
-
def convert_bytes (bytes)
|
98
|
-
if bytes < 1024
|
99
|
-
sprintf("%6dB", bytes)
|
100
|
-
elsif bytes < 1024 * 1000 # 1000kb
|
101
|
-
sprintf("%5.1fKB", bytes.to_f / 1024)
|
102
|
-
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
103
|
-
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
104
|
-
else
|
105
|
-
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def transfer_rate
|
110
|
-
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
111
|
-
sprintf("%s/s", convert_bytes(bytes_per_second))
|
112
|
-
end
|
113
|
-
|
114
|
-
def bytes
|
115
|
-
convert_bytes(@current)
|
116
|
-
end
|
117
|
-
|
118
|
-
def format_time (t)
|
119
|
-
t = t.to_i
|
120
|
-
sec = t % 60
|
121
|
-
min = (t / 60) % 60
|
122
|
-
hour = t / 3600
|
123
|
-
sprintf("%02d:%02d:%02d", hour, min, sec)
|
124
|
-
end
|
125
|
-
|
126
|
-
# ETA stands for Estimated Time of Arrival.
|
127
|
-
def eta
|
128
|
-
if @current == 0
|
129
|
-
"ETA: --:--:--"
|
130
|
-
else
|
131
|
-
elapsed_time = Time.now - @start_time
|
132
|
-
estimated_time = elapsed_time * @total / @current - elapsed_time
|
133
|
-
sprintf("ETA: %s", format_time(estimated_time))
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def elapsed
|
138
|
-
elapsed_time = Time.now - @start_time
|
139
|
-
sprintf("Time: %s", format_time(elapsed_time))
|
140
|
-
end
|
141
|
-
|
142
|
-
def eol
|
143
|
-
if @finished_p then "\n" else "\r" end
|
144
|
-
end
|
145
|
-
|
146
|
-
def do_percentage
|
147
|
-
if @total.zero?
|
148
|
-
100
|
149
|
-
else
|
150
|
-
@current * 100 / @total
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def get_width
|
155
|
-
# return 80
|
156
|
-
# FIXME: I don't know how portable it is.
|
157
|
-
default_width = 80
|
158
|
-
begin
|
159
|
-
tiocgwinsz = 0x5413
|
160
|
-
data = [0, 0, 0, 0].pack("SSSS")
|
161
|
-
if @out.ioctl(tiocgwinsz, data) >= 0 then
|
162
|
-
unpacked = data.unpack("SSSS")
|
163
|
-
cols = unpacked[1]
|
164
|
-
# Commented this because Aptana was complaining about
|
165
|
-
# The unused variables
|
166
|
-
# rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
167
|
-
if cols >= 0 then cols else default_width end
|
168
|
-
else
|
169
|
-
default_width
|
170
|
-
end
|
171
|
-
rescue Exception
|
172
|
-
default_width
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def show
|
177
|
-
arguments = @format_arguments.map do |method|
|
178
|
-
method = sprintf("fmt_%s", method)
|
179
|
-
send(method)
|
180
|
-
end
|
181
|
-
line = sprintf(@format, *arguments)
|
182
|
-
|
183
|
-
width = get_width
|
184
|
-
if(line.length == width - 1)
|
185
|
-
@out.print(line + eol)
|
186
|
-
@out.flush
|
187
|
-
elsif(line.length >= width)
|
188
|
-
@terminal_width = [@terminal_width - (line.length - width + 1), 0].max
|
189
|
-
if @terminal_width == 0 then @out.print(line + eol) else show end
|
190
|
-
else # line.length < width - 1
|
191
|
-
@terminal_width += width - line.length + 1
|
192
|
-
show
|
193
|
-
end
|
194
|
-
@previous_time = Time.now
|
195
|
-
end
|
196
|
-
|
197
|
-
def show_if_needed
|
198
|
-
if @total.zero?
|
199
|
-
cur_percentage = 100
|
200
|
-
prev_percentage = 0
|
201
|
-
else
|
202
|
-
cur_percentage = (@current * 100 / @total).to_i
|
203
|
-
prev_percentage = (@previous * 100 / @total).to_i
|
204
|
-
end
|
205
|
-
|
206
|
-
# Use "!=" instead of ">" to support negative changes
|
207
|
-
if cur_percentage != prev_percentage ||
|
208
|
-
Time.now - @previous_time >= 1 || @finished_p
|
209
|
-
show
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
public
|
214
|
-
def clear
|
215
|
-
@out.print "\r"
|
216
|
-
@out.print(" " * (get_width - 1))
|
217
|
-
@out.print "\r"
|
218
|
-
end
|
219
|
-
|
220
|
-
def finish
|
221
|
-
@current = @total
|
222
|
-
@finished_p = true
|
223
|
-
show
|
224
|
-
end
|
225
|
-
|
226
|
-
def finished?
|
227
|
-
@finished_p
|
228
|
-
end
|
229
|
-
|
230
|
-
def file_transfer_mode
|
231
|
-
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
232
|
-
end
|
233
|
-
|
234
|
-
def format= (format)
|
235
|
-
@format = format
|
236
|
-
end
|
237
|
-
|
238
|
-
def format_arguments= (arguments)
|
239
|
-
@format_arguments = arguments
|
240
|
-
end
|
241
|
-
|
242
|
-
def halt
|
243
|
-
@finished_p = true
|
244
|
-
show
|
245
|
-
end
|
246
|
-
|
247
|
-
def inc (step = 1)
|
248
|
-
@current += step
|
249
|
-
@current = @total if @current > @total
|
250
|
-
show_if_needed
|
251
|
-
@previous = @current
|
252
|
-
end
|
253
|
-
|
254
|
-
def set (count)
|
255
|
-
if count < 0 || count > @total
|
256
|
-
@total = count
|
257
|
-
end
|
258
|
-
@current = count
|
259
|
-
show_if_needed
|
260
|
-
@previous = @current
|
261
|
-
end
|
262
|
-
|
263
|
-
def inspect
|
264
|
-
"#<ProgressBar:#{@current}/#{@total}>"
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
# Used instead of $stderr when Log.debug == true
|
269
|
-
# This helps keep us from junking up unit test
|
270
|
-
# output with download status messages
|
271
|
-
class MockOutput # :nodoc:[all]
|
272
|
-
def print(str)
|
273
|
-
end
|
274
|
-
|
275
|
-
def puts(str)
|
276
|
-
end
|
277
|
-
|
278
|
-
def flush
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
class ReversedProgressBar < ProgressBar # :nodoc:[all]
|
283
|
-
def do_percentage
|
284
|
-
100 - super
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
class ProgressBarOutputStream # :nodoc:[all]
|
289
|
-
attr_reader :title
|
290
|
-
|
291
|
-
def initialize(mgr)
|
292
|
-
@mgr = mgr
|
293
|
-
@msg = ''
|
294
|
-
end
|
295
|
-
|
296
|
-
def print(msg)
|
297
|
-
@msg = msg
|
298
|
-
end
|
299
|
-
|
300
|
-
def flush
|
301
|
-
@mgr.flush
|
302
|
-
end
|
303
|
-
|
304
|
-
def to_s
|
305
|
-
return @msg.clone.split("\n").join("").split("\r").join("")
|
306
|
-
end
|
307
|
-
|
308
|
-
end
|
309
|
-
|
310
|
-
class ProgressBarManager # :nodoc:[all]
|
311
|
-
include Singleton
|
312
|
-
|
313
|
-
def initialize
|
314
|
-
@finished = {}
|
315
|
-
@bars = {}
|
316
|
-
@outs = {}
|
317
|
-
end
|
318
|
-
|
319
|
-
def add(title, total1)
|
320
|
-
# if(@bars[title])
|
321
|
-
# raise StandardError.new
|
322
|
-
# end
|
323
|
-
@outs[title] = ProgressBarOutputStream.new(self)
|
324
|
-
@bars[title] = ProgressBarImpl.new(title, total1, @outs[title])
|
325
|
-
end
|
326
|
-
|
327
|
-
def print(title)
|
328
|
-
str = ''
|
329
|
-
str += @outs[title].to_s
|
330
|
-
str += "\r"
|
331
|
-
outio.print "\r"
|
332
|
-
outio.print str
|
333
|
-
end
|
334
|
-
|
335
|
-
def outio
|
336
|
-
ProgressBar.outio
|
337
|
-
end
|
338
|
-
|
339
|
-
def flush
|
340
|
-
@bars.keys.each do |title|
|
341
|
-
print(title)
|
342
|
-
end
|
343
|
-
|
344
|
-
@bars.values.each do |bar|
|
345
|
-
if(bar.finished?)
|
346
|
-
print(bar.title)
|
347
|
-
outio.print "\n"
|
348
|
-
@outs.delete(bar.title)
|
349
|
-
@bars.delete(bar.title)
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
end
|