deedubs-gitosis_fu 0.1.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dan Williams
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = gitosis_fu
2
+
3
+ Library to make editing your gitosis config's fun again!
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Dan Williams. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gitosis_fu"
8
+ gem.summary = %Q{Gitosis Ruby Library}
9
+ gem.description = %Q{TODO: longer description of your gem}
10
+ gem.email = "dan.williams@itthugs.com"
11
+ gem.homepage = "http://github.com/deedubs/gitosis_fu"
12
+ gem.authors = ["Dan Williams"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+
33
+
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION')
40
+ version = File.read('VERSION')
41
+ else
42
+ version = ""
43
+ end
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "gitosis_fu #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gitosis_fu}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dan Williams"]
12
+ s.date = %q{2009-08-20}
13
+ s.description = %q{TODO: longer description of your gem}
14
+ s.email = %q{dan.williams@itthugs.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "gitosis_fu.gemspec",
27
+ "lib/gitosis_fu.rb",
28
+ "lib/ini.rb",
29
+ "spec/gitosis_fu_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/deedubs/gitosis_fu}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Gitosis Ruby Library}
37
+ s.test_files = [
38
+ "spec/gitosis_fu_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
data/lib/gitosis_fu.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'lib/ini'
2
+
3
+ class GitosisFu
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ reload!
8
+ end
9
+
10
+ def admins
11
+ @admin_object['members'].split(' ')
12
+ end
13
+
14
+ def available_users
15
+ @available_users ||= Dir.glob(File.join(@path,'keydir','*.pub')).collect {|key| key.gsub(File.join(@path,'keydir','/'),'').chomp('.pub') }
16
+ end
17
+
18
+ def groups
19
+ @groups ||= @config.collect {|g| Group.new(g)}
20
+ end
21
+
22
+ def raw_config
23
+ @config
24
+ end
25
+
26
+ def to_ini
27
+ default = {:gitosis=>{:generator=>'gitosis_admin'}}
28
+
29
+ group_hashes = {}
30
+ groups.each{|g| group_hashes.merge! g.to_h}
31
+ group_hashes.merge default
32
+ end
33
+
34
+ def write
35
+ Ini.write_to_file(@path,to_ini,"This gitosis install is managed by gitosis_admin\n")
36
+ end
37
+
38
+ private
39
+ def reload!
40
+ @config = Ini.read_from_file(File.join(@path,'gitosis.conf'))
41
+ @config.delete('gitosis')
42
+ @admin_object = @config.delete('group gitosis-admin')
43
+ @groups = @available_users = nil
44
+ end
45
+ end
46
+
47
+ class Group
48
+ attr_accessor :name,:members, :projects
49
+
50
+ def initialize(config_hash)
51
+ @config = config_hash
52
+
53
+ @name = config_hash[0].sub('group ','')
54
+ @members = config_hash[1]['members'].split(' ')
55
+ end
56
+
57
+ def projects
58
+ @projects ||= [projects_readonly, projects_writable].compact.flatten
59
+ end
60
+
61
+ def projects_readonly
62
+ projects = @config[1]['readonly']
63
+ projects.split(' ').collect{|p| Project.new(p,false)} if projects
64
+ end
65
+
66
+ def projects_writable
67
+ projects = @config[1]['writable']
68
+ projects.split(' ').collect{|p| Project.new(p,true)} if projects
69
+ end
70
+
71
+ def to_h
72
+ {"group #{name}"=>{:writeable=>projects_writable.join(' '), :readonly=>projects_readonly.join(' '),:members=>@members.join(' ')}}
73
+ end
74
+ end
75
+
76
+ class Project
77
+ attr_accessor :name, :writable
78
+
79
+ def initialize(name, writable=false)
80
+ @name = name
81
+ @writable = writable
82
+ end
83
+
84
+ def to_s
85
+ @name
86
+ end
87
+ end
88
+
data/lib/ini.rb ADDED
@@ -0,0 +1,264 @@
1
+ #
2
+ # ini.rb - read and write ini files
3
+ #
4
+ # Copyright (C) 2007 Jeena Paradies
5
+ # License: GPL
6
+ # Author: Jeena Paradies (info@jeenaparadies.net)
7
+ #
8
+ # == Overview
9
+ #
10
+ # This file provides a read-wite handling for ini files.
11
+ # The data of a ini file is represented by a object which
12
+ # is populated with strings.
13
+
14
+ class Ini
15
+
16
+ # Class with methods to read from and write into ini files.
17
+ #
18
+ # A ini file is a text file in a specific format,
19
+ # it may include several fields which are sparated by
20
+ # field headlines which are enclosured by "[]".
21
+ # Each field may include several key-value pairs.
22
+ #
23
+ # Each key-value pair is represented by one line and
24
+ # the value is sparated from the key by a "=".
25
+ #
26
+ # == Examples
27
+ #
28
+ # === Example ini file
29
+ #
30
+ # # this is the first comment which will be saved in the comment attribute
31
+ # mail=info@example.com
32
+ # domain=example.com # this is a comment which will not be saved
33
+ # [database]
34
+ # db=example
35
+ # user=john
36
+ # passwd=very-secure
37
+ # host=localhost
38
+ # # this is another comment
39
+ # [filepaths]
40
+ # tmp=/tmp/example
41
+ # lib=/home/john/projects/example/lib
42
+ # htdocs=/home/john/projects/example/htdocs
43
+ # [ texts ]
44
+ # wellcome=Wellcome on my new website!
45
+ # Website description = This is only a example. # and another comment
46
+ #
47
+ # === Example object
48
+ #
49
+ # A Ini#comment stores:
50
+ # "this is the first comment which will be saved in the comment attribute"
51
+ #
52
+ # A Ini object stores:
53
+ #
54
+ # {
55
+ # "mail" => "info@example.com",
56
+ # "domain" => "example.com",
57
+ # "database" => {
58
+ # "db" => "example",
59
+ # "user" => "john",
60
+ # "passwd" => "very-secure",
61
+ # "host" => "localhost"
62
+ # },
63
+ # "filepaths" => {
64
+ # "tmp" => "/tmp/example",
65
+ # "lib" => "/home/john/projects/example/lib",
66
+ # "htdocs" => "/home/john/projects/example/htdocs"
67
+ # }
68
+ # "texts" => {
69
+ # "wellcome" => "Wellcome on my new website!",
70
+ # "Website description" => "This is only a example."
71
+ # }
72
+ # }
73
+ #
74
+ # As you can see this module gets rid of all comments, linebreaks
75
+ # and unnecessary spaces at the beginning and the end of each
76
+ # field headline, key or value.
77
+ #
78
+ # === Using the object
79
+ #
80
+ # Using the object is stright forward:
81
+ #
82
+ # ini = Ini.new("path/settings.ini")
83
+ # ini["mail"] = "info@example.com"
84
+ # ini["filepaths"] = { "tmp" => "/tmp/example" }
85
+ # ini.comment = "This is\na comment"
86
+ # puts ini["filepaths"]["tmp"]
87
+ # # => /tmp/example
88
+ # ini.write()
89
+ #
90
+
91
+ #
92
+ # :inihash is a hash which holds all ini data
93
+ # :comment is a string which holds the comments on the top of the file
94
+ #
95
+ attr_accessor :inihash, :comment
96
+
97
+ #
98
+ # Creating a new Ini object
99
+ #
100
+ # +path+ is a path to the ini file
101
+ # +load+ if nil restores the data if possible
102
+ # if true restores the data, if not possible raises an error
103
+ # if false does not resotre the data
104
+ #
105
+ def initialize(path, load=nil)
106
+ @path = path
107
+ @inihash = {}
108
+
109
+ if load or ( load.nil? and FileTest.readable_real? @path )
110
+ restore()
111
+ end
112
+ end
113
+
114
+ #
115
+ # Retrive the ini data for the key +key+
116
+ #
117
+ def [](key)
118
+ @inihash[key]
119
+ end
120
+
121
+ #
122
+ # Set the ini data for the key +key+
123
+ #
124
+ def []=(key, value)
125
+ raise TypeError, "String expected" unless key.is_a? String
126
+ raise TypeError, "String or Hash expected" unless value.is_a? String or value.is_a? Hash
127
+
128
+ @inihash[key] = value
129
+ end
130
+
131
+ #
132
+ # Restores the data from file into the object
133
+ #
134
+ def restore()
135
+ @inihash = Ini.read_from_file(@path)
136
+ @comment = Ini.read_comment_from_file(@path)
137
+ end
138
+
139
+ #
140
+ # Store data from the object in the file
141
+ #
142
+ def update()
143
+ Ini.write_to_file(@path, @inihash, @comment)
144
+ end
145
+
146
+ #
147
+ # Reading data from file
148
+ #
149
+ # +path+ is a path to the ini file
150
+ #
151
+ # returns a hash which represents the data from the file
152
+ #
153
+ def Ini.read_from_file(path)
154
+
155
+ inihash = {}
156
+ headline = nil
157
+
158
+ IO.foreach(path) do |line|
159
+
160
+
161
+ line = line.strip.split(/#/)[0]
162
+ next unless line
163
+ # read it only if the line doesn't begin with a "=" and is long enough
164
+ unless line.length < 2 and line[0,1] == "="
165
+
166
+ # it's a headline if the line begins with a "[" and ends with a "]"
167
+ if line[0,1] == "[" and line[line.length - 1, line.length] == "]"
168
+
169
+ # get rid of the [] and unnecessary spaces
170
+ headline = line[1, line.length - 2 ].strip
171
+ inihash[headline] = {}
172
+ else
173
+
174
+ key, value = line.split(/=/, 2)
175
+
176
+ key = key.strip unless key.nil?
177
+ value = value.strip unless value.nil?
178
+
179
+ unless headline.nil?
180
+ inihash[headline][key] = value
181
+ else
182
+ inihash[key] = value unless key.nil?
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ inihash
189
+ end
190
+
191
+ #
192
+ # Reading comments from file
193
+ #
194
+ # +path+ is a path to the ini file
195
+ #
196
+ # Returns a string with comments from the beginning of the
197
+ # ini file.
198
+ #
199
+ def Ini.read_comment_from_file(path)
200
+ comment = ""
201
+
202
+ IO.foreach(path) do |line|
203
+ line.strip!
204
+ break unless line[0,1] == "#" or line == ""
205
+
206
+ comment << "#{line[1, line.length ].strip}\n"
207
+ end
208
+
209
+ comment
210
+ end
211
+
212
+ #
213
+ # Writing a ini hash into a file
214
+ #
215
+ # +path+ is a path to the ini file
216
+ # +inihash+ is a hash representing the ini File. Default is a empty hash.
217
+ # +comment+ is a string with comments which appear on the
218
+ # top of the file. Each line will get a "#" before.
219
+ # Default is no comment.
220
+ #
221
+ def Ini.write_to_file(path, inihash={}, comment=nil)
222
+ raise TypeError, "String expected" unless comment.is_a? String or comment.nil?
223
+
224
+ raise TypeError, "Hash expected" unless inihash.is_a? Hash
225
+ File.open(path, "w") { |file|
226
+
227
+ unless comment.nil?
228
+ comment.each do |line|
229
+ file << "# #{line}"
230
+ end
231
+ end
232
+
233
+ file << Ini.to_s(inihash)
234
+ }
235
+ end
236
+
237
+ #
238
+ # Turn a hash (up to 2 levels deepness) into a ini string
239
+ #
240
+ # +inihash+ is a hash representing the ini File. Default is a empty hash.
241
+ #
242
+ # Returns a string in the ini file format.
243
+ #
244
+ def Ini.to_s(inihash={})
245
+ str = ""
246
+
247
+ inihash.each do |key, value|
248
+
249
+ if value.is_a? Hash
250
+ str << "[#{key.to_s}]\n"
251
+
252
+ value.each do |under_key, under_value|
253
+ str << "#{under_key.to_s}=#{under_value.to_s unless under_value.nil?}\n"
254
+ end
255
+
256
+ else
257
+ str << "#{key.to_s}=#{value.to_s unless value2.nil?}\n"
258
+ end
259
+ end
260
+
261
+ str
262
+ end
263
+
264
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "GitosisFu" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'gitosis_fu'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deedubs-gitosis_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "TODO: longer description of your gem"
17
+ email: dan.williams@itthugs.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - gitosis_fu.gemspec
33
+ - lib/gitosis_fu.rb
34
+ - lib/ini.rb
35
+ - spec/gitosis_fu_spec.rb
36
+ - spec/spec_helper.rb
37
+ has_rdoc: false
38
+ homepage: http://github.com/deedubs/gitosis_fu
39
+ licenses:
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Gitosis Ruby Library
64
+ test_files:
65
+ - spec/gitosis_fu_spec.rb
66
+ - spec/spec_helper.rb