jeni 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -4,6 +4,11 @@
4
4
  == History
5
5
 
6
6
 
7
+ [jeni-0.2.1 26-Oct-2012]
8
+
9
+ Added relative paths to targets that can take /usr/ or /usr/local as their root.
10
+ Got rspec tests to work
11
+
7
12
  [jeni-0.2.0 04-Oct-2012]
8
13
 
9
14
  Application forked from local 'jeni' due to Gam-space name clash.
data/README.md CHANGED
@@ -8,7 +8,7 @@ for straight directories instead of gems, if required.
8
8
 
9
9
  **GitHub:** [https://github.com/osburn-sharp/jeni](https://github.com/osburn-sharp/jeni)
10
10
 
11
- **RubyDoc:** [http://rdoc.info/github/osburn-sharp/jeni/frames](http://rdoc.info/github/osburn-sharp/jeni/frames)
11
+ **RubyDoc:** [http://rubydoc.info/github/osburn-sharp/jeni/frames](http://rubydoc.info/github/osburn-sharp/jeni/frames)
12
12
 
13
13
  **RubyGems:** [https://rubygems.org/gems/jeni](https://rubygems.org/gems/jeni)
14
14
 
@@ -18,7 +18,7 @@ To install,
18
18
 
19
19
  gem install jeni.
20
20
 
21
- It is a plain library with no binaries or the like. Documentation is available from [RDoc]()
21
+ It is a plain library with no binaries or the like.
22
22
 
23
23
  ## Getting Started
24
24
 
@@ -36,8 +36,8 @@ This is a simple example:
36
36
  jeni.pretend(opt[:pretend])
37
37
  # copy a file
38
38
  jeni.file('source.rb', '/etc/target.rb')
39
- # create a wrapper
40
- jeni.wrapper('sbin/jenerate.rb', '/usr/sbin/jenerate')
39
+ # create a wrapper in /usr/local
40
+ jeni.wrapper('sbin/jenerate.rb', 'sbin/jenerate')
41
41
  end.run!
42
42
  # and run jeni
43
43
 
@@ -93,6 +93,10 @@ If the source is a relative path then it will be looked for relative to the Inst
93
93
  So, for a gem {Jeni::Installer.new_from_gem} it will be relative to the gem's directory and for a directory
94
94
  {Jeni::Installer.new} it will be relative to that. If the source is an absolute path (starts with '/')
95
95
  then it will be used as given.
96
+
97
+ If the target is a relative path then it will be relative to /usr/local unless you
98
+ use the -u switch (with the optparse option) or the {Jeni::Options.usr} method to set
99
+ it to '/usr'.
96
100
 
97
101
  Global options can also be set, as defined in #{Jeni::Options}. The same options can be set using {Jeni::Optparse#optparse}
98
102
  to automatically process command line options. Call it with ARGV instead of manually setting Jeni's options.
@@ -134,7 +138,8 @@ Check the {file:Gemfile} for other dependencies.
134
138
 
135
139
  ### Documentation
136
140
 
137
- Documentation is best viewed using Yard. Documentation is available from [Rubydoc](http://rdoc.info/github/osburn-sharp/jeni/frames)
141
+ Documentation is best viewed using Yard. Documentation is available from
142
+ [Rubydoc](http://rubydoc.info/github/osburn-sharp/jeni/frames)
138
143
 
139
144
  ## Testing/Modifying
140
145
 
data/lib/jeni.rb CHANGED
@@ -65,6 +65,7 @@ module Jeni
65
65
  #@gem_spec = Gem::Specification.find_by_name(@gem_name)
66
66
  #@gem_dir = @gem_spec.gem_dir
67
67
  @source_root = source_root
68
+ @target_root = '/usr/local/'
68
69
  @commands = []
69
70
  @errors = {}
70
71
  @owner = nil
@@ -170,10 +171,13 @@ module Jeni
170
171
  end
171
172
 
172
173
  # copy a file from the source, relative to the gem home to the target
173
- # which is absolute
174
+ #
175
+ # If the target is relative it will joined to the target_root, which is
176
+ # by default /usr/local. This root can be changed to /usr with either
177
+ # {Jeni::Options.usr} or through {Jeni::Optparse}.
174
178
  #
175
179
  # @param [String] source is the gem-relative path to the file to copy
176
- # @param [String] target is an absolute path to copy to
180
+ # @param [String] target is a relative or absolute path to copy to
177
181
  # @params [Hash] opts options for copying the file
178
182
  # @option opts [String] :chown the name of the owner
179
183
  # @option opts [String] :chgrp the name of the group
@@ -187,11 +191,11 @@ module Jeni
187
191
  chmod = opts[:chmod]
188
192
 
189
193
  gsource = check_file(source)
190
- check_target(target, owner)
194
+ gtarget = check_target(target, owner)
191
195
  check_chmod(chmod)
192
196
 
193
- @commands << {:file => [gsource, target]}
194
- process_options(opts, target)
197
+ @commands << {:file => [gsource, gtarget]}
198
+ process_options(opts, gtarget)
195
199
  end
196
200
 
197
201
  # copy all of the files in the source directory to the target directory
@@ -298,11 +302,11 @@ module Jeni
298
302
  opts[:chgrp] = locals.delete(:chgrp)
299
303
 
300
304
  gsource = check_file(source)
301
- check_target(target, opts[:owner])
305
+ gtarget = check_target(target, opts[:owner])
302
306
  check_chmod(opts[:chmod])
303
307
 
304
- @commands << {:generate => [gsource, target, locals]}
305
- process_options(opts, target)
308
+ @commands << {:generate => [gsource, gtarget, locals]}
309
+ process_options(opts, gtarget)
306
310
  end
307
311
 
308
312
  # as for {Jeni::Installer#template} but searches for the source template from a list of predefined
@@ -318,11 +322,11 @@ module Jeni
318
322
  opts[:chmod] = locals.delete(:chmod)
319
323
  opts[:chgrp] = locals.delete(:chgrp)
320
324
 
321
- check_target(target, opts[:owner])
325
+ gtarget = check_target(target, opts[:owner])
322
326
  check_chmod(opts[:chmod])
323
327
 
324
- @commands << {:generate => [gsource, target, locals]}
325
- process_options(opts, target)
328
+ @commands << {:generate => [gsource, gtarget, locals]}
329
+ process_options(opts, gtarget)
326
330
  end
327
331
 
328
332
  # create a wrapper script at target to call source in a similar manner to Gem's wrapper
@@ -341,10 +345,10 @@ module Jeni
341
345
 
342
346
  check_gem(:wrapper)
343
347
  gsource = check_file(source)
344
- check_target(target, owner)
348
+ gtarget = check_target(target, owner)
345
349
 
346
- @commands << {:wrap => [source, target, gsource]}
347
- @commands << {:chmod => {:file => target, :mode => 0755}} if opts.has_key?(:chmod)
350
+ @commands << {:wrap => [source, gtarget, gsource]}
351
+ @commands << {:chmod => {:file => gtarget, :mode => 0755}} if opts.has_key?(:chmod)
348
352
  end
349
353
 
350
354
  # create a link at target to source
@@ -355,8 +359,8 @@ module Jeni
355
359
  def link(source, target)
356
360
  #gsource = File.expand_path(File.join(@source_root, source))
357
361
  gsource = check_file(source)
358
- check_target(target)
359
- @commands << {:link => [gsource, target]}
362
+ gtarget = check_target(target)
363
+ @commands << {:link => [gsource, gtarget]}
360
364
  end
361
365
 
362
366
  # output a message in the same format as other messages
data/lib/jeni/options.rb CHANGED
@@ -63,6 +63,11 @@ module Jeni
63
63
  @group = group
64
64
  end
65
65
 
66
+ # set the default target root to /usr instead of /usr/local
67
+ def usr
68
+ @target_root = '/usr/'
69
+ end
70
+
66
71
  end
67
72
 
68
73
  end
data/lib/jeni/optparse.rb CHANGED
@@ -69,6 +69,10 @@ module Jeni
69
69
  @group = g
70
70
  end
71
71
 
72
+ opts.on('-u', '--usr', 'set the default target to /usr instead of /usr/local') do
73
+ @target_root = '/usr/'
74
+ end
75
+
72
76
  opts.on_tail('-h', '--help', 'you are looking at it') do
73
77
  puts opts
74
78
  exit 0
data/lib/jeni/utils.rb CHANGED
@@ -43,6 +43,9 @@ module Jeni
43
43
  # this will create a target if it does not exist (and all intermediate paths) unless
44
44
  # the nomkdir option is set
45
45
  def check_target(target, owner=nil)
46
+ unless target[0,1] == '/'
47
+ target = File.expand_path(File.join(@target_root, target))
48
+ end
46
49
  dir = File.dirname(target)
47
50
  unless FileTest.directory?(dir)
48
51
  unless @nomkdir
@@ -50,13 +53,15 @@ module Jeni
50
53
  if owner then
51
54
  @commands << {:chown => {:file => dir, :owner => owner}}
52
55
  end
53
- return
56
+ return target
54
57
  end
55
58
  @errors[:missing] = dir
56
59
  end
57
60
  @errors[:unwritable] = dir unless FileTest.writable?(dir)
61
+ return target
58
62
  rescue
59
63
  @errors[:unwritable] = dir unless FileTest.writable?(dir)
64
+ return target
60
65
  end
61
66
 
62
67
  # ensure this is called for a gem
data/lib/jeni/version.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # Created by Jevoom
2
2
  #
3
- # 04-Oct-2012
4
- # Application forked from local 'jeni' due to Gam-space name clash.
3
+ # 26-Oct-2012
4
+ # Added relative paths to targets that can take /usr/ or /usr/local as their root.
5
+ # Got rspec tests to work
5
6
 
6
7
  module Jeni
7
- # version set to 0.2.0
8
- Version = '0.2.0'
9
- # date set to 04-Oct-2012
10
- Version_Date = '04-Oct-2012'
11
- #ident string set to: jeni-0.2.0 04-Oct-2012
12
- Ident = 'jeni-0.2.0 04-Oct-2012'
8
+ # version set to 0.2.1
9
+ Version = '0.2.1'
10
+ # date set to 26-Oct-2012
11
+ Version_Date = '26-Oct-2012'
12
+ #ident string set to: jeni-0.2.1 26-Oct-2012
13
+ Ident = 'jeni-0.2.1 26-Oct-2012'
13
14
  end
@@ -24,6 +24,7 @@ class JeniUtils
24
24
  include Jeni::Utils
25
25
  include Jeni::Options
26
26
  include Jeni::IO
27
+ include Jeni::Actions
27
28
  def initialize
28
29
  @app_name = 'jeni'
29
30
  @errors = {}
@@ -114,14 +115,16 @@ describe Jeni do
114
115
  source_old = File.join(test_dir, 'source', 'jeni.rb')
115
116
  source = File.join(test_dir, 'source', 'jeni-diff.rb')
116
117
  target = File.join(test_dir, 'target', 'jeni.rb')
117
- diff = Diffy::Diff.new(source, target, :source=>'files').to_s(:color)
118
+ diff = Diffy::Diff.new(target, source, :source=>'files').to_s(:color)
118
119
  response = @jeni.say(:exists, target, :warning, true)
119
120
  response2 = @jeni.say(:skipping, target, :warning, true)
120
- @jeni.should_receive(:puts).with(response)
121
- @jeni.should_receive(:puts).with(response2)
122
- @jeni.should_receive(:print).twice
123
- @jeni.should_receive(:gets).and_return('d', 'n')
121
+ @jeni.should_receive(:puts).once.with(response)
122
+ @jeni.should_receive(:print).once
123
+ @jeni.should_receive(:gets).and_return('d')
124
124
  @jeni.should_receive(:puts).with(diff)
125
+ @jeni.should_receive(:print).once
126
+ @jeni.should_receive(:gets).and_return('n')
127
+ @jeni.should_receive(:puts).once.with(response2)
125
128
  #@jeni.should_receive(:print)
126
129
  @jeni.copy(source, target).should be_nil
127
130
  FileTest.exists?(target).should be_true
File without changes
@@ -0,0 +1,10 @@
1
+ # Author: Robert Sharp
2
+ # Created at: 16:14 25-10-12
3
+
4
+ module Amodule
5
+ class Aclass
6
+ def amethod
7
+ puts "Welcome"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/ruby -w
2
+
3
+ puts "Just a test"
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby18
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'jeni' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+ # Updated to wrap non-bin executables
9
+ #
10
+
11
+ require 'rubygems'
12
+
13
+ version = ">= 0"
14
+
15
+ # check if there is a version spec here, e.g.: gem_name _0.1.2_ args
16
+ if ARGV.first
17
+ str = ARGV.first
18
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
19
+ if str =~ /\A_(.*)_\z/
20
+ # there is, so get it
21
+ version = $1
22
+ ARGV.shift
23
+ end
24
+ end
25
+
26
+ gem_spec = Gem::Specification.find_by_name('jeni', version)
27
+ gem_path = File.join(gem_spec.gem_dir, 'source/jeni.rb')
28
+
29
+ gem 'jeni', version
30
+ load gem_path
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: R.J.Sharp
3
+ # Email:: robert(a)osburn-sharp.ath.cx
4
+ # Copyright:: Copyright (c) 2012
5
+ # License:: Open Software Licence v3.0
6
+ #
7
+ # This software is licensed for use under the Open Software Licence v. 3.0
8
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
9
+ # and in the file LICENCE. Under the terms of this licence, all derivative works
10
+ # must themselves be licensed under the Open Software Licence v. 3.0
11
+ #
12
+ #
13
+ # [requires go here]
14
+ require 'rubygems'
15
+ require 'jerbil'
16
+
17
+ # = Jeni
18
+ #
19
+ # [Description of the main module]
20
+ module Jeni
21
+ class Installer
22
+
23
+ def initialize(gem_name)
24
+ @gem_name = gem_name
25
+ @gem_spec = Gem::Specification.find_by_name(@gem_name)
26
+ @commands = []
27
+ end
28
+
29
+ def self.construct(gem_name, options={}, &block)
30
+ @pretend = options[:pretend] || true # JUST FOR NOW!
31
+ installer = self.new(gem_name)
32
+ block.call(installer)
33
+ return self
34
+ end
35
+
36
+ def run!(pretent=false)
37
+
38
+ end
39
+
40
+ # copy a file from the source, relative to the gem home to the target
41
+ # which is absolute
42
+ def file(source, target, opts={})
43
+ @commands << {:file => {source => target}}
44
+ if opts.has_key?(:chown) then
45
+ @commands << {:chown => opts[:chown]}
46
+ end
47
+ end
48
+
49
+ # copy all of the files in a directory
50
+ def directory(source, target, opts={})
51
+
52
+ end
53
+
54
+ # create a wrapper at target to call source
55
+ def wrapper(source, target)
56
+
57
+ end
58
+
59
+ def link(source, target)
60
+
61
+ end
62
+
63
+ end
64
+ end
File without changes
@@ -1,5 +1,5 @@
1
1
  # Author: Me
2
- # Created at: 10:28 14-09-12
2
+ # Created at: 16:15 25-10-12
3
3
 
4
4
  module Amodule
5
5
  class Aclass
@@ -1,6 +1,6 @@
1
1
  # THIS IS A STANDARD TEMPLATE
2
2
  # Author: Robert
3
- # Created at: 10:28 14-09-12
3
+ # Created at: 16:15 25-10-12
4
4
 
5
5
  module Amodule
6
6
  class Aclass
@@ -0,0 +1,63 @@
1
+ #
2
+ # Author:: R.J.Sharp
3
+ # Email:: robert(a)osburn-sharp.ath.cx
4
+ # Copyright:: Copyright (c) 2012
5
+ # License:: Open Software Licence v3.0
6
+ #
7
+ # This software is licensed for use under the Open Software Licence v. 3.0
8
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
9
+ # and in the file LICENCE. Under the terms of this licence, all derivative works
10
+ # must themselves be licensed under the Open Software Licence v. 3.0
11
+ #
12
+ #
13
+ # [requires go here]
14
+ require 'rubygems'
15
+
16
+ # = Jeni
17
+ #
18
+ # [Description of the main module]
19
+ module Jeni
20
+ class Installer
21
+
22
+ def initialize(gem_name)
23
+ @gem_name = gem_name
24
+ @gem_spec = Gem::Specification.find_by_name(@gem_name)
25
+ @commands = []
26
+ end
27
+
28
+ def self.construct(gem_name, options={}, &block)
29
+ @pretend = options[:pretend] || true # JUST FOR NOW!
30
+ installer = self.new(gem_name)
31
+ block.call(installer)
32
+ return self
33
+ end
34
+
35
+ def run!(pretent=false)
36
+
37
+ end
38
+
39
+ # copy a file from the source, relative to the gem home to the target
40
+ # which is absolute
41
+ def file(source, target, opts={})
42
+ @commands << {:file => {source => target}}
43
+ if opts.has_key?(:chown) then
44
+ @commands << {:chown => opts[:chown]}
45
+ end
46
+ end
47
+
48
+ # copy all of the files in a directory
49
+ def directory(source, target, opts={})
50
+
51
+ end
52
+
53
+ # create a wrapper at target to call source
54
+ def wrapper(source, target)
55
+
56
+ end
57
+
58
+ def link(source, target)
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -7,7 +7,7 @@ require 'rspec/mocks/standalone'
7
7
 
8
8
  gspec = double("Gem::Specification")
9
9
  Gem::Specification.stub(:find_by_name).and_return(gspec)
10
- test_dir = File.dirname(__FILE__)
10
+ test_dir = File.expand_path(File.dirname(__FILE__))
11
11
  target_dir = File.join(test_dir, 'target2')
12
12
  FileUtils.mkdir(target_dir) unless FileTest.directory?(target_dir)
13
13
  FileUtils.rm_f Dir.glob("#{target_dir}/**")
@@ -26,5 +26,5 @@ Jeni::Installer.new_from_gem('jeni') do |jeni|
26
26
  jeni.wrapper('source/executable', File.join(target_dir, 'executable'), :chmod=>true)
27
27
  jeni.link('source/jeni.rb', File.join(target_dir, 'jeni_link.rb'))
28
28
  jeni.link('source/shebang.rb', File.join(target_dir, 'jeni_link.rb'))
29
- jeni.link('/etc/conf.d/unicorn', File.join(target_dir, 'unicorn.jeni'))
29
+ jeni.link('/etc/init.d/unicorn', File.join(target_dir, 'unicorn.jeni'))
30
30
  end.run!
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  $LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
5
5
  require 'jeni'
6
6
 
7
- test_dir = File.dirname(__FILE__)
7
+ test_dir = File.expand_path(File.dirname(__FILE__))
8
8
  target_dir = File.join(test_dir, 'target2')
9
9
  FileUtils.mkdir(target_dir) unless FileTest.directory?(target_dir)
10
10
  FileUtils.rm_f Dir.glob("#{target_dir}/**")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeni
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dr Robert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-04 00:00:00 Z
18
+ date: 2012-10-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -94,13 +94,13 @@ files:
94
94
  - spec/spec_helper.rb
95
95
  - spec/jeni_spec.rb
96
96
  - spec/jeni_utils_spec.rb
97
- - test/examples/source/jenny-diff.rb
98
- - test/examples/source/jenny.rb
99
97
  - test/examples/source/shebang.rb
100
98
  - test/examples/source/executable
101
99
  - test/examples/source/template.haml.rb
102
100
  - test/examples/source/coati.haml.conf
103
101
  - test/examples/source/subfiles/subfile_1.rb
102
+ - test/examples/source/jeni.rb
103
+ - test/examples/source/jeni-diff.rb
104
104
  - test/examples/test1.rb
105
105
  - test/examples/test_args
106
106
  - test/examples/test2.rb
@@ -114,17 +114,22 @@ files:
114
114
  - test/examples/target/archive/coati.haml.conf
115
115
  - test/examples/target/archive/subfiles/subfile_1.rb
116
116
  - test/examples/target/jenny_link.rb
117
- - test/examples/target2/jenny_test.rb
118
- - test/examples/target2/jenny.rb
117
+ - test/examples/target/test.rb
118
+ - test/examples/target/jeni.rb
119
+ - test/examples/target/jeni_template.rb
120
+ - test/examples/target/shebang.rb
121
+ - test/examples/target2/subfiles/subfile_1.rb
122
+ - test/examples/target2/jeni_test.rb
123
+ - test/examples/target2/jeni.rb
119
124
  - test/examples/target2/shebang.rb
120
- - test/examples/target2/jenny-diff.rb
121
125
  - test/examples/target2/executable
122
126
  - test/examples/target2/template.haml.rb
123
127
  - test/examples/target2/coati.haml.conf
124
- - test/examples/target2/jenny_template.rb
128
+ - test/examples/target2/jeni-diff.rb
129
+ - test/examples/target2/jeni_template.rb
125
130
  - test/examples/target2/coati.conf
126
131
  - test/examples/target2/std_template.rb
127
- - test/examples/target2/jenny_link.rb
132
+ - test/examples/target2/jeni_link.rb
128
133
  homepage:
129
134
  licenses:
130
135
  - Open Software Licence v3.0