Skip to contentSkip to conversation

Checksums.ini again - new format this time

PATCH Marcin Juszkiewicz 8 participants 15 messages Oct 29, 2009 – Nov 10, 2009

lore
Share & tools
lore
#0 lore raw

Hi

I know that checksums.ini returns many times on ML so many of you are bored with it. But I have some stuff to show/share about it.

Sometime ago new format was suggested for conf/checksums.ini and I implemented it today. It looks simple and is simple:

[archivename]
url0=url-to-sources
url1=alternative-url-to-sources
url2=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

What differs from old implementation? Use of archive names instead of urls so no more "I fetch from my local Debian mirror and got hit by lack of checksums" etc problems. By default OE does not even care about urls - it just checks for section by archive name and use md5/sha256 sums to check does file is the proper one. Urls can be used by source mirror building tools.

How many changes are needed? Few:

1. 3 lines patch to base.bbclass
2. new checksums sorter
3. old checksums -> new checksums converter

I think that it would be nice to switch to that.

Ideas? Opinions?

Regards,

Signature · 3 lines
JID:      [email protected]
Website:  http://marcin.juszkiewicz.com.pl/
LinkedIn: http://www.linkedin.com/in/marcinjuszkiewicz
classes/base.bbclass +3 -0
index d29ba4b..bf7d49c 100644
@@ -72,6 +72,9 @@ def base_chk_file(parser, pn, pv, src_uri, localpath, data):
     elif parser.has_section(src_uri):
         md5    = parser.get(src_uri, "md5")
         sha256 = parser.get(src_uri, "sha256")
+    elif parser.has_section(os.path.basename(src_uri)):
+        md5    = parser.get(os.path.basename(src_uri), "md5")
+        sha256 = parser.get(os.path.basename(src_uri), "sha256")
     else:
         no_checksum = True
 

#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et

# Copyright (C) 2007 OpenedHand
# Copyright (C) 2009 Marcin Juszkiewicz
#
# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#
# OpenEmbedded source checksums converter
#

# based on oe-checksums-sorter.py
#
# This script parse conf/checksums.ini and converts it to new format.
# Duplicate entries are removed.
#

import ConfigParser
import getopt
import os
import sys
import tempfile

def usage(rc):
print """usage: %s [--inplace|-i] conf/checksums.ini

--inplace, -i: update file in place (default is to write to stdout)

If no input file is given, will read from standard input. """ % sys.argv[0]
sys.exit(rc)

try:

    optlist, args = getopt.getopt(sys.argv[1:], "ih", ["inplace", "help"])
except getopt.GetoptError, e:
    print >> sys.stderr, "%s: %s" % (sys.argv[0], e)
    usage(1)

inplace = False
infp = sys.stdin
filename = None
for opt, val in optlist:

    if opt == '-i' or opt == '--inplace':
        inplace = True
    elif opt == 'h' or opt == '--help':
        usage(0)
    else:
        print >> sys.stderr, "%s: %s: invalid argument" % (sys.argv[0], opt)
        usage(1)

if len(args) == 0:

    if inplace:
        print >> sys.stderr, "%s: --inplace requires a filename" % sys.argv[0]
        usage(1)

elif len(args) == 1:
filename = args[0]
try:
infp = open(filename, "r")
except Exception, e:
print >> sys.stderr, "%s: %s" % (sys.argv[0], e) sys.exit(1)
else:
print >> sys.stderr, "%s: extra arguments" % sys.argv[0] usage(1)

out = sys.stdout
tmpfn = None
if inplace:
outfd, tmpfn = tempfile.mkstemp(prefix='cksums',
dir=os.path.dirname(filename) or '.')
os.chmod(tmpfn, os.stat(filename).st_mode)
out = os.fdopen(outfd, 'w')

checksums_parser = ConfigParser.SafeConfigParser() checksums_parser.readfp(infp)

new_list = []
seen = {}

for source in checksums_parser.sections():
archive = source.split("/")[-1]
md5 = checksums_parser.get(source, "md5")
sha = checksums_parser.get(source, "sha256")

tup = (archive, source, md5, sha)
if not seen.has_key(tup):
new_list.append(tup)
seen[tup] = 1

