ubuntu_update 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f59e4d4351972df1f32366e0f1c181704a921ff2
4
+ data.tar.gz: e4f97553b7cc49dab98cb72e08de67795677afa7
5
+ SHA512:
6
+ metadata.gz: a776c72bb27be43da939e23093f0002b02c432d483563b848a4e51c54674f141ce82060add0de55aa2bb40328c9202e9fd56bb11b879a765e023a0abcce11cd1
7
+ data.tar.gz: 276bb7c10c0fd6ea2aec41d234e27f9ab54ab69c592acf53b3edd8c96f759e23251368bb1c828ba3da0f380216297a61fd2759e4d202b087a67473a157ab20d9
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ubuntu_update.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ gem 'mocha'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 taufekj
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # UbuntuUpdate
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ubuntu_update'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ubuntu_update
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/ubuntu_update/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ubuntu_update ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ubuntu_update'
3
+ require 'ubuntu_update/options_parser'
4
+ require 'ubuntu_update/command_executor'
5
+
6
+ options_parser = UbuntuUpdate::OptionsParser.new
7
+ options_parser.parse(ARGV)
8
+
9
+ command_executor = UbuntuUpdate::CommandExecutor.new
10
+
11
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
12
+ updater.execute_command
13
+
14
+
@@ -0,0 +1,10 @@
1
+
2
+ module UbuntuUpdate
3
+ class CommandExecutor
4
+
5
+ def execute(command)
6
+ exec command
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,53 @@
1
+ require 'optparse'
2
+
3
+ module UbuntuUpdate
4
+ class OptionsParser
5
+
6
+ def initialize
7
+
8
+ end
9
+
10
+ def parse arguments
11
+ @options = {}
12
+
13
+
14
+ @option_parser = OptionParser.new do |opts|
15
+
16
+ opts.banner = "Usage: ubuntu_upgrade.rb [options]"
17
+
18
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
19
+ @options[:verbose] = v
20
+ end
21
+
22
+ opts.on("-p", "--update", "Run apt-get update") do |p|
23
+ @options[:update] = p
24
+ end
25
+
26
+ opts.on("-g", "--upgrade", "Run apt-get update") do |g|
27
+ @options[:upgrade] = g
28
+ end
29
+
30
+ opts.on("-h", "--help", "Show usage summary") do |h|
31
+ @options[:help] = h
32
+ @summary = opts.help
33
+ end
34
+ end
35
+
36
+ @option_parser.parse! arguments
37
+
38
+ @options
39
+ end
40
+
41
+ def get_summary
42
+ @summary
43
+ end
44
+
45
+ def get_engine
46
+ @option_parser
47
+ end
48
+
49
+ def get_options
50
+ @options
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module UbuntuUpdate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,77 @@
1
+ require "ubuntu_update/version"
2
+
3
+ module UbuntuUpdate
4
+ class Updater
5
+
6
+ @options_parser
7
+ @command_list
8
+ @@print_summary_command = "echo '%{summary}'"
9
+ @@apt_get_command = "sudo apt-get %{command}"
10
+ @resolved_command
11
+
12
+ def initialize (options_parser, command_executor)
13
+ @command_executor = command_executor
14
+ @options_parser = options_parser
15
+ @command_list = []
16
+ end
17
+
18
+ def execute_command
19
+ @command_executor.execute get_command
20
+ end
21
+
22
+ private
23
+
24
+ def get_command
25
+
26
+ build_commands
27
+
28
+ join_commands
29
+ end
30
+
31
+ def join_commands
32
+ @command_list * " && "
33
+ end
34
+
35
+ def build_commands
36
+ if @options_parser.get_options.has_key? (:help)
37
+ @command_list.push(get_print_summary)
38
+ else
39
+ if @options_parser.get_options.has_key? (:update) or
40
+ options_does_not_contains_any_command?
41
+ @command_list.push(get_update)
42
+ end
43
+ if @options_parser.get_options.has_key? (:upgrade)
44
+ @command_list.push(get_upgrade)
45
+ end
46
+ end
47
+ end
48
+
49
+ def options_does_not_contains_any_command?
50
+ not [:update, :upgrade].any? {|k| @options_parser.get_options.key?(k)}
51
+ end
52
+
53
+ def get_print_summary
54
+ @@print_summary_command % {:summary => @options_parser.get_summary}
55
+ end
56
+
57
+ def get_update
58
+ resolve_command(:update)
59
+ end
60
+
61
+ def get_upgrade
62
+ upgrade_command = "upgrade%{confirm}"
63
+
64
+ if @options_parser.get_options[:yes]
65
+ confirm = " -y"
66
+ else
67
+ confirm = ""
68
+ end
69
+ upgrade_command = upgrade_command % {:confirm => confirm}
70
+ resolve_command(upgrade_command)
71
+ end
72
+
73
+ def resolve_command(command)
74
+ @@apt_get_command % {:command => command}
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,2 @@
1
+ require 'spec_helper'
2
+
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'ubuntu_update/options_parser'
3
+
4
+ describe UbuntuUpdate::OptionsParser, "#get_summary" do
5
+ # it "it should print out usage syntax" do
6
+ # options_parser = UbuntuUpdate::OptionsParser.new
7
+ # options_parser.parse([])
8
+ # expect(options_parser.get_summary).to include("Usage: ubuntu_upgrade.rb [options]")
9
+ # expect(options_parser.get_summary).to include("-v, --[no-]verbose")
10
+ # expect(options_parser.get_options).not_to include(:verbose)
11
+ # end
12
+
13
+ it "it should contains :verbose when passed -v in the argument" do
14
+ options_parser = UbuntuUpdate::OptionsParser.new
15
+ options_parser.parse(["-v"])
16
+ expect(options_parser.get_options).to include({:verbose=>true})
17
+ end
18
+
19
+ it "it should contains :update when passed -p in the argument" do
20
+ options_parser = UbuntuUpdate::OptionsParser.new
21
+ options_parser.parse(["-p"])
22
+ expect(options_parser.get_options).to include({:update=>true})
23
+ end
24
+
25
+ it "it should contains :upgrade when passed -g in the argument" do
26
+ options_parser = UbuntuUpdate::OptionsParser.new
27
+ options_parser.parse(["-g"])
28
+ expect(options_parser.get_options).to include({:upgrade=>true})
29
+ end
30
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ #Added mocha integration for mocking
90
+ config.mock_framework = :mocha
91
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'ubuntu_update'
3
+ require 'ubuntu_update/options_parser'
4
+ require 'ubuntu_update/command_executor'
5
+
6
+
7
+ describe UbuntuUpdate::Updater, "#execute_command" do
8
+
9
+ it "it should show summary when --help is passed in" do
10
+ options_parser = UbuntuUpdate::OptionsParser.new
11
+ options_parser.expects(:get_options).at_least(1).returns({:help => true})
12
+ options_parser.expects(:get_summary).at_least(1).returns("My script summary")
13
+
14
+ command_executor = UbuntuUpdate::CommandExecutor.new
15
+ command_executor.expects(:execute).with(includes("My script summary"))
16
+
17
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
18
+ updater.execute_command
19
+ end
20
+
21
+ it "it should run apt-get update when no argument passed in" do
22
+ options_parser = UbuntuUpdate::OptionsParser.new
23
+ options_parser.expects(:get_options).at_least(1).returns({})
24
+
25
+ command_executor = UbuntuUpdate::CommandExecutor.new
26
+ command_executor.expects(:execute).with("sudo apt-get update")
27
+
28
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
29
+ updater.execute_command
30
+ end
31
+
32
+ it "it should run apt-get update when passed in {:update=>true}" do
33
+ options_parser = UbuntuUpdate::OptionsParser.new
34
+ options_parser.expects(:get_options).at_least(1).returns({:update=>true})
35
+
36
+ command_executor = UbuntuUpdate::CommandExecutor.new
37
+ command_executor.expects(:execute).with("sudo apt-get update")
38
+
39
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
40
+ updater.execute_command
41
+ end
42
+
43
+ it "it should run apt-get update when passed in {:upgrade=>true}" do
44
+ options_parser = UbuntuUpdate::OptionsParser.new
45
+ options_parser.expects(:get_options).at_least(1).returns({:upgrade=>true})
46
+
47
+ command_executor = UbuntuUpdate::CommandExecutor.new
48
+ command_executor.expects(:execute).with("sudo apt-get upgrade")
49
+
50
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
51
+ updater.execute_command
52
+ end
53
+
54
+ it "it should run apt-get upgrade with -y when passed in {:yes=>true}" do
55
+ options_parser = UbuntuUpdate::OptionsParser.new
56
+ options_parser.expects(:get_options).at_least(1).returns({:yes=>true, :upgrade=>true})
57
+
58
+ command_executor = UbuntuUpdate::CommandExecutor.new
59
+ command_executor.expects(:execute).with("sudo apt-get upgrade -y")
60
+
61
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
62
+ updater.execute_command
63
+ end
64
+
65
+ it "it should run apt-get upgrade and upgrade when passed in {:update=>true, :upgrade=>true}" do
66
+ options_parser = UbuntuUpdate::OptionsParser.new
67
+ options_parser.expects(:get_options).at_least(1).returns({:update=>true, :upgrade=>true})
68
+
69
+ command_executor = UbuntuUpdate::CommandExecutor.new
70
+ command_executor.expects(:execute).with("sudo apt-get update && sudo apt-get upgrade")
71
+
72
+ updater = UbuntuUpdate::Updater.new options_parser, command_executor
73
+ updater.execute_command
74
+ end
75
+ end
Binary file
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ubuntu_update/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ubuntu_update"
8
+ spec.version = UbuntuUpdate::VERSION
9
+ spec.authors = ["taufekj"]
10
+ spec.email = ["taufek@gmail.com"]
11
+ spec.summary = "Ubuntu update helper"
12
+ spec.description = "Tool that wraps Ubuntu update/upgrade command line"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubuntu_update
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - taufekj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Tool that wraps Ubuntu update/upgrade command line
42
+ email:
43
+ - taufek@gmail.com
44
+ executables:
45
+ - ubuntu_update
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/ubuntu_update
56
+ - lib/ubuntu_update.rb
57
+ - lib/ubuntu_update/command_executor.rb
58
+ - lib/ubuntu_update/options_parser.rb
59
+ - lib/ubuntu_update/version.rb
60
+ - spec/command_executor_spec.rb
61
+ - spec/options_parser_spec.rb
62
+ - spec/spec_helper.rb
63
+ - spec/ubuntu_update_spec.rb
64
+ - ubuntu_update-0.0.1.gem
65
+ - ubuntu_update.gemspec
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.2.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Ubuntu update helper
90
+ test_files:
91
+ - spec/command_executor_spec.rb
92
+ - spec/options_parser_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/ubuntu_update_spec.rb