jeni 0.2.1 → 0.2.3

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.
data/History.txt CHANGED
@@ -4,6 +4,18 @@
4
4
  == History
5
5
 
6
6
 
7
+ [jeni-0.2.3 21-Nov-2012]
8
+
9
+ Generate templates to /tmp directory before transferring to target. Allow users to
10
+ generate to an alternative target directory, either with target= method or optparse.
11
+ Allow a block for optparse that passes through the optparse object to allow custom
12
+ options to be added. Add classify method so templates can convert e.g. project name
13
+ into a Ruby class (my_project -> MyProject).
14
+
15
+ [jeni-0.2.2 15-Nov-2012]
16
+
17
+ Ensure new users/groups are remember for subsequent user/group tests
18
+
7
19
  [jeni-0.2.1 26-Oct-2012]
8
20
 
9
21
  Added relative paths to targets that can take /usr/ or /usr/local as their root.
data/lib/jeni/actions.rb CHANGED
@@ -153,7 +153,7 @@ module Jeni
153
153
  puts target if @verbose
154
154
 
155
155
  # and write it out to the target, but make it a temp
156
- temp_file = target_file + "._temp"
156
+ temp_file = File.join('/tmp', File.basename(target_file) + "._temp")
157
157
  File.open(temp_file, 'w') do |tfile|
158
158
  target.each_line do |tline|
159
159
  tfile.puts tline
data/lib/jeni/options.rb CHANGED
@@ -68,6 +68,11 @@ module Jeni
68
68
  @target_root = '/usr/'
69
69
  end
70
70
 
71
+ # set the default target root to the value given
72
+ def target=(path)
73
+ @target_root = path
74
+ end
75
+
71
76
  end
72
77
 
73
78
  end
data/lib/jeni/optparse.rb CHANGED
@@ -73,6 +73,15 @@ module Jeni
73
73
  @target_root = '/usr/'
74
74
  end
75
75
 
76
+ opts.on('-t', '--target [PATH]', String, 'set the default target to value given') do |t|
77
+ @target_root = t
78
+ end
79
+
80
+
81
+ if block_given? then
82
+ yield(opts)
83
+ end
84
+
76
85
  opts.on_tail('-h', '--help', 'you are looking at it') do
77
86
  puts opts
78
87
  exit 0
data/lib/jeni/utils.rb CHANGED
@@ -79,13 +79,13 @@ module Jeni
79
79
  def check_user(user)
80
80
  Etc.getpwnam(user)
81
81
  rescue ArgumentError
82
- @errors[:no_user] = "User does not exist: #{user}"
82
+ @errors[:no_user] = "User does not exist: #{user}" unless @new_users.include?(user)
83
83
  end
84
84
 
85
85
  def check_group(group)
86
86
  Etc.getgrnam(group)
87
87
  rescue ArgumentError
88
- @errors[:group] = "Group does not exist: #{group}"
88
+ @errors[:group] = "Group does not exist: #{group}" unless @new_groups.include?(group)
89
89
  end
90
90
 
91
91
  # check there is no user
@@ -114,6 +114,8 @@ module Jeni
114
114
  return skip
115
115
  rescue ArgumentError
116
116
  # will get here if user does NOT exist
117
+ @new_users << user
118
+ @new_groups << user if opts.has_key?(:user_group)
117
119
  return false # do not skip!
118
120
  end
119
121
 
@@ -134,6 +136,7 @@ module Jeni
134
136
  return skip
135
137
  rescue ArgumentError
136
138
  # will get here if user does NOT exist
139
+ @new_groups << group
137
140
  return false
138
141
  end
139
142
 
@@ -151,6 +154,16 @@ module Jeni
151
154
  end
152
155
  end
153
156
 
157
+ # convert a filename etc to a proper class name
158
+ # For example, converts 'my_service' to 'MyService'
159
+ #
160
+ # @param [String] string to convert to a classname
161
+ # @return [String] converted classname
162
+ def classify(string)
163
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
164
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
165
+ end
166
+
154
167
 
155
168
  # helper to add commands for options
