Merge lp:~milo/linaro-image-tools/boards-support into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 551
Merged at revision: 538
Proposed branch: lp:~milo/linaro-image-tools/boards-support
Merge into: lp:linaro-image-tools/11.11
Diff against target: 3436 lines (+1871/-432)
15 files modified
linaro-hwpack-install (+20/-5)
linaro_image_tools/hwpack/builder.py (+145/-48)
linaro_image_tools/hwpack/config.py (+495/-205)
linaro_image_tools/hwpack/hardwarepack.py (+170/-25)
linaro_image_tools/hwpack/hardwarepack_format.py (+9/-0)
linaro_image_tools/hwpack/hwpack_convert.py (+15/-3)
linaro_image_tools/hwpack/hwpack_fields.py (+3/-0)
linaro_image_tools/hwpack/tests/__init__.py (+1/-0)
linaro_image_tools/hwpack/tests/test_config.py (+10/-8)
linaro_image_tools/hwpack/tests/test_config_v3.py (+738/-0)
linaro_image_tools/hwpack/tests/test_hardwarepack.py (+133/-86)
linaro_image_tools/hwpack/tests/test_hwpack_converter.py (+24/-0)
linaro_image_tools/media_create/boards.py (+27/-27)
linaro_image_tools/media_create/chroot_utils.py (+12/-2)
linaro_image_tools/media_create/tests/test_media_create.py (+69/-23)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/boards-support
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Stevan Radaković Pending
Linaro Infrastructure Pending
Review via email: mp+116300@code.launchpad.net

Description of the change

With this branch I added support for the boards section in the Config class and metadata file.

I reworked a couple of sections in the metadata file, where we were modifying fields value. Now that happens in the builder.py file, reworking the necessary fields there, and in metadata we just reset the whole attribute that holds the modified values.

I reworked a little bit the builder class in order to clean up also the methods call.

To post a comment you must log in.
Revision history for this message
Milo Casagrande (milo) wrote :

This branch applies to the one that is already in review. Once that gets in, this one would be easier to read.

551. By Milo Casagrande

