diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2016-01-26 15:34:30 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-18 07:41:16 +0000 |
commit | ca552bb4b1d877193ba6235e6216d06b984c62db (patch) | |
tree | d6c12a0cf6b77e0a9a859dd85c51539207d87246 /bitbake/lib/bb | |
parent | 8f61f2d8812df8d8e57affd7c8a45c1054c59b83 (diff) | |
download | poky-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')
-rw-r--r-- | bitbake/lib/bb/checksum.py | 47 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 45 |
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 | ||
18 | import glob | ||
19 | import operator | ||
18 | import os | 20 | import os |
19 | import stat | 21 | import stat |
20 | import bb.utils | 22 | import 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 | |||
29 | from __future__ import print_function | 29 | from __future__ import print_function |
30 | import os, re | 30 | import os, re |
31 | import signal | 31 | import signal |
32 | import glob | ||
33 | import logging | 32 | import logging |
34 | import urllib | 33 | import urllib |
35 | import urlparse | 34 | import urlparse |
36 | import operator | ||
37 | import bb.persist_data, bb.utils | 35 | import bb.persist_data, bb.utils |
38 | import bb.checksum | 36 | import bb.checksum |
39 | from bb import data | 37 | from 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 | ||
1155 | class FetchData(object): | 1112 | class FetchData(object): |