Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb48591' into 'master'
[repomd-pattern-builder] Adapt to use python3. Fixes JB#48591

See merge request mer-core/repomd-pattern-builder!1
  • Loading branch information
mlehtima committed Feb 15, 2020
2 parents 313a253 + 1a011b8 commit 0ef82a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 81 deletions.
30 changes: 15 additions & 15 deletions repomd-pattern-builder.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

# This script is used to convert .yaml files to patterns and package groups.
# Copyright (C) 2011 Marko Saukko <FIRSTNAME.LASTNAME@gmail.com>
Expand Down Expand Up @@ -34,7 +34,7 @@
def process_yaml(stream, version, release, xmlroot, nsmap_name, newobsapi):
"Process all documents in the yaml stream and return a count of number handled"

all_docs = yaml.load_all(stream)
all_docs = yaml.load_all(stream, Loader = yaml.SafeLoader)

for y in all_docs:
# <pattern>
Expand All @@ -46,7 +46,7 @@ def process_yaml(stream, version, release, xmlroot, nsmap_name, newobsapi):
# Old OBS isn't able to handle these options.
if newobsapi:
# <version>
if y.has_key('Version') or version:
if 'Version' in y or version:
entry = etree.SubElement(proot, "version")
ver = "0"
if version:
Expand All @@ -56,22 +56,22 @@ def process_yaml(stream, version, release, xmlroot, nsmap_name, newobsapi):

# Set to 0 by default as that is what OBS expects.
epoch = "0"
if y.has_key('Epoch'):
if 'Epoch' in y:
epoch = y['Epoch']

# As above...
rel = "0"
if release:
rel = release
if y.has_key('Release'):
if 'Release' in y:
rel = y['Release']

entry.set('ver', "%s" % ver)
entry.set('epoch', "%s" % epoch)
entry.set('rel', "%s" % rel)

# <arch>
if y.has_key('Arch'):
if 'Arch' in y:
etree.SubElement(proot, "arch").text = "%s" % y['Arch']

# <summary>
Expand All @@ -87,20 +87,20 @@ def process_yaml(stream, version, release, xmlroot, nsmap_name, newobsapi):

package_keys = ['Packages','Conflicts', 'Requires', 'Recommends', 'Suggests', 'Provides', 'Obsoletes']
for key in package_keys:
if not y.has_key(key):
if key not in y:
continue

collect = y[key]
if key == "Packages":
# Support obsoleted keys, this should be removed in the future
key = "Requires"
print "WARNING: Oboleted key 'Packages' in .yaml please change to 'Requires'."
print ("WARNING: Oboleted key 'Packages' in .yaml please change to 'Requires'.")

req = etree.SubElement(proot, "{%s}%s" % (rpm_ns,key.lower()))

for p in collect:
if type(p).__name__=='dict':
print "ERROR: Found dict and expected string value. '%s'" % (p)
print ("ERROR: Found dict and expected string value. '%s'" % (p))
sys.exit(1)
entry = etree.SubElement(req, "{%s}entry" %rpm_ns)

Expand All @@ -127,7 +127,7 @@ def create_patterns(patterns_dir, version, release, outputdir, newobsapi):
if not f.endswith('.yaml'):
continue

stream = file("%s/%s" %(patterns_dir,f), 'r')
stream = open("%s/%s" %(patterns_dir,f), 'r')
xmlroot = etree.Element("temporary_root", nsmap=NSMAP)

process_yaml(stream, version, release, xmlroot, NSMAP, newobsapi)
Expand All @@ -136,10 +136,10 @@ def create_patterns(patterns_dir, version, release, outputdir, newobsapi):

name = pattern.find("name")
if name == None:
print "Pattern didn't have name skipping."
print ("Pattern didn't have name skipping.")
continue
output_file = "%s/%s.xml" % (outputdir,name.text.lower())
print "Working on %s" % (output_file)
print ("Working on %s" % (output_file))

etree.ElementTree(pattern).write(output_file, pretty_print=True)

Expand All @@ -152,7 +152,7 @@ def merge_patterns(patterns_dir, version, release, outputdir, newobsapi):
for f in dirlist:
if not f.endswith('.yaml'):
continue
print "Merging %s to %s." % (f,output_file)
print ("Merging %s to %s." % (f,output_file))
stream = file("%s/%s" %(patterns_dir,f), 'r')
process_yaml(stream, version, release, xmlroot, NSMAP_GROUP, newobsapi)

Expand Down Expand Up @@ -188,15 +188,15 @@ def merge_patterns(patterns_dir, version, release, outputdir, newobsapi):
(options, args) = parser.parse_args()

if (options.groupxml):
print "ERROR: Groupxml isn't supported atm."
print ("ERROR: Groupxml isn't supported atm.")
exit(1)

if (not options.patternsxml and not options.patternxml):
# Default to patternxml.
options.patternxml = True

if (not options.patterndir or not os.path.exists(options.patterndir)):
print "Error: Pattern dir '%s' doesn't exist." % (options.patterndir)
print ("Error: Pattern dir '%s' doesn't exist." % (options.patterndir))
exit(1)

if options.outputdir and not os.path.exists(options.outputdir):
Expand Down
48 changes: 8 additions & 40 deletions rpm/repomd-pattern-builder.spec
@@ -1,75 +1,43 @@
#
# Do NOT Edit the Auto-generated Part!
# Generated by: spectacle version 0.25
#

Name: repomd-pattern-builder

# >> macros
# << macros

Summary: Scripts to build patterns for the rpm repository.
Summary: Scripts to build patterns for the rpm repository
Version: 0.3
Release: 1
Group: Software Management/Package Manager
License: GPLv2
URL: https://gitorious.org/meego-developer-edition-for-n900/repomd-pattern-builder
License: GPLv2+
URL: https://git.sailfishos.org/mer-core/repomd-pattern-builder
Source0: %{name}-%{version}.tar.xz
Source100: repomd-pattern-builder.yaml
Requires: python
Requires: python-yaml
Requires: python-lxml
Requires: python3-base
Requires: python3-yaml
Requires: python3-lxml
Requires: /usr/bin/xmllint

%description
Script that converts .yaml structures to suitable rpm patterns and package groups.


%package tests
Summary: tests for %{name}
Group: QA/Tests
Summary: Tests for %{name}
Requires: %{name} = %{version}-%{release}
Requires: diffutils

%description tests
%{summary}.



%prep
%setup -q -n %{name}-%{version}

# >> setup
# << setup

%build
# >> build pre
# << build pre



# >> build post
# << build post

%install
rm -rf %{buildroot}
# >> install pre
%make_install
# << install pre

# >> install post
# << install post


%files
%defattr(-,root,root,-)
# >> files
%license COPYING
%{_bindir}/%{name}.py
# << files

%files tests
%defattr(-,root,root,-)
# >> files tests
/opt/tests/repomd-pattern-builder/tests.xml
/opt/tests/repomd-pattern-builder/data/*
# << files tests
26 changes: 0 additions & 26 deletions rpm/repomd-pattern-builder.yaml

This file was deleted.

0 comments on commit 0ef82a2

Please sign in to comment.