new_list.sort()

archive = ''
archiveid = 0 # for urlX entries
sums = {} # to keep md5/sha256 in case of archive change

for entry in new_list:

    if archive != entry[0]:

        if archive != '': # not totally first entry
            print >> out, "md5=%s\nsha256=%s\n" % (sums[0], sums[1]) # print old sums
            sums = (entry[2], entry[3])

        print >> out, "[%s]\nurl0=%s" % (entry[0], entry[1])
        archive = entry[0]
        archiveid = 1

    else:
        print >> out, "url%d=%s" % (archiveid, entry[1])
        archiveid += 1

    sums = (entry[2], entry[3])

print >> out, "md5=%s\nsha256=%s\n" % (entry[2], entry[3])

if inplace:

    out.close()
    os.rename(tmpfn, filename)

#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et

# Copyright (C) 2007 OpenedHand
# Copyright (C) 2009 Marcin Juszkiewicz
#
# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#
# OpenEmbedded source checksums sorter
#
# This script parse conf/checksums.ini and sorts it alphabetically by archive

# name source archive. Duplicate entries are removed.
#

import ConfigParser
import getopt
import os
import sys
import tempfile

def usage(rc):
print """usage: %s [--inplace|-i] conf/checksums.ini

--inplace, -i: update file in place (default is to write to stdout)

If no input file is given, will read from standard input. """ % sys.argv[0]
sys.exit(rc)

try:

    optlist, args = getopt.getopt(sys.argv[1:], "ih", ["inplace", "help"])
except getopt.GetoptError, e:
    print >> sys.stderr, "%s: %s" % (sys.argv[0], e)
    usage(1)

inplace = False
infp = sys.stdin
filename = None
for opt, val in optlist:

    if opt == '-i' or opt == '--inplace':
        inplace = True
    elif opt == 'h' or opt == '--help':
        usage(0)
    else:
        print >> sys.stderr, "%s: %s: invalid argument" % (sys.argv[0], opt)
        usage(1)

if len(args) == 0:

    if inplace:
        print >> sys.stderr, "%s: --inplace requires a filename" % sys.argv[0]
        usage(1)

elif len(args) == 1:
filename = args[0]
try:
infp = open(filename, "r")
except Exception, e:
print >> sys.stderr, "%s: %s" % (sys.argv[0], e) sys.exit(1)
else:
print >> sys.stderr, "%s: extra arguments" % sys.argv[0] usage(1)

out = sys.stdout
tmpfn = None
if inplace:
outfd, tmpfn = tempfile.mkstemp(prefix='cksums',
dir=os.path.dirname(filename) or '.')
os.chmod(tmpfn, os.stat(filename).st_mode)
out = os.fdopen(outfd, 'w')

checksums_parser = ConfigParser.ConfigParser()
checksums_parser.readfp(infp)

new_list = []
seen = {}

for archive in checksums_parser.sections():
md5 = checksums_parser.get(archive, "md5")
sha = checksums_parser.get(archive, "sha256")

tup = (archive, md5, sha)

urls = []
for item in checksums_parser.items(archive):
if item[0].startswith('url'):
urls.append(item[1])

urls.sort()
for url in urls:
tup += (url, '')

if not seen.has_key(archive):
new_list.append(tup)
seen[archive] = 1

new_list.sort()

for entry in new_list:

    print >> out, "[%s]" % entry[0] 

    archiveid = 0
    for a in range(3, len(entry)):
        if entry[a]:
            print >> out, "url%d=%s" % (archiveid, entry[a])
            archiveid += 1
    print >> out, "md5=%s\nsha256=%s\n" % (entry[1], entry[2])

if inplace:

    out.close()
    os.rename(tmpfn, filename)
#1 lore raw
Quoted 1 line · Marcin Juszkiewicz

Ideas? Opinions?

There's already a checksums.ini session scheduled at OEDEM. Let's talk about it then.

p.

#2 lore raw
Quoted 5 lines · Phil Blundell
Quoted 1 line · Marcin Juszkiewicz

Ideas? Opinions?

There's already a checksums.ini session scheduled at OEDEM. Let's talk about it then.

What's wrong with talking about it in the open right now?

