summaryrefslogtreecommitdiffstats
path: root/bitbake
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
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')
-rw-r--r--bitbake/lib/bb/checksum.py47
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py45
2 files changed, 48 insertions, 44 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
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 83122e856c..914553aaf7 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -29,11 +29,9 @@ from __future__ import absolute_import
29from __future__ import print_function 29from __future__ import print_function
30import os, re 30import os, re
31import signal 31import signal
32import glob
33import logging 32import logging
34import urllib 33import urllib
35import urlparse 34import urlparse
36import operator
37import bb.persist_data, bb.utils 35import bb.persist_data, bb.utils
38import bb.checksum 36import bb.checksum
39from bb import data 37from bb import data
@@ -1108,48 +1106,7 @@ def get_file_checksums(filelist, pn):
1108 it proceeds 1106 it proceeds
1109 1107
1110 """ 1108 """
1111 1109 return _checksum_cache.get_checksums(filelist, pn)
1112 def checksum_file(f):
1113 try:
1114 checksum = _checksum_cache.get_checksum(f)
1115 except OSError as e:
1116 bb.warn("Unable to get checksum for %s SRC_URI entry %s: %s" % (pn, os.path.basename(f), e))
1117 return None
1118 return checksum
1119
1120 def checksum_dir(pth):
1121 # Handle directories recursively
1122 dirchecksums = []
1123 for root, dirs, files in os.walk(pth):
1124 for name in files:
1125 fullpth = os.path.join(root, name)
1126 checksum = checksum_file(fullpth)
1127 if checksum:
1128 dirchecksums.append((fullpth, checksum))
1129 return dirchecksums
1130
1131 checksums = []
1132 for pth in filelist.split():
1133 exist = pth.split(":")[1]
1134 if exist == "False":
1135 continue
1136 pth = pth.split(":")[0]
1137 if '*' in pth:
1138 # Handle globs
1139 for f in glob.glob(pth):
1140 if os.path.isdir(f):
1141 checksums.extend(checksum_dir(f))
1142 else:
1143 checksum = checksum_file(f)
1144 checksums.append((f, checksum))
1145 elif os.path.isdir(pth):
1146 checksums.extend(checksum_dir(pth))
1147 else:
1148 checksum = checksum_file(pth)
1149 checksums.append((pth, checksum))
1150
1151 checksums.sort(key=operator.itemgetter(1))
1152 return checksums
1153 1110
1154 1111
1155class FetchData(object): 1112class FetchData(object):