Merged other changes.

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-hwpack-install'
2--- linaro-hwpack-install 2012-07-05 14:44:04 +0000
3+++ linaro-hwpack-install 2012-07-23 15:38:22 +0000
4@@ -41,7 +41,7 @@
5 FORCE_YES="no"
6 SOURCES_LIST_FILE="${TEMP_DIR}/sources.list"
7 APT_GET_OPTIONS="Dir::Etc::SourceList=${SOURCES_LIST_FILE}"
8-SUPPORTED_FORMATS="1.0 2.0" # A space-separated list of hwpack formats.
9+SUPPORTED_FORMATS="1.0 2.0 3.0" # A space-separated list of hwpack formats.
10
11 sudo="sudo"
12 if [ $(id -u) -eq 0 ]; then
13@@ -53,12 +53,15 @@
14 exit 1
15 }
16
17-usage_msg="Usage: $(basename $0) [--install-latest] [--force-yes] HWPACK_TARBALL"
18+usage_msg="Usage: $(basename $0) [--install-latest] [--force-yes] --hwpack-version <version> --hwpack-arch <architecture> --hwpack-name <name> HWPACK_TARBALL"
19 if [ $# -eq 0 ]; then
20 die $usage_msg
21 fi
22
23 HWPACK_TARBALL_FOUND="no"
24+HWPACK_VERSION=""
25+HWPACK_ARCH=""
26+HWPACK_NAME=""
27
28 while [ $# -gt 0 ]; do
29 case "$1" in
30@@ -68,6 +71,18 @@
31 --force-yes)
32 FORCE_YES="yes"
33 shift;;
34+ --hwpack-version)
35+ HWPACK_VERSION=$2
36+ shift;
37+ shift;;
38+ --hwpack-arch)
39+ HWPACK_ARCH=$2
40+ shift;
41+ shift;;
42+ --hwpack-name)
43+ HWPACK_NAME=$2
44+ shift;
45+ shift;;
46 --*)
47 die $usage_msg "\nUnrecognized option: \"$1\"";;
48 *)
49@@ -79,6 +94,9 @@
50 done
51
52 [ "$HWPACK_TARBALL_FOUND" = "no" ] && die $usage_msg
53+[ "$HWPACK_VERSION" = "" ] && die $usage_msg
54+[ "$HWPACK_ARCH" = "" ] && die $usage_msg
55+[ "$HWPACK_NAME" = "" ] && die $usage_msg
56
57 # Try to acquire fd #9 (i.e. /var/lock/hwpack) for 2 seconds.
58 # Using 9 as the file descriptor because of https://launchpad.net/bugs/249620
59@@ -125,7 +143,6 @@
60 "Try using a newer version of $(basename $0)."
61
62 # Check the architecture of the hwpack matches that of the host system.
63-HWPACK_ARCH=`grep ARCHITECTURE "${HWPACK_DIR}/metadata" | cut -d "=" -f2`
64 [ "$HWPACK_ARCH" == `dpkg --print-architecture` ] || \
65 die "Hardware pack architecture ($HWPACK_ARCH) does not match the host's architecture"
66
67@@ -209,8 +226,6 @@
68 # For "older" hwpacks that don't have a dependency package, we just
69 # manually install the contents of the hwpack.
70
71-HWPACK_NAME=`grep NAME "${HWPACK_DIR}/metadata" | cut -d "=" -f2`
72-HWPACK_VERSION=`grep VERSION "${HWPACK_DIR}/metadata" | cut -d "=" -f2`
73 dependency_package="hwpack-${HWPACK_NAME}"
74 if grep -q "^${dependency_package}=${HWPACK_VERSION}\$" "${HWPACK_DIR}"/manifest; then
75 DEP_PACKAGE_PRESENT="yes"
76
77=== modified file 'linaro_image_tools/hwpack/builder.py'
78--- linaro_image_tools/hwpack/builder.py 2012-06-13 14:53:32 +0000
79+++ linaro_image_tools/hwpack/builder.py 2012-07-23 15:38:22 +0000
80@@ -36,6 +36,20 @@
81 PackageFetcher,
82 )
83
84+from linaro_image_tools.hwpack.hwpack_fields import (
85+ FILE_FIELD,
86+ PACKAGE_FIELD,
87+ SPL_FILE_FIELD,
88+ SPL_PACKAGE_FIELD,
89+)
90+
91+# The fields that hold packages to be installed.
92+PACKAGE_FIELDS = [PACKAGE_FIELD, SPL_PACKAGE_FIELD]
93+# The fields that hold values that should be reset to newly calculated ones.
94+# The values of the dictionary are the fields whose values should be reset.
95+FIELDS_TO_CHANGE = {PACKAGE_FIELD: FILE_FIELD,
96+ SPL_PACKAGE_FIELD: SPL_FILE_FIELD}
97+
98
99 logger = logging.getLogger(__name__)
100
101@@ -92,6 +106,9 @@
102 self.format = self.config.format
103 self.version = version
104 self.local_debs = local_debs
105+ self.package_unpacker = None
106+ self.hwpack = None
107+ self.packages = None
108
109 def find_fetched_package(self, packages, wanted_package_name):
110 wanted_package = None
111@@ -104,81 +121,161 @@
112 wanted_package_name)
113 return wanted_package
114
115- def add_file_to_hwpack(self, package, wanted_file, package_unpacker,
116- hwpack, target_path):
117- tempfile_name = package_unpacker.get_file(
118+ def add_file_to_hwpack(self, package, wanted_file, target_path):
119+ tempfile_name = self.package_unpacker.get_file(
120 package.filepath, wanted_file)
121- return hwpack.add_file(target_path, tempfile_name)
122+ return self.hwpack.add_file(target_path, tempfile_name)
123+
124+ def find_bootloader_packages(self, bootloaders_config):
125+ """Loop through the bootloaders dictionary searching for packages
126+ that should be installed, based on known keywords.
127+
128+ :param bootloaders_config: The bootloaders dictionary to loop through.
129+ :return A list of packages, without duplicates."""
130+ boot_packages = []
131+ for key, value in bootloaders_config.iteritems():
132+ if isinstance(value, dict):
133+ boot_packages.extend(self.find_bootloader_packages(value))
134+ else:
135+ if key in PACKAGE_FIELDS:
136+ boot_packages.append(value)
137+ # Eliminate duplicates.
138+ return list(set(boot_packages))
139+
140+ def _set_new_values(self, config_dictionary):
141+ """Loop through the bootloaders sections of a hwpack, also from the
142+ boards section, changing the necessary values with the newly calculated
143+ ones.
144+
145+ :param config_dictionary: The dictionary from the Config we need to
146+ look into.
147+ """
148+ remove_packages = []
149+ for key, value in config_dictionary.iteritems():
150+ if isinstance(value, dict):
151+ self._set_new_values(value)
152+ else:
153+ if key in FIELDS_TO_CHANGE.keys():
154+ if key == PACKAGE_FIELD:
155+ # Need to use the correct path for the packages.
156+ path = self.hwpack.U_BOOT_DIR
157+ else:
158+ path = self.hwpack.SPL_DIR
159+ change_field = FIELDS_TO_CHANGE.get(key)
160+ boot_package = value
161+ boot_file = config_dictionary.get(change_field)
162+ if boot_package is not None and boot_file is not None:
163+ package = self.find_fetched_package(
164+ self.packages,
165+ boot_package)
166+ file_to_add = self.add_file_to_hwpack(
167+ package, boot_file, path)
168+ config_dictionary[change_field] = file_to_add
169+ remove_packages.append(package)
170+ # Clean up duplicates.
171+ for package in remove_packages:
172+ if package in self.packages:
173+ self.packages.remove(package)
174
175 def build(self):
176 for architecture in self.config.architectures:
177 logger.info("Building for %s" % architecture)
178 metadata = Metadata.from_config(
179 self.config, self.version, architecture)
180- hwpack = HardwarePack(metadata)
181+ self.hwpack = HardwarePack(metadata)
182 sources = self.config.sources
183 with LocalArchiveMaker() as local_archive_maker:
184- hwpack.add_apt_sources(sources)
185+ self.hwpack.add_apt_sources(sources)
186 sources = sources.values()
187- packages = self.config.packages[:]
188- if self.config.u_boot_package is not None:
189- packages.append(self.config.u_boot_package)
190- if self.config.spl_package is not None:
191- packages.append(self.config.spl_package)
192+ self.packages = self.config.packages[:]
193+ # Loop through multiple bootloaders.
194+ # In V3 of hwpack configuration, all the bootloaders info and
195+ # packages are in the bootloaders section.
196+ if self.format.format_as_string == '3.0':
197+ if self.config.bootloaders is not None:
198+ self.packages.extend(self.find_bootloader_packages(
199+ self.config.bootloaders))
200+ if self.config.boards is not None:
201+ self.packages.extend(self.find_bootloader_packages(
202+ self.config.boards))
203+ else:
204+ if self.config.u_boot_package is not None:
205+ self.packages.append(self.config.u_boot_package)
206+ if self.config.spl_package is not None:
207+ self.packages.append(self.config.spl_package)
208 local_packages = [
209 FetchedPackage.from_deb(deb)
210 for deb in self.local_debs]
211 sources.append(
212 local_archive_maker.sources_entry_for_debs(
213 local_packages, LOCAL_ARCHIVE_LABEL))
214- packages.extend([lp.name for lp in local_packages])
215+ self.packages.extend([lp.name for lp in local_packages])
216 logger.info("Fetching packages")
217 fetcher = PackageFetcher(
218 sources, architecture=architecture,
219 prefer_label=LOCAL_ARCHIVE_LABEL)
220 with fetcher:
221- with PackageUnpacker() as package_unpacker:
222+ with PackageUnpacker() as self.package_unpacker:
223 fetcher.ignore_packages(self.config.assume_installed)
224- packages = fetcher.fetch_packages(
225- packages,
226+ self.packages = fetcher.fetch_packages(
227+ self.packages,
228 download_content=self.config.include_debs)
229
230- u_boot_package = None
231- if self.config.u_boot_file is not None:
232- assert self.config.u_boot_package is not None
233- u_boot_package = self.find_fetched_package(
234- packages, self.config.u_boot_package)
235- hwpack.metadata.u_boot = self.add_file_to_hwpack(
236- u_boot_package, self.config.u_boot_file,
237- package_unpacker, hwpack, hwpack.U_BOOT_DIR)
238-
239- spl_package = None
240- if self.config.spl_file is not None:
241- assert self.config.spl_package is not None
242- spl_package = self.find_fetched_package(
243- packages, self.config.spl_package)
244- hwpack.metadata.spl = self.add_file_to_hwpack(
245- spl_package, self.config.spl_file,
246- package_unpacker, hwpack, hwpack.SPL_DIR)
247-
248- # u_boot_package and spl_package can be identical
249- if (u_boot_package is not None and
250- u_boot_package in packages):
251- packages.remove(u_boot_package)
252- if (spl_package is not None and
253- spl_package in packages):
254- packages.remove(spl_package)
255+ # On a v3 hwpack, all the values we need to check are
256+ # in the bootloaders and boards section, so we loop
257+ # through both of them changing what is necessary.
258+ if self.config.format.format_as_string == '3.0':
259+ if self.config.bootloaders is not None:
260+ self._set_new_values(self.config.bootloaders)
261+ metadata.bootloaders = self.config.bootloaders
262+ if self.config.boards is not None:
263+ self._set_new_values(self.config.boards)
264+ metadata.boards = self.config.boards
265+ else:
266+ u_boot_package = None
267+ if self.config.u_boot_file is not None:
268+ assert self.config.u_boot_package is not None
269+ u_boot_package = self.find_fetched_package(
270+ self.packages,
271+ self.config.u_boot_package)
272+ self.hwpack.metadata.u_boot = \
273+ self.add_file_to_hwpack(
274+ u_boot_package,
275+ self.config.u_boot_file,
276+ self.hwpack.U_BOOT_DIR)
277+
278+ spl_package = None
279+ if self.config.spl_file is not None:
280+ assert self.config.spl_package is not None
281+ spl_package = self.find_fetched_package(
282+ self.packages,
283+ self.config.spl_package)
284+ self.hwpack.metadata.spl = \
285+ self.add_file_to_hwpack(
286+ spl_package,
287+ self.config.spl_file,
288+ self.hwpack.SPL_DIR)
289+
290+ # u_boot_package and spl_package can be identical
291+ if (u_boot_package is not None and
292+ u_boot_package in self.packages):
293+ self.packages.remove(u_boot_package)
294+ if (spl_package is not None and
295+ spl_package in self.packages):
296+ self.packages.remove(spl_package)
297
298 logger.debug("Adding packages to hwpack")
299- hwpack.add_packages(packages)
300+ self.hwpack.add_packages(self.packages)
301 for local_package in local_packages:
302- if local_package not in packages:
303+ if local_package not in self.packages:
304 logger.warning(
305 "Local package '%s' not included",
306 local_package.name)
307- hwpack.add_dependency_package(self.config.packages)
308- with open(hwpack.filename(), 'w') as f:
309- hwpack.to_file(f)
310- logger.info("Wrote %s" % hwpack.filename())
311- with open(hwpack.filename('.manifest.txt'), 'w') as f:
312- f.write(hwpack.manifest_text())
313+ self.hwpack.add_dependency_package(
314+ self.config.packages)
315+ with open(self.hwpack.filename(), 'w') as f:
316+ self.hwpack.to_file(f)
317+ logger.info("Wrote %s" % self.hwpack.filename())
318+ with open(self.hwpack.filename('.manifest.txt'),
319+ 'w') as f:
320+ f.write(self.hwpack.manifest_text())
321
322=== modified file 'linaro_image_tools/hwpack/config.py'
323--- linaro_image_tools/hwpack/config.py 2012-06-13 14:53:32 +0000
324+++ linaro_image_tools/hwpack/config.py 2012-07-23 15:38:22 +0000
325@@ -20,14 +20,68 @@
326 # USA.
327
328 import ConfigParser
329+from operator import attrgetter
330 import re
331 import string
332+import yaml
333
334 from linaro_image_tools.hwpack.hardwarepack_format import (
335 HardwarePackFormatV1,
336 HardwarePackFormatV2,
337+ HardwarePackFormatV3,
338 )
339
340+from hwpack_fields import (
341+ ARCHITECTURES_FIELD,
342+ ARCHITECTURE_FIELD,
343+ ASSUME_INSTALLED_FIELD,
344+ BOARDS_FIELD,
345+ BOOTLOADERS_FIELD,
346+ BOOT_MIN_SIZE_FIELD,
347+ BOOT_SCRIPT_FIELD,
348+ DD_FIELD,
349+ DTB_ADDR_FIELD,
350+ DTB_FILE_FIELD,
351+ ENV_DD_FIELD,
352+ EXTRA_BOOT_OPTIONS_FIELD,
353+ EXTRA_SERIAL_OPTIONS_FIELD,
354+ FILE_FIELD,
355+ FORMAT_FIELD,
356+ INCLUDE_DEBS_FIELD,
357+ IN_BOOT_PART_FIELD,
358+ INITRD_ADDR_FIELD,
359+ INITRD_FILE_FIELD,
360+ KERNEL_ADDR_FIELD,
361+ KERNEL_FILE_FIELD,
362+ LOAD_ADDR_FIELD,
363+ LOADER_MIN_SIZE_FIELD,
364+ LOADER_START_FIELD,
365+ MAINTAINER_FIELD,
366+ MMC_ID_FIELD,
367+ NAME_FIELD,
368+ ORIGIN_FIELD,
369+ PACKAGE_FIELD,
370+ PACKAGES_FIELD,
371+ PARTITION_LAYOUT_FIELD,
372+ ROOT_MIN_SIZE_FIELD,
373+ SAMSUNG_BL1_LEN_FIELD,
374+ SAMSUNG_BL1_START_FIELD,
375+ SAMSUNG_BL2_LEN_FIELD,
376+ SAMSUNG_ENV_LEN_FIELD,
377+ SERIAL_TTY_FIELD,
378+ SNOWBALL_STARTUP_FILES_CONFIG_FIELD,
379+ SOURCES_FIELD,
380+ SPL_DD_FIELD,
381+ SPL_FILE_FIELD,
382+ SPL_IN_BOOT_PART_FIELD,
383+ SPL_PACKAGE_FIELD,
384+ SUPPORT_FIELD,
385+ WIRED_INTERFACES_FIELD,
386+ WIRELESS_INTERFACES_FIELD,
387+ DEFINED_PARTITION_LAYOUTS,
388+ VERSION_FIELD,
389+)
390+
391
392 class HwpackConfigError(Exception):
393 pass
394@@ -35,81 +89,101 @@
395
396 class Config(object):
397 """Encapsulation of a hwpack-create configuration."""
398+ translate_v2_to_v3 = {}
399+ translate_v2_metadata = {}
400
401 MAIN_SECTION = "hwpack"
402- NAME_KEY = "name"
403 NAME_REGEX = r"[a-z0-9][a-z0-9+\-.]+$"
404- INCLUDE_DEBS_KEY = "include-debs"
405- SUPPORT_KEY = "support"
406 SOURCES_ENTRY_KEY = "sources-entry"
407- PACKAGES_KEY = "packages"
408 PACKAGE_REGEX = NAME_REGEX
409 PATH_REGEX = r"\w[\w+\-./_]+$"
410 GLOB_REGEX = r"[\w+\-./_\*]+$"
411- ORIGIN_KEY = "origin"
412- MAINTAINER_KEY = "maintainer"
413- ARCHITECTURES_KEY = "architectures"
414+ INCLUDE_DEBS_KEY = "include-debs"
415+ translate_v2_to_v3[INCLUDE_DEBS_KEY] = INCLUDE_DEBS_FIELD
416+ translate_v2_metadata[ARCHITECTURES_FIELD] = "ARCHITECTURE"
417 ASSUME_INSTALLED_KEY = "assume-installed"
418+ translate_v2_to_v3[ASSUME_INSTALLED_KEY] = ASSUME_INSTALLED_FIELD
419 U_BOOT_PACKAGE_KEY = "u_boot_package"
420+ translate_v2_to_v3[U_BOOT_PACKAGE_KEY] = PACKAGE_FIELD
421 U_BOOT_FILE_KEY = "u_boot_file"
422+ translate_v2_to_v3[U_BOOT_FILE_KEY] = FILE_FIELD
423+ translate_v2_metadata[U_BOOT_FILE_KEY] = "U_BOOT"
424 SPL_FILE_KEY = "spl_file"
425- SERIAL_TTY_KEY = "serial_tty"
426- KERNEL_ADDR_KEY = "kernel_addr"
427- INITRD_ADDR_KEY = "initrd_addr"
428- LOAD_ADDR_KEY = "load_addr"
429- DTB_ADDR_KEY = "dtb_addr"
430- WIRED_INTERFACES_KEY = "wired_interfaces"
431- WIRELESS_INTERFACES_KEY = "wireless_interfaces"
432- PARTITION_LAYOUT_KEY = "partition_layout"
433- MMC_ID_KEY = "mmc_id"
434- FORMAT_KEY = "format"
435- BOOT_MIN_SIZE_KEY = "boot_min_size"
436- ROOT_MIN_SIZE_KEY = "root_min_size"
437- LOADER_MIN_SIZE_KEY = "loader_min_size"
438- LOADER_START_KEY = "loader_start"
439- SPL_PACKAGE_KEY = "spl_package"
440- VMLINUZ_KEY = "kernel_file"
441- INITRD_KEY = "initrd_file"
442- DTB_FILE_KEY = "dtb_file"
443- EXTRA_BOOT_OPTIONS_KEY = 'extra_boot_options'
444- BOOT_SCRIPT_KEY = 'boot_script'
445+ translate_v2_metadata[SPL_FILE_KEY] = "SPL"
446 UBOOT_IN_BOOT_PART_KEY = 'u_boot_in_boot_part'
447+ translate_v2_to_v3[UBOOT_IN_BOOT_PART_KEY] = IN_BOOT_PART_FIELD
448 UBOOT_DD_KEY = 'u_boot_dd'
449- SPL_IN_BOOT_PART_KEY = 'spl_in_boot_part'
450- SPL_DD_KEY = 'spl_dd'
451- ENV_DD_KEY = 'env_dd'
452- EXTRA_SERIAL_OPTS_KEY = 'extra_serial_options'
453- SNOWBALL_STARTUP_FILES_CONFIG_KEY = 'snowball_startup_files_config'
454- SAMSUNG_BL1_START_KEY = 'samsung_bl1_start'
455- SAMSUNG_BL1_LEN_KEY = 'samsung_bl1_len'
456- SAMSUNG_ENV_LEN_KEY = 'samsung_env_len'
457- SAMSUNG_BL2_LEN_KEY = 'samsung_bl2_len'
458-
459- DEFINED_PARTITION_LAYOUTS = [
460- 'bootfs16_rootfs',
461- 'bootfs_rootfs',
462- 'reserved_bootfs_rootfs',
463- ]
464-
465- def __init__(self, fp):
466+ translate_v2_to_v3[UBOOT_DD_KEY] = DD_FIELD
467+
468+ def __init__(self, fp, bootloader=None, board=None):
469 """Create a Config.
470
471 :param fp: a file-like object containing the configuration.
472 """
473+ obfuscated_e = None
474+ obfuscated_yaml_e = ""
475 try:
476 self.parser = ConfigParser.RawConfigParser()
477 self.parser.readfp(fp)
478 except ConfigParser.Error, e:
479 obfuscated_e = re.sub(r"([^ ]https://).+?(@)", r"\1***\2", str(e))
480- raise ConfigParser.Error(obfuscated_e)
481+
482+ if obfuscated_e:
483+ # obfuscated_e being set indicates that something went wrong.
484+ # It could be that the input is in fact YAML. Try the YAML
485+ # parser.
486+ try:
487+ fp.seek(0)
488+ self.parser = yaml.safe_load(fp)
489+ except yaml.YAMLError, e:
490+ obfuscated_yaml_e = re.sub(r"([^ ]https://).+?(@)",
491+ r"\1***\2", str(e))
492+ else:
493+ # If YAML parsed OK, we don't have an error.
494+ obfuscated_e = None
495+ self.set_board(board)
496+ self.set_bootloader(bootloader)
497+
498+ if obfuscated_e:
499+ # If INI parsing from ConfigParser or YAML parsing failed,
500+ # print both error messages.
501+ msg = ("Failed to parse hardware pack configuration. Tried to "
502+ "parse as both INI and YAML. INI parsing error:\n" +
503+ obfuscated_e + "\n" +
504+ "YAML parser error:\n" +
505+ obfuscated_yaml_e)
506+ raise ConfigParser.Error(msg)
507+
508+ def set_bootloader(self, bootloader):
509+ """Set bootloader used to look up configuration in bootloader section.
510+
511+ If bootloader is None / empty and there is only one bootloader
512+ available, use that.
513+ """
514+ if not bootloader:
515+ # Auto-detect bootloader. If there is a single bootloader specified
516+ # then use it, else, error.
517+ bootloaders = self.bootloaders
518+ if isinstance(bootloaders, dict):
519+ # We have a list of bootloaders in the expected format
520+ bootloaders = bootloaders.keys()
521+ if len(bootloaders) == 1:
522+ bootloader = bootloaders[0]
523+
524+ self.bootloader = bootloader
525+
526+ def set_board(self, board):
527+ """Set board used to look up per-board configuration"""
528+ self.board = board
529
530 def validate(self):
531 """Check that this configuration follows the schema.
532
533 :raises HwpackConfigError: if it does not.
534 """
535- if not self.parser.has_section(self.MAIN_SECTION):
536- raise HwpackConfigError("No [%s] section" % self.MAIN_SECTION)
537+ if isinstance(self.parser, ConfigParser.RawConfigParser):
538+ if not self.parser.has_section(self.MAIN_SECTION):
539+ raise HwpackConfigError("No [%s] section" % self.MAIN_SECTION)
540 self._validate_format()
541 self._validate_name()
542 self._validate_include_debs()
543@@ -153,88 +227,234 @@
544 self._validate_samsung_env_len()
545 self._validate_samsung_bl2_len()
546
547- self._validate_sections()
548+ self._validate_sources()
549
550 @property
551 def format(self):
552 """The format of the hardware pack. A subclass of HardwarePackFormat.
553 """
554- try:
555- format_string = self.parser.get(self.MAIN_SECTION, self.FORMAT_KEY)
556- except ConfigParser.NoOptionError:
557- # Default to 1.0 to aviod breaking existing hwpack files.
558- # When this code no longer supports 1.0, it effectively makes
559- # explicitly specifying format in hwpack files mandatory.
560- format_string = "1.0"
561+ if isinstance(self.parser, ConfigParser.RawConfigParser):
562+ try:
563+ format_string = self.parser.get(self.MAIN_SECTION,
564+ FORMAT_FIELD)
565+ except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
566+ # Default to 1.0 to aviod breaking existing hwpack files.
567+ # When this code no longer supports 1.0, it effectively makes
568+ # explicitly specifying format in hwpack files mandatory.
569+ format_string = "1.0"
570+ else:
571+ format_string = self.parser.get(FORMAT_FIELD)
572
573 if format_string == '1.0':
574 return HardwarePackFormatV1()
575 elif format_string == '2.0':
576 return HardwarePackFormatV2()
577+ elif format_string == 3.0 or format_string == '3.0':
578+ return HardwarePackFormatV3()
579 else:
580- raise HwpackConfigError("Format version '%s' is not supported." % \
581- format_string)
582+ raise HwpackConfigError("Format version '%s' is not supported." %
583+ format_string)
584
585 @property
586 def name(self):
587 """The name of the hardware pack. A str."""
588- return self.parser.get(self.MAIN_SECTION, self.NAME_KEY)
589+ return self._get_option(NAME_FIELD)
590+
591+ @property
592+ def version(self):
593+ return self._get_option(VERSION_FIELD)
594
595 @property
596 def include_debs(self):
597 """Whether the hardware pack should contain .debs. A bool."""
598 try:
599- if not self.parser.get(
600- self.MAIN_SECTION, self.INCLUDE_DEBS_KEY):
601+ if self._get_option(self.INCLUDE_DEBS_KEY) == None:
602 return True
603- return self.parser.getboolean(
604- self.MAIN_SECTION, self.INCLUDE_DEBS_KEY)
605+ try:
606+ return self._get_option_bool(self.INCLUDE_DEBS_KEY)
607+ except ValueError as e:
608+ raise HwpackConfigError("Invalid value for include-debs: %s" %
609+ e)
610 except ConfigParser.NoOptionError:
611 return True
612
613 @property
614+ def bootloaders(self):
615+ """Bootloaders available in the hardware pack"""
616+ return self._get_option(BOOTLOADERS_FIELD)
617+
618+ @property
619+ def boards(self):
620+ """Multiple boards available in the hardware pack."""
621+ return self._get_option(BOARDS_FIELD)
622+
623+ @property
624 def uboot_in_boot_part(self):
625 """Whether uboot binary should be put in the boot partition. A str."""
626- return self.parser.get(self.MAIN_SECTION, self.UBOOT_IN_BOOT_PART_KEY)
627+ return self._get_bootloader_option(self.UBOOT_IN_BOOT_PART_KEY)
628
629 @property
630 def uboot_dd(self):
631 """If the uboot binary should be dd:d to the boot partition
632 this field specifies the offset. An int."""
633- return self._get_option_from_main_section(self.UBOOT_DD_KEY)
634+ return self._get_bootloader_option(self.UBOOT_DD_KEY)
635
636 @property
637 def spl_in_boot_part(self):
638 """Whether spl binary should be put in the boot partition. A str."""
639- return self._get_option_from_main_section(self.SPL_IN_BOOT_PART_KEY)
640+ return self._get_bootloader_option(SPL_IN_BOOT_PART_FIELD)
641
642 @property
643 def spl_dd(self):
644 """If the spl binary should be dd:d to the boot partition
645 this field specifies the offset. An int."""
646- return self._get_option_from_main_section(self.SPL_DD_KEY)
647+ return self._get_bootloader_option(SPL_DD_FIELD)
648
649 @property
650 def env_dd(self):
651 """If the env should be dd:d to the boot partition. 'Yes' or 'No'."""
652- return self._get_option_from_main_section(self.ENV_DD_KEY)
653-
654- def _get_option_from_main_section(self, key):
655- """Get the value from the main section for the given key.
656+ return self._get_bootloader_option(ENV_DD_FIELD)
657+
658+ def _get_option_bool(self, key):
659+ """Gets a boolean value from the key."""
660+ if self.format.format_as_string == '3.0':
661+ value = self._get_option(key, convert_to="disable")
662+ if isinstance(value, bool):
663+ return value
664+ else:
665+ raise ValueError(value)
666+ else:
667+ try:
668+ return self.parser.getboolean(self.MAIN_SECTION, key)
669+ except ConfigParser.NoOptionError:
670+ return None
671+
672+ def _get_bootloader_option(self, key, join_list_with=False,
673+ convert_to=None):
674+ """Get an option inside the current bootloader section."""
675+ if self._is_v3:
676+ if not self.bootloader:
677+ raise ValueError("bootloader not set.")
678+ if not isinstance(key, list):
679+ keys = [key]
680+ keys = [BOOTLOADERS_FIELD, self.bootloader] + keys
681+ else:
682+ keys = key
683+
684+ return self._get_option(keys, join_list_with, convert_to)
685+
686+ def _bool_to_string(self, value):
687+ """Convert value, treated as boolean, to string "yes" or "no"."""
688+ if value:
689+ return "yes"
690+ else:
691+ return "no"
692+
693+ def _hex_addrress(self, value):
694+ """Convert value to 8 character hex string"""
695+ converted_value = value
696+ if not isinstance(value, str):
697+ converted_value = "0x%08x" % value
698+ return converted_value
699+
700+ def _v2_key_to_v3(self, key):
701+ """Convert V2 key to a V3 key"""
702+ if key in self.translate_v2_to_v3:
703+ key = self.translate_v2_to_v3[key]
704+ return key
705+
706+ def _get_v3_option(self, keys):
707+ """Find value in config dictionary based on supplied list (keys)."""
708+ result = self.parser
709+ for key in keys:
710+ key = self._v2_key_to_v3(key)
711+ if result is not None:
712+ result = result.get(key, None)
713+ return result
714+
715+ def get_option(self, name):
716+ """Return the value of an attribute by name.
717+
718+ Used when you can't use a property.
719+ """
720+ return attrgetter(name)(self)
721+
722+ def _get_option(self, key, join_list_with=False, convert_to=None):
723+ """Return value for the given key. Precedence to board specific values.
724
725 :param key: the key to return the value for.
726 :type key: str.
727+ :param join_list_with: Used to convert lists to strings.
728+ :type join_list_with: str
729+ :param convert_to: Used to convert stored value to another type.
730+ :type convert_to: type or function.
731 :return: the value for that key, or None if the key is not present
732 or the value is empty.
733 :rtype: str or None.
734 """
735- try:
736- result = self.parser.get(self.MAIN_SECTION, key)
737+ if self.format.format_as_string == "3.0":
738+ if not isinstance(key, list):
739+ keys = [key]
740+ else:
741+ keys = key
742+
743+ result = None # Just mark result as not set yet...
744+
745+ # If board is set, search board specific keys first
746+ if self.board:
747+ result = self._get_v3_option([BOARDS_FIELD, self.board] + keys)
748+
749+ # If a board specific value isn't found, look for a global one
750+ if result == None:
751+ result = self._get_v3_option(keys)
752+
753+ # If no value is found, bail early (return None)
754+ if result == None:
755+ return None
756+
757+ # <v3 compatibility: Lists of items can be converted to strings
758+ if join_list_with and isinstance(result, list):
759+ result = join_list_with.join(result)
760+
761+ # <v3 compatibility:
762+ # To aid code that is trying to keep the format of results the
763+ # same as before, we have some type conversions. By default
764+ # booleans are "yes" or "no", integers are converted to
765+ # strings.
766+ if not convert_to:
767+ if isinstance(result, int):
768+ if isinstance(result, bool):
769+ convert_to = self._bool_to_string
770+ else:
771+ convert_to = str
772+
773+ if convert_to and convert_to != "disable":
774+ if isinstance(result, list):
775+ new_list = []
776+ for item in result:
777+ new_list = convert_to(item)
778+ result = new_list
779+ else:
780+ result = convert_to(result)
781+ else:
782+ try:
783+ result = self.parser.get(self.MAIN_SECTION, key)
784+ except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
785+ # May be trying to read a metadata file, which has uppercase
786+ # keys, some of which need translating to different strings...
787+ if key in self.translate_v2_metadata:
788+ key = self.translate_v2_metadata[key]
789+ else:
790+ key = key.upper()
791+ try:
792+ result = self.parser.get(self.MAIN_SECTION, key)
793+ except (ConfigParser.NoOptionError,
794+ ConfigParser.NoSectionError):
795+ result = None
796 if not result:
797- return None
798- return result
799- except ConfigParser.NoOptionError:
800- return None
801+ result = None
802+
803+ return result
804
805 @property
806 def serial_tty(self):
807@@ -242,7 +462,7 @@
808
809 A str.
810 """
811- return self._get_option_from_main_section(self.SERIAL_TTY_KEY)
812+ return self._get_option(SERIAL_TTY_FIELD)
813
814 @property
815 def extra_boot_options(self):
816@@ -250,7 +470,8 @@
817
818 A str.
819 """
820- return self._get_option_from_main_section(self.EXTRA_BOOT_OPTIONS_KEY)
821+ return self._get_bootloader_option(EXTRA_BOOT_OPTIONS_FIELD,
822+ join_list_with=" ")
823
824 @property
825 def extra_serial_opts(self):
826@@ -258,7 +479,7 @@
827
828 A str.
829 """
830- return self._get_option_from_main_section(self.EXTRA_SERIAL_OPTS_KEY)
831+ return self._get_option(EXTRA_SERIAL_OPTIONS_FIELD, join_list_with=" ")
832
833 @property
834 def boot_script(self):
835@@ -266,7 +487,7 @@
836
837 A str.
838 """
839- return self._get_option_from_main_section(self.BOOT_SCRIPT_KEY)
840+ return self._get_option(BOOT_SCRIPT_FIELD)
841
842 @property
843 def snowball_startup_files_config(self):
844@@ -274,8 +495,7 @@
845
846 A str.
847 """
848- return self._get_option_from_main_section(
849- self.SNOWBALL_STARTUP_FILES_CONFIG_KEY)
850+ return self._get_option(SNOWBALL_STARTUP_FILES_CONFIG_FIELD)
851
852 @property
853 def kernel_addr(self):
854@@ -283,7 +503,8 @@
855
856 An int.
857 """
858- return self._get_option_from_main_section(self.KERNEL_ADDR_KEY)
859+ return self._get_option(KERNEL_ADDR_FIELD,
860+ convert_to=self._hex_addrress)
861
862 @property
863 def initrd_addr(self):
864@@ -291,7 +512,8 @@
865
866 An int.
867 """
868- return self._get_option_from_main_section(self.INITRD_ADDR_KEY)
869+ return self._get_option(INITRD_ADDR_FIELD,
870+ convert_to=self._hex_addrress)
871
872 @property
873 def load_addr(self):
874@@ -299,7 +521,7 @@
875
876 An int.
877 """
878- return self._get_option_from_main_section(self.LOAD_ADDR_KEY)
879+ return self._get_option(LOAD_ADDR_FIELD, convert_to=self._hex_addrress)
880
881 @property
882 def dtb_addr(self):
883@@ -307,7 +529,7 @@
884
885 An int.
886 """
887- return self._get_option_from_main_section(self.DTB_ADDR_KEY)
888+ return self._get_option(DTB_ADDR_FIELD, convert_to=self._hex_addrress)
889
890 @property
891 def wired_interfaces(self):
892@@ -315,7 +537,7 @@
893
894 A list of str.
895 """
896- return self._get_list_from_main_section(self.WIRED_INTERFACES_KEY)
897+ return self._get_list(WIRED_INTERFACES_FIELD)
898
899 @property
900 def wireless_interfaces(self):
901@@ -323,7 +545,7 @@
902
903 A list of str.
904 """
905- return self._get_list_from_main_section(self.WIRELESS_INTERFACES_KEY)
906+ return self._get_list(WIRELESS_INTERFACES_FIELD)
907
908 @property
909 def partition_layout(self):
910@@ -333,7 +555,7 @@
911
912 A str.
913 """
914- return self._get_option_from_main_section(self.PARTITION_LAYOUT_KEY)
915+ return self._get_option(PARTITION_LAYOUT_FIELD, join_list_with=" ")
916
917 @property
918 def mmc_id(self):
919@@ -341,7 +563,7 @@
920
921 An int.
922 """
923- return self._get_option_from_main_section(self.MMC_ID_KEY)
924+ return self._get_option(MMC_ID_FIELD)
925
926 @property
927 def root_min_size(self):
928@@ -349,7 +571,7 @@
929
930 An int.
931 """
932- return self._get_option_from_main_section(self.ROOT_MIN_SIZE_KEY)
933+ return self._get_option(ROOT_MIN_SIZE_FIELD)
934
935 @property
936 def boot_min_size(self):
937@@ -357,7 +579,7 @@
938
939 An int.
940 """
941- return self._get_option_from_main_section(self.BOOT_MIN_SIZE_KEY)
942+ return self._get_option(BOOT_MIN_SIZE_FIELD)
943
944 @property
945 def loader_min_size(self):
946@@ -365,7 +587,7 @@
947
948 An int.
949 """
950- return self._get_option_from_main_section(self.LOADER_MIN_SIZE_KEY)
951+ return self._get_option(LOADER_MIN_SIZE_FIELD)
952
953 @property
954 def loader_start(self):
955@@ -373,7 +595,7 @@
956
957 An int.
958 """
959- return self._get_option_from_main_section(self.LOADER_START_KEY)
960+ return self._get_option(LOADER_START_FIELD)
961
962 @property
963 def origin(self):
964@@ -381,7 +603,7 @@
965
966 A str or None if no origin should be recorded.
967 """
968- return self._get_option_from_main_section(self.ORIGIN_KEY)
969+ return self._get_option(ORIGIN_FIELD)
970
971 @property
972 def maintainer(self):
973@@ -389,7 +611,7 @@
974
975 A str or None if not maintainer should be recorded.
976 """
977- return self._get_option_from_main_section(self.MAINTAINER_KEY)
978+ return self._get_option(MAINTAINER_FIELD)
979
980 @property
981 def support(self):
982@@ -397,17 +619,21 @@
983
984 A str or None if no support level should be recorded.
985 """
986- return self._get_option_from_main_section(self.SUPPORT_KEY)
987+ return self._get_option(SUPPORT_FIELD)
988
989- def _get_list_from_main_section(self, key):
990- raw_values = self._get_option_from_main_section(key)
991- if raw_values is None:
992+ def _get_list(self, key):
993+ values = self._get_option(key)
994+ if values is None:
995 return []
996- values = re.split("\s+", raw_values)
997+
998+ if not isinstance(values, list):
999+ values = re.split("\s+", values)
1000+
1001 filtered_values = []
1002 for value in values:
1003 if value not in filtered_values:
1004 filtered_values.append(value)
1005+
1006 return filtered_values
1007
1008 @property
1009@@ -416,7 +642,7 @@
1010
1011 A list of str.
1012 """
1013- return self._get_list_from_main_section(self.PACKAGES_KEY)
1014+ return self._get_list(PACKAGES_FIELD)
1015
1016 @property
1017 def u_boot_package(self):
1018@@ -424,7 +650,7 @@
1019
1020 A str.
1021 """
1022- return self._get_option_from_main_section(self.U_BOOT_PACKAGE_KEY)
1023+ return self._get_bootloader_option(self.U_BOOT_PACKAGE_KEY)
1024
1025 @property
1026 def u_boot_file(self):
1027@@ -432,7 +658,7 @@
1028
1029 A str.
1030 """
1031- return self._get_option_from_main_section(self.U_BOOT_FILE_KEY)
1032+ return self._get_bootloader_option(self.U_BOOT_FILE_KEY)
1033
1034 @property
1035 def spl_file(self):
1036@@ -440,7 +666,7 @@
1037
1038 A str.
1039 """
1040- return self._get_option_from_main_section(self.SPL_FILE_KEY)
1041+ return self._get_bootloader_option(SPL_FILE_FIELD)
1042
1043 @property
1044 def spl_package(self):
1045@@ -448,7 +674,7 @@
1046
1047 A str.
1048 """
1049- return self._get_option_from_main_section(self.SPL_PACKAGE_KEY)
1050+ return self._get_bootloader_option(SPL_PACKAGE_FIELD)
1051
1052 @property
1053 def vmlinuz(self):
1054@@ -456,7 +682,7 @@
1055
1056 A str.
1057 """
1058- return self._get_option_from_main_section(self.VMLINUZ_KEY)
1059+ return self._get_option(KERNEL_FILE_FIELD)
1060
1061 @property
1062 def initrd(self):
1063@@ -464,7 +690,7 @@
1064
1065 A str.
1066 """
1067- return self._get_option_from_main_section(self.INITRD_KEY)
1068+ return self._get_option(INITRD_FILE_FIELD)
1069
1070 @property
1071 def dtb_file(self):
1072@@ -472,7 +698,7 @@
1073
1074 A str.
1075 """
1076- return self._get_option_from_main_section(self.DTB_FILE_KEY)
1077+ return self._get_option(DTB_FILE_FIELD)
1078
1079 @property
1080 def samsung_bl1_start(self):
1081@@ -480,7 +706,7 @@
1082
1083 A str.
1084 """
1085- return self._get_option_from_main_section(self.SAMSUNG_BL1_START_KEY)
1086+ return self._get_option(SAMSUNG_BL1_START_FIELD)
1087
1088 @property
1089 def samsung_bl1_len(self):
1090@@ -488,7 +714,7 @@
1091
1092 A str.
1093 """
1094- return self._get_option_from_main_section(self.SAMSUNG_BL1_LEN_KEY)
1095+ return self._get_option(SAMSUNG_BL1_LEN_FIELD)
1096
1097 @property
1098 def samsung_env_len(self):
1099@@ -496,7 +722,7 @@
1100
1101 A str.
1102 """
1103- return self._get_option_from_main_section(self.SAMSUNG_ENV_LEN_KEY)
1104+ return self._get_option(SAMSUNG_ENV_LEN_FIELD)
1105
1106 @property
1107 def samsung_bl2_len(self):
1108@@ -504,7 +730,7 @@
1109
1110 A str.
1111 """
1112- return self._get_option_from_main_section(self.SAMSUNG_BL2_LEN_KEY)
1113+ return self._get_option(SAMSUNG_BL2_LEN_FIELD)
1114
1115 @property
1116 def architectures(self):
1117@@ -512,7 +738,15 @@
1118
1119 A list of str.
1120 """
1121- return self._get_list_from_main_section(self.ARCHITECTURES_KEY)
1122+ return self._get_list(ARCHITECTURES_FIELD)
1123+
1124+ @property
1125+ def architecture(self):
1126+ """The architectures to build the hwpack for.
1127+
1128+ A list of str.
1129+ """
1130+ return self._get_option(ARCHITECTURE_FIELD)
1131
1132 @property
1133 def assume_installed(self):
1134@@ -520,7 +754,7 @@
1135
1136 A list of str.
1137 """
1138- return self._get_list_from_main_section(self.ASSUME_INSTALLED_KEY)
1139+ return self._get_list(self.ASSUME_INSTALLED_KEY)
1140
1141 @property
1142 def sources(self):
1143@@ -528,13 +762,16 @@
1144
1145 A dict mapping source identifiers to sources entries.
1146 """
1147- sources = {}
1148- sections = self.parser.sections()
1149- for section_name in sections:
1150- if section_name == self.MAIN_SECTION:
1151- continue
1152- sources[section_name] = self.parser.get(
1153- section_name, self.SOURCES_ENTRY_KEY)
1154+ if self._is_v3:
1155+ sources = self.parser.get(SOURCES_FIELD)
1156+ else:
1157+ sources = {}
1158+ sections = self.parser.sections()
1159+ for section_name in sections:
1160+ if section_name == self.MAIN_SECTION:
1161+ continue
1162+ sources[section_name] = self.parser.get(
1163+ section_name, self.SOURCES_ENTRY_KEY)
1164 return sources
1165
1166 def _validate_format(self):
1167@@ -575,19 +812,25 @@
1168 def _validate_vmlinuz(self):
1169 vmlinuz = self.vmlinuz
1170 if not vmlinuz:
1171- raise HwpackConfigError("No kernel_file in the [%s] section" % \
1172- self.MAIN_SECTION)
1173+ raise HwpackConfigError(self._not_found_message(KERNEL_FILE_FIELD))
1174 self._assert_matches_pattern(
1175 self.GLOB_REGEX, vmlinuz, "Invalid path: %s" % vmlinuz)
1176
1177 def _validate_initrd(self):
1178 initrd = self.initrd
1179 if not initrd:
1180- raise HwpackConfigError("No initrd_file in the [%s] section" % \
1181- self.MAIN_SECTION)
1182+ raise HwpackConfigError(self._not_found_message(INITRD_FILE_FIELD))
1183 self._assert_matches_pattern(
1184 self.GLOB_REGEX, initrd, "Invalid path: %s" % initrd)
1185
1186+ def _not_found_message(self, thing, v2_section=None):
1187+ if self._is_v3:
1188+ return "No " + thing + " found in the metadata"
1189+ else:
1190+ if not v2_section:
1191+ v2_section = self.MAIN_SECTION
1192+ return "No " + thing + " in the [" + v2_section + "] section"
1193+
1194 def _validate_dtb_file(self):
1195 dtb_file = self.dtb_file
1196 if dtb_file is not None:
1197@@ -624,36 +867,40 @@
1198 if len(serial_tty) < 4 or serial_tty[:3] != 'tty':
1199 raise HwpackConfigError("Invalid serial tty: %s" % serial_tty)
1200
1201- def _validate_addr(self, addr):
1202- return re.match(r"^0x[a-fA-F0-9]{8}$", addr)
1203+ def _validate_addr(self, key):
1204+ """Validate the address for the given key.
1205+ Assumptions:
1206+ 1. key name is of the form name_addr
1207+ 2. property name matches key name
1208+
1209+ Currently these assumptions are met and it seems reasonable to place
1210+ these restrictions on future code.
1211+ """
1212+ name = re.sub("_addr", "", key)
1213+
1214+ try:
1215+ addr = attrgetter(key)(self)
1216+ except TypeError:
1217+ raise HwpackConfigError("Invalid %s address: %s" %
1218+ (name, self._get_option(key)))
1219+
1220+ if addr == None:
1221+ return
1222+
1223+ if not re.match(r"^0x[a-fA-F0-9]{8}$", addr):
1224+ raise HwpackConfigError("Invalid %s address: %s" % (name, addr))
1225
1226 def _validate_kernel_addr(self):
1227- addr = self.kernel_addr
1228- if addr is None:
1229- return
1230- if not self._validate_addr(addr):
1231- raise HwpackConfigError("Invalid kernel address: %s" % addr)
1232+ self._validate_addr(KERNEL_ADDR_FIELD)
1233
1234 def _validate_initrd_addr(self):
1235- addr = self.initrd_addr
1236- if addr is None:
1237- return
1238- if not self._validate_addr(addr):
1239- raise HwpackConfigError("Invalid initrd address: %s" % addr)
1240+ self._validate_addr(INITRD_ADDR_FIELD)
1241
1242 def _validate_load_addr(self):
1243- addr = self.load_addr
1244- if addr is None:
1245- return
1246- if not self._validate_addr(addr):
1247- raise HwpackConfigError("Invalid load address: %s" % addr)
1248+ self._validate_addr(LOAD_ADDR_FIELD)
1249
1250 def _validate_dtb_addr(self):
1251- addr = self.dtb_addr
1252- if addr is None:
1253- return
1254- if not self._validate_addr(addr):
1255- raise HwpackConfigError("Invalid dtb address: %s" % addr)
1256+ self._validate_addr(DTB_ADDR_FIELD)
1257
1258 def _validate_wired_interfaces(self):
1259 pass
1260@@ -662,12 +909,19 @@
1261 pass
1262
1263 def _validate_partition_layout(self):
1264- if self.partition_layout not in self.DEFINED_PARTITION_LAYOUTS:
1265- raise HwpackConfigError(
1266- "Undefined partition layout %s in the [%s] section. "
1267- "Valid partition layouts are %s."
1268- % (self.partition_layout, self.MAIN_SECTION,
1269- ", ".join(self.DEFINED_PARTITION_LAYOUTS)))
1270+ if self.partition_layout not in DEFINED_PARTITION_LAYOUTS:
1271+ if self._is_v3:
1272+ message = ("Undefined partition layout %s. "
1273+ "Valid partition layouts are %s." %
1274+ (self.partition_layout,
1275+ ", ".join(DEFINED_PARTITION_LAYOUTS)))
1276+ else:
1277+ message = ("Undefined partition layout %s in the [%s] section."
1278+ " Valid partition layouts are %s." %
1279+ (self.partition_layout, self.MAIN_SECTION,
1280+ ", ".join(DEFINED_PARTITION_LAYOUTS)))
1281+
1282+ raise HwpackConfigError(message)
1283
1284 def _validate_mmc_id(self):
1285 mmc_id = self.mmc_id
1286@@ -725,14 +979,25 @@
1287 except ValueError:
1288 raise HwpackConfigError(
1289 "Invalid value for include-debs: %s"
1290- % self.parser.get("hwpack", "include-debs"))
1291+ % self.include_debs)
1292+
1293+ @property
1294+ def _is_v3(self):
1295+ """Checks if format is 3.0."""
1296+ return self.format.format_as_string == '3.0'
1297+
1298+ def _validate_bool(self, value):
1299+ """Checks if a value is boolean or not, represented by "yes" or "no".
1300+ """
1301+ if not isinstance(value, str):
1302+ return False
1303+ return string.lower(value) in ['yes', 'no']
1304
1305 def _validate_uboot_in_boot_part(self):
1306- uboot_in_boot_part = self.uboot_in_boot_part
1307- if string.lower(uboot_in_boot_part) not in ['yes', 'no']:
1308+ if not self._validate_bool(self.uboot_in_boot_part):
1309 raise HwpackConfigError(
1310 "Invalid value for u_boot_in_boot_part: %s"
1311- % self.parser.get("hwpack", "u_boot_in_boot_part"))
1312+ % self.uboot_in_boot_part)
1313
1314 def _validate_spl_in_boot_part(self):
1315 spl_in_boot_part = self.spl_in_boot_part
1316@@ -741,7 +1006,7 @@
1317 if string.lower(spl_in_boot_part) not in ['yes', 'no']:
1318 raise HwpackConfigError(
1319 "Invalid value for spl_in_boot_part: %s"
1320- % self.parser.get("hwpack", "spl_in_boot_part"))
1321+ % self.spl_in_boot_part)
1322
1323 def _validate_env_dd(self):
1324 env_dd = self.env_dd
1325@@ -750,7 +1015,7 @@
1326 if string.lower(env_dd) not in ['yes', 'no']:
1327 raise HwpackConfigError(
1328 "Invalid value for env_dd: %s"
1329- % self.parser.get("hwpack", "env_dd"))
1330+ % self.env_dd)
1331
1332 def _validate_uboot_dd(self):
1333 uboot_dd = self.uboot_dd
1334@@ -778,33 +1043,40 @@
1335 raise HwpackConfigError(
1336 "Invalid value for support: %s" % support)
1337
1338+ def _invalid_package_message(self, package_name, section_name, value):
1339+ if self._is_v3:
1340+ message = ("Invalid value in %s in the metadata: %s" %
1341+ (package_name, value))
1342+ else:
1343+ message = ("Invalid value in %s in the [%s] section: %s" %
1344+ (package_name, section_name, value))
1345+ return message
1346+
1347 def _validate_packages(self):
1348 packages = self.packages
1349 if not packages:
1350- raise HwpackConfigError(
1351- "No %s in the [%s] section"
1352- % (self.PACKAGES_KEY, self.MAIN_SECTION))
1353+ raise HwpackConfigError(self._not_found_message(PACKAGES_FIELD))
1354 for package in packages:
1355 self._assert_matches_pattern(
1356- self.PACKAGE_REGEX, package, "Invalid value in %s in the " \
1357- "[%s] section: %s" % (self.PACKAGES_KEY, self.MAIN_SECTION,
1358- package))
1359+ self.PACKAGE_REGEX, package,
1360+ self._invalid_package_message(
1361+ PACKAGES_FIELD, self.MAIN_SECTION, package))
1362
1363 def _validate_u_boot_package(self):
1364 u_boot_package = self.u_boot_package
1365 if u_boot_package is not None:
1366 self._assert_matches_pattern(
1367- self.PACKAGE_REGEX, u_boot_package, "Invalid value in %s in " \
1368- "the [%s] section: %s" % (
1369- self.U_BOOT_PACKAGE_KEY, self.MAIN_SECTION,
1370- u_boot_package))
1371+ self.PACKAGE_REGEX, u_boot_package,
1372+ self._invalid_package_message(
1373+ self.U_BOOT_PACKAGE_KEY, self.MAIN_SECTION,
1374+ u_boot_package))
1375
1376 def _validate_spl_package(self):
1377 spl_package = self.spl_package
1378 if spl_package is not None:
1379 self._assert_matches_pattern(
1380- self.PACKAGE_REGEX, spl_package, "Invalid value in %s in " \
1381- "the [%s] section: %s" % (self.SPL_PACKAGE_KEY,
1382+ self.PACKAGE_REGEX, spl_package,
1383+ self._invalid_package_message(SPL_PACKAGE_FIELD,
1384 self.MAIN_SECTION,
1385 spl_package))
1386
1387@@ -852,48 +1124,66 @@
1388 architectures = self.architectures
1389 if not architectures:
1390 raise HwpackConfigError(
1391- "No %s in the [%s] section"
1392- % (self.ARCHITECTURES_KEY, self.MAIN_SECTION))
1393+ self._not_found_message(ARCHITECTURES_FIELD))
1394
1395 def _validate_assume_installed(self):
1396 assume_installed = self.assume_installed
1397 for package in assume_installed:
1398 self._assert_matches_pattern(
1399- self.PACKAGE_REGEX, package, "Invalid value in %s in the " \
1400- "[%s] section: %s" % (self.ASSUME_INSTALLED_KEY,
1401- self.MAIN_SECTION, package))
1402-
1403- def _validate_section_sources_entry(self, section_name):
1404- try:
1405- sources_entry = self.parser.get(
1406- section_name, self.SOURCES_ENTRY_KEY)
1407- if not sources_entry:
1408+ self.PACKAGE_REGEX, package,
1409+ self._invalid_package_message(self.ASSUME_INSTALLED_KEY,
1410+ self.MAIN_SECTION, package))
1411+
1412+ def _message_start(self, key, section_name):
1413+ if self._is_v3:
1414+ message = "The %s, %s " % (key, section_name)
1415+ else:
1416+ message = "The %s in the [%s] section " % (key, section_name)
1417+ return message
1418+
1419+ def _validate_source(self, section_name):
1420+ if self._is_v3:
1421+ sources_entry = self._get_option([SOURCES_FIELD] + [section_name])
1422+ else:
1423+ try:
1424+ sources_entry = self.parser.get(
1425+ section_name, self.SOURCES_ENTRY_KEY)
1426+ except ConfigParser.NoOptionError:
1427+ raise HwpackConfigError(
1428+ "No %s in the [%s] section"
1429+ % (self.SOURCES_ENTRY_KEY, section_name))
1430+
1431+ if not sources_entry:
1432+ raise HwpackConfigError(
1433+ self._message_start(self.SOURCES_ENTRY_KEY, section_name) +
1434+ "is missing the URI")
1435+ if len(sources_entry.split(" ", 1)) < 2:
1436+ raise HwpackConfigError(
1437+ self._message_start(self.SOURCES_ENTRY_KEY, section_name) +
1438+ "is missing the distribution")
1439+ if sources_entry.startswith("deb"):
1440+ raise HwpackConfigError(
1441+ self._message_start(self.SOURCES_ENTRY_KEY, section_name) +
1442+ "shouldn't start with 'deb'")
1443+
1444+ def _validate_sources(self):
1445+ if self._is_v3:
1446+ source_dict = self.parser.get(SOURCES_FIELD)
1447+ if not source_dict:
1448+ return
1449+ if isinstance(source_dict, dict):
1450+ sources = source_dict.keys()
1451+ else:
1452 raise HwpackConfigError(
1453 "The %s in the [%s] section is missing the URI"
1454- % (self.SOURCES_ENTRY_KEY, section_name))
1455- if len(sources_entry.split(" ", 1)) < 2:
1456- raise HwpackConfigError(
1457- "The %s in the [%s] section is missing the distribution"
1458- % (self.SOURCES_ENTRY_KEY, section_name))
1459- if sources_entry.startswith("deb"):
1460- raise HwpackConfigError(
1461- "The %s in the [%s] section shouldn't start with 'deb'"
1462- % (self.SOURCES_ENTRY_KEY, section_name))
1463- except ConfigParser.NoOptionError:
1464- raise HwpackConfigError(
1465- "No %s in the [%s] section"
1466- % (self.SOURCES_ENTRY_KEY, section_name))
1467-
1468- def _validate_section(self, section_name):
1469- self._validate_section_sources_entry(section_name)
1470-
1471- def _validate_sections(self):
1472- sections = self.parser.sections()
1473+ % (self.SOURCES_ENTRY_KEY, source_dict))
1474+ else:
1475+ sources = self.parser.sections()
1476 found = False
1477- for section_name in sections:
1478- if section_name == self.MAIN_SECTION:
1479+ for source_name in sources:
1480+ if source_name == self.MAIN_SECTION:
1481 continue
1482- self._validate_section(section_name)
1483+ self._validate_source(source_name)
1484 found = True
1485 if not found:
1486 raise HwpackConfigError(
1487
1488=== modified file 'linaro_image_tools/hwpack/hardwarepack.py'
1489--- linaro_image_tools/hwpack/hardwarepack.py 2012-06-13 14:49:14 +0000
1490+++ linaro_image_tools/hwpack/hardwarepack.py 2012-07-23 15:38:22 +0000
1491@@ -32,6 +32,44 @@
1492 from linaro_image_tools.hwpack.hardwarepack_format import (
1493 HardwarePackFormatV1,
1494 )
1495+from linaro_image_tools.hwpack.hwpack_convert import (
1496+ dump,
1497+)
1498+
1499+from hwpack_fields import (
1500+ BOARDS_FIELD,
1501+ BOOTLOADERS_FIELD,
1502+ BOOT_MIN_SIZE_FIELD,
1503+ BOOT_SCRIPT_FIELD,
1504+ DTB_ADDR_FIELD,
1505+ DTB_FILE_FIELD,
1506+ EXTRA_SERIAL_OPTIONS_FIELD,
1507+ FORMAT_FIELD,
1508+ INITRD_ADDR_FIELD,
1509+ INITRD_FILE_FIELD,
1510+ KERNEL_ADDR_FIELD,
1511+ KERNEL_FILE_FIELD,
1512+ LOAD_ADDR_FIELD,
1513+ LOADER_MIN_SIZE_FIELD,
1514+ LOADER_START_FIELD,
1515+ MAINTAINER_FIELD,
1516+ METADATA_ARCH_FIELD,
1517+ METADATA_VERSION_FIELD,
1518+ MMC_ID_FIELD,
1519+ NAME_FIELD,
1520+ ORIGIN_FIELD,
1521+ PARTITION_LAYOUT_FIELD,
1522+ ROOT_MIN_SIZE_FIELD,
1523+ SAMSUNG_BL1_LEN_FIELD,
1524+ SAMSUNG_BL1_START_FIELD,
1525+ SAMSUNG_BL2_LEN_FIELD,
1526+ SAMSUNG_ENV_LEN_FIELD,
1527+ SERIAL_TTY_FIELD,
1528+ SNOWBALL_STARTUP_FILES_CONFIG_FIELD,
1529+ SUPPORT_FIELD,
1530+ WIRED_INTERFACES_FIELD,
1531+ WIRELESS_INTERFACES_FIELD,
1532+)
1533
1534
1535 class Metadata(object):
1536@@ -127,6 +165,16 @@
1537 self.samsung_bl2_len = samsung_bl2_len
1538
1539 @classmethod
1540+ def add_v3_config(self, boards=None, bootloaders=None):
1541+ """Add fields that are specific to the v3 config format.
1542+ These fields are not present in the earlier config files.
1543+
1544+ :param boards: The boards section of the hwpack.
1545+ :param bootloaders: The bootloaders section of the hwpack."""
1546+ self.boards = boards
1547+ self.bootloaders = bootloaders
1548+
1549+ @classmethod
1550 def from_config(cls, config, version, architecture):
1551 """Create a Metadata from a Config object.
1552
1553@@ -153,39 +201,137 @@
1554 # Helper variable to adhere to the line length limit.
1555 snowball_startup_config = config.snowball_startup_files_config
1556 metadata.add_v2_config(
1557- serial_tty=config.serial_tty,
1558+ boot_min_size=config.boot_min_size,
1559+ boot_script=config.boot_script,
1560+ dtb_addr=config.dtb_addr,
1561+ dtb_file=config.dtb_file,
1562+ env_dd=config.env_dd,
1563+ extra_boot_options=config.extra_boot_options,
1564+ extra_serial_opts=config.extra_serial_opts,
1565+ initrd_addr=config.initrd_addr,
1566+ initrd=config.initrd,
1567 kernel_addr=config.kernel_addr,
1568- initrd_addr=config.initrd_addr,
1569 load_addr=config.load_addr,
1570- wired_interfaces=config.wired_interfaces,
1571- wireless_interfaces=config.wireless_interfaces,
1572+ loader_min_size=config.loader_min_size,
1573+ loader_start=config.loader_start,
1574+ mmc_id=config.mmc_id,
1575 partition_layout=config.partition_layout,
1576- mmc_id=config.mmc_id,
1577- boot_min_size=config.boot_min_size,
1578 root_min_size=config.root_min_size,
1579- loader_min_size=config.loader_min_size,
1580- loader_start=config.loader_start,
1581- vmlinuz=config.vmlinuz,
1582- initrd=config.initrd,
1583- dtb_file=config.dtb_file,
1584- dtb_addr=config.dtb_addr,
1585- extra_boot_options=config.extra_boot_options,
1586- boot_script=config.boot_script,
1587- uboot_in_boot_part=config.uboot_in_boot_part,
1588- uboot_dd=config.uboot_dd,
1589- spl_in_boot_part=config.spl_in_boot_part,
1590- spl_dd=config.spl_dd,
1591- env_dd=config.env_dd,
1592- extra_serial_opts=config.extra_serial_opts,
1593- snowball_startup_files_config=snowball_startup_config,
1594+ samsung_bl1_len=config.samsung_bl1_len,
1595 samsung_bl1_start=config.samsung_bl1_start,
1596- samsung_bl1_len=config.samsung_bl1_len,
1597+ samsung_bl2_len=config.samsung_bl2_len,
1598 samsung_env_len=config.samsung_env_len,
1599- samsung_bl2_len=config.samsung_bl2_len)
1600+ serial_tty=config.serial_tty,
1601+ snowball_startup_files_config=snowball_startup_config,
1602+ spl_dd=config.spl_dd,
1603+ spl_in_boot_part=config.spl_in_boot_part,
1604+ uboot_dd=config.uboot_dd,
1605+ uboot_in_boot_part=config.uboot_in_boot_part,
1606+ vmlinuz=config.vmlinuz,
1607+ wired_interfaces=config.wired_interfaces,
1608+ wireless_interfaces=config.wireless_interfaces,
1609+ )
1610+ if config.format.format_as_string == '3.0':
1611+ metadata.add_v3_config(boards=config.boards,
1612+ bootloaders=config.bootloaders)
1613 return metadata
1614
1615 def __str__(self):
1616- """Get the contents of the metadata file."""
1617+ if self.format.format_as_string == '3.0':
1618+ return self.create_metadata_new()
1619+ else:
1620+ return self.create_metadata_old()
1621+
1622+ def create_metadata_new(self):
1623+ """Get the contents of the metadata file.
1624+
1625+ The metadata file is almost an identical copy of the hwpack
1626+ configuration file. Only a couple of fields are different, and some
1627+ are missing.
1628+
1629+ :return A string.
1630+ """
1631+ metadata = ""
1632+ metadata += dump({FORMAT_FIELD: self.format.format_as_string})
1633+ metadata += dump({NAME_FIELD: self.name})
1634+ metadata += dump({METADATA_VERSION_FIELD: self.version})
1635+ # This is a single 'architecture' hwpack, each arch will get its own,
1636+ # it is not retrieved from the Config.
1637+ metadata += dump({METADATA_ARCH_FIELD: self.architecture})
1638+ if self.origin is not None:
1639+ metadata += dump({ORIGIN_FIELD: self.origin})
1640+ if self.maintainer is not None:
1641+ metadata += dump({MAINTAINER_FIELD: self.maintainer})
1642+ if self.support is not None:
1643+ metadata += dump({SUPPORT_FIELD: self.support})
1644+ if self.boards is not None:
1645+ metadata += dump({BOARDS_FIELD: self.boards})
1646+ if self.bootloaders is not None:
1647+ metadata += dump({BOOTLOADERS_FIELD: self.bootloaders})
1648+ if self.serial_tty is not None:
1649+ metadata += dump({SERIAL_TTY_FIELD: self.serial_tty})
1650+ if self.kernel_addr is not None:
1651+ metadata += dump({KERNEL_ADDR_FIELD: self.kernel_addr})
1652+ if self.initrd_addr is not None:
1653+ metadata += dump({INITRD_ADDR_FIELD: self.initrd_addr})
1654+ if self.load_addr is not None:
1655+ metadata += dump({LOAD_ADDR_FIELD: self.load_addr})
1656+ if self.dtb_addr is not None:
1657+ metadata += dump({DTB_ADDR_FIELD: self.dtb_addr})
1658+ if self.wired_interfaces != []:
1659+ eth_interfaces = " ".join(self.wired_interfaces)
1660+ metadata += dump({WIRED_INTERFACES_FIELD: eth_interfaces})
1661+ if self.wireless_interfaces != []:
1662+ wifi_interfaces = " ".join(self.wireless_interfaces)
1663+ metadata += dump({WIRELESS_INTERFACES_FIELD: wifi_interfaces})
1664+ if self.partition_layout is not None:
1665+ metadata += dump({PARTITION_LAYOUT_FIELD: self.partition_layout})
1666+ if self.mmc_id is not None:
1667+ metadata += dump({MMC_ID_FIELD: self.mmc_id})
1668+ if self.boot_min_size is not None:
1669+ metadata += dump({BOOT_MIN_SIZE_FIELD: self.boot_min_size})
1670+ if self.root_min_size is not None:
1671+ metadata += dump({ROOT_MIN_SIZE_FIELD: self.root_min_size})
1672+ if self.loader_min_size is not None:
1673+ metadata += dump({LOADER_MIN_SIZE_FIELD: self.loader_min_size})
1674+ if self.loader_start is not None:
1675+ metadata += dump({LOADER_START_FIELD: self.loader_start})
1676+ if self.vmlinuz is not None:
1677+ metadata += dump({KERNEL_FILE_FIELD: self.vmlinuz})
1678+ if self.initrd is not None:
1679+ metadata += dump({INITRD_FILE_FIELD: self.initrd})
1680+ if self.dtb_file is not None:
1681+ # XXX In V3 this one should be a list, called dtb_files.
1682+ metadata += dump({DTB_FILE_FIELD: self.dtb_file})
1683+ if self.boot_script is not None:
1684+ metadata += dump({BOOT_SCRIPT_FIELD: self.boot_script})
1685+ if self.extra_serial_opts is not None:
1686+ # XXX Check why and where once we get a list once a string.
1687+ if isinstance(self.extra_serial_opts, list):
1688+ extra_serial_options = " ".join(self.extra_serial_opts)
1689+ else:
1690+ extra_serial_options = self.extra_serial_opts
1691+ metadata += dump({
1692+ EXTRA_SERIAL_OPTIONS_FIELD:
1693+ extra_serial_options})
1694+ if self.snowball_startup_files_config is not None:
1695+ metadata += dump({SNOWBALL_STARTUP_FILES_CONFIG_FIELD:
1696+ self.snowball_startup_files_config})
1697+ if self.samsung_bl1_start is not None:
1698+ metadata += dump({SAMSUNG_BL1_START_FIELD: self.samsung_bl1_start})
1699+ if self.samsung_bl1_len is not None:
1700+ metadata += dump({SAMSUNG_BL1_LEN_FIELD: self.samsung_bl1_len})
1701+ if self.samsung_env_len is not None:
1702+ metadata += dump({SAMSUNG_ENV_LEN_FIELD: self.samsung_env_len})
1703+ if self.samsung_bl2_len is not None:
1704+ metadata += dump({SAMSUNG_BL2_LEN_FIELD: self.samsung_bl2_len})
1705+ return metadata
1706+
1707+ def create_metadata_old(self):
1708+ """Get the contents of the metadata file.
1709+
1710+ Creates a metadata file for v1 and v2 of the hwpack config file.
1711+ """
1712 metadata = "NAME=%s\n" % self.name
1713 metadata += "VERSION=%s\n" % self.version
1714 metadata += "ARCHITECTURE=%s\n" % self.architecture
1715@@ -264,7 +410,6 @@
1716 metadata += "SAMSUNG_ENV_LEN=%s\n" % self.samsung_env_len
1717 if self.samsung_bl2_len is not None:
1718 metadata += "SAMSUNG_BL2_LEN=%s\n" % self.samsung_bl2_len
1719-
1720 return metadata
1721
1722
1723
1724=== modified file 'linaro_image_tools/hwpack/hardwarepack_format.py'
1725--- linaro_image_tools/hwpack/hardwarepack_format.py 2012-06-13 14:26:02 +0000
1726+++ linaro_image_tools/hwpack/hardwarepack_format.py 2012-07-23 15:38:22 +0000
1727@@ -57,3 +57,12 @@
1728 self.is_supported = True
1729 self.is_deprecated = False
1730 self.has_v2_fields = True
1731+
1732+
1733+class HardwarePackFormatV3(HardwarePackFormat):
1734+ def __init__(self):
1735+ super(HardwarePackFormatV3, self).__init__()
1736+ self.format_as_string = "3.0"
1737+ self.is_supported = True
1738+ self.is_deprecated = False
1739+ self.has_v2_fields = True
1740
1741=== modified file 'linaro_image_tools/hwpack/hwpack_convert.py'
1742--- linaro_image_tools/hwpack/hwpack_convert.py 2012-07-19 15:10:43 +0000
1743+++ linaro_image_tools/hwpack/hwpack_convert.py 2012-07-23 15:38:22 +0000
1744@@ -46,6 +46,7 @@
1745 SPL_FILE_FIELD,
1746 WIRED_INTERFACES_FIELD,
1747 WIRELESS_INTERFACES_FIELD,
1748+ INCLUDE_DEBS_FIELD,
1749 )
1750
1751 # This is the main section of an INI-style hwpack config file.
1752@@ -70,6 +71,7 @@
1753
1754 # Old field, the only one with a dash: since the format is new, convert it.
1755 ASSUME_INSTALLED_OLD = 'assume-installed'
1756+INCLUDE_DEBS_OLD = 'include-debs'
1757
1758 # The default bootloader for the bootloaders section.
1759 DEFAULT_BOOTLOADER = 'u_boot'
1760@@ -121,6 +123,8 @@
1761 self.wireless_interfaces = []
1762 # SPL entries
1763 self.spl = {}
1764+ # The list of packages that should be installed.
1765+ self.assume_installed = []
1766
1767 def _parse(self):
1768 """Parses the config file and stores its values."""
1769@@ -171,9 +175,14 @@
1770 elif key in UBOOT_KEYS:
1771 self._set_bootloaders(key, value)
1772 continue
1773- # Convert an old key into the new one.
1774+ # Create list.
1775 elif key == ASSUME_INSTALLED_OLD:
1776- key = ASSUME_INSTALLED_FIELD
1777+ self.parse_list_string(
1778+ self.assume_installed,
1779+ value)
1780+ continue
1781+ elif key == INCLUDE_DEBS_OLD:
1782+ key = INCLUDE_DEBS_FIELD
1783 self.hwpack[key] = value
1784 else:
1785 # Here we have only sources sections.
1786@@ -231,6 +240,9 @@
1787 if self.architectures:
1788 archs = {ARCHITECTURES_FIELD: self.architectures}
1789 converted += dump(archs)
1790+ if self.assume_installed:
1791+ installed = {ASSUME_INSTALLED_FIELD: self.assume_installed}
1792+ converted += dump(installed)
1793 if self.extra_serial_options:
1794 serial_options = {EXTRA_SERIAL_OPTIONS_FIELD:
1795 self.extra_serial_options}
1796@@ -271,7 +283,7 @@
1797
1798 :param python_object: The object to serialize.
1799 """
1800- return yaml.dump(python_object, default_flow_style=False, indent=True)
1801+ return yaml.dump(python_object, default_flow_style=False)
1802
1803
1804 def check_and_validate_args(args):
1805
1806=== modified file 'linaro_image_tools/hwpack/hwpack_fields.py'
1807--- linaro_image_tools/hwpack/hwpack_fields.py 2012-07-19 15:10:43 +0000
1808+++ linaro_image_tools/hwpack/hwpack_fields.py 2012-07-23 15:38:22 +0000
1809@@ -25,6 +25,7 @@
1810 # Try to keep it alphabetically sorted per section.
1811 #
1812 ARCHITECTURES_FIELD = 'architectures'
1813+ARCHITECTURE_FIELD = 'architecture'
1814 ASSUME_INSTALLED_FIELD = 'assume_installed'
1815 BOARDS_FIELD = 'boards'
1816 BOOTLOADERS_FIELD = 'bootloaders'
1817@@ -36,6 +37,7 @@
1818 DTB_FILES_FIELD = 'dtb_files'
1819 EXTRA_SERIAL_OPTIONS_FIELD = 'extra_serial_options'
1820 FORMAT_FIELD = 'format'
1821+INCLUDE_DEBS_FIELD = 'include_debs'
1822 INITRD_ADDR_FIELD = 'initrd_addr'
1823 INITRD_FILE_FIELD = 'initrd_file'
1824 KERNEL_ADDR_FIELD = 'kernel_addr'
1825@@ -55,6 +57,7 @@
1826 SUPPORT_FIELD = 'support'
1827 WIRED_INTERFACES_FIELD = 'wired_interfaces'
1828 WIRELESS_INTERFACES_FIELD = 'wireless_interfaces'
1829+VERSION_FIELD = 'version'
1830
1831 # Bootloaders specific fields
1832 DD_FIELD = 'dd'
1833
1834=== modified file 'linaro_image_tools/hwpack/tests/__init__.py'
1835--- linaro_image_tools/hwpack/tests/__init__.py 2012-07-19 07:49:47 +0000
1836+++ linaro_image_tools/hwpack/tests/__init__.py 2012-07-23 15:38:22 +0000
1837@@ -27,6 +27,7 @@
1838 'linaro_image_tools.hwpack.tests.test_better_tarfile',
1839 'linaro_image_tools.hwpack.tests.test_builder',
1840 'linaro_image_tools.hwpack.tests.test_config',
1841+ 'linaro_image_tools.hwpack.tests.test_config_v3',
1842 'linaro_image_tools.hwpack.tests.test_hardwarepack',
1843 'linaro_image_tools.hwpack.tests.test_hwpack_converter',
1844 'linaro_image_tools.hwpack.tests.test_packages',
1845
1846=== modified file 'linaro_image_tools/hwpack/tests/test_config.py'
1847--- linaro_image_tools/hwpack/tests/test_config.py 2012-06-13 14:32:49 +0000
1848+++ linaro_image_tools/hwpack/tests/test_config.py 2012-07-23 15:38:22 +0000
1849@@ -24,6 +24,9 @@
1850 from testtools import TestCase
1851
1852 from linaro_image_tools.hwpack.config import Config, HwpackConfigError
1853+from linaro_image_tools.hwpack.hwpack_fields import (
1854+ DEFINED_PARTITION_LAYOUTS,
1855+)
1856
1857
1858 class ConfigTests(TestCase):
1859@@ -72,7 +75,7 @@
1860
1861 def test_validate_no_name(self):
1862 config = self.get_config("[hwpack]\n")
1863- self.assertValidationError("No name in the [hwpack] section", config)
1864+ self.assertValidationError("Empty value for name", config)
1865
1866 def test_validate_empty_name(self):
1867 config = self.get_config("[hwpack]\nname = \n")
1868@@ -87,7 +90,8 @@
1869 "[hwpack]\nname = ahwpack\n"
1870 "include-debs = if you don't mind\n")
1871 self.assertValidationError(
1872- "Invalid value for include-debs: if you don't mind", config)
1873+ "Invalid value for include-debs: Not a boolean: if you don't mind",
1874+ config)
1875
1876 def test_validate_invalid_supported(self):
1877 config = self.get_config(
1878@@ -192,11 +196,9 @@
1879 self.assertEqual(None, config.validate())
1880
1881 def test_validate_supported_format(self):
1882- config = self.get_config(
1883- self.valid_start
1884- + "\nformat = 0.9\n")
1885- self.assertValidationError(
1886- "Format version '0.9' is not supported.", config)
1887+ contents = self.valid_start + "format = 0.9\n"
1888+ config = Config(StringIO(contents))
1889+ self.assertRaises(HwpackConfigError, config.validate)
1890
1891 def test_validate_invalid_u_boot_package_name(self):
1892 config = self.get_config(
1893@@ -307,7 +309,7 @@
1894 "Undefined partition layout %s in the [%s] section. "
1895 "Valid partition layouts are %s."
1896 % (partition_layout, 'hwpack',
1897- ", ".join(config.DEFINED_PARTITION_LAYOUTS)), config)
1898+ ", ".join(DEFINED_PARTITION_LAYOUTS)), config)
1899
1900 def test_validate_wired_interfaces(self):
1901 self.assertTrue("XXX What is an invalid interface name?")
1902
1903=== added file 'linaro_image_tools/hwpack/tests/test_config_v3.py'
1904--- linaro_image_tools/hwpack/tests/test_config_v3.py 1970-01-01 00:00:00 +0000
1905+++ linaro_image_tools/hwpack/tests/test_config_v3.py 2012-07-23 15:38:22 +0000
1906@@ -0,0 +1,738 @@
1907+# Copyright (C) 2010 - 2012 Linaro
1908+#
1909+# Author: James Tunnicliffe <james.tunnicliffe@linaro.org>
1910+#
1911+# This file is part of Linaro Image Tools.
1912+#
1913+# Linaro Image Tools is free software; you can redistribute it and/or
1914+# modify it under the terms of the GNU General Public License
1915+# as published by the Free Software Foundation; either version 2
1916+# of the License, or (at your option) any later version.
1917+#
1918+# Linaro Image Tools is distributed in the hope that it will be useful,
1919+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1920+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1921+# GNU General Public License for more details.
1922+#
1923+# You should have received a copy of the GNU General Public License
1924+# along with Linaro Image Tools; if not, write to the Free Software
1925+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1926+# USA.
1927+
1928+import re
1929+from StringIO import StringIO
1930+from testtools import TestCase
1931+
1932+from linaro_image_tools.hwpack.config import Config, HwpackConfigError
1933+from linaro_image_tools.hwpack.hwpack_fields import (
1934+ DEFINED_PARTITION_LAYOUTS,
1935+)
1936+
1937+
1938+class ConfigTests(TestCase):
1939+
1940+ valid_start = (
1941+ "name: ahwpack\npackages: foo\narchitectures: armel\n")
1942+ valid_start_v3 = valid_start + "format: 3.0\n"
1943+ valid_complete_v3 = (valid_start_v3 +
1944+ "serial_tty: ttySAC1\n"
1945+ "partition_layout:\n"
1946+ " - bootfs_rootfs\n"
1947+ "boot_script: boot.scr\n"
1948+ "extra_serial_options:\n"
1949+ " - console=tty0\n"
1950+ " - console=ttyO2,115200n8\n"
1951+ "mmc_id: 0:1\n"
1952+ "kernel_file: boot/vmlinuz-*-linaro-omap\n"
1953+ "initrd_file: boot/initrd.img-*-linaro-omap\n"
1954+ "dtb_file: boot/dt-*-linaro-omap/omap4-panda.dtb\n"
1955+ "bootloaders:\n"
1956+ " u_boot:\n"
1957+ " package: u-boot-linaro-s5pv310\n"
1958+ " file: usr/lib/u-boot/smdkv310/u-boot.bin\n"
1959+ " spl_package: x-loader-omap4-panda\n"
1960+ " spl_file: usr/lib/x-loader/omap4430panda/MLO\n"
1961+ " in_boot_part: True\n"
1962+ " extra_boot_options:\n"
1963+ " - earlyprintk\n"
1964+ " - fixrtc\n"
1965+ " - nocompcache\n"
1966+ " - vram=48M\n"
1967+ " - omapfb.vram=0:24M\n"
1968+ " - mem=456M@0x80000000\n"
1969+ " - mem=512M@0xA0000000\n")
1970+ valid_end = "sources:\n sources-entry: foo bar\n"
1971+
1972+ def test_create(self):
1973+ config = Config(StringIO())
1974+ self.assertTrue(config is not None)
1975+
1976+ def get_config(self, contents):
1977+ if not re.search("\s*format\s*:", contents):
1978+ contents = "format: 3.0\n" + contents
1979+ return Config(StringIO(contents), bootloader="u_boot")
1980+
1981+ def assertConfigError(self, contents, f, *args, **kwargs):
1982+ e = self.assertRaises(HwpackConfigError, f, *args, **kwargs)
1983+ self.assertEqual(contents, str(e))
1984+
1985+ def assertValidationError(self, contents, validate_function):
1986+ self.assertConfigError(contents, validate_function)
1987+
1988+ def test_validate_empty_name(self):
1989+ config = self.get_config("name: ")
1990+ self.assertValidationError("Empty value for name",
1991+ config._validate_name)
1992+
1993+ def test_validate_invalid_name(self):
1994+ config = self.get_config("name: ~~\n")
1995+ self.assertValidationError("Invalid name: ~~",
1996+ config._validate_name)
1997+
1998+ def test_validate_invalid_include_debs(self):
1999+ config = self.get_config(
2000+ "name: ahwpack\n"
2001+ "include_debs: if you don't mind\n")
2002+ self.assertValidationError(
2003+ "Invalid value for include-debs: if you don't mind",
2004+ config._validate_include_debs)
2005+
2006+ def test_validate_invalid_supported(self):
2007+ config = self.get_config(
2008+ "name: ahwpack\nsupport: if you pay us\n")
2009+ self.assertValidationError(
2010+ "Invalid value for support: if you pay us",
2011+ config._validate_support)
2012+
2013+ def test_validate_no_packages(self):
2014+ config = self.get_config(
2015+ "name: ahwpack\n\n")
2016+ self.assertValidationError(
2017+ "No packages found in the metadata", config._validate_packages)
2018+
2019+ def test_validate_empty_packages(self):
2020+ config = self.get_config(
2021+ "name: ahwpack\npackages: \n")
2022+ self.assertValidationError(
2023+ "No packages found in the metadata", config._validate_packages)
2024+
2025+ def test_validate_invalid_package_name(self):
2026+ config = self.get_config(
2027+ "name: ahwpack\npackages: foo ~~ bar\n")
2028+ self.assertValidationError(
2029+ "Invalid value in packages in the metadata: ~~",
2030+ config._validate_packages)
2031+
2032+ def test_validate_no_architectures(self):
2033+ config = self.get_config(
2034+ "name: ahwpack\npackages: foo\n")
2035+ self.assertValidationError(
2036+ "No architectures found in the metadata",
2037+ config._validate_architectures)
2038+
2039+ def test_validate_empty_architectures(self):
2040+ config = self.get_config(
2041+ "name: ahwpack\npackages: foo\n"
2042+ "architectures: \n")
2043+ self.assertValidationError(
2044+ "No architectures found in the metadata",
2045+ config._validate_architectures)
2046+
2047+ def test_validate_invalid_package_name_in_assume_installed(self):
2048+ config = self.get_config(
2049+ "name: ahwpack\npackages: foo\n"
2050+ "architectures: armel\nassume_installed:\n - bar\n - ~~\n")
2051+ self.assertValidationError(
2052+ "Invalid value in assume-installed in the metadata: ~~",
2053+ config._validate_assume_installed)
2054+
2055+ def test_validate_other_section_empty_sources_entry(self):
2056+ config = self.get_config(
2057+ self.valid_start + "sources:\n ubuntu: \n")
2058+ self.assertValidationError(
2059+ "The sources-entry, ubuntu is missing the URI",
2060+ config._validate_sources)
2061+
2062+ def test_validate_other_section_only_uri_in_sources_entry(self):
2063+ config = self.get_config(
2064+ self.valid_start + "sources:\n ubuntu: foo\n")
2065+ self.assertValidationError(
2066+ "The sources-entry, ubuntu is missing the distribution",
2067+ config._validate_sources)
2068+
2069+ def test_validate_other_section_sources_entry_starting_with_deb(self):
2070+ config = self.get_config(self.valid_start +
2071+ "sources:\n ubuntu: deb http://example.org/ foo main\n")
2072+ self.assertValidationError(
2073+ "The sources-entry, ubuntu shouldn't start with 'deb'",
2074+ config._validate_sources)
2075+
2076+ def test_validate_other_section_sources_entry_starting_with_deb_src(self):
2077+ config = self.get_config(self.valid_start +
2078+ "sources:\n ubuntu: deb-src http://example.org/ foo main\n")
2079+ self.assertValidationError(
2080+ "The sources-entry, ubuntu shouldn't start with 'deb'",
2081+ config._validate_sources)
2082+
2083+ def test_validate_valid_config(self):
2084+ config = self.get_config(self.valid_complete_v3)
2085+ self.assertEqual(None, config.validate())
2086+
2087+ def test_validate_supported_format(self):
2088+ config = self.get_config(self.valid_start + "format: 0.9\n")
2089+ self.assertValidationError(
2090+ "Format version '0.9' is not supported.", config._validate_format)
2091+
2092+ def test_validate_invalid_u_boot_package_name(self):
2093+ config = self.get_config(self.valid_start_v3 +
2094+ "bootloaders:\n"
2095+ " u_boot:\n"
2096+ " package: ~~\n")
2097+ self.assertValidationError(
2098+ "Invalid value in u_boot_package in the metadata: ~~",
2099+ config._validate_u_boot_package)
2100+
2101+ def test_validate_invalid_u_boot_file(self):
2102+ config = self.get_config(self.valid_start_v3 +
2103+ "bootloaders:\n"
2104+ " u_boot:\n"
2105+ " file: ~~\n")
2106+ self.assertValidationError("Invalid path: ~~",
2107+ config._validate_u_boot_file)
2108+
2109+ def test_validate_invalid_kernel_file(self):
2110+ config = self.get_config(self.valid_start_v3 +
2111+ "kernel_file: ~~\n")
2112+ self.assertValidationError("Invalid path: ~~",
2113+ config._validate_vmlinuz)
2114+
2115+ def test_validate_empty_kernel_file(self):
2116+ config = self.get_config(self.valid_start_v3 +
2117+ "kernel_file: \n")
2118+ self.assertValidationError("No kernel_file found in the metadata",
2119+ config._validate_vmlinuz)
2120+
2121+ def test_validate_invalid_initrd_file(self):
2122+ config = self.get_config(self.valid_start_v3 +
2123+ "initrd_file: ~~\n")
2124+ self.assertValidationError("Invalid path: ~~", config._validate_initrd)
2125+
2126+ def test_validate_empty_initrd_file(self):
2127+ config = self.get_config(self.valid_start_v3 +
2128+ "kernel_file: \n")
2129+ self.assertValidationError("No initrd_file found in the metadata",
2130+ config._validate_initrd)
2131+
2132+ def test_validate_invalid_boot_script(self):
2133+ config = self.get_config(self.valid_start_v3 + "boot_script: ~~")
2134+ self.assertValidationError("Invalid path: ~~",
2135+ config._validate_boot_script)
2136+
2137+ def test_validate_invalid_dtb_file(self):
2138+ config = self.get_config(self.valid_start_v3 +
2139+ "dtb_file: ~~\n")
2140+ self.assertValidationError("Invalid path: ~~",
2141+ config._validate_dtb_file)
2142+
2143+ def test_validate_invalid_spl_package_name(self):
2144+ config = self.get_config(self.valid_start_v3 +
2145+ "bootloaders:\n"
2146+ " u_boot:\n"
2147+ " spl_package: ~~\n")
2148+ config.set_board("panda")
2149+ self.assertValidationError(
2150+ "Invalid value in spl_package in the metadata: ~~",
2151+ config._validate_spl_package)
2152+
2153+ def test_validate_invalid_spl_file(self):
2154+ config = self.get_config(self.valid_start_v3 +
2155+ "boards:\n"
2156+ " panda:\n"
2157+ " bootloaders:\n"
2158+ " u_boot:\n"
2159+ " spl_file: ~~\n")
2160+ config.set_board("panda")
2161+ self.assertValidationError("Invalid path: ~~",
2162+ config._validate_spl_file)
2163+
2164+ def test_validate_partition_layout(self):
2165+ partition_layout = 'apafs_bananfs'
2166+ config = self.get_config(self.valid_start_v3 +
2167+ "partition_layout: " + partition_layout)
2168+ self.assertValidationError(
2169+ "Undefined partition layout %s. "
2170+ "Valid partition layouts are %s."
2171+ % (partition_layout,
2172+ ", ".join(DEFINED_PARTITION_LAYOUTS)),
2173+ config._validate_partition_layout)
2174+
2175+ def test_validate_wired_interfaces(self):
2176+ self.assertTrue("XXX What is an invalid interface name?")
2177+
2178+ def test_validate_wireless_interfaces(self):
2179+ self.assertTrue("XXX What is an invalid interface name?")
2180+
2181+ def test_validate_u_boot_in_boot_part_bool(self):
2182+ config = self.get_config(
2183+ self.valid_start_v3 +
2184+ "bootloaders:\n"
2185+ " u_boot:\n"
2186+ " in_boot_part: Nope\n")
2187+ self.assertValidationError(
2188+ "Invalid value for u_boot_in_boot_part: Nope",
2189+ config._validate_uboot_in_boot_part)
2190+
2191+ def test_find_board_specific_variable(self):
2192+ config = self.get_config(
2193+ self.valid_start_v3 +
2194+ "boards:\n"
2195+ " panda:\n"
2196+ " bootloaders:\n"
2197+ " u_boot:\n"
2198+ " in_boot_part: Yes\n")
2199+
2200+ config.set_bootloader("u_boot")
2201+ config.set_board("panda")
2202+
2203+ config._validate_uboot_in_boot_part()
2204+ self.assertEqual(config.uboot_in_boot_part, "yes")
2205+
2206+ def test_board_specific_overwrites_global(self):
2207+ config = self.get_config(
2208+ self.valid_start_v3 +
2209+ "bootloaders:\n"
2210+ " u_boot:\n"
2211+ " in_boot_part: No\n"
2212+ "boards:\n"
2213+ " panda:\n"
2214+ " bootloaders:\n"
2215+ " u_boot:\n"
2216+ " in_boot_part: Yes\n")
2217+
2218+ config.set_bootloader("u_boot")
2219+ config.set_board("panda")
2220+
2221+ config._validate_uboot_in_boot_part()
2222+ self.assertEqual(config.uboot_in_boot_part, "yes")
2223+
2224+ def test_validate_serial_tty(self):
2225+ config = self.get_config(self.valid_start_v3 + "serial_tty: tty\n")
2226+ self.assertValidationError("Invalid serial tty: tty",
2227+ config._validate_serial_tty)
2228+
2229+ config = self.get_config(self.valid_start_v3 + "serial_tty: ttxSAC1\n")
2230+ self.assertValidationError("Invalid serial tty: ttxSAC1",
2231+ config._validate_serial_tty)
2232+
2233+ def test_validate_mmc_id(self):
2234+ config = self.get_config(self.valid_complete_v3 +
2235+ "mmc_id: x\n")
2236+ self.assertValidationError("Invalid mmc_id x", config._validate_mmc_id)
2237+
2238+ def test_validate_boot_min_size(self):
2239+ config = self.get_config(self.valid_complete_v3 +
2240+ "boot_min_size: x\n")
2241+ self.assertValidationError("Invalid boot min size x",
2242+ config._validate_boot_min_size)
2243+
2244+ def test_validate_root_min_size(self):
2245+ config = self.get_config(self.valid_complete_v3 +
2246+ "root_min_size: x\n")
2247+ self.assertValidationError("Invalid root min size x",
2248+ config._validate_root_min_size)
2249+
2250+ def test_validate_loader_min_size(self):
2251+ config = self.get_config(self.valid_complete_v3 +
2252+ "loader_min_size: x\n")
2253+ self.assertValidationError("Invalid loader min size x",
2254+ config._validate_loader_min_size)
2255+
2256+ def test_validate_kernel_addr(self):
2257+ # V3 change: All numerical inputs are good addresses (since YAML
2258+ # converts them to ingegers and we convert them back to the correct
2259+ # format). We don't need 8 digit hex values for addresses.
2260+ config = self.get_config(self.valid_complete_v3 +
2261+ "kernel_addr: 0x8000000\n")
2262+ config._validate_kernel_addr()
2263+ config = self.get_config(self.valid_complete_v3 +
2264+ "kernel_addr: 0x8000000x\n")
2265+ self.assertValidationError(
2266+ "Invalid kernel address: 0x8000000x", config._validate_kernel_addr)
2267+ config = self.get_config(self.valid_complete_v3 +
2268+ "kernel_addr: 80000000\n")
2269+ config._validate_kernel_addr()
2270+
2271+ def test_validate_initrd_addr(self):
2272+ # V3 change: All numerical inputs are good addresses (since YAML
2273+ # converts them to ingegers and we convert them back to the correct
2274+ # format). We don't need 8 digit hex values for addresses.
2275+ config = self.get_config(self.valid_complete_v3 +
2276+ "initrd_addr: 0x8000000\n")
2277+ config._validate_initrd_addr()
2278+ config = self.get_config(self.valid_complete_v3 +
2279+ "initrd_addr: 0x8000000x\n")
2280+ self.assertValidationError(
2281+ "Invalid initrd address: 0x8000000x", config._validate_initrd_addr)
2282+ config = self.get_config(self.valid_complete_v3 +
2283+ "initrd_addr: 80000000\n")
2284+ config._validate_initrd_addr()
2285+
2286+ def test_validate_load_addr(self):
2287+ # V3 change: All numerical inputs are good addresses (since YAML
2288+ # converts them to ingegers and we convert them back to the correct
2289+ # format). We don't need 8 digit hex values for addresses.
2290+ config = self.get_config(self.valid_complete_v3 +
2291+ "load_addr: 0x8000000\n")
2292+ config._validate_load_addr()
2293+ config = self.get_config(self.valid_complete_v3 +
2294+ "load_addr: 0x8000000x\n")
2295+ self.assertValidationError("Invalid load address: 0x8000000x",
2296+ config._validate_load_addr)
2297+ config = self.get_config(self.valid_complete_v3 +
2298+ "load_addr: 80000000\n")
2299+ config._validate_load_addr()
2300+
2301+ def test_validate_dtb_addr(self):
2302+ # V3 change: All numerical inputs are good addresses (since YAML
2303+ # converts them to ingegers and we convert them back to the correct
2304+ # format). We don't need 8 digit hex values for addresses.
2305+ config = self.get_config(self.valid_complete_v3 +
2306+ "dtb_addr: 0x8000000\n")
2307+ config._validate_dtb_addr()
2308+ config = self.get_config(self.valid_complete_v3 +
2309+ "dtb_addr: 0x8000000x\n")
2310+ self.assertValidationError("Invalid dtb address: 0x8000000x",
2311+ config._validate_dtb_addr)
2312+ config = self.get_config(self.valid_complete_v3 +
2313+ "dtb_addr: 80000000\n")
2314+ config._validate_dtb_addr()
2315+
2316+ def test_wired_interfaces(self):
2317+ config = self.get_config(self.valid_complete_v3 +
2318+ "wired_interfaces:\n - eth0\n" +
2319+ self.valid_end)
2320+ config.validate()
2321+ self.assertEqual(["eth0"], config.wired_interfaces)
2322+ config = self.get_config(self.valid_complete_v3 +
2323+ "wired_interfaces:\n"
2324+ " - eth0\n"
2325+ " - eth1\n"
2326+ " - usb2\n" +
2327+ self.valid_end)
2328+ config.validate()
2329+ self.assertEqual(["eth0", "eth1", "usb2"], config.wired_interfaces)
2330+
2331+ def test_wireless_interfaces(self):
2332+ config = self.get_config(self.valid_complete_v3 +
2333+ "wireless_interfaces:\n"
2334+ " - wlan0\n" +
2335+ self.valid_end)
2336+ config.validate()
2337+ self.assertEqual(["wlan0"], config.wireless_interfaces)
2338+ config = self.get_config(self.valid_complete_v3 +
2339+ "wireless_interfaces:\n"
2340+ " - wlan0\n"
2341+ " - wl1\n"
2342+ " - usb2\n" +
2343+ self.valid_end)
2344+ config.validate()
2345+ self.assertEqual(["wlan0", "wl1", "usb2"], config.wireless_interfaces)
2346+
2347+ def test_partition_layout(self):
2348+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2349+ config.validate()
2350+ self.assertEqual("bootfs_rootfs",
2351+ config.partition_layout)
2352+
2353+ def test_u_boot_file(self):
2354+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2355+ config.validate()
2356+ self.assertEqual("usr/lib/u-boot/smdkv310/u-boot.bin",
2357+ config.u_boot_file)
2358+
2359+ def test_u_boot_package(self):
2360+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2361+ config.validate()
2362+ self.assertEqual("u-boot-linaro-s5pv310",
2363+ config.u_boot_package)
2364+
2365+ def test_spl_file(self):
2366+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2367+ config.validate()
2368+ self.assertEqual("usr/lib/x-loader/omap4430panda/MLO",
2369+ config.spl_file)
2370+
2371+ def test_kernel_file(self):
2372+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2373+ config.validate()
2374+ self.assertEqual("boot/vmlinuz-*-linaro-omap",
2375+ config.vmlinuz)
2376+
2377+ def test_initrd_file(self):
2378+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2379+ config.validate()
2380+ self.assertEqual("boot/initrd.img-*-linaro-omap",
2381+ config.initrd)
2382+
2383+ def test_dtb_file(self):
2384+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2385+ config.validate()
2386+ self.assertEqual("boot/dt-*-linaro-omap/omap4-panda.dtb",
2387+ config.dtb_file)
2388+
2389+ def test_extra_boot_options(self):
2390+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2391+ config.validate()
2392+ self.assertEqual(
2393+ "earlyprintk fixrtc nocompcache vram=48M "
2394+ "omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000",
2395+ config.extra_boot_options)
2396+
2397+ def test_extra_serial_opts(self):
2398+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2399+ config.validate()
2400+ self.assertEqual('console=tty0 console=ttyO2,115200n8',
2401+ config.extra_serial_opts)
2402+
2403+ def test_boot_script(self):
2404+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2405+ config.validate()
2406+ self.assertEqual("boot.scr",
2407+ config.boot_script)
2408+
2409+ def test_u_boot_in_boot_part(self):
2410+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2411+ config.validate()
2412+ self.assertEqual("yes",
2413+ config.uboot_in_boot_part)
2414+
2415+ def test_spl_package(self):
2416+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2417+ config.validate()
2418+ self.assertEqual("x-loader-omap4-panda",
2419+ config.spl_package)
2420+
2421+ def test_serial_tty(self):
2422+ config = self.get_config(self.valid_complete_v3 + self.valid_end)
2423+ config.validate()
2424+ self.assertEqual("ttySAC1", config.serial_tty)
2425+
2426+ def test_mmc_id(self):
2427+ config = self.get_config(self.valid_complete_v3 +
2428+ "mmc_id: 0:1\n" +
2429+ self.valid_end)
2430+ config.validate()
2431+ self.assertEqual("0:1", config.mmc_id)
2432+
2433+ def test_boot_min_size(self):
2434+ config = self.get_config(self.valid_complete_v3 +
2435+ "boot_min_size: 50\n" +
2436+ self.valid_end)
2437+ config.validate()
2438+ self.assertEqual("50", config.boot_min_size)
2439+
2440+ def test_root_min_size(self):
2441+ config = self.get_config(self.valid_complete_v3 +
2442+ "root_min_size: 50\n" +
2443+ self.valid_end)
2444+ config.validate()
2445+ self.assertEqual("50", config.root_min_size)
2446+
2447+ def test_loader_min_size(self):
2448+ config = self.get_config(self.valid_complete_v3 +
2449+ "loader_min_size: 2\n" +
2450+ self.valid_end)
2451+ config.validate()
2452+ self.assertEqual("2", config.loader_min_size)
2453+
2454+ def test_kernel_addr(self):
2455+ config = self.get_config(self.valid_complete_v3 +
2456+ "kernel_addr: 0x80000000\n" +
2457+ self.valid_end)
2458+ config.validate()
2459+ self.assertEqual("0x80000000", config.kernel_addr)
2460+ config = self.get_config(self.valid_complete_v3 +
2461+ "kernel_addr: 0x8aBcdEFf\n" +
2462+ self.valid_end)
2463+ config.validate()
2464+ self.assertEqual("0x8abcdeff", config.kernel_addr)
2465+
2466+ def test_initrd_addr(self):
2467+ config = self.get_config(self.valid_complete_v3 +
2468+ "initrd_addr: 0x80000000\n" +
2469+ self.valid_end)
2470+ config.validate()
2471+ self.assertEqual("0x80000000", config.initrd_addr)
2472+ config = self.get_config(self.valid_complete_v3 +
2473+ "initrd_addr: 0x8aBcdEFf\n" +
2474+ self.valid_end)
2475+ config.validate()
2476+ self.assertEqual("0x8abcdeff", config.initrd_addr)
2477+
2478+ def test_load_addr(self):
2479+ config = self.get_config(self.valid_complete_v3 +
2480+ "load_addr: 0x80000000\n" +
2481+ self.valid_end)
2482+ config.validate()
2483+ self.assertEqual("0x80000000", config.load_addr)
2484+ config = self.get_config(self.valid_complete_v3 +
2485+ "load_addr: 0x8aBcdEFf\n" +
2486+ self.valid_end)
2487+ config.validate()
2488+ self.assertEqual("0x8abcdeff", config.load_addr)
2489+
2490+ def test_dtb_addr(self):
2491+ config = self.get_config(self.valid_complete_v3 +
2492+ "dtb_addr: 0x80000000\n" +
2493+ self.valid_end)
2494+ config.validate()
2495+ self.assertEqual("0x80000000", config.dtb_addr)
2496+ config = self.get_config(self.valid_complete_v3 +
2497+ "dtb_addr: 0x8aBcdEFf\n" +
2498+ self.valid_end)
2499+ config.validate()
2500+ self.assertEqual("0x8abcdeff", config.dtb_addr)
2501+
2502+ def test_name(self):
2503+ config = self.get_config(
2504+ "name: ahwpack\n"
2505+ "packages: foo\n"
2506+ "architectures: armel\n")
2507+ self.assertEqual("ahwpack", config.name)
2508+
2509+ def test_include_debs(self):
2510+ config = self.get_config(self.valid_start + "include_debs: false\n")
2511+ self.assertEqual(False, config.include_debs)
2512+
2513+ def test_include_debs_defaults_true(self):
2514+ config = self.get_config(self.valid_start)
2515+ self.assertEqual(True, config.include_debs)
2516+
2517+ def test_include_debs_defaults_true_on_empty(self):
2518+ config = self.get_config(self.valid_start + "include_debs: \n")
2519+ self.assertEqual(True, config.include_debs)
2520+
2521+ def test_origin(self):
2522+ config = self.get_config(self.valid_start + "origin: linaro\n")
2523+ self.assertEqual("linaro", config.origin)
2524+
2525+ def test_origin_default_None(self):
2526+ config = self.get_config(self.valid_start)
2527+ self.assertEqual(None, config.origin)
2528+
2529+ def test_origin_None_on_empty(self):
2530+ config = self.get_config(self.valid_start + "origin: \n")
2531+ self.assertEqual(None, config.origin)
2532+
2533+ def test_maintainer(self):
2534+ maintainer = "Linaro Developers <linaro-dev@lists.linaro.org>"
2535+ config = self.get_config(
2536+ self.valid_start
2537+ + "maintainer: %s\n" % maintainer)
2538+ self.assertEqual(maintainer, config.maintainer)
2539+
2540+ def test_maintainer_default_None(self):
2541+ config = self.get_config(self.valid_start)
2542+ self.assertEqual(None, config.maintainer)
2543+
2544+ def test_maintainer_None_on_empty(self):
2545+ config = self.get_config(self.valid_start + "maintainer: \n")
2546+ self.assertEqual(None, config.maintainer)
2547+
2548+ def test_support_supported(self):
2549+ config = self.get_config(self.valid_start + "support: supported\n")
2550+ self.assertEqual("supported", config.support)
2551+
2552+ def test_support_unsupported(self):
2553+ config = self.get_config(self.valid_start + "support: unsupported\n")
2554+ self.assertEqual("unsupported", config.support)
2555+
2556+ def test_support_default_None(self):
2557+ config = self.get_config(self.valid_start)
2558+ self.assertEqual(None, config.support)
2559+
2560+ def test_support_None_on_empty(self):
2561+ config = self.get_config(self.valid_start + "support: \n")
2562+ self.assertEqual(None, config.support)
2563+
2564+ def test_packages(self):
2565+ config = self.get_config(
2566+ "name: ahwpack\n"
2567+ "packages:\n"
2568+ " - foo\n"
2569+ " - bar\n"
2570+ "architectures: armel\n")
2571+ self.assertEqual(["foo", "bar"], config.packages)
2572+
2573+ def test_packages_filters_duplicates(self):
2574+ config = self.get_config(
2575+ "name: ahwpack\n"
2576+ "packages:\n"
2577+ " - foo\n"
2578+ " - bar\n"
2579+ " - foo\n"
2580+ "architectures: armel\n")
2581+ self.assertEqual(["foo", "bar"], config.packages)
2582+
2583+ def test_sources_single(self):
2584+ config = self.get_config(
2585+ self.valid_start
2586+ + "sources:\n"
2587+ " ubuntu: http://example.org foo\n")
2588+ self.assertEqual({"ubuntu": "http://example.org foo"}, config.sources)
2589+
2590+ def test_sources_multiple(self):
2591+ config = self.get_config(
2592+ self.valid_start
2593+ + "sources:\n"
2594+ " ubuntu: http://example.org foo\n"
2595+ " linaro: http://example.org bar\n")
2596+ self.assertEqual(
2597+ {"ubuntu": "http://example.org foo",
2598+ "linaro": "http://example.org bar"},
2599+ config.sources)
2600+
2601+ def test_architectures(self):
2602+ config = self.get_config(
2603+ "hello: there\n"
2604+ "name: ahwpack\n"
2605+ "packages: foo\n"
2606+ "architectures:\n"
2607+ " - foo\n"
2608+ " - bar\n")
2609+ self.assertEqual(["foo", "bar"], config.architectures)
2610+
2611+ def test_architectures_filters_duplicates(self):
2612+ config = self.get_config(
2613+ "name: ahwpack\n"
2614+ "packages: foo\n"
2615+ "architectures:\n"
2616+ " - foo\n"
2617+ " - bar\n"
2618+ " - foo\n")
2619+ self.assertEqual(["foo", "bar"], config.architectures)
2620+
2621+ def test_assume_installed(self):
2622+ config = self.get_config(
2623+ "name: ahwpack\n"
2624+ "packages:\n"
2625+ " - foo\n"
2626+ "architectures:\n"
2627+ " - armel\n"
2628+ "assume_installed:\n"
2629+ " - foo\n"
2630+ " - bar\n")
2631+ self.assertEqual(["foo", "bar"], config.assume_installed)
2632+
2633+ def test_assume_installed_filters_duplicates(self):
2634+ config = self.get_config(
2635+ "name: ahwpack\n"
2636+ "packages:\n"
2637+ " - foo\n"
2638+ "architectures:\n"
2639+ " - armel\n"
2640+ "assume_installed:\n"
2641+ " - foo\n"
2642+ " - bar\n"
2643+ " - foo\n")
2644+ self.assertEqual(["foo", "bar"], config.assume_installed)
2645
2646=== modified file 'linaro_image_tools/hwpack/tests/test_hardwarepack.py'
2647--- linaro_image_tools/hwpack/tests/test_hardwarepack.py 2012-06-13 14:53:32 +0000
2648+++ linaro_image_tools/hwpack/tests/test_hardwarepack.py 2012-07-23 15:38:22 +0000
2649@@ -40,6 +40,7 @@
2650 from linaro_image_tools.hwpack.hardwarepack_format import (
2651 HardwarePackFormatV1,
2652 HardwarePackFormatV2,
2653+ HardwarePackFormatV3,
2654 )
2655
2656
2657@@ -87,174 +88,157 @@
2658
2659 def test_str(self):
2660 metadata = Metadata("ahwpack", "4", "armel")
2661- self.assertEqual(
2662- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n", str(metadata))
2663+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n")
2664+ self.assertEqual(expected_out, str(metadata))
2665
2666 def test_str_with_origin(self):
2667 metadata = Metadata("ahwpack", "4", "armel", origin="linaro")
2668- self.assertEqual(
2669- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\nORIGIN=linaro\n",
2670- str(metadata))
2671+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2672+ "ORIGIN=linaro\n")
2673+ self.assertEqual(expected_out, str(metadata))
2674
2675 def test_str_with_maintainer(self):
2676 metadata = Metadata(
2677 "ahwpack", "4", "armel", maintainer="Some Maintainer")
2678- self.assertEqual(
2679- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2680- "MAINTAINER=Some Maintainer\n",
2681- str(metadata))
2682+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2683+ "MAINTAINER=Some Maintainer\n")
2684+ self.assertEqual(expected_out, str(metadata))
2685
2686 def test_str_with_support(self):
2687 metadata = Metadata("ahwpack", "4", "armel", support="unsupported")
2688- self.assertEqual(
2689- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2690- "SUPPORT=unsupported\n",
2691- str(metadata))
2692+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2693+ "SUPPORT=unsupported\n")
2694+ self.assertEqual(expected_out, str(metadata))
2695
2696 def test_str_with_serial_tty(self):
2697 metadata = Metadata("ahwpack", "4", "armel",
2698 format=HardwarePackFormatV2())
2699 metadata.add_v2_config(serial_tty='ttyO2')
2700- self.assertEqual(
2701- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2702- "SERIAL_TTY=ttyO2\n",
2703- str(metadata))
2704+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2705+ "SERIAL_TTY=ttyO2\n")
2706+ self.assertEqual(expected_out, str(metadata))
2707
2708 def test_str_with_kernel_addr(self):
2709 metadata = Metadata("ahwpack", "4", "armel",
2710 format=HardwarePackFormatV2())
2711 metadata.add_v2_config(kernel_addr='0x80000000')
2712- self.assertEqual(
2713- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2714- "KERNEL_ADDR=0x80000000\n",
2715- str(metadata))
2716+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2717+ "KERNEL_ADDR=0x80000000\n")
2718+ self.assertEqual(expected_out, str(metadata))
2719
2720 def test_str_with_initrd_addr(self):
2721 metadata = Metadata("ahwpack", "4", "armel",
2722 format=HardwarePackFormatV2())
2723 metadata.add_v2_config(initrd_addr='0x80000000')
2724- self.assertEqual(
2725- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2726- "INITRD_ADDR=0x80000000\n",
2727- str(metadata))
2728+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2729+ "INITRD_ADDR=0x80000000\n")
2730+ self.assertEqual(expected_out, str(metadata))
2731
2732 def test_str_with_load_addr(self):
2733 metadata = Metadata("ahwpack", "4", "armel",
2734 format=HardwarePackFormatV2())
2735 metadata.add_v2_config(load_addr='0x80000000')
2736- self.assertEqual(
2737- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2738- "LOAD_ADDR=0x80000000\n",
2739- str(metadata))
2740+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2741+ "LOAD_ADDR=0x80000000\n")
2742+ self.assertEqual(expected_out, str(metadata))
2743
2744 def test_str_with_dtb_addr(self):
2745 metadata = Metadata("ahwpack", "4", "armel",
2746 format=HardwarePackFormatV2())
2747 metadata.add_v2_config(dtb_addr='0x80000000')
2748- self.assertEqual(
2749- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2750- "DTB_ADDR=0x80000000\n",
2751- str(metadata))
2752+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2753+ "DTB_ADDR=0x80000000\n")
2754+ self.assertEqual(expected_out, str(metadata))
2755
2756 def test_str_with_wired_interfaces(self):
2757 metadata = Metadata("ahwpack", "4", "armel",
2758 format=HardwarePackFormatV2())
2759 metadata.add_v2_config(wired_interfaces=['eth0', 'usb0'])
2760- self.assertEqual(
2761- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2762- "WIRED_INTERFACES=eth0 usb0\n",
2763- str(metadata))
2764+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2765+ "WIRED_INTERFACES=eth0 usb0\n")
2766+ self.assertEqual(expected_out, str(metadata))
2767
2768 def test_str_with_wireless_interfaces(self):
2769 metadata = Metadata("ahwpack", "4", "armel",
2770 format=HardwarePackFormatV2())
2771 metadata.add_v2_config(wireless_interfaces=['wlan0', 'wl0'])
2772- self.assertEqual(
2773- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2774- "WIRELESS_INTERFACES=wlan0 wl0\n",
2775- str(metadata))
2776+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2777+ "WIRELESS_INTERFACES=wlan0 wl0\n")
2778+ self.assertEqual(expected_out, str(metadata))
2779
2780 def test_str_with_partition_layout(self):
2781 metadata = Metadata("ahwpack", "4", "armel",
2782 format=HardwarePackFormatV2())
2783 metadata.add_v2_config(partition_layout='bootfs_rootfs')
2784- self.assertEqual(
2785- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2786- "PARTITION_LAYOUT=bootfs_rootfs\n",
2787- str(metadata))
2788+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2789+ "PARTITION_LAYOUT=bootfs_rootfs\n")
2790+ self.assertEqual(expected_out, str(metadata))
2791
2792 def test_str_with_mmc_id(self):
2793 metadata = Metadata("ahwpack", "4", "armel",
2794 format=HardwarePackFormatV2())
2795 metadata.add_v2_config(mmc_id='1')
2796- self.assertEqual(
2797- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2798- "MMC_ID=1\n",
2799- str(metadata))
2800+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2801+ "MMC_ID=1\n")
2802+ self.assertEqual(expected_out, str(metadata))
2803
2804 def test_str_with_boot_min_size(self):
2805 metadata = Metadata("ahwpack", "4", "armel",
2806 format=HardwarePackFormatV2())
2807 metadata.add_v2_config(boot_min_size='50')
2808- self.assertEqual(
2809- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2810- "BOOT_MIN_SIZE=50\n",
2811- str(metadata))
2812+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2813+ "BOOT_MIN_SIZE=50\n")
2814+ self.assertEqual(expected_out, str(metadata))
2815
2816 def test_str_with_root_min_size(self):
2817 metadata = Metadata("ahwpack", "4", "armel",
2818 format=HardwarePackFormatV2())
2819 metadata.add_v2_config(root_min_size='100')
2820- self.assertEqual(
2821- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2822- "ROOT_MIN_SIZE=100\n",
2823- str(metadata))
2824+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2825+ "ROOT_MIN_SIZE=100\n")
2826+ self.assertEqual(expected_out, str(metadata))
2827
2828 def test_str_with_loader_min_size(self):
2829 metadata = Metadata("ahwpack", "4", "armel",
2830 format=HardwarePackFormatV2())
2831 metadata.add_v2_config(loader_min_size='1')
2832- self.assertEqual(
2833- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2834- "LOADER_MIN_SIZE=1\n",
2835- str(metadata))
2836+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2837+ "LOADER_MIN_SIZE=1\n")
2838+ self.assertEqual(expected_out, str(metadata))
2839
2840 def test_str_with_kernel_file(self):
2841 metadata = Metadata("ahwpack", "4", "armel",
2842 format=HardwarePackFormatV2())
2843 metadata.add_v2_config(vmlinuz='boot/vmlinuz-3.0.0-1002-linaro-omap')
2844- self.assertEqual(
2845- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2846- "KERNEL_FILE=boot/vmlinuz-3.0.0-1002-linaro-omap\n",
2847- str(metadata))
2848+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2849+ "KERNEL_FILE=boot/vmlinuz-3.0.0-1002-linaro-omap\n")
2850+ self.assertEqual(expected_out, str(metadata))
2851
2852 def test_str_with_initrd_file(self):
2853 metadata = Metadata("ahwpack", "4", "armel",
2854 format=HardwarePackFormatV2())
2855 metadata.add_v2_config(initrd='boot/initrd.img-3.0.0-1002-linaro-omap')
2856- self.assertEqual(
2857- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2858- "INITRD_FILE=boot/initrd.img-3.0.0-1002-linaro-omap\n",
2859- str(metadata))
2860+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2861+ "INITRD_FILE=boot/initrd.img-3.0.0-1002-linaro-omap\n")
2862+ self.assertEqual(expected_out, str(metadata))
2863
2864 def test_str_with_dtb_file(self):
2865 metadata = Metadata("ahwpack", "4", "armel",
2866 format=HardwarePackFormatV2())
2867 metadata.add_v2_config(
2868 dtb_file='boot/dt-3.0.0-1002-linaro-omap/omap4-panda.dtb')
2869- self.assertEqual(
2870- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2871- "DTB_FILE=boot/dt-3.0.0-1002-linaro-omap/omap4-panda.dtb\n",
2872- str(metadata))
2873+ expected_out = ("NAME=ahwpack\nVERSION=4\n"
2874+ "ARCHITECTURE=armel\nDTB_FILE="
2875+ "boot/dt-3.0.0-1002-linaro-omap/omap4-panda.dtb\n")
2876+ self.assertEqual(expected_out, str(metadata))
2877
2878 def test_str_with_boot_script(self):
2879 metadata = Metadata("ahwpack", "4", "armel",
2880 format=HardwarePackFormatV2())
2881 metadata.add_v2_config(boot_script='boot.scr')
2882- self.assertEqual(
2883- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2884- "BOOT_SCRIPT=boot.scr\n",
2885- str(metadata))
2886+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2887+ "BOOT_SCRIPT=boot.scr\n")
2888+ self.assertEqual(expected_out, str(metadata))
2889
2890 def test_str_with_extra_boot_options(self):
2891 metadata = Metadata("ahwpack", "4", "armel",
2892@@ -263,21 +247,21 @@
2893 extra_boot_options=(
2894 'earlyprintk fixrtc nocompcache vram=48M omapfb.vram=0:24M '
2895 'mem=456M@0x80000000 mem=512M@0xA0000000'))
2896- self.assertEqual(
2897- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2898- "EXTRA_BOOT_OPTIONS=earlyprintk fixrtc nocompcache vram=48M "
2899- "omapfb.vram=0:24M mem=456M@0x80000000 mem=512M@0xA0000000\n",
2900- str(metadata))
2901+ expected_out = ("NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2902+ "EXTRA_BOOT_OPTIONS=earlyprintk fixrtc nocompcache "
2903+ "vram=48M omapfb.vram=0:24M "
2904+ "mem=456M@0x80000000 mem=512M@0xA0000000\n")
2905+ self.assertEqual(expected_out, str(metadata))
2906
2907 def test_str_with_extra_serial_options(self):
2908 metadata = Metadata("ahwpack", "4", "armel",
2909 format=HardwarePackFormatV2())
2910 metadata.add_v2_config(
2911 extra_serial_opts='console=tty0 console=ttyO2,115200n8')
2912- self.assertEqual(
2913- "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n"
2914- "EXTRA_SERIAL_OPTIONS=console=tty0 console=ttyO2,115200n8\n",
2915- str(metadata))
2916+ expected_out = ("NAME=ahwpack\nVERSION=4\n"
2917+ "ARCHITECTURE=armel\nEXTRA_SERIAL_OPTIONS="
2918+ "console=tty0 console=ttyO2,115200n8\n")
2919+ self.assertEqual(expected_out, str(metadata))
2920
2921 def test_from_config(self):
2922 class Config:
2923@@ -296,6 +280,69 @@
2924 self.assertEqual("i386", metadata.architecture)
2925
2926
2927+class NewMetadataTests(TestCase):
2928+
2929+ def setUp(self):
2930+ super(NewMetadataTests, self).setUp()
2931+
2932+ def test_format(self):
2933+ metadata = Metadata("ahwpack", "4", "armel",
2934+ format=HardwarePackFormatV3())
2935+ # Need to call also this one!
2936+ metadata.add_v2_config()
2937+ metadata.add_v3_config(bootloaders=None)
2938+ expected_out = ("format: '3.0'\nname: ahwpack\nversion: '4'\n"
2939+ "architecture: armel\n")
2940+ self.assertEqual(expected_out, str(metadata))
2941+
2942+ def test_section_bootloaders(self):
2943+ bootloaders = {'u_boot': {'file': 'a_file'}}
2944+ metadata = Metadata("ahwpack", "4", "armel",
2945+ format=HardwarePackFormatV3())
2946+ # Need to call also this one!
2947+ metadata.add_v2_config()
2948+ metadata.add_v3_config(bootloaders=bootloaders)
2949+ expected_out = ("format: '3.0'\nname: ahwpack\nversion: '4'\n"
2950+ "architecture: armel\nbootloaders:\n u_boot:\n"
2951+ " file: a_file\n")
2952+ self.assertEqual(expected_out, str(metadata))
2953+
2954+ def test_section_wireless(self):
2955+ metadata = Metadata("ahwpack", "4", "armel",
2956+ format=HardwarePackFormatV3())
2957+ wireless_list = ['wlan0', 'wl0']
2958+ # Need to call also this one!
2959+ metadata.add_v2_config(wireless_interfaces=wireless_list)
2960+ metadata.add_v3_config(bootloaders=None)
2961+ expected_out = ("format: '3.0'\nname: ahwpack\nversion: '4'\n"
2962+ "architecture: armel\nwireless_interfaces: wlan0 "
2963+ "wl0\n")
2964+ self.assertEqual(expected_out, str(metadata))
2965+
2966+ def test_section_wired(self):
2967+ metadata = Metadata("ahwpack", "4", "armel",
2968+ format=HardwarePackFormatV3())
2969+ wired_list = ['eth0', 'usb0']
2970+ # Need to call also this one!
2971+ metadata.add_v2_config(wired_interfaces=wired_list)
2972+ metadata.add_v3_config(bootloaders=None)
2973+ expected_out = ("format: '3.0'\nname: ahwpack\nversion: '4'\n"
2974+ "architecture: armel\nwired_interfaces: eth0 usb0\n")
2975+ self.assertEqual(expected_out, str(metadata))
2976+
2977+ def test_section_extra_serial_options(self):
2978+ metadata = Metadata("ahwpack", "4", "armel",
2979+ format=HardwarePackFormatV3())
2980+ options = ['option1', 'option2,option3']
2981+ # Need to call also this one!
2982+ metadata.add_v2_config(extra_serial_opts=options)
2983+ metadata.add_v3_config(bootloaders=None)
2984+ expected_out = ("format: '3.0'\nname: ahwpack\nversion: '4'\n"
2985+ "architecture: armel\nextra_serial_options: option1 "
2986+ "option2,option3\n")
2987+ self.assertEqual(expected_out, str(metadata))
2988+
2989+
2990 class HardwarePackTests(TestCase):
2991
2992 def setUp(self):
2993
2994=== modified file 'linaro_image_tools/hwpack/tests/test_hwpack_converter.py'
2995--- linaro_image_tools/hwpack/tests/test_hwpack_converter.py 2012-07-19 15:21:06 +0000
2996+++ linaro_image_tools/hwpack/tests/test_hwpack_converter.py 2012-07-23 15:38:22 +0000
2997@@ -130,3 +130,27 @@
2998 converter = HwpackConverter(input_file, output_file)
2999 converter._parse()
3000 self.assertEqual(out_format, str(converter))
3001+
3002+ def test_assume_installed(self):
3003+ """Tests the correct creation of the extra_serial_options part."""
3004+ ini_format = ("[hwpack]\nformat=2.0\nassume-installed=install1 "
3005+ "install2")
3006+ out_format = ("format: '3.0'\nassume_installed:\n- install1\n- "
3007+ "install2\n")
3008+ input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
3009+ get_file_name()
3010+ output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
3011+ converter = HwpackConverter(input_file, output_file)
3012+ converter._parse()
3013+ self.assertEqual(out_format, str(converter))
3014+
3015+ def test_include_debs(self):
3016+ """Tests the correct creation of the extra_serial_options part."""
3017+ ini_format = ("[hwpack]\nformat=2.0\ninclude-debs=yes")
3018+ out_format = ("format: '3.0'\ninclude_debs: true\n")
3019+ input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
3020+ get_file_name()
3021+ output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
3022+ converter = HwpackConverter(input_file, output_file)
3023+ converter._parse()
3024+ self.assertEqual(out_format, str(converter))
3025
3026=== modified file 'linaro_image_tools/media_create/boards.py'
3027--- linaro_image_tools/media_create/boards.py 2012-06-13 14:41:42 +0000
3028+++ linaro_image_tools/media_create/boards.py 2012-07-23 15:38:22 +0000
3029@@ -36,6 +36,7 @@
3030 import shutil
3031 import string
3032 import logging
3033+from linaro_image_tools.hwpack.config import Config
3034
3035 from parted import Device
3036
3037@@ -43,7 +44,7 @@
3038
3039 from linaro_image_tools.media_create.partitions import (
3040 partition_mounted, SECTOR_SIZE, register_loopback)
3041-
3042+from StringIO import StringIO
3043
3044 KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s'
3045 INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s'
3046@@ -114,6 +115,7 @@
3047 class HardwarepackHandler(object):
3048 FORMAT_1 = '1.0'
3049 FORMAT_2 = '2.0'
3050+ FORMAT_3 = '3.0'
3051 FORMAT_MIXED = '1.0and2.0'
3052 metadata_filename = 'metadata'
3053 format_filename = 'FORMAT'
3054@@ -158,18 +160,18 @@
3055 if self.tempdir is not None and os.path.exists(self.tempdir):
3056 shutil.rmtree(self.tempdir)
3057
3058- def get_field(self, section, field):
3059+ def get_field(self, field):
3060 data = None
3061 hwpack_with_data = None
3062 for hwpack_tarfile in self.hwpack_tarfiles:
3063 metadata = hwpack_tarfile.extractfile(self.metadata_filename)
3064- # Use RawConfigParser which does not support the magical
3065- # interpolation behavior of ConfigParser so we don't mess up
3066- # metadata accidentally.
3067- parser = ConfigParser.RawConfigParser()
3068- parser.readfp(self.FakeSecHead(metadata))
3069+ lines = metadata.readlines()
3070+ if re.search("=", lines[0]) and not re.search(":", lines[0]):
3071+ # Probably V2 hardware pack without [hwpack] on the first line
3072+ lines = ["[hwpack]\n"] + lines
3073+ parser = Config(StringIO("".join(lines)))
3074 try:
3075- new_data = parser.get(section, field)
3076+ new_data = parser.get_option(field)
3077 if new_data is not None:
3078 assert data is None, "The metadata field '%s' is set to " \
3079 "'%s' and new value '%s' is found" % (field, data,
3080@@ -178,11 +180,12 @@
3081 hwpack_with_data = hwpack_tarfile
3082 except ConfigParser.NoOptionError:
3083 continue
3084+
3085 return data, hwpack_with_data
3086
3087 def get_format(self):
3088 format = None
3089- supported_formats = [self.FORMAT_1, self.FORMAT_2]
3090+ supported_formats = [self.FORMAT_1, self.FORMAT_2, self.FORMAT_3]
3091 for hwpack_tarfile in self.hwpack_tarfiles:
3092 format_file = hwpack_tarfile.extractfile(self.format_filename)
3093 format_string = format_file.read().strip()
3094@@ -196,8 +199,7 @@
3095 return format
3096
3097 def get_file(self, file_alias):
3098- file_name, hwpack_tarfile = self.get_field(self.main_section,
3099- file_alias)
3100+ file_name, hwpack_tarfile = self.get_field(file_alias)
3101 if file_name is not None:
3102 hwpack_tarfile.extract(file_name, self.tempdir)
3103 file_name = os.path.join(self.tempdir, file_name)
3104@@ -289,8 +291,7 @@
3105 def get_metadata_field(cls, field_name):
3106 """ Return the metadata value for field_name if it can be found.
3107 """
3108- data, _ = cls.hardwarepack_handler.get_field(
3109- cls.hardwarepack_handler.main_section, field_name)
3110+ data, _ = cls.hardwarepack_handler.get_field(field_name)
3111 return data
3112
3113 @classmethod
3114@@ -305,7 +306,7 @@
3115 if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_1):
3116 return
3117
3118- if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_2):
3119+ if (cls.hwpack_format != cls.hardwarepack_handler.FORMAT_1):
3120 # Clear V1 defaults.
3121 cls.kernel_addr = None
3122 cls.initrd_addr = None
3123@@ -334,19 +335,19 @@
3124 cls.serial_tty = cls.get_metadata_field('serial_tty')
3125 wired_interfaces = cls.get_metadata_field('wired_interfaces')
3126 if wired_interfaces is not None:
3127- cls.wired_interfaces = wired_interfaces.split(' ')
3128+ cls.wired_interfaces = wired_interfaces
3129 wireless_interfaces = cls.get_metadata_field(
3130 'wireless_interfaces')
3131 if wireless_interfaces is not None:
3132- cls.wireless_interfaces = wireless_interfaces.split(' ')
3133- cls.vmlinuz = cls.get_metadata_field('kernel_file')
3134- cls.initrd = cls.get_metadata_field('initrd_file')
3135+ cls.wireless_interfaces = wireless_interfaces
3136+ cls.vmlinuz = cls.get_metadata_field('vmlinuz')
3137+ cls.initrd = cls.get_metadata_field('initrd')
3138 cls.dtb_file = cls.get_metadata_field('dtb_file')
3139 cls.extra_boot_args_options = cls.get_metadata_field(
3140 'extra_boot_options')
3141 cls.boot_script = cls.get_metadata_field('boot_script')
3142 cls.extra_serial_opts = cls.get_metadata_field(
3143- 'extra_serial_options')
3144+ 'extra_serial_opts')
3145 cls.snowball_startup_files_config = cls.get_metadata_field(
3146 'snowball_startup_files_config')
3147
3148@@ -379,7 +380,7 @@
3149 align_up(int(loader_min_size) * 1024 ** 2,
3150 SECTOR_SIZE) / SECTOR_SIZE)
3151
3152- uboot_in_boot_part = cls.get_metadata_field('u_boot_in_boot_part')
3153+ uboot_in_boot_part = cls.get_metadata_field('uboot_in_boot_part')
3154 if uboot_in_boot_part is None:
3155 cls.uboot_in_boot_part = False
3156 elif string.lower(uboot_in_boot_part) == 'yes':
3157@@ -401,7 +402,7 @@
3158 elif string.lower(env_dd) == 'no':
3159 cls.env_dd = False
3160
3161- uboot_dd = cls.get_metadata_field('u_boot_dd')
3162+ uboot_dd = cls.get_metadata_field('uboot_dd')
3163 # Either uboot_dd is not specified, or it contains the dd offset.
3164 if uboot_dd is None:
3165 cls.uboot_dd = False
3166@@ -700,7 +701,7 @@
3167 boot_device_or_file, k_img_data, i_img_data,
3168 d_img_data):
3169 with cls.hardwarepack_handler:
3170- spl_file = cls.get_file('spl')
3171+ spl_file = cls.get_file('spl_file')
3172 if cls.spl_in_boot_part:
3173 assert spl_file is not None, (
3174 "SPL binary could not be found")
3175@@ -715,7 +716,7 @@
3176 if cls.spl_dd:
3177 cls._dd_file(spl_file, boot_device_or_file, cls.spl_dd)
3178
3179- uboot_file = cls.get_file('u_boot')
3180+ uboot_file = cls.get_file('u_boot_file')
3181 if cls.uboot_dd:
3182 cls._dd_file(uboot_file, boot_device_or_file, cls.uboot_dd)
3183
3184@@ -764,7 +765,6 @@
3185 if is_live:
3186 parts_dir = 'casper'
3187 uboot_parts_dir = os.path.join(chroot_dir, parts_dir)
3188-
3189 cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
3190 with partition_mounted(boot_partition, boot_disk):
3191 if cls.uboot_in_boot_part:
3192@@ -781,7 +781,7 @@
3193 else:
3194 default = None
3195 # </legacy v1 support>
3196- uboot_bin = cls.get_file('u_boot', default=default)
3197+ uboot_bin = cls.get_file('u_boot_file', default=default)
3198 assert uboot_bin is not None, (
3199 "uboot binary could not be found")
3200
3201@@ -1277,7 +1277,7 @@
3202 # XXX: delete this method when hwpacks V1 can die
3203 assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
3204 with cls.hardwarepack_handler:
3205- uboot_file = cls.get_file('u_boot', default=os.path.join(
3206+ uboot_file = cls.get_file('u_boot_file', default=os.path.join(
3207 chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor,
3208 'u-boot.imx'))
3209 install_mx5_boot_loader(uboot_file, boot_device_or_file,
3210@@ -1778,7 +1778,7 @@
3211 default = _get_mlo_file(chroot_dir)
3212 except AssertionError:
3213 default = None
3214- mlo_file = cls.get_file('spl', default=default)
3215+ mlo_file = cls.get_file('spl_file', default=default)
3216 cmd_runner.run(["cp", "-v", mlo_file, boot_disk], as_root=True).wait()
3217 # XXX: Is this really needed?
3218 cmd_runner.run(["sync"]).wait()
3219
3220=== modified file 'linaro_image_tools/media_create/chroot_utils.py'
3221--- linaro_image_tools/media_create/chroot_utils.py 2012-06-13 14:11:28 +0000
3222+++ linaro_image_tools/media_create/chroot_utils.py 2012-07-23 15:38:22 +0000
3223@@ -25,7 +25,7 @@
3224 is_arm_host,
3225 find_command,
3226 )
3227-
3228+from linaro_image_tools.media_create.boards import HardwarepackHandler
3229
3230 # It'd be nice if we could use atexit here, but all the things we need to undo
3231 # have to happen right after install_hwpacks completes and the atexit
3232@@ -97,7 +97,17 @@
3233 print "-" * 60
3234 print "Installing (linaro-hwpack-install) %s in target rootfs." % (
3235 hwpack_basename)
3236- args = ['linaro-hwpack-install']
3237+
3238+ # Get infromation required by linaro-hwpack-install
3239+ with HardwarepackHandler([hwpack_file]) as hwpack:
3240+ version, _ = hwpack.get_field("version")
3241+ architecture, _ = hwpack.get_field("architecture")
3242+ name, _ = hwpack.get_field("name")
3243+
3244+ args = ['linaro-hwpack-install',
3245+ '--hwpack-version', version,
3246+ '--hwpack-arch', architecture,
3247+ '--hwpack-name', name]
3248 if hwpack_force_yes:
3249 args.append('--force-yes')
3250 args.append('/%s' % hwpack_basename)
3251
3252=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
3253--- linaro_image_tools/media_create/tests/test_media_create.py 2012-07-17 15:33:19 +0000
3254+++ linaro_image_tools/media_create/tests/test_media_create.py 2012-07-23 15:38:22 +0000
3255@@ -216,22 +216,22 @@
3256
3257 def test_get_metadata(self):
3258 data = 'data to test'
3259- metadata = self.metadata + "TEST=%s\n" % data
3260+ metadata = self.metadata + "U_BOOT=%s\n" % data
3261 tarball = self.add_to_tarball(
3262 [('metadata', metadata)])
3263 hp = HardwarepackHandler([tarball])
3264 with hp:
3265- test_data, _ = hp.get_field(hp.main_section, 'test')
3266+ test_data, _ = hp.get_field('u_boot_file')
3267 self.assertEqual(test_data, data)
3268
3269 def test_preserves_formatters(self):
3270 data = '%s%d'
3271- metadata = self.metadata + "TEST=%s\n" % data
3272+ metadata = self.metadata + "U_BOOT=%s\n" % data
3273 tarball = self.add_to_tarball(
3274 [('metadata', metadata)])
3275 hp = HardwarepackHandler([tarball])
3276 with hp:
3277- test_data, _ = hp.get_field(hp.main_section, 'test')
3278+ test_data, _ = hp.get_field('u_boot_file')
3279 self.assertEqual(test_data, data)
3280
3281 def test_creates_tempdir(self):
3282@@ -252,15 +252,14 @@
3283
3284 def test_get_file(self):
3285 data = 'test file contents\n'
3286- metadata_file = 'TESTFILE'
3287 file_in_archive = 'testfile'
3288- metadata = self.metadata + "%s=%s\n" % (metadata_file, file_in_archive)
3289+ metadata = self.metadata + "%s=%s\n" % ('U_BOOT', file_in_archive)
3290 tarball = self.add_to_tarball(
3291 [('metadata', metadata),
3292 (file_in_archive, data)])
3293 hp = HardwarepackHandler([tarball])
3294 with hp:
3295- test_file = hp.get_file(metadata_file)
3296+ test_file = hp.get_file('u_boot_file')
3297 self.assertEquals(data, open(test_file, 'r').read())
3298
3299
3300@@ -272,7 +271,7 @@
3301 def __enter__(self):
3302 return self
3303
3304- def get_field(self, section, field):
3305+ def get_field(self, field):
3306 try:
3307 return self.metadata_dict[field], None
3308 except:
3309@@ -367,7 +366,7 @@
3310 class config(BoardConfig):
3311 pass
3312 config.set_metadata('ahwpack.tar.gz')
3313- self.assertEquals(data_to_set.split(' '), config.wired_interfaces)
3314+ self.assertEquals(data_to_set, config.wired_interfaces)
3315
3316 def test_sets_wireless_interfaces(self):
3317 self.useFixture(MockSomethingFixture(
3318@@ -382,7 +381,7 @@
3319 class config(BoardConfig):
3320 pass
3321 config.set_metadata('ahwpack.tar.gz')
3322- self.assertEquals(data_to_set.split(' '), config.wireless_interfaces)
3323+ self.assertEquals(data_to_set, config.wireless_interfaces)
3324
3325 def test_sets_mmc_id(self):
3326 self.useFixture(MockSomethingFixture(
3327@@ -3225,6 +3224,20 @@
3328
3329
3330 class TestInstallHWPack(TestCaseWithFixtures):
3331+ def create_minimal_v3_hwpack(self, location, name, version, architecture):
3332+ metadata = "\n".join([
3333+ "name: " + name,
3334+ "version: " + version,
3335+ "architecture: " + architecture,
3336+ "format: 3.0"
3337+ ])
3338+ print metadata
3339+ tar_file = tarfile.open(location, mode='w:gz')
3340+ tarinfo = tarfile.TarInfo("metadata")
3341+ tarinfo.size = len(metadata)
3342+ tar_file.addfile(tarinfo, StringIO(metadata))
3343+ tar_file.close()
3344+
3345 def mock_prepare_chroot(self, chroot_dir, tmp_dir):
3346 def fake_prepare_chroot(chroot_dir, tmp_dir):
3347 cmd_runner.run(['prepare_chroot %s %s' % (chroot_dir, tmp_dir)],
3348@@ -3278,12 +3291,23 @@
3349 sys, 'stdout', open('/dev/null', 'w')))
3350 fixture = self.useFixture(MockCmdRunnerPopenFixture())
3351 chroot_dir = 'chroot_dir'
3352+ hwpack_dir = tempfile.mkdtemp()
3353+ hwpack_file_name = 'hwpack.tgz'
3354+ hwpack_tgz_location = os.path.join(hwpack_dir, hwpack_file_name)
3355+ hwpack_name = "foo"
3356+ hwpack_version = "4"
3357+ hwpack_architecture = "armel"
3358+ self.create_minimal_v3_hwpack(hwpack_tgz_location, hwpack_name,
3359+ hwpack_version, hwpack_architecture)
3360 force_yes = False
3361- install_hwpack(chroot_dir, 'hwpack.tgz', force_yes)
3362+ install_hwpack(chroot_dir, hwpack_tgz_location, force_yes)
3363 self.assertEquals(
3364- ['%s cp hwpack.tgz %s' % (sudo_args, chroot_dir),
3365- '%s %s %s linaro-hwpack-install /hwpack.tgz'
3366- % (sudo_args, chroot_args, chroot_dir)],
3367+ ['%s cp %s %s' % (sudo_args, hwpack_tgz_location, chroot_dir),
3368+ '%s %s %s linaro-hwpack-install --hwpack-version %s '
3369+ '--hwpack-arch %s --hwpack-name %s /%s'
3370+ % (sudo_args, chroot_args, chroot_dir,
3371+ hwpack_version, hwpack_architecture, hwpack_name,
3372+ hwpack_file_name)],
3373 fixture.mock.commands_executed)
3374
3375 fixture.mock.calls = []
3376@@ -3303,9 +3327,23 @@
3377
3378 prefer_dir = preferred_tools_dir()
3379
3380+ hwpack_dir = tempfile.mkdtemp()
3381+ hwpack_file_names = ['hwpack1.tgz', 'hwpack2.tgz']
3382+ hwpack_tgz_locations = []
3383+ hwpack_names = []
3384+ for hwpack_file_name in hwpack_file_names:
3385+ hwpack_tgz_location = os.path.join(hwpack_dir, hwpack_file_name)
3386+ hwpack_tgz_locations.append(hwpack_tgz_location)
3387+ hwpack_names.append(hwpack_file_name)
3388+ hwpack_version = "4"
3389+ hwpack_architecture = "armel"
3390+ self.create_minimal_v3_hwpack(
3391+ hwpack_tgz_location, hwpack_file_name, hwpack_version,
3392+ hwpack_architecture)
3393+
3394 install_hwpacks(
3395- chroot_dir, tmp_dir, prefer_dir, force_yes, [], 'hwpack1.tgz',
3396- 'hwpack2.tgz')
3397+ chroot_dir, tmp_dir, prefer_dir, force_yes, [],
3398+ hwpack_tgz_locations[0], hwpack_tgz_locations[1])
3399 linaro_hwpack_install = find_command(
3400 'linaro-hwpack-install', prefer_dir=prefer_dir)
3401 expected = [
3402@@ -3313,19 +3351,27 @@
3403 'cp %(linaro_hwpack_install)s %(chroot_dir)s/usr/bin',
3404 'mount proc %(chroot_dir)s/proc -t proc',
3405 'chroot %(chroot_dir)s true',
3406- 'cp hwpack1.tgz %(chroot_dir)s',
3407- ('%(chroot_args)s %(chroot_dir)s linaro-hwpack-install '
3408- '--force-yes /hwpack1.tgz'),
3409- 'cp hwpack2.tgz %(chroot_dir)s',
3410- ('%(chroot_args)s %(chroot_dir)s linaro-hwpack-install '
3411- '--force-yes /hwpack2.tgz'),
3412+ 'cp %(hwpack1)s %(chroot_dir)s',
3413+ ('%(chroot_args)s %(chroot_dir)s linaro-hwpack-install '
3414+ '--hwpack-version %(hp_version)s '
3415+ '--hwpack-arch %(hp_arch)s --hwpack-name %(hp_name1)s'
3416+ ' --force-yes /hwpack1.tgz'),
3417+ 'cp %(hwpack2)s %(chroot_dir)s',
3418+ ('%(chroot_args)s %(chroot_dir)s linaro-hwpack-install '
3419+ '--hwpack-version %(hp_version)s '
3420+ '--hwpack-arch %(hp_arch)s --hwpack-name %(hp_name2)s'
3421+ ' --force-yes /hwpack2.tgz'),
3422 'rm -f %(chroot_dir)s/hwpack2.tgz',
3423 'rm -f %(chroot_dir)s/hwpack1.tgz',
3424 'umount -v %(chroot_dir)s/proc',
3425 'rm -f %(chroot_dir)s/usr/bin/linaro-hwpack-install']
3426 keywords = dict(
3427 chroot_dir=chroot_dir, tmp_dir=tmp_dir, chroot_args=chroot_args,
3428- linaro_hwpack_install=linaro_hwpack_install)
3429+ linaro_hwpack_install=linaro_hwpack_install,
3430+ hwpack1=hwpack_tgz_locations[0],
3431+ hwpack2=hwpack_tgz_locations[1],
3432+ hp_version=hwpack_version, hp_name1=hwpack_names[0],
3433+ hp_name2=hwpack_names[1], hp_arch=hwpack_architecture)
3434 expected = [
3435 "%s %s" % (sudo_args, line % keywords) for line in expected]
3436 self.assertEquals(expected, fixture.mock.commands_executed)

Subscribers

People subscribed via source and target branches