From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id B1F3A1384B4 for ; Sat, 26 Dec 2015 17:42:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 015EEE07E0; Sat, 26 Dec 2015 17:42:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 984E9E07E0 for ; Sat, 26 Dec 2015 17:42:57 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 776D9340554 for ; Sat, 26 Dec 2015 17:42:56 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B2B5D732 for ; Sat, 26 Dec 2015 17:42:49 +0000 (UTC) From: "Alex Legler" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Alex Legler" Message-ID: <1451151750.c0c412ef02302ccf9e306d091d429e7df3d6278f.a3li@gentoo> Subject: [gentoo-commits] data/api:master commit in: bin/ X-VCS-Repository: data/api X-VCS-Files: bin/projects-xml.rb X-VCS-Directories: bin/ X-VCS-Committer: a3li X-VCS-Committer-Name: Alex Legler X-VCS-Revision: c0c412ef02302ccf9e306d091d429e7df3d6278f X-VCS-Branch: master Date: Sat, 26 Dec 2015 17:42:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: bef4fd5a-d73a-4166-bd08-a64ade9a5728 X-Archives-Hash: da3a7f395bef8cd9849929254101ca29 commit: c0c412ef02302ccf9e306d091d429e7df3d6278f Author: Alex Legler a3li li> AuthorDate: Sat Dec 26 17:42:30 2015 +0000 Commit: Alex Legler gentoo org> CommitDate: Sat Dec 26 17:42:30 2015 +0000 URL: https://gitweb.gentoo.org/data/api.git/commit/?id=c0c412ef Add projects.xml generation script bin/projects-xml.rb | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/bin/projects-xml.rb b/bin/projects-xml.rb new file mode 100755 index 0000000..328cc93 --- /dev/null +++ b/bin/projects-xml.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby +# Generates projects.xml as per GLEP-67 from projects.json via semantic-data-toolkit. +# The file is only touched if contents change. +# +# Usage: projects-xml.rb +# +# Alex Legler + +require 'net/http' +require 'json' +require 'nokogiri' + +PROJECTS_JSON = URI('https://wiki.gentoo.org/rdf/projects.json') + +projects = begin + JSON.parse(Net::HTTP.get(PROJECTS_JSON)) +rescue JSON::ParserError + abort 'Cannot load projects.json.' +end + +parent_map = Hash.new { |h, k| h[k] = [] } + +projects.each_pair do |id, project| + parent_map[project['parent']] << id if project.key? 'parent' +end + +projects_xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| + xml.doc.create_internal_subset('projects', nil, 'http://www.gentoo.org/dtd/projects.dtd') + xml.projects do + projects.each_pair do |id, project| + xml.project do + xml.email project['email'] + xml.name project['name'] + xml.url project['href'] + xml.description project['description'] + + if parent_map.key? id + parent_map[id].each do |subproject_id| + attributes = { ref: projects[subproject_id]['email'] } + attributes['inherit-members'] = '1' if projects[subproject_id]['propagates_members'] + + xml.subproject nil, attributes + end + end + + project['members'].sort { |a, b| a['nickname'].casecmp(b['nickname']) }.each do |member| + attributes = {} + attributes['is-lead'] = '1' if member['is_lead'] + + xml.member nil, attributes do + xml.email member['email'] + xml.name member['name'] + xml.role member['role'] if member.key?('role') && !member['role'].empty? + end + end + end + end + end +end + +output_file = ARGV[0] + +generated_xml = projects_xml.to_xml +current_xml = begin + File.read(output_file) +rescue Errno::ENOENT + '' +end + +File.write(output_file, projects_xml.to_xml) unless generated_xml == current_xml