summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-11-09 11:44:55 -0800
committerAnas Nashif <anas.nashif@intel.com>2012-11-09 11:44:55 -0800
commit44b560e25016645fa5a9984cd0ca2e380046a185 (patch)
tree75883f4c10375062d09100e852bbda2a2226ebdd /scripts
downloadpattern-tools-44b560e25016645fa5a9984cd0ca2e380046a185.tar.gz
pattern-tools-44b560e25016645fa5a9984cd0ca2e380046a185.tar.bz2
pattern-tools-44b560e25016645fa5a9984cd0ca2e380046a185.zip
initial checkin 001
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cleanup-patterns.py34
-rwxr-xr-xscripts/convert-to-yaml.py41
-rwxr-xr-xscripts/find-duplicates.py23
-rwxr-xr-xscripts/gitlog2changelog.py124
-rwxr-xr-xscripts/merge-patterns.py91
-rwxr-xr-xscripts/merge-request.sh20
-rwxr-xr-xscripts/test-patterns.sh15
-rwxr-xr-xscripts/update.sh14
8 files changed, 362 insertions, 0 deletions
diff --git a/scripts/cleanup-patterns.py b/scripts/cleanup-patterns.py
new file mode 100755
index 0000000..ab1e5ec
--- /dev/null
+++ b/scripts/cleanup-patterns.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import yaml
+import sys, os
+import optparse
+
+
+def sort_pkgs(patterns_dir='patterns'):
+ for f in os.listdir(patterns_dir):
+ if not f.endswith('.yaml'):
+ continue
+ print f
+ stream = file("%s/%s" %(patterns_dir,f), 'r+')
+ y = yaml.load(stream)
+ if y.has_key('Packages'):
+ y['Packages'] = sorted(y['Packages'])
+ yf = yaml.dump(y, default_flow_style=False)
+ stream.seek(0)
+ stream.write(yf)
+ stream.close()
+
+
+
+if __name__ == '__main__':
+ parser = optparse.OptionParser()
+
+ parser.add_option("-s", "--sort", action="store_true", default=False,
+ help="sort packages")
+
+ (options, args) = parser.parse_args()
+
+ if options.sort:
+ sort_pkgs()
+
diff --git a/scripts/convert-to-yaml.py b/scripts/convert-to-yaml.py
new file mode 100755
index 0000000..19eb0ee
--- /dev/null
+++ b/scripts/convert-to-yaml.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+
+import xml.etree.ElementTree as ET
+import sys
+import yaml
+import os
+
+
+
+for f in os.listdir("patterns"):
+ if '.xml' not in f:
+ continue
+ tree = ET.parse("patterns/%s" %f)
+
+ p = {}
+ namespace="http://linux.duke.edu/metadata/rpm"
+ pns = 'http://novell.com/package/metadata/suse/pattern'
+ n = tree.find('{%s}name' %pns).text
+ if n.startswith("meego-"):
+ n = n[6:]
+ p['Name'] = n
+ s = tree.find('{%s}summary' %pns).text
+ if s.startswith("MeeGo"):
+ s = s[5:].lstrip()
+ p['Summary'] = s
+ p['Description'] = tree.find('{%s}description' %pns).text
+ req = tree.findall('.//{%s}entry' % namespace)
+ pkgs = []
+ for r in req:
+ pkgs.append(r.attrib.get("name"))
+
+ p['Packages'] = pkgs
+ yf = yaml.dump(p, default_flow_style=False)
+
+ yfn = os.path.basename(f).rpartition(".")[0] + ".yaml"
+ if yfn.startswith("meego-"):
+ yfn = yfn[6:]
+ fp = open("new/%s" %yfn, 'w')
+ fp.write(yf)
+ fp.close()
+
diff --git a/scripts/find-duplicates.py b/scripts/find-duplicates.py
new file mode 100755
index 0000000..c725e92
--- /dev/null
+++ b/scripts/find-duplicates.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import xml.etree.ElementTree as ET
+import sys
+
+tree1 = ET.parse(sys.argv[1])
+tree2= ET.parse(sys.argv[2])
+
+namespace="http://linux.duke.edu/metadata/rpm"
+req1 = tree1.findall('.//{%s}entry' % namespace)
+req2 = tree2.findall('.//{%s}entry' % namespace)
+l2 = []
+l1 = []
+for r in req1:
+ l1.append(r.attrib.get("name"))
+for r in req2:
+ l2.append(r.attrib.get("name"))
+
+s1 = set(sorted(l1))
+s2 = set(sorted(l2))
+intersection = s1 & s2
+for i in intersection:
+ print i
diff --git a/scripts/gitlog2changelog.py b/scripts/gitlog2changelog.py
new file mode 100755
index 0000000..ce69b68
--- /dev/null
+++ b/scripts/gitlog2changelog.py
@@ -0,0 +1,124 @@
+#!/usr/bin/python
+# Copyright 2008 Marcus D. Hanwell <marcus@cryos.org>
+# Distributed under the terms of the GNU General Public License v2 or later
+
+import string, re, os
+
+# Execute git log with the desired command line options.
+fin = os.popen('git log --summary --stat --no-merges --date=short', 'r')
+# Create a ChangeLog file in the current directory.
+fout = open('ChangeLog', 'w')
+
+# Set up the loop variables in order to locate the blocks we want
+authorFound = False
+dateFound = False
+messageFound = False
+filesFound = False
+message = ""
+messageNL = False
+files = ""
+prevAuthorLine = ""
+
+# The main part of the loop
+for line in fin:
+ # The commit line marks the start of a new commit object.
+ if string.find(line, 'commit') >= 0:
+ # Start all over again...
+ authorFound = False
+ dateFound = False
+ messageFound = False
+ messageNL = False
+ message = ""
+ filesFound = False
+ files = ""
+ continue
+ # Match the author line and extract the part we want
+ elif re.match('Author:', line) >=0:
+ authorList = re.split(': ', line, 1)
+ author = authorList[1]
+ author = author[0:len(author)-1]
+ authorFound = True
+ # Match the date line
+ elif re.match('Date:', line) >= 0:
+ dateList = re.split(': ', line, 1)
+ date = dateList[1]
+ date = date[0:len(date)-1]
+ dateFound = True
+ # The svn-id lines are ignored
+ elif re.match(' git-svn-id:', line) >= 0:
+ continue
+ # The sign off line is ignored too
+ elif re.search('Signed-off-by', line) >= 0:
+ continue
+ # Extract the actual commit message for this commit
+ elif authorFound & dateFound & messageFound == False:
+ # Find the commit message if we can
+ if len(line) == 1:
+ if messageNL:
+ messageFound = True
+ else:
+ messageNL = True
+ elif len(line) == 4:
+ messageFound = True
+ else:
+ if len(message) == 0:
+ message = message + line.strip()
+ else:
+ message = message + " " + line.strip()
+ # If this line is hit all of the files have been stored for this commit
+ elif re.search('files changed', line) >= 0:
+ filesFound = True
+ continue
+ # Collect the files for this commit. FIXME: Still need to add +/- to files
+ elif authorFound & dateFound & messageFound:
+ fileList = re.split(' \| ', line, 2)
+ if len(fileList) > 1:
+ if len(files) > 0:
+ files = files + ", " + fileList[0].strip()
+ else:
+ files = fileList[0].strip()
+ # All of the parts of the commit have been found - write out the entry
+ if authorFound & dateFound & messageFound & filesFound:
+ # First the author line, only outputted if it is the first for that
+ # author on this day
+ authorLine = date + " " + author
+ if len(prevAuthorLine) == 0:
+ fout.write(authorLine + "\n")
+ elif authorLine == prevAuthorLine:
+ pass
+ else:
+ fout.write("\n" + authorLine + "\n")
+
+ # Assemble the actual commit message line(s) and limit the line length
+ # to 80 characters.
+ commitLine = "* " + files + ": " + message
+ i = 0
+ commit = ""
+ while i < len(commitLine):
+ if len(commitLine) < i + 78:
+ commit = commit + "\n " + commitLine[i:len(commitLine)]
+ break
+ index = commitLine.rfind(' ', i, i+78)
+ if index > i:
+ commit = commit + "\n " + commitLine[i:index]
+ i = index+1
+ else:
+ commit = commit + "\n " + commitLine[i:78]
+ i = i+79
+
+ # Write out the commit line
+ fout.write(commit + "\n")
+
+ #Now reset all the variables ready for a new commit block.
+ authorFound = False
+ dateFound = False
+ messageFound = False
+ messageNL = False
+ message = ""
+ filesFound = False
+ files = ""
+ prevAuthorLine = authorLine
+
+# Close the input and output lines now that we are finished.
+fin.close()
+fout.close()
diff --git a/scripts/merge-patterns.py b/scripts/merge-patterns.py
new file mode 100755
index 0000000..f6b9068
--- /dev/null
+++ b/scripts/merge-patterns.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+
+import yaml
+import sys, os
+import optparse
+from lxml import etree
+
+
+def create_patterns(arch='i586', split=False, patterns_dir='patterns', output="."):
+
+ rpm_ns="http://linux.duke.edu/metadata/rpm"
+ pattern_ns="http://novell.com/package/metadata/suse/pattern"
+ PATTERN = "{%s}" % pattern_ns
+ if not split:
+ xmlroot = etree.Element("patterns")
+ NSMAP = {None : pattern_ns, "rpm": rpm_ns, "patterns": pattern_ns}
+ else:
+ NSMAP = {None : pattern_ns, "rpm": rpm_ns}
+
+ count = 0
+ for f in os.listdir(patterns_dir):
+ if not f.endswith('.yaml'):
+ continue
+ count = count + 1
+ stream = file("%s/%s" %(patterns_dir,f), 'r')
+ y = yaml.load(stream)
+ if y.has_key('Arch') and y['Arch'] != arch:
+ print "Skipping pattern '%s' because architecture doesn't match ('%s' vs '%s')." % (y['Name'], y['Arch'], arch)
+ continue
+ if split:
+ proot = etree.Element("pattern", nsmap=NSMAP)
+ else:
+ proot = etree.SubElement(xmlroot, "pattern", nsmap=NSMAP)
+
+ etree.SubElement(proot, "name").text = y['Name']
+ etree.SubElement(proot, "summary").text = y['Summary']
+ etree.SubElement(proot, "description").text = y['Description']
+ etree.SubElement(proot, "uservisible")
+ cat = etree.SubElement(proot, "category")
+ cat.text = "Base Group"
+ cat.set("lang", "en")
+ req = etree.SubElement(proot, "{%s}requires" %rpm_ns)
+ if y.has_key('Patterns'):
+ collect = []
+ for pat in y['Patterns']:
+ if os.path.exists("%s/%s.yaml" %(patterns_dir, pat)):
+ pf = file("%s/%s.yaml" %(patterns_dir, pat), 'r')
+ pfy = yaml.load(pf)
+ if pfy.has_key('Packages'):
+ collect += pfy['Packages']
+ elif y.has_key('Packages'):
+ collect = y['Packages']
+
+ for p in collect:
+ if type(p).__name__=='dict':
+ a = p.values()[0]
+ if a == arch:
+ entry = etree.SubElement(req, "{%s}entry" %rpm_ns)
+ entry.set("name", p.keys()[0])
+ entry.set("arch", arch)
+ else:
+ entry = etree.SubElement(req, "{%s}entry" %rpm_ns)
+ entry.set("name", p)
+ if split:
+ tree = etree.ElementTree(proot)
+ tree.write("%s.xml" %y['Name'], pretty_print=True)
+
+ if not split:
+ xmlroot.set('count', "%d" %count)
+ tree = etree.ElementTree(xmlroot)
+ tree.write("%s/patterns.xml" %(output))
+
+
+if __name__ == '__main__':
+ parser = optparse.OptionParser()
+
+ parser.add_option("-a", "--arch", type="string", dest="arch", default="i586", help="architecture")
+ parser.add_option("-s", "--split", action="store_true", dest="split", default=False,
+ help="split patterns into single files")
+ parser.add_option("-p", "--pattern-dir", type="string", dest="patterns", default="patterns",
+ help="Directory where patterns reside.")
+ parser.add_option("-o", "--output-dir", type="string", dest="output", default=".",
+ help="Directory where to put patterns file.")
+
+ (options, args) = parser.parse_args()
+
+ if options.arch and options.arch in ['i586', 'arm']:
+ create_patterns(arch=options.arch, split=options.split, patterns_dir=options.patterns, output=options.output)
+ else:
+ sys.stderr.write("Unsupported architecture\n")
+ sys.exit(1)
diff --git a/scripts/merge-request.sh b/scripts/merge-request.sh
new file mode 100755
index 0000000..43275d0
--- /dev/null
+++ b/scripts/merge-request.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+if [ -z "$1" ]; then
+ echo "Merge request number needed"
+ exit 1
+fi
+
+# Check out a new branch for integration
+git checkout -b merge-requests/$1
+
+# Fetch the merge request into this branch
+git pull git://gitorious.org/meego-os-base/package-groups.git refs/merge-requests/$1
+
+# Show the commits, assess they are okay
+git log --pretty=oneline --abbrev-commit master..merge-requests/$1
+
+# To apply the changes to your branch:
+git checkout master
+git merge merge-requests/$1
+git push origin master
diff --git a/scripts/test-patterns.sh b/scripts/test-patterns.sh
new file mode 100755
index 0000000..fd1c888
--- /dev/null
+++ b/scripts/test-patterns.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+if [ -z "$1" ]; then
+ echo "You need to provide a pattern name as an argument"
+ exit 1
+fi
+PATTERN=$@
+TMPDIR=`mktemp -d`
+mkdir -p $TMPDIR
+CMD="zypper --gpg-auto-import-keys -R $TMPDIR "
+$CMD ar http://download.meego.com/snapshots/1.1.90.3.20110216.81/oss/repos/ia32/packages/ oss
+$CMD ar http://download.meego.com/snapshots/1.1.90.3.20110216.81/non-oss/repos/ia32/packages/ non-oss
+$CMD in --dry-run --type pattern $PATTERN
+
+rm -rf $TMPDIR
diff --git a/scripts/update.sh b/scripts/update.sh
new file mode 100755
index 0000000..22eca32
--- /dev/null
+++ b/scripts/update.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+ARCH=$1
+mkdir new
+for i in `ls -1 patterns/*.xml`; do
+ base=`basename $i`
+ xsltproc --stringparam arch $ARCH xsl/filter.xsl $i > new/$base
+done
+echo "<index>" > INDEX.xml;
+for i in `ls -1 new/*.xml`; do echo "<file>$i</file>" >> INDEX.xml; done;
+echo "</index>" >> INDEX.xml
+xsltproc xsl/merge.xsl INDEX.xml > patterns.xml
+xsltproc xsl/comps.xsl patterns.xml > group.xml
+rm -rf new