2 # ex:ts=4:sw=4:sts=4:et
4 # Opie recipe checksum rewriter
6 # A crude script for rewriting recipes to contain checksum information
8 # Some portions copied from oe-source-checker.py, copyright (C) 2007 OpenedHand
13 def rewrite(recpfilename
, sourcedir
):
19 f
= open(recpfilename
, 'r')
21 if line
.startswith('require '):
22 pn
= os
.path
.basename(recpfilename
)
23 pn
= pn
[0:pn
.find("_")]
24 incfilename
= line
[8:].strip().replace("${PN}", pn
)
25 f2
= open(os
.path
.join(os
.path
.dirname(recpfilename
), incfilename
))
27 if line2
.startswith('APPNAME '):
28 appname
= line2
[line2
.find('"'):].strip('\n\r"')
30 output
= output
+ line
33 if line
.startswith('SRC_URI['):
36 if line
.startswith('APPNAME '):
37 appname
= line
[line
.find('"'):].strip('\n\r"')
38 output
= output
+ line
41 if not insrc
and line
.startswith('SRC_URI '):
46 pos
= line
.find('-split_')
47 pos2
= line
.find('.tar.bz2')
48 if pos
> -1 and pos2
> -1:
49 name
= line
[pos
+1:pos2
]
50 name
= name
.replace('${APPNAME}', 'appname')
51 output
= output
+ line
.replace('.tar.bz2', '.tar.bz2;name=%s' % name
)
52 filename
= line
.strip('\n\r\t "\\').replace('${APPNAME}', appname
)
54 filename
= filename
[filename
.find('"')+1:]
55 filename
= filename
.replace('http://sources.openembedded.org/', '')
56 localpath
= os
.path
.join(sourcedir
, filename
)
57 if not os
.path
.isfile(localpath
):
58 raise IOError("file %s not found" % localpath
)
60 md5pipe
= os
.popen('md5sum ' + localpath
)
61 md5data
= (md5pipe
.readline().split() or [ "" ])[0]
64 shapipe
= os
.popen('sha256sum ' + localpath
)
65 shadata
= (shapipe
.readline().split() or [ "" ])[0]
68 sums
= sums
+ 'SRC_URI[%s.md5sum] = "%s"\n' % (name
, md5data
)
69 sums
= sums
+ 'SRC_URI[%s.sha256sum] = "%s"\n' % (name
, shadata
)
72 output
= output
+ line
74 if (srcfirst
and line
.count('"') > 1) or (not srcfirst
and line
.find('"') > -1):
77 output
= output
+ sums
81 output
= output
+ line
85 f
= open(recpfilename
, 'w')
92 print """syntax: %s recipe dl_dir
93 recipe - recipe.bb file
94 dl_dir - location of local source files""" % sys
.argv
[0]
100 if not os
.path
.isfile(recipe
):
101 print >> sys
.stderr
, "%s: recipe file %s not found" % recipe
104 if not os
.path
.isdir(dl_dir
):
105 print >> sys
.stderr
, "%s: source dir %s not found" % dl_dir
108 rewrite(recipe
, dl_dir
)