[sysadmin-bin] parse doap directly instead of relying on ldap
- From: Olav Vitters <ovitters src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] parse doap directly instead of relying on ldap
- Date: Tue, 20 Jan 2015 20:50:03 +0000 (UTC)
commit 4ce3c42b4104cd7411fe4bc6f73b26b7225decde
Author: Olav Vitters <olav vitters nl>
Date: Tue Jan 20 21:49:59 2015 +0100
parse doap directly instead of relying on ldap
ftpadmin | 91 ++++++++++++++++++++++++--------------------------------------
1 files changed, 35 insertions(+), 56 deletions(-)
---
diff --git a/ftpadmin b/ftpadmin
index 47b3aa7..a9800f4 100755
--- a/ftpadmin
+++ b/ftpadmin
@@ -5,8 +5,6 @@ import os
import os.path
import grp
import pwd
-import ldap
-import ldap.filter
import re
import tempfile
import tarfile
@@ -263,7 +261,6 @@ class BasicInfo(object):
FTPROOT='/ftp/pub/GNOME'
FTPROOT_DEBUG='/ftp/tmp'
URLROOT='https://download.gnome.org'
- DOAPURL='https://git.gnome.org/doap/%s'
BLOCKSIZE=2*1024*1024 # (dot will be printed per block for progress indication)
# Note: this defines the formats install-module can read
@@ -294,7 +291,7 @@ class DOAP(BasicInfo):
NS_GNOME = "http://api.gnome.org/doap-extensions#"
DOAP_URL = 'https://git.gnome.org/repositories.doap'
- DOAP_CACHE = ''
+ DOAP_CACHE = '/ftp/cache/doap.json'
GNOME_REPO = 'git://git.gnome.org/'
TARBALL_PATH_PREFIX = '/sources/'
@@ -308,6 +305,7 @@ class DOAP(BasicInfo):
def __init__(self):
self._did_doap = False
+ self.doap()
def doap(self):
@@ -315,14 +313,15 @@ class DOAP(BasicInfo):
# Note: some data is still in MAINTAINERS files. These are converted
# to DOAP information by scripts in gitadmin-bin module.
+ changed = False
etag = None
last_modified = None
# XXX - unfinished
- valid_uids = set(grp.getgrnam('olav').gr_mem)
+ #valid_uids = set(grp.getgrnam('olav').gr_mem)
# XXX
# XXX - unfinished
- if not os.path.exists(self.jsonfile):
+ if not os.path.exists(self.DOAP_CACHE):
force_refresh = True
if not force_refresh:
@@ -359,9 +358,9 @@ class DOAP(BasicInfo):
else:
etag, last_modified, UID_TO_MODULES, TARBALL_TO_MODULE, info = self._parse_url_handle(url_handle)
- self._info = info
- self._tarball_to_module = TARBALL_TO_MODULE
- self._uid_to_module = UID_TO_MODULES
+ self.info = info
+ self.tarball_to_module = TARBALL_TO_MODULE
+ self.uid_to_module = UID_TO_MODULES
if changed:
# save the new information
@@ -863,56 +862,48 @@ class ModuleInfo(DirectoryInfo):
relpath = os.path.join(self.section, self.module)
DirectoryInfo.__init__(self, relpath, limit_module=module)
- def _set_ldap(self):
+ def _set_doap(self):
# Determine maintainers and module name
+ doap = DOAP()
+ self.__class__._doap = doap
+
self._maintainers = []
self._reponame = self.module
- data = get_module_info(self.module)
- if len(data):
- self._maintainers = data[0][1].get('maintainerUid', [])
- self._reponame = data[0][1]['cn'][0]
+
+ modules = doap.tarball_to_module.get(self.module, [])
+ if not modules: modules.append(self.module)
+
+ if len(modules) == 1:
+ self._reponame = self.module
+ else:
+ self._reponame = list(modules)[0]
+
+ # XXX - restrict to gnomecvs users
+ self._maintainers = doap.info.get(self._reponame, {}).get('maintainers', [])
@property
def maintainers(self):
if not hasattr(self, '_maintainers'):
- self._set_ldap()
+ self._set_doap()
return self._maintainers
@property
def reponame(self):
- if not hasattr(self, '_reponame'):
- self._set_ldap()
+ if not hasattr(self.__class__, '_doap'):
+ self._set_doap()
return self._reponame
@property
def doap(self):
- if not hasattr(self, '_doap'):
- import xml.sax
- # Fetch DOAP file
- try:
- self._doap = semi_rdf.read_rdf(self.DOAPURL % self.reponame)
- except xml.sax._exceptions.SAXParseException:
- self._doap = []
+ if not hasattr(self.__class__, '_doap'):
+ self._set_doap()
- return self._doap
+ return self.__class__._doap
- def get_one_from_doap(self, needle, default=None):
- for node in self.doap:
- if node.name != (self.DOAP, "Project"):
- continue
- val = node.find_property((self.DOAP, needle))
- if val is not None:
- return val
- return default
-
- def get_from_doap(self, needle):
- for node in self.doap:
- if node.name != (self.DOAP, "Project"):
- continue
- for property in node.find_properties((self.DOAP, needle)):
- yield property
+ def get_from_doap(self, needle, default=None):
+ return self.doap.info.get(self._reponame, {}).get(needle, default)
def get_bz_product_from_doap(self):
for bz in self.get_from_doap('bug-database'):
@@ -1198,10 +1189,10 @@ Install %s? [Y/n]""" % self.module,
}
modulename = None
- desc = self.moduleinfo.get_one_from_doap('description')
- desc = self.moduleinfo.get_one_from_doap('shortdesc') if desc is None else desc
+ desc = self.moduleinfo.get_from_doap('description')
+ desc = self.moduleinfo.get_from_doap('shortdesc') if desc is None else desc
if desc is not None:
- modulename = self.moduleinfo.get_one_from_doap('name', self.module)
+ modulename = self.moduleinfo.get_from_doap('name', self.module)
self._print_header(mail, "About %s" % (modulename or self.module))
print >>mail, ""
for paragraph in desc.encode('utf-8').split("\n\n"):
@@ -1499,18 +1490,6 @@ class InstallSuites(BasicInfo):
subprocess.call(cmd, stdout=f, cwd=os.path.join(self.FTPROOT, relpath))
print ""
-l = None
-def get_module_info(module):
- global l # evil
-
- if l is None:
- l = ldap.open('ldap.gnome.org')
- l.protocol_version = ldap.VERSION3
-
- filter = ldap.filter.filter_format("(|(cn=%s)(tarballName=%s))", (module, module))
- data = l.search_s (LDAP_BASE, ldap.SCOPE_SUBTREE, filter, None)
-
- return data
def cmd_install(options, parser):
tarballs = [file for file in options.tarball if os.path.exists(file)]
@@ -1621,7 +1600,7 @@ def cmd_show_doap(options, parser):
import textwrap
print options.module
moduleinfo = ModuleInfo(options.module)
- desc = moduleinfo.get_one_from_doap('description', '')
+ desc = moduleinfo.get_from_doap('description', '')
for paragraph in desc.split("\n\n"):
if "\n" in paragraph: paragraph = re_whitespace.sub(" ", paragraph)
print textwrap.fill(paragraph)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]