#3 lore raw
In reply to Marcin Juszkiewicz
Quoted 24 lines · Marcin Juszkiewicz

Hi

I know that checksums.ini returns many times on ML so many of you are bored with it. But I have some stuff to show/share about it.

Sometime ago new format was suggested for conf/checksums.ini and I implemented it today. It looks simple and is simple:

[archivename]
url0=url-to-sources
url1=alternative-url-to-sources
url2=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

What differs from old implementation? Use of archive names instead of urls so no more "I fetch from my local Debian mirror and got hit by lack of checksums" etc problems. By default OE does not even care about urls - it just checks for section by archive name and use md5/sha256 sums to check does file is the proper one. Urls can be used by source mirror building tools.

How many changes are needed? Few:

Quoted 7 lines

1. 3 lines patch to base.bbclass
2. new checksums sorter
3. old checksums -> new checksums converter

I think that it would be nice to switch to that.

Ideas? Opinions?

Even though the cabal apparantly doesn't want people to respond to your idea, I'm going to respond anyway.

I like your idea and think we should implement it. I'm not sure how the urlX entries would benefit my usecase, but I suppose it doesn't hurt to have them.

regards,

Koen

#4 lore raw
In reply to Marcin Juszkiewicz

Hello,

Quoted 7 lines · Marcin Juszkiewicz

[archivename]
url0=url-to-sources
url1=alternative-url-to-sources
url2=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Can we simplify this a bit? i.e.

archivename
url=url-to-sources
url=alternative-url-to-sources
url=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Why not just url instead of url0, url1, url2, ... ?

If you need ordering, just use the order they appear in the file.

+1 for the idea,

Regards,

Signature · 1 line
Leon
#6 lore raw
Quoted 2 lines · On Sunday 01 November 2009 23:59:18 Andrea Adami wrote:

And what about having a checksum file in each dir of /recipes ? If the checksum changes the PR should be changed too.

I think that is the best way in terms of scalability and BB collections. We have some weird cases where we might do require ../ but these are broken or need to duplicate the checksums...

z.

#7 lore raw

Holger Hans Peter Freyther <[email protected]> [2009-11-02 03:09:56]:

Quoted 8 lines · On Sunday 01 November 2009 23:59:18 Andrea Adami wrote:
Quoted 2 lines

And what about having a checksum file in each dir of /recipes ? If the checksum changes the PR should be changed too.

I think that is the best way in terms of scalability and BB collections. We have some weird cases where we might do require ../ but these are broken or need to duplicate the checksums...

I like this idea more than one monolitic checksum file. checksums.ini is place for storing of a duplicate information anyway. You need to enter URL in checksums, you need to enter URL again into recipe.

Wouldn't it be better to write URL with checksum once at one place and reuse it than in recipe as some kind of variable or something like that?

Well, at least that hrw's modification avoids sorting process...

-- ynezz

#8 lore raw
Quoted 11 lines · Petr ?tetiar

Holger Hans Peter Freyther <[email protected]> [2009-11-02 03:09:56]:

Quoted 8 lines · On Sunday 01 November 2009 23:59:18 Andrea Adami wrote:
Quoted 2 lines

And what about having a checksum file in each dir of /recipes ? If the checksum changes the PR should be changed too.

I think that is the best way in terms of scalability and BB collections. We have some weird cases where we might do require ../ but these are broken or need to duplicate the checksums...

Quoted 6 lines

I like this idea more than one monolitic checksum file. checksums.ini is place for storing of a duplicate information anyway. You need to enter URL in checksums, you need to enter URL again into recipe.

Wouldn't it be better to write URL with checksum once at one place and reuse it than in recipe as some kind of variable or something like that?

It was discussed during OEDEM and the conclusion was to switch to using checksums in SRC_URIs of corresponding recipes.

--
Denys

#9 lore raw
In reply to Leon Woestenberg
Quoted 14 lines · On Sunday 01 November 2009 21:35:32 Leon Woestenberg wrote:

Hello,

On Thu, Oct 29, 2009 at 12:41 PM, Marcin Juszkiewicz

Quoted 6 lines · <[email protected]> wrote:

[archivename]
url0=url-to-sources
url1=alternative-url-to-sources
url2=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Can we simplify this a bit? i.e.

