summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/checksum.py
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2016-01-26 15:34:30 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-18 07:41:16 +0000
commitca552bb4b1d877193ba6235e6216d06b984c62db (patch)
treed6c12a0cf6b77e0a9a859dd85c51539207d87246 /bitbake/lib/bb/checksum.py
parent8f61f2d8812df8d8e57affd7c8a45c1054c59b83 (diff)
downloadpoky-ca552bb4b1d877193ba6235e6216d06b984c62db.tar.gz
bitbake: FileChecksumCache: add get_checksums() method
Move the local file checksum functionality from bb.fetch2 into bb.checksum module. (Bitbake rev: 4f60933283f377d68f191db849dac6c1dc7a0aed) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/checksum.py')
-rw-r--r--bitbake/lib/bb/checksum.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/bitbake/lib/bb/checksum.py b/bitbake/lib/bb/checksum.py
index 514ff0b1e6..7fb46d8db5 100644
--- a/bitbake/lib/bb/checksum.py
+++ b/bitbake/lib/bb/checksum.py
@@ -15,6 +15,8 @@
15# with this program; if not, write to the Free Software Foundation, Inc., 15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 17
18import glob
19import operator
18import os 20import os
19import stat 21import stat
20import bb.utils 22import bb.utils
@@ -88,3 +90,48 @@ class FileChecksumCache(MultiProcessCache):
88 dest[0][h] = source[0][h] 90 dest[0][h] = source[0][h]
89 else: 91 else:
90 dest[0][h] = source[0][h] 92 dest[0][h] = source[0][h]
93
94 def get_checksums(self, filelist, pn):
95 """Get checksums for a list of files"""
96
97 def checksum_file(f):
98 try:
99 checksum = self.get_checksum(f)
100 except OSError as e:
101 bb.warn("Unable to get checksum for %s SRC_URI entry %s: %s" % (pn, os.path.basename(f), e))
102 return None
103 return checksum
104
105 def checksum_dir(pth):
106 # Handle directories recursively
107 dirchecksums = []
108 for root, dirs, files in os.walk(pth):
109 for name in files:
110 fullpth = os.path.join(root, name)
111 checksum = checksum_file(fullpth)
112 if checksum:
113 dirchecksums.append((fullpth, checksum))
114 return dirchecksums
115
116 checksums = []
117 for pth in filelist.split():
118 exist = pth.split(":")[1]
119 if exist == "False":
120 continue
121 pth = pth.split(":")[0]
122 if '*' in pth:
123 # Handle globs
124 for f in glob.glob(pth):
125 if os.path.isdir(f):
126 checksums.extend(checksum_dir(f))
127 else:
128 checksum = checksum_file(f)
129 checksums.append((f, checksum))
130 elif os.path.isdir(pth):
131 checksums.extend(checksum_dir(pth))
132 else:
133 checksum = checksum_file(pth)
134 checksums.append((pth, checksum))
135
136 checksums.sort(key=operator.itemgetter(1))
137 return checksums