[Xfce4-commits] <xfce-git-migration:master> add script to generate repos listing for cgit

Brian J. Tarricone brian at tarricone.org
Wed Aug 12 03:40:04 CEST 2009


Updating branch refs/heads/master
         to b8c26b915244cad04b6218a1fe929de380e4df99 (commit)
       from 423cad44aceb30c8d37020523f1e496a8b5d42e3 (commit)

commit b8c26b915244cad04b6218a1fe929de380e4df99
Author: Brian J. Tarricone <brian at tarricone.org>
Date:   Wed Aug 12 01:37:43 2009 +0000

    add script to generate repos listing for cgit

 gen-cgit-repos.rb |  149 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 0 deletions(-)

diff --git a/gen-cgit-repos.rb b/gen-cgit-repos.rb
new file mode 100755
index 0000000..4dce43c
--- /dev/null
+++ b/gen-cgit-repos.rb
@@ -0,0 +1,149 @@
+#!/usr/bin/ruby
+
+require 'rubygems'
+#require 'grit'
+require 'rexml/document'
+
+MAIN_REPOS_ROOT = '/var/git'
+USER_REPOS_ROOT = '/var/spool/gitosis/repositories'
+CGIT_REPOS_FILE = '/etc/cgit/repos'
+
+BLACKLIST = [ 'gitosis-admin', 'xfce-server-files' ]
+
+$cur_repo_group = ''
+
+def parse_module_xml(modulexml)
+  metadata = {}
+
+  xml = REXML::Document.new modulexml
+  return {} unless xml
+
+  project = xml.elements['Project']
+  return {} unless project
+
+  project.elements.each do |elem|
+    if elem.name == 'name'
+      metadata['name'] = elem.get_text.to_s if elem.has_text?
+    elsif elem.name == 'shortdesc'
+      metadata['desc'] = elem.get_text.to_s if elem.has_text?
+    elsif elem.name == 'maintainer'
+      elem.elements.each do |maint_elem|
+        if maint_elem.prefix == 'foaf' and maint_elem.name == 'Person'
+          maint_elem.elements.each do |person_elem|
+            if person_elem.prefix == 'foaf' and person_elem.name == 'name'
+              metadata['owner'] = person_elem.get_text.to_s if person_elem.has_text?
+            elsif person_elem.prefix == 'gnome' and person_elem.name == 'userid'
+              metadata['owner'] = person_elem.get_text.to_s if !metadata.has_key?('owner') and person_elem.has_text?
+            end
+          end
+        end
+      end
+    end
+  end
+
+  metadata
+end
+
+def check_module_xml(git_dir, url_prefix, use_group)
+  metadata = {}
+
+#  repo = Grit::Git.new git_dir
+#  exit 0 unless repo
+#  mastertree = Grit::Tree.construct repo, 'master', [ 'module.xml' ]
+#  exit 0 unless mastertree
+
+#  modulexml_blob = mastertree/'module.xml'
+#  exit 0 unless modulexml_blob
+
+#  modulexml = modulexml_blob.data
+#  exit 0 unless modulexml
+
+  # this is so much easier than figuring out grit
+  ENV['GIT_DIR'] = git_dir
+  modulexml_sha1 = `git ls-tree master 2>/dev/null | awk '/[[:space:]]module.xml$/{ print $3 }'`
+  if modulexml_sha1 and modulexml_sha1 != ''
+    modulexml = `git cat-file -p #{modulexml_sha1} 2>/dev/null`
+    if modulexml and modulexml != ''
+      metadata = parse_module_xml(modulexml)
+    end
+  end
+
+  metadata['owner'] = '(unknown owner)' unless metadata.has_key?('owner')
+  metadata['desc'] = "create a module.xml file to set this module's description" unless metadata.has_key?('desc')
+
+  m = git_dir.match(/([^\/]+?)\/([^\/]+)$/)
+  if m and m[1]
+    repo_group = m[1]
+  else
+    repo_group = ''
+  end
+
+  repos_str = ''
+
+  if $cur_repo_group != repo_group
+    $cur_repo_group = repo_group
+    repos_str += 'repo.group=' + repo_group + "\n\n" if use_group
+  end
+
+  url = m[0].sub(/\.git$/, '')
+
+  repos_str += 'repo.url=' + url_prefix + url + "\n"
+  if use_group
+    name = m[2].sub(/\.git$/, '')
+    repos_str += 'repo.name=' + name + "\n"
+  else
+    repos_str += 'repo.name=' + url + "\n"
+  end
+  repos_str += 'repo.path=' + git_dir + "\n"
+  repos_str += 'repo.desc=' + metadata['desc'] + "\n"
+  repos_str += 'repo.owner=' + metadata['owner'] + "\n"
+  repos_str += "\n"
+
+  repos_str
+end
+
+def process_dir(dir, prefix='', use_group=true)
+  repos_str = ''
+
+  Dir.open(dir) do |d|
+    d.each do |de|
+      if de == 'hooks'
+        if BLACKLIST.detect { |b| !dir.match(/#{b}/).nil? }
+          return ''
+        end
+        return check_module_xml(dir, prefix, use_group)
+      end
+    end
+
+    # if we get here, then we're just a normal directory
+    d.entries.sort.each do |de|
+      subdir = dir + '/' + de
+      if de[0,1] != '.' and FileTest.directory?(subdir)
+        repos_str += process_dir(subdir, prefix, use_group)
+      end
+    end
+  end
+
+  repos_str
+end
+
+repos_str = process_dir(MAIN_REPOS_ROOT)
+repos_str += "repo.group=personal\n\n"
+repos_str += process_dir(USER_REPOS_ROOT, '~/', false)
+
+unless repos_str.nil?
+  f = File.new(CGIT_REPOS_FILE + '.new', File::CREAT|File::WRONLY, 0644)
+  if f
+    f.write repos_str
+    f.close
+    begin
+      File.rename(CGIT_REPOS_FILE + '.new', CGIT_REPOS_FILE)
+    rescue
+      begin
+        File.unlink(CGIT_REPOS_FILE + '.new')
+      rescue
+      end
+    end
+  end
+end
+#puts repos_str



More information about the Xfce4-commits mailing list