Quoted 8 lines

archivename
url=url-to-sources
url=alternative-url-to-sources
url=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Why not just url instead of url0, url1, url2, ... ?

the problem with archivename there is no gurantee that the name will be globally unique. E.g. with Open Palmtop Integreated Environment (OPIE) One Password.. (OPIE) there was a clash and we might or might not have had a clash in release versions too...

z.

#10 lore raw
Quoted 22 lines · Holger Hans Peter Freyther
Quoted 21 lines · On Sunday 01 November 2009 21:35:32 Leon Woestenberg wrote:

Hello,

On Thu, Oct 29, 2009 at 12:41 PM, Marcin Juszkiewicz

Quoted 6 lines · <[email protected]> wrote:

[archivename]
url0=url-to-sources
url1=alternative-url-to-sources
url2=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Can we simplify this a bit? i.e.

archivename
url=url-to-sources
url=alternative-url-to-sources
url=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Quoted 6 lines
Quoted 1 line

Why not just url instead of url0, url1, url2, ... ?

the problem with archivename there is no gurantee that the name will be globally unique. E.g. with Open Palmtop Integreated Environment (OPIE) One Password.. (OPIE) there was a clash and we might or might not have had a clash in release versions too...

Archives get stored by archive name in DL_DIR already, so that's a moot point.

regards,

Koen

#11 lore raw
Quoted 7 lines · On Monday 02 November 2009 09:41:42 Koen Kooi wrote:
Quoted 4 lines

the problem with archivename there is no gurantee that the name will be globally unique. E.g. with Open Palmtop Integreated Environment (OPIE) One Password.. (OPIE) there was a clash and we might or might not have had a clash in release versions too...

Archives get stored by archive name in DL_DIR already, so that's a moot point.

No, it means we have another bug somewhere else. :)

#12 lore raw

Hello,

Quoted 4 lines · Holger Hans Peter Freyther

On Monday 02 November 2009 09:41:42 Koen Kooi wrote:

No, it means we have another bug somewhere else. :)

We must define a key for finding the correct entry. I think the package name should be that key value and has always been?

(Or did we use the full original URL as the lookup key for the package in the checksum file?)

BTW, googling for the MD5/SHA256 is a very good cheat for finding alternative locations, as I have learned during development of 'witpa'.

Regards,

Signature · 1 line
Leon
#13 lore raw
In reply to Holger Hans Peter Freyther

Dnia poniedziałek, 2 listopada 2009 o 03:06:33 Holger Hans Peter Freyther napisał(a):

Quoted 4 lines

the problem with archivename there is no gurantee that the name will be globally unique. E.g. with Open Palmtop Integreated Environment (OPIE) One Password.. (OPIE) there was a clash and we might or might not have had a
clash in release versions too...

So far we have nearly 9k entries and no repeated names. When we will get such one then we can keep URLs for them as keys instead of archive names. OE supports both situations (my scripts not).

Regards,

Signature · 3 lines
JID:      [email protected]
Website:  http://marcin.juszkiewicz.com.pl/
LinkedIn: http://www.linkedin.com/in/marcinjuszkiewicz
#14 lore raw
In reply to Leon Woestenberg

Dnia niedziela, 1 listopada 2009 o 21:35:32 Leon Woestenberg napisał(a):

Quoted 17 lines

On Thu, Oct 29, 2009 at 12:41 PM, Marcin Juszkiewicz

Quoted 6 lines

[archivename]
url0=url-to-sources
url1=alternative-url-to-sources
url2=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Can we simplify this a bit? i.e.

archivename
url=url-to-sources
url=alternative-url-to-sources
url=another-alternative-url-to-sources
md5=md5sum
sha256=sha256sum

Quoted 3 lines

Why not just url instead of url0, url1, url2, ... ?

If you need ordering, just use the order they appear in the file.

ConfigParser class which we use will not behave properly I think (not tested that). And urlX lines are not used by OE anyway (but are usable for mirror scripts).

Regards,

Signature · 3 lines
JID:      [email protected]
Website:  http://marcin.juszkiewicz.com.pl/
LinkedIn: http://www.linkedin.com/in/marcinjuszkiewicz