msmcommd: add libmsmhll as dependency and bump PR
[openembedded.git] / contrib / opie / opie_checksum_rewrite.py
blob5e16ee9085ac4b2eef64a126a6eb53e2769e8775
1 #!/usr/bin/env python
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
10 import os
11 import sys
13 def rewrite(recpfilename, sourcedir):
14 insrc = False
15 srcfirst = False
16 sums = ''
17 appname = ''
18 output = ''
19 f = open(recpfilename, 'r')
20 for line in f:
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))
26 for line2 in f2:
27 if line2.startswith('APPNAME '):
28 appname = line2[line2.find('"'):].strip('\n\r"')
29 f2.close()
30 output = output + line
31 continue
33 if line.startswith('SRC_URI['):
34 continue
36 if line.startswith('APPNAME '):
37 appname = line[line.find('"'):].strip('\n\r"')
38 output = output + line
39 continue
41 if not insrc and line.startswith('SRC_URI '):
42 insrc = True
43 srcfirst = True
45 if insrc:
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)
53 if srcfirst:
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]
62 md5pipe.close()
64 shapipe = os.popen('sha256sum ' + localpath)
65 shadata = (shapipe.readline().split() or [ "" ])[0]
66 shapipe.close()
68 sums = sums + 'SRC_URI[%s.md5sum] = "%s"\n' % (name, md5data)
69 sums = sums + 'SRC_URI[%s.sha256sum] = "%s"\n' % (name, shadata)
71 else:
72 output = output + line
74 if (srcfirst and line.count('"') > 1) or (not srcfirst and line.find('"') > -1):
75 insrc = False
76 if sums:
77 output = output + sums
79 srcfirst = False
80 else:
81 output = output + line
83 f.close()
85 f = open(recpfilename, 'w')
86 f.write(output)
87 f.close()
91 if len(sys.argv) < 3:
92 print """syntax: %s recipe dl_dir
93 recipe - recipe.bb file
94 dl_dir - location of local source files""" % sys.argv[0]
95 sys.exit(1)
97 recipe = sys.argv[1]
98 dl_dir = sys.argv[2]
100 if not os.path.isfile(recipe):
101 print >> sys.stderr, "%s: recipe file %s not found" % recipe
102 sys.exit(1)
104 if not os.path.isdir(dl_dir):
105 print >> sys.stderr, "%s: source dir %s not found" % dl_dir
106 sys.exit(1)
108 rewrite(recipe, dl_dir)