156
169
  def process_options(opts, target)
data/lib/jeni/version.rb CHANGED
@@ -1,14 +1,17 @@
1
1
  # Created by Jevoom
2
2
  #
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
3
+ # 21-Nov-2012
4
+ # Generate templates to /tmp directory before transferring to target. Allow users to
5
+ # generate to an alternative target directory, either with target= method or optparse.
6
+ # Allow a block for optparse that passes through the optparse object to allow custom
7
+ # options to be added. Add classify method so templates can convert e.g. project name
8
+ # into a Ruby class (my_project -> MyProject).
6
9
 
7
10
  module Jeni
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'
11
+ # version set to 0.2.3
12
+ Version = '0.2.3'
13
+ # date set to 21-Nov-2012
14
+ Version_Date = '21-Nov-2012'
15
+ #ident string set to: jeni-0.2.3 21-Nov-2012
16
+ Ident = 'jeni-0.2.3 21-Nov-2012'
14
17
  end
data/lib/jeni.rb CHANGED
@@ -70,6 +70,9 @@ module Jeni
70
70
  @errors = {}
71
71
  @owner = nil
72
72
  @gem_dir = nil
73
+ # record any new users and groups requested
74
+ @new_users = Array.new
75
+ @new_groups = Array.new
73
76
  if block_given? then
74
77
  yield self
75
78
  else
@@ -255,6 +258,7 @@ module Jeni
255
258
  # @option opts [String] :home path to home directory for user, defaults to /home/$user
256
259
  # @option opts [String] :shell path to shell for user, defaults to /bin/bash
257
260
  # @option opts [Boolean] :skip set true to skip if user exists else fail
261
+ # @option opts [Boolean] :user_group to create a user group for this user
258
262
  #
259
263
  def user(name, opts={})
260
264
  skip = opts[:skip]
@@ -29,6 +29,8 @@ class JeniUtils
29
29
  @app_name = 'jeni'
30
30
  @errors = {}
31
31
  @commands = []
32
+ @new_users = Array.new
33
+ @new_groups = Array.new
32
34
  @source_root = File.expand_path(File.dirname(__FILE__) + '/../test/examples')
33
35
  end
34
36
  attr_accessor :errors
@@ -238,9 +240,11 @@ describe Jeni do
238
240
  puts err
239
241
  end
240
242
  @jeni.errors?.should be_false
241
- @jeni.check_new_user("peppapig", {:uid=>10101}, false)
243
+ @jeni.check_new_user("peppapiglet", {:uid=>10101}, false)
242
244
  @jeni.errors?.should be_false
243
- @jeni.check_new_user("peppapig", {:uid=>10101, :home=>'/home/peppa', :shell=>'/bin/bourne'}, false)
245
+ @jeni.check_new_user("peppapiglet", {:uid=>10101, :home=>'/home/peppa', :shell=>'/bin/bourne'}, false)
246
+ @jeni.errors?.should be_false
247
+ @jeni.check_user("peppapiglet")
244
248
  @jeni.errors?.should be_false
245
249
  end
246
250
 
@@ -268,6 +272,8 @@ describe Jeni do
268
272
  @jeni.errors?.should be_false
269
273
  @jeni.check_new_group("piglets", {:gid=>10101}, false)
270
274
  @jeni.errors?.should be_false
275
+ @jeni.check_group("piglets")
276
+ @jeni.errors?.should be_false
271
277
  end
272
278
 
273
279
  it "should throw errors for invalid groups" do
@@ -1,5 +1,5 @@
1
1
  # Author: Robert Sharp
2
- # Created at: 16:14 25-10-12
2
+ # Created at: 15:12 13-11-12
3
3
 
4
4
  module Amodule
5
5
  class Aclass
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: 21
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 3
10
+ version: 0.2.3
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-26 00:00:00 Z
18
+ date: 2012-11-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -119,17 +119,6 @@ files:
119
119
  - test/examples/target/jeni_template.rb
120
120
  - test/examples/target/shebang.rb
121
121
  - test/examples/target2/subfiles/subfile_1.rb
