[Xfce4-commits] <moka:nick/maintainer-improvements> Add cgit repo file generator.
Nick Schermer
noreply at xfce.org
Sat Nov 19 12:22:01 CET 2011
Updating branch refs/heads/nick/maintainer-improvements
to d0292b34ed5ac09216c92e31d76956adc451c193 (commit)
from cce813c2601f4d8d733579988d909c92a9f2043b (commit)
commit d0292b34ed5ac09216c92e31d76956adc451c193
Author: Nick Schermer <nick at xfce.org>
Date: Sat Nov 19 12:20:05 2011 +0100
Add cgit repo file generator.
examples/{gitolite/gitolite.rb => cgit/cgit.rb} | 4 +-
lib/helpers/cgit.rb | 53 +++++++++++++++++++++++
lib/moka.rb | 20 ++++-----
lib/views/index_login.haml | 7 ++-
4 files changed, 68 insertions(+), 16 deletions(-)
diff --git a/examples/gitolite/gitolite.rb b/examples/cgit/cgit.rb
similarity index 83%
copy from examples/gitolite/gitolite.rb
copy to examples/cgit/cgit.rb
index fc1b5d6..21614aa 100755
--- a/examples/gitolite/gitolite.rb
+++ b/examples/cgit/cgit.rb
@@ -15,5 +15,5 @@ Moka::Models::Configuration.load do |conf|
conf.set :archive_dir, '/home/nick/websites/archive.xfce.org/'
end
-generator = Moka::Gitolite.new
-generator.run('/tmp/gitolitetest')
+generator = Moka::CGit.new
+generator.run('/tmp/cgitrepos', '/var/git')
diff --git a/lib/helpers/cgit.rb b/lib/helpers/cgit.rb
new file mode 100644
index 0000000..949b88a
--- /dev/null
+++ b/lib/helpers/cgit.rb
@@ -0,0 +1,53 @@
+require 'rubygems'
+require 'sinatra'
+require 'pp'
+
+module Moka
+ class CGit
+ include Moka::Models
+
+ def run(repofile, gitpath, prepend_files = nil)
+
+ conf = "# This file is generated by Moka\n\n"
+ public = Moka::Models::Group.get('public')
+
+ for classification in Moka::Models::Classification.find_all.sort
+
+ sect = ""
+
+ for name in classification.project_names.sort
+
+ path = File.join(gitpath, classification.name, name) + ".git"
+ next unless File.directory?(path)
+
+ project = Moka::Models::Project.get(name)
+ next if project == nil
+
+ # only show public projects
+ next unless project.groups.include?(public)
+
+ sect << "repo.url=#{classification.name}/#{project.name}\n"
+ sect << "repo.name=#{project.name}\n"
+ sect << "repo.path=#{path}\n"
+ sect << "repo.desc=#{project.shortdesc}\n"
+ sect << "repo.owner=#{project.owner}\n\n"
+ end
+
+ if not sect.empty?
+ conf << "section=#{classification.name}\n\n"
+ conf << sect
+ end
+ end
+
+ # write contents to file
+ cfile = File.new(repofile, "w+")
+ begin
+ cfile.flock(File::LOCK_SH)
+ cfile.puts conf
+ ensure
+ cfile.flock(File::LOCK_UN)
+ end
+ cfile.close
+ end
+ end
+end
diff --git a/lib/moka.rb b/lib/moka.rb
index b63e932..bf28b6d 100755
--- a/lib/moka.rb
+++ b/lib/moka.rb
@@ -4,22 +4,20 @@ require 'sass'
directory = File.expand_path(File.dirname(__FILE__))
-models = ['configuration', 'classification', 'group', 'role', 'maintainer', 'collection', 'project', 'archive']
-for model in models
- require File.join(directory, 'models', model)
+for n in ['archive', 'classification', 'collection', 'configuration', 'group', 'maintainer', 'project', 'role']
+ require File.join(directory, 'models', n)
end
-require File.join(directory, 'helpers', 'general')
-require File.join(directory, 'helpers', 'gitolite')
+for n in ['cgit', 'general', 'gitolite']
+ require File.join(directory, 'helpers', n)
+end
-helpers = ['announcements', 'authentication', 'collections', 'projects', 'maintainers']
-for helper in helpers
- require File.join(directory, 'controllers', helper)
+for n in ['announcements', 'authentication', 'collections', 'projects', 'maintainers']
+ require File.join(directory, 'controllers', n)
end
-middlewares = ['feeds', 'identica', 'mailinglists']
-for middleware in middlewares
- require File.join(directory, 'middleware', middleware)
+for n in ['feeds', 'identica', 'mailinglists']
+ require File.join(directory, 'middleware', n)
end
module Moka
diff --git a/lib/views/index_login.haml b/lib/views/index_login.haml
index 5c202ac..f345c48 100644
--- a/lib/views/index_login.haml
+++ b/lib/views/index_login.haml
@@ -1,6 +1,7 @@
-%h2 Utilities
-%p
- %a{:href => "/announcements"} Publish announcements
+- if authentication_user.authorized?('identica')
+ %h2 Utilities
+ %p
+ %a{:href => "/announcements"} Publish announcements
%h2 Collections
%table
More information about the Xfce4-commits
mailing list