Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update <releases> in appdata #34

Merged
merged 3 commits into from Aug 29, 2019

Conversation

@wjt
Copy link
Contributor

commented Aug 27, 2019

Doing this without generating a huge diff was a lot more involved than I
expected, but this seems to work OK now.

I have tested this locally against:

  • endlessm/eos-google-chrome-app, which currently has no <releases>: the checker adds it
  • flathub/us.zoom.Zoom, which already has <releases>: it prepends a new one, albeit with the attributes in a different order to the existing entries. There's a test marked expectedFailure for this; the order has no semantic impact and the 18 repos I checked have no trend towards one or another.

Fixes #17.

src/checker.py Outdated Show resolved Hide resolved
src/lib/appdata.py Show resolved Hide resolved
src/lib/appdata.py Show resolved Hide resolved
src/lib/appdata.py Outdated Show resolved Hide resolved
src/lib/appdata.py Outdated Show resolved Hide resolved
src/lib/appdata.py Outdated Show resolved Hide resolved
tests/test_appdata.py Show resolved Hide resolved

@wjt wjt force-pushed the 17-update-releases-in-appdata branch from 8dd4447 to 8a508a1 Aug 29, 2019

wjt added 2 commits Aug 26, 2019
Update <releases> in appdata
Doing this without generating a huge diff was a lot more involved than I
expected, but this seems to work OK now.

You might hope that you could write something like:

    from xml.dom import minidom

    def add_releases(appdata_path, out, version, date):
        document = minidom.parse(appdata_path)
        releases, = document.getElementsByTagName("releases")
        previous_release, *_ = releases.getElementsByTagName("release")

        new_release = document.createElement("release")
        new_release.setAttribute("version", version)
        new_release.setAttribute("date", date)

        releases.insertBefore(new_release, releases.firstChild)
        whitespace = previous_release.previousSibling
        if whitespace is not None and whitespace.nodeType == minidom.Node.TEXT_NODE:
            releases.insertBefore(whitespace.cloneNode(False), new_release)

        out.write(releases.toxml("UTF-8").decode("UTF-8"))

This is a nice concise function, and it does preserve almost all
formatting.  But, attribute order is not preserved, because
minidom.Element.writexml() unconditionally sorts attributes by name.

Instead, use a SAX-based parser plus the LexicalHandler extension to
preserve comments. There are a few cases where this implementation
doesn't quite behave as one would like, illustrated by tests decorated
with '@unittest.expectedFailure'.

Fixes #17.
debianrepochecker: strip Debian revision from package
endlessm/eos-google-chrome-app#28 added the
following to the appdata:

    <release version="76.0.3809.132-1" date="2019-08-27"/>

I think the -1 is ugly.

@wjt wjt force-pushed the 17-update-releases-in-appdata branch from 8a508a1 to fe82ed9 Aug 29, 2019

@andrunko
Copy link
Contributor

left a comment

lgtm with a small comment regarding the release date/timestamps for debian packages and firefox. I will leave it to you to decide whether you want to work on it (I am fine to do it as a follow-up change).

@wjt wjt merged commit d9bbc17 into master Aug 29, 2019

@wjt wjt deleted the 17-update-releases-in-appdata branch Aug 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.