scriptster 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45f7a48fa5788b100b93bea2ff05b294ea399835
4
+ data.tar.gz: 72d91cd953dedefb677c67fe083a7176dba6caf8
5
+ SHA512:
6
+ metadata.gz: e07766cc64e52fddaf942400820d283144fad567aa0baa22739295ef52b4c76b94edfef29668d04f9b0a7f49b1113dd2c70abdf75f7a2cdaaf71d2b00234c1e5
7
+ data.tar.gz: 09340b5aaa14387dca1307090e8850a2c73c1952186a2522f5b29956d47f16c4318b5ccd04be2b91432ac6ddecd6125208d2f6e67a44855c024b61b4e19d36b8
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scriptster.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Radek Pazdera
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,43 @@
1
+ # Scriptster
2
+
3
+ A small library to make your scripts hip ;-).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'scriptster'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install scriptster
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ```ruby
24
+ require 'scriptster'
25
+
26
+ Scriptster::configure do |conf|
27
+ conf[:name] = "my-script"
28
+ end
29
+
30
+ Scriptster::log :info, "Starting ..."
31
+
32
+ Scriptster::ShellCmd.new "git branch",
33
+ :show_out = true,
34
+ :show_err = true,
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/scriptster/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,154 @@
1
+ # scriptster - A small library to make your scipts nicer
2
+ # Copyright (c) 2014 Radek Pazdera
3
+
4
+ # MIT License
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+
23
+
24
+ require "tco"
25
+
26
+ Tco::configure do |conf|
27
+ conf.names["green"] = "#99ad6a"
28
+ conf.names["yellow"] = "#d8ad4c"
29
+ conf.names["red"] = "#cc333f"
30
+ conf.names["light-grey"] = "#ababab"
31
+ conf.names["dark-grey"] = "#2b2b2b"
32
+ conf.names["purple"] = "#90559e"
33
+ conf.names["blue"] = "#4D9EEB"
34
+ conf.names["orange"] = "#ff842a"
35
+ conf.names["brown"] = "#6a4a3c"
36
+
37
+ conf.styles["info"] = {
38
+ :fg => "green",
39
+ :bg => "dark-grey",
40
+ :bright => false,
41
+ :underline => false
42
+ }
43
+ conf.styles["warn"] = {
44
+ :fg => "dark-grey",
45
+ :bg => "yellow",
46
+ :bright => false,
47
+ :underline => false
48
+ }
49
+ conf.styles["err"] = {
50
+ :fg => "dark-grey",
51
+ :bg => "red",
52
+ :bright => false,
53
+ :underline => false
54
+ }
55
+ conf.styles["debug"] = {
56
+ :fg => "light-grey",
57
+ :bg => "dark-grey",
58
+ :bright => false,
59
+ :underline => false
60
+ }
61
+
62
+ conf.styles["script-name"] = {
63
+ :fg => "purple",
64
+ :bg => "dark-grey",
65
+ :bright => false,
66
+ :underline => false
67
+ }
68
+ end
69
+
70
+ module Scriptster
71
+ module Logger
72
+ @@script_name = "scriptster"
73
+ @@file = nil
74
+ @@time = false
75
+
76
+ @@message_types = {
77
+ :info => "info",
78
+ :warn => "warn",
79
+ :err => "err",
80
+ :debug => "debug"
81
+ }
82
+
83
+ @@verbosity = :verbose
84
+ @@logger_verbosity_levels = {
85
+ :essential => 0,
86
+ :important => 1,
87
+ :informative => 2,
88
+ :verbose => 3
89
+ }
90
+
91
+ def self.set_script_name(name)
92
+ @@script_name = name
93
+ end
94
+
95
+ def self.set_verbosity(level)
96
+ msg = "Message verbosity level not recognised (#{})."
97
+ raise msg unless @@logger_verbosity_levels.has_key? level.to_sym
98
+
99
+ @@verbosity = level.to_sym
100
+ end
101
+
102
+ def self.set_file(file)
103
+ @@file.close if @@file
104
+ @@file = File.open file, "w"
105
+ end
106
+
107
+ def self.set_time(time_enabled)
108
+ @@time = time_enabled
109
+ end
110
+
111
+ def self.log(msg_type, msg, verbosity=nil)
112
+ now = Time.now.strftime "%Y-%m-%d %H-%M "
113
+ out = now + @@script_name.style("script-name") << " "
114
+ file = now + @@script_name + " "
115
+
116
+ case msg_type
117
+ when :info
118
+ out << "info".style(@@message_types[:info])
119
+ file << "info"
120
+ verbosity = :informative unless verbosity
121
+ when :warn
122
+ out << "WARN".style(@@message_types[:warn])
123
+ file << "WARN"
124
+ verbosity = :informative unless verbosity
125
+ when :err
126
+ out << "ERR!".style(@@message_types[:err])
127
+ file << "ERR!"
128
+ verbosity = :essential unless verbosity
129
+ when :debug
130
+ out << "dbg?".style(@@message_types[:debug])
131
+ file << "dbg?"
132
+ verbosity = :verbose unless verbosity
133
+ end
134
+
135
+ if verbosity <= @@verbosity
136
+ out << " " << msg.chomp
137
+ puts out
138
+ STDOUT.flush
139
+
140
+ # Strip colours from the message before writing to a file
141
+ file << " " << msg.chomp.gsub(/\033\[[0-9]+(;[0-9]+){0,2}m/, "")
142
+ @@file.puts file if @@file
143
+ end
144
+ end
145
+
146
+ def log(msg_type, msg, verbosity=nil)
147
+ Logger::log msg_type, msg
148
+ end
149
+
150
+ def tag(tag, msg)
151
+ tag.fg("blue").bg("dark-grey") << " " << msg
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,114 @@
1
+ # scriptster - A small library to make your scipts nicer
2
+ # Copyright (c) 2014 Radek Pazdera
3
+
4
+ # MIT License
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+
23
+ require "open3"
24
+ require "tco"
25
+
26
+ require "scriptster/logger"
27
+
28
+ module Scriptster
29
+ class ShellCmd
30
+ attr_reader :status, :out, :err
31
+
32
+ include Logger
33
+
34
+ def initialize(cmd, opts={})
35
+ @out = ""
36
+ @err = ""
37
+
38
+ @show_out = false
39
+ @show_err = true
40
+ @raise_on_error = true
41
+ @tag = "shell"
42
+ @expect = 0
43
+
44
+ opts.each do |k, v|
45
+ self.instance_variable_set("@#{k.to_s}", v)
46
+ end
47
+
48
+ @cmd = cmd
49
+ @status = nil
50
+
51
+ run
52
+ end
53
+
54
+ private
55
+ def run
56
+ Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
57
+ pid = wait_thr.pid
58
+
59
+ stdout_buffer=""
60
+ stderr_buffer=""
61
+
62
+ begin
63
+ loop do
64
+ IO.select([stdout,stderr]).flatten.compact.each do |io|
65
+ stdout_buffer += io.readpartial(1) if io.fileno == stdout.fileno
66
+ stderr_buffer += io.readpartial(1) if io.fileno == stderr.fileno
67
+ end
68
+ break if stdout.closed? && stderr.closed?
69
+
70
+ stdout_buffer.sub!(/.*\n/m) do
71
+ @out += $&
72
+ if @show_out
73
+ $&.strip.split("\n").each do |line|
74
+ line = tag(@tag, line) if @tag
75
+ log(:info, line)
76
+ end
77
+ end
78
+
79
+ ''
80
+ end
81
+
82
+ stderr_buffer.sub!(/.*\n/m) do
83
+ @err += $&
84
+ if @show_err
85
+ $&.strip.split("\n").each do |line|
86
+ line = tag(@tag, line) if @tag
87
+ log(:err, line)
88
+ end
89
+ end
90
+
91
+ ''
92
+ end
93
+ end
94
+ rescue EOFError
95
+ ;
96
+ end
97
+
98
+ @status = wait_thr.value
99
+ end
100
+
101
+ if (@expect.is_a?(Array) && !@expect.include?(@status.exitstatus)) ||
102
+ (@expect.is_a?(Integer) && @status.exitstatus != @expect)
103
+ unless @show_err
104
+ err_lines = @err.split "\n"
105
+ err_lines.each do |l|
106
+ l = tag(@tag, l.fg("red")) if @tag
107
+ log(:err, l.chomp)
108
+ end
109
+ end
110
+ raise "'#{@cmd}' failed!".fg("red") if @raise_on_error
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,3 @@
1
+ module Scriptster
2
+ VERSION = "0.0.1"
3
+ end
data/lib/scriptster.rb ADDED
@@ -0,0 +1,46 @@
1
+ # scriptster - A small library to make your scipts nicer
2
+ # Copyright (c) 2014 Radek Pazdera
3
+
4
+ # MIT License
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+
23
+ require "scriptster/version"
24
+ require "scriptster/logger"
25
+ require "scriptster/shellcmd"
26
+
27
+ module Scriptster
28
+ class << self
29
+ include Logger
30
+ end
31
+
32
+ def self.configure
33
+ c = {
34
+ :name => "scriptster",
35
+ :verbosity => :informative,
36
+ :file => nil,
37
+ :time => true
38
+ }
39
+
40
+ yield c
41
+
42
+ Logger.set_script_name c[:name]
43
+ Logger.set_verbosity c[:verbosity]
44
+ Logger.set_file c[:file]
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scriptster/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scriptster"
8
+ spec.version = Scriptster::VERSION
9
+ spec.authors = ["Radek Pazdera"]
10
+ spec.email = ["radek@pazdera.co.uk"]
11
+ spec.summary = %q{Make your Ruby scipts hip.}
12
+ spec.description = %q{A simple library for making your scipts a bit nicer.}
13
+ spec.homepage = "https://github.com/pazdera/scriptster"
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_runtime_dependency "tco", "~> 0.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.1"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scriptster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Radek Pazdera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tco
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ description: A simple library for making your scipts a bit nicer.
56
+ email:
57
+ - radek@pazdera.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/scriptster.rb
68
+ - lib/scriptster/logger.rb
69
+ - lib/scriptster/shellcmd.rb
70
+ - lib/scriptster/version.rb
71
+ - scriptster.gemspec
72
+ homepage: https://github.com/pazdera/scriptster
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Make your Ruby scipts hip.
96
+ test_files: []