#!/usr/bin/python import os, re, sha, stat, time, urllib, xml.sax.saxutils def generate_dict(name, version, tarball): regex = re.compile('^  \[Download\]$' % tarball) found_license = -1 # Handle CPAN's new "UNAUTHORIZED RELEASE" feature. if name in [ 'Algorithm-Diff', 'TermReadKey' ]: url = 'http://search.cpan.org/dist/%s-%s/' % (name, version) else: url = 'http://search.cpan.org/dist/%s/' % name f = urllib.urlopen(url) for line in f.readlines(): # match download path m = regex.match(line) if m: path = m.group(1) # match license if found_license >= 0: found_license = found_license + 1 if found_license == 2: license = line.strip() found_license = -1 if line == ' License\n': found_license = 0 f.close() filename = 'modules/%s/%s' % (name, tarball) # Calculate checksum. h = sha.new() f = file(filename) h.update(f.read()) f.close() checksum = h.hexdigest() # Determine import date. svn_info_command = os.popen('svn info %s | grep \'^Last Changed Date: \' | awk \'{ print $4 }\'' % filename) import_date = svn_info_command.read().strip() svn_info_command.close() # Output dictionary. print '\t' print '\t\tOpenSourceProject' print '\t\t%s' % name print '\t\tOpenSourceVersion' print '\t\t%s' % version print '\t\tOpenSourceWebsiteURL' print '\t\t%s' % url print '\t\tOpenSourceURL' print '\t\thttp://search.cpan.org/CPAN/%s/%s' % (path, tarball) print '\t\tOpenSourceSHA1' print '\t\t%s' % checksum print '\t\tOpenSourceImportDate' print '\t\t%s' % import_date print '\t\tOpenSourceLicense' print '\t\t%s' % xml.sax.saxutils.escape(license) print '\t\tOpenSourceLicenseFile' print '\t\tsvk.txt' print '\t' # Grab the raw module list. make_command = os.popen('make -C modules plist') modules = map(lambda x: x.strip(), make_command.readlines()) make_command.close() # Split and sort the raw list. module_list = [] for idx in range(0, len(modules), 3): module_list.append(modules[idx:idx+3]) module_list.sort(key=lambda x: x[0].lower()) # Output property list header. print '' print '' print '' print '' # Output dictionary for each module. map(lambda x: generate_dict(x[0], x[1], x[2]), module_list) # Output property list footer. print '' print ''