run_later 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dfb58101aa27c52c928b5df3f50e0381dac5f51
4
- data.tar.gz: 8dcd5bd2a65ffa840c21853dbebb018be09542d5
3
+ metadata.gz: 4e2c8d4f53a87dce5ec0750a223484a183d97a25
4
+ data.tar.gz: 0898d83d7bc4244824ca24233efd09ca5f39d3d9
5
5
  SHA512:
6
- metadata.gz: 54ed1867743fe000c9cf54d6fa00d58ae135d76790a03e6ef38f3161b629d57a0213673b8053c53998ca57a610a795cd836138db89cd074f63d2ca2fac2f7440
7
- data.tar.gz: f7fbf0464cccbd8b4163deb5d73d30efdf36bb1aaf7dec6301580aa98c359913a3b4c90d121db27ff429216ee800b77c5a95f87a92a0cd7934c567af342ba76b
6
+ metadata.gz: d7af322629470337fe9f9f31dd84bbb16fec9af1bf659f6fb0aa8d9f0cd6e8a789813b334e2cfcaccae147b85663b62d2ad168e2123b7623e5979641a5ea7d9b
7
+ data.tar.gz: 83f9c41dd38915391dd877496367d426b9ed9b07f4aa3195dbd1c8f7e67c00cb1c8af7ea8dc7a22a23edd9d26505177f82a0d88d829af9878498004ac48d53c5
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ notes.txt
16
+ _README.md
data/README.md CHANGED
@@ -1,26 +1,63 @@
1
+ ### Please read me!
2
+
3
+ #This is a Totally experimental gem
4
+
5
+
6
+ ![alt tag](https://pbs.twimg.com/media/CDhU3qoWIAAc_NK.png:large)
7
+
1
8
  # RunLater
2
9
 
3
- TODO: Write a gem description
10
+ RunLater is a gem for running commands later.
11
+ It saves the commands in a yaml file (`~/.run_later/commands.yaml`) and executed it when you call `perform`
12
+
13
+ Because when you running scripts with Ruby, systems commands are running with `sh` and doent `source` load any file like `~/.profile` or `.~/.bash_profile` so we need to `preload` it with before
14
+
15
+ ## Usage
16
+
17
+ $ run_later queue --commands='brew upgrade && brew install phantomjs'
18
+
19
+ later:
20
+
21
+ $ run_later perform
22
+
23
+
24
+
25
+ ## Options:
26
+
27
+ ```bash
28
+
29
+ --commands='brew upgrade && brew install phantomjs' # Commands to execute
30
+ [--preload=~/.bash_profile ~/.rvmrc] # Source files to be loaded before execution (separated by space)
31
+ # Default: ["~/.profile", "~/.bash_profile"]
32
+ [--sudo], [--no-sudo] # If commands require sudo
33
+ [--env=foo:bar joe:doe] # System variables to be set before execution (key:value separated by space)
34
+
35
+
36
+
37
+ ````
38
+
39
+ ## Example
40
+
41
+ ```bash
42
+
43
+ run_later --commands='brew upgrade && brew install phantomjs' --sudo --env=foo:bar joe:doe --preload=~/.bash_profile ~/.rvmrc
44
+
45
+ ````
46
+
47
+ #### Note: this gems its still under development so please dont use it in production
4
48
 
5
49
  ## Installation
6
50
 
7
51
  Add this line to your application's Gemfile:
8
52
 
9
53
  ```ruby
10
- gem 'run_later'
54
+ gem 'run_later', :git => 'git://github.com/msroot/run_later.git'
11
55
  ```
12
56
 
13
57
  And then execute:
14
58
 
15
59
  $ bundle
16
60
 
17
- Or install it yourself as:
18
-
19
- $ gem install run_later
20
-
21
- ## Usage
22
-
23
- TODO: Write usage instructions here
24
61
 
25
62
  ## Contributing
26
63
 
@@ -29,3 +66,29 @@ TODO: Write usage instructions here
29
66
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
67
  4. Push to the branch (`git push origin my-new-feature`)
31
68
  5. Create a new Pull Request
69
+
70
+
71
+ ## License
72
+
73
+ Copyright (c) 2015 Ioannis Kolovos
74
+
75
+ MIT License
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining
78
+ a copy of this software and associated documentation files (the
79
+ "Software"), to deal in the Software without restriction, including
80
+ without limitation the rights to use, copy, modify, merge, publish,
81
+ distribute, sublicense, and/or sell copies of the Software, and to
82
+ permit persons to whom the Software is furnished to do so, subject to
83
+ the following conditions:
84
+
85
+ The above copyright notice and this permission notice shall be
86
+ included in all copies or substantial portions of the Software.
87
+
88
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
91
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
92
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
93
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
94
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/run_later.rb CHANGED
@@ -1,19 +1,196 @@
1
+ # MIT License Copyright (c) 2015 Ioannis Kolovos
2
+ # See License
3
+ #
4
+ # RunLater is a gem for running commands later.
5
+ # It saves the commands in a yaml file (`~/.run_later/commands.yaml`) and executed it when you call `perform`
6
+ #
7
+ # Usage:
8
+ #
9
+ # $ run_later queue --commands='brew upgrade && brew install phantomjs'
10
+ #
11
+ # Later:
12
+ #
13
+ # $ run_later perform
14
+ #
15
+ # Methods:
16
+ #
17
+ # $ run_later queue params # Adding commands
18
+ # $ run_later clean # remove ~/.run_later
19
+ # $ run_later perform # executes the queue
20
+ # $ run_later list # view queue
21
+ #
22
+ # For more details use:
23
+ #
24
+ # $ run_later help
25
+ #
26
+ #
27
+ # Sourcing:
28
+ #
29
+ # When you running system commands with Ruby, is using `sh` so you have to load sources like `~/.profile` or `.~/.bash_profile`
30
+ # Default loaded are: ["~/.profile", "~/.bash_profile"]
31
+ #
32
+ #
33
+ # Options:
34
+ #
35
+ #
36
+ # --commands='brew upgrade && brew install phantomjs' # Commands to execute
37
+ # --preload=~/.bash_profile ~/.rvmrc # Source files to be loaded before execution (separated by space)
38
+ # # Default: ["~/.profile", "~/.bash_profile"]
39
+ # --sudo, --no-sudo # If commands require sudo
40
+ # --env=foo:bar joe:doe # System variables to be set before execution (key:value separated by space)
41
+ #
42
+ #
43
+ # Example:
44
+ # $ run_later --commands='brew upgrade && brew install phantomjs' --sudo --env=foo:bar joe:doe --preload=~/.bash_profile ~/.rvmrc
45
+ #
46
+ #
47
+
48
+
1
49
  require "run_later/version"
2
50
  require "thor"
3
51
  require 'yaml'
4
52
  require 'fileutils'
5
53
 
6
54
 
55
+
7
56
  module RunLater
8
57
 
9
58
  class CLI < Thor
10
59
  default_task :queue
60
+
11
61
  desc "queue", "Queue commands"
62
+
63
+ method_option :commands,
64
+ :type => :string,
65
+ :alias=> :c,
66
+ :required => true,
67
+ :banner => "'brew upgrade && brew install phantomjs'",
68
+ :desc => "Commands to execute"
69
+
70
+ method_option :preload,
71
+ :type => :array,
72
+ :alias=> :p,
73
+ :banner => "~/.bash_profile ~/.rvmrc",
74
+ :default => [ "~/.profile", "~/.bash_profile"],
75
+ :desc => "Source files to be loaded before execution (separated by space)"
76
+
77
+ method_option :sudo,
78
+ :type => :boolean,
79
+ :default => false,
80
+ :desc => "If commands require sudo"
81
+
82
+ method_option :env,
83
+ :type => :hash,
84
+ :alias=> :e,
85
+ :banner => "foo:bar joe:doe",
86
+ :desc => "System variables to be set before execution (key:value separated by space)"
87
+
12
88
  def queue
13
- say "Currently under development", :green
14
- say "Check next version", :green
89
+ initialize_files!
90
+ commands = get_commands
91
+ commands << options.merge({
92
+ id: Time.now.to_i
93
+ })
94
+
95
+ say "Adding `#{options[:commands]}`", :green
96
+
97
+ open(defaults[:commands], 'w') do |f|
98
+ f.write commands.to_yaml
99
+ end
100
+ end
101
+
102
+ desc "perform", "Perform and save log"
103
+ def perform
104
+ initialize_files!
105
+ say "Empty", :green and return if get_commands.empty?
106
+
107
+ log = defaults[:log]
108
+
109
+ IO.popen("/bin/bash", "w") do |shell|
110
+
111
+ shell.puts("echo #{Time.now} >> #{log}")
112
+
113
+ get_commands.map{ |command|
114
+ line = '--------------------------'
115
+
116
+ say "#{line} Starting: #{Time.now} #{line}", :yellow
117
+
118
+ say_status "ID", command[:id]
119
+
120
+ # load preloads
121
+ command[:preload].each {|source|
122
+ say_status "Loading:", source
123
+ # shell.puts("source #{source}")
124
+ system("source #{source}")
125
+ }
126
+
127
+ # load env
128
+ command[:env].each {|key, value|
129
+ env = "#{key}=#{value}"
130
+ say_status "Setting ENV", env
131
+ system("export #{env}")
132
+ # shell.puts("source #{source}")
133
+ } unless command[:env].nil?
134
+
135
+
136
+ say_status "Running", command[:commands], :yellow
137
+ # shell.puts("sudo #{command[:commands]} >> #{log}")
138
+ success = system("#{command[:commands]} >> #{log}")
139
+
140
+
141
+ say_status 'Status', (success ? "🍺" : "😩" ), (success ? :green : :red)
142
+
143
+ }
144
+
145
+ say_status "Output saved", log, :green
146
+
147
+
148
+
149
+ end
15
150
  end
16
151
 
17
152
 
153
+ desc "clean", "clean"
154
+ def clean
155
+ `rm -rf #{defaults[:root]}`
156
+ end
157
+
158
+ desc "list", "list commands"
159
+ def list
160
+ initialize_files!
161
+ say get_commands
162
+ end
163
+
164
+ private
165
+
166
+ def defaults
167
+ root = File.join(ENV['HOME'], '.run_later')
168
+ env = '/usr/bin/env'
169
+ set = 'set'
170
+
171
+ {
172
+ root: root,
173
+ commands: File.join(root, 'commands.yaml'),
174
+ log: File.join(root, "run_later.log")
175
+ }
176
+ end
177
+
178
+ def get_commands
179
+ YAML::load_file defaults[:commands]
180
+ end
181
+
182
+ def commands_exist?
183
+ File.exist? defaults[:commands]
184
+ end
185
+
186
+ def initialize_files!
187
+ FileUtils.mkdir_p(defaults[:root]) unless File.directory? defaults[:root]
188
+
189
+ File.open(defaults[:commands], "w") do |file|
190
+ file.write [].to_yaml
191
+ end unless commands_exist?
192
+
193
+ end
194
+
18
195
  end
19
196
  end
@@ -1,3 +1,3 @@
1
1
  module RunLater
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
Binary file
Binary file
data/run_later.gemspec CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Ioannis Kolovos"]
10
10
  spec.email = ["yannis.kolovos@gmail.com"]
11
11
  spec.summary = "Run commands later"
12
- spec.homepage = ""
12
+ spec.description = "Save commands to be run later and run them"
13
+ spec.homepage = "https://github.com/msroot/run_later"
13
14
  spec.license = "MIT"
14
15
 
15
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_later
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ioannis Kolovos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-26 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.19.1
55
- description:
55
+ description: Save commands to be run later and run them
56
56
  email:
57
57
  - yannis.kolovos@gmail.com
58
58
  executables:
@@ -68,8 +68,10 @@ files:
68
68
  - bin/run_later
69
69
  - lib/run_later.rb
70
70
  - lib/run_later/version.rb
71
+ - run_later-0.0.1.gem
72
+ - run_later-0.0.2.gem
71
73
  - run_later.gemspec
72
- homepage: ''
74
+ homepage: https://github.com/msroot/run_later
73
75
  licenses:
74
76
  - MIT
75
77
  metadata: {}
@@ -89,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
91
  version: '0'
90
92
  requirements: []
91
93
  rubyforge_project:
92
- rubygems_version: 2.2.2
94
+ rubygems_version: 2.4.5.1
93
95
  signing_key:
94
96
  specification_version: 4
95
97
  summary: Run commands later