[Xfce4-commits] <moka:nick/maintainer-improvements> Add script to generate gitolite config.

Nick Schermer noreply at xfce.org
Sun Oct 9 20:44:02 CEST 2011


Updating branch refs/heads/nick/maintainer-improvements
         to c28c0f2805343cccc26d9b955ae0a6af3699fc4c (commit)
       from 1940bbc1366d6fd697c540b124e2477a97636e86 (commit)

commit c28c0f2805343cccc26d9b955ae0a6af3699fc4c
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Oct 9 20:43:07 2011 +0200

    Add script to generate gitolite config.

 bin/xfce-gitolite.rb              |   93 +++++++++++++++++++++++++++++++++++++
 lib/models/archive.rb             |    2 +-
 lib/models/classification.rb      |   10 ++++
 lib/views/maintainer_profile.haml |    3 +-
 4 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/bin/xfce-gitolite.rb b/bin/xfce-gitolite.rb
new file mode 100755
index 0000000..58e0c7c
--- /dev/null
+++ b/bin/xfce-gitolite.rb
@@ -0,0 +1,93 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'dm-core'
+require 'dm-migrations'
+require 'moka'
+
+# global configuration
+Moka::Models::Configuration.load do |conf|
+  conf.set :moka_url, 'http://localhost:9292'
+  conf.set :archive_dir, '/home/nick/websites/archive.xfce.org/'
+  conf.set :mirror, 'http://archive.xfce.org/'
+  conf.set :collection_release_pattern, /^([0-9]).([0-9]+)(pre[0-9])?$/
+  conf.set :noreply, 'noreply at xfce.org'
+end
+
+# Connect to the database
+directory = File.expand_path(File.dirname(__FILE__))
+db = File.join(directory, '../examples/xfce/example.db')
+
+#DataMapper::Logger.new($stdout, :debug)
+DataMapper.setup(:default, 'sqlite://' + db)
+
+gitolitedir = '/tmp/gitolitetest'
+
+keydir = File.join(gitolitedir, "keydir")
+File.makedirs(keydir) unless File.directory?(keydir)
+
+confdir = File.join(gitolitedir, "conf")
+File.makedirs(confdir) unless File.directory?(confdir)
+
+# project array
+projects = Hash.new
+
+for maintainer in Moka::Models::Maintainer.all(:active => true).sort
+
+  # update ssh key of this user
+  if maintainer.pubkeys and not maintainer.pubkeys.empty?
+    filename = File.join(keydir, maintainer.username + ".pub")
+    file = File.new(filename, "w+")
+
+    if file
+      begin
+        file.flock(File::LOCK_SH)
+        file.puts maintainer.pubkeys
+      ensure
+        file.flock(File::LOCK_UN)
+      end
+      file.close
+    else
+      puts "Unable to open file " + filename
+    end
+  end
+
+  # store the projects this maintainer handles
+  for project in maintainer.projects
+    if not projects[project.name]
+      projects[project.name ] = Array.new
+    end
+    projects[project.name] << maintainer.username
+  end
+end
+
+
+repo_rules = ""
+
+# build the gitolite config file
+for classification in Moka::Models::Classification.find_all.sort
+
+  for project in classification.project_names.sort
+
+    repo_rules << "repo " + classification.name + "/" + project + "\n"
+
+    if projects[project]
+      repo_rules << "\tRW ="
+      for username in projects[project].sort
+        repo_rules << " " + username
+      end
+      repo_rules << "\n"
+    end
+  repo_rules << "\n"
+  end
+end
+
+# write config file
+cfile = File.new(File.join(confdir, "gitolite.conf"), "w+")
+begin
+  cfile.flock(File::LOCK_SH)
+  cfile.puts repo_rules
+ensure
+  cfile.flock(File::LOCK_UN)
+end
+cfile.close
diff --git a/lib/models/archive.rb b/lib/models/archive.rb
index 4d1cd97..b4a1e0c 100755
--- a/lib/models/archive.rb
+++ b/lib/models/archive.rb
@@ -170,7 +170,7 @@ module Moka
               cdir = Dir.new(classification_dir(classification))
 
               classification.project_names = cdir.entries.select do |entry|
-                entry != '.' and entry != '.' \
+                entry != '.' and entry != '..' \
                   and File.directory?(File.join(classification_dir(classification), entry))
               end
             end
diff --git a/lib/models/classification.rb b/lib/models/classification.rb
index d202524..a8f066b 100755
--- a/lib/models/classification.rb
+++ b/lib/models/classification.rb
@@ -11,6 +11,16 @@ module Moka
         @directory = directory
         @project_names = []
       end
+      
+      def ==(other)
+        other.is_a?(self.class) \
+          and other.name == name
+      end
+
+      def <=>(other)
+        return 0 unless other.is_a?(self.class)
+        name <=> other.name
+      end
 
       def self.find_all
         Archive.instance.classifications
diff --git a/lib/views/maintainer_profile.haml b/lib/views/maintainer_profile.haml
index d716a24..43d4fe2 100644
--- a/lib/views/maintainer_profile.haml
+++ b/lib/views/maintainer_profile.haml
@@ -34,8 +34,7 @@
     %input{:type => "text", :name => "realname", :value => @maintainer.realname}
   %p
     %label{:for => "pubkeys"} SSH public-keys:
-    %textarea{:name => "pubkeys", :rows => "5", :wrap => "off"}
-      #{@maintainer.pubkeys}
+    %textarea{:name => "pubkeys", :rows => "5", :wrap => "off"} #{@maintainer.pubkeys}
   %p.info
     Each line of the public keys should start with ssh-dsa or ssh-rsa else
     the key is not saved. Updating the keys on the server can take up to 1


More information about the Xfce4-commits mailing list