122
- - test/examples/target2/jeni_test.rb
123
- - test/examples/target2/jeni.rb
124
- - test/examples/target2/shebang.rb
125
- - test/examples/target2/executable
126
- - test/examples/target2/template.haml.rb
127
- - test/examples/target2/coati.haml.conf
128
- - test/examples/target2/jeni-diff.rb
129
- - test/examples/target2/jeni_template.rb
130
- - test/examples/target2/coati.conf
131
- - test/examples/target2/std_template.rb
132
- - test/examples/target2/jeni_link.rb
133
122
  homepage:
134
123
  licenses:
135
124
  - Open Software Licence v3.0
@@ -1,36 +0,0 @@
1
- upstream coati {
2
- server unix:/home/robert/dev/rails/coati/tmp/.sock fail_timeout=0;
3
- }
4
-
5
-
6
- server {
7
- listen 192.168.0.20:80;
8
- server_name coati.lucius.osburn-sharp.ath.cx;
9
-
10
- access_log /home/robert/dev/rails/coati/log/access.log;
11
- error_log /home/robert/dev/rails/coati/log/error.log;
12
-
13
- root /home/robert/dev/rails/coati/public/;
14
- index index.html;
15
-
16
- location / {
17
- proxy_set_header X-Real-IP $remote_addr;
18
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
- proxy_set_header Host $http_host;
20
- proxy_redirect off;
21
-
22
- if (-f $request_filename/index.html) {
23
- rewrite (.*) $1/index.html break;
24
- }
25
-
26
- if (-f $request_filename.html) {
27
- rewrite (.*) $1.html break;
28
- }
29
-
30
- if (!-f $request_filename) {
31
- proxy_pass http://coati;
32
- break;
33
- }
34
- }
35
-
36
- }
@@ -1,37 +0,0 @@
1
- upstream coati {
2
- server unix:#{root}/tmp/.sock fail_timeout=0;
3
- }
4
-
5
-
6
- server {
7
- listen 192.168.0.20:80;
8
- server_name #{app_name}.lucius.osburn-sharp.ath.cx;
9
-
10
- access_log #{root}/log/access.log;
11
- error_log #{root}/log/error.log;
12
-
13
- root #{root}/public/;
14
- index index.html;
15
-
16
- location / {
17
- proxy_set_header X-Real-IP $remote_addr;
18
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
- proxy_set_header Host $http_host;
20
- proxy_redirect off;
21
-
22
- if (-f $request_filename/index.html) {
23
- rewrite (.*) $1/index.html break;
24
- }
25
-
26
- if (-f $request_filename.html) {
27
- rewrite (.*) $1.html break;
28
- }
29
-
30
- if (!-f $request_filename) {
31
- proxy_pass http://coati;
32
- break;
33
- }
34
- }
35
-
36
- }
37
-
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby18
2
-
3
- puts "Executing"
@@ -1,64 +0,0 @@
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
@@ -1,63 +0,0 @@
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
@@ -1,63 +0,0 @@
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
@@ -1,10 +0,0 @@
1
- # Author: Me
2
- # Created at: 16:15 25-10-12
3
-
4
- module Amodule
5
- class Aclass
6
- def amethod
7
- puts "Welcome and well met"
8
- end
9
- end
10
- end
@@ -1,63 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- #! /usr/bin/ruby -w
2
-
3
- puts "Just a test"
@@ -1,12 +0,0 @@
1
- # THIS IS A STANDARD TEMPLATE
2
- # Author: Robert
3
- # Created at: 16:15 25-10-12
4
-
5
- module Amodule
6
- class Aclass
7
- def amethod
8
- puts "How do you do?"
9
- end
10
- end
11
- end
12
- # the standard
@@ -1,10 +0,0 @@
1
- # Author: #{author}
2
- # Created at: #{Time.now.strftime("%H:%M %d-%m-%y")}
3
-
4
- module Amodule
5
- class Aclass
6
- def amethod
7
- puts "#{greeting}"
8
- end
9
- end
10
- end