~pundiramit/linaro-image-tools/origen_quad

« back to all changes in this revision

Viewing changes to linaro-media-create

  • Committer: Milo Casagrande
  • Date: 2012-10-24 13:34:59 UTC
  • mfrom: (584.1.2 bug1059579)
  • Revision ID: milo@ubuntu.com-20121024133459-ku3i2kr1tgmz5hr9
Re-enabled use of common logging infrastructure, fixed error with global variable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import sys
24
24
import tempfile
25
 
import logging
26
25
 
27
26
from linaro_image_tools import cmd_runner
28
27
 
57
56
    MissingRequiredOption,
58
57
    path_in_tarfile_exists,
59
58
    prep_media_path,
 
59
    get_logger,
60
60
    )
61
61
 
62
62
# Just define the global variables
106
106
    parser = get_args_parser()
107
107
    args = parser.parse_args()
108
108
 
109
 
    ch = logging.StreamHandler()
110
 
    ch.setLevel(logging.INFO)
111
 
    formatter = logging.Formatter("%(message)s")
112
 
    ch.setFormatter(formatter)
113
 
    logger = logging.getLogger("linaro_image_tools")
114
 
    logger.setLevel(logging.INFO)
115
 
    logger.addHandler(ch)
 
109
    logger = get_logger(debug=args.debug)
116
110
 
117
111
    try:
118
112
        additional_option_checks(args)
119
113
    except IncompatibleOptions as e:
120
114
        parser.print_help()
121
 
        print >> sys.stderr, "\nError:", e.value
 
115
        logger.error(e.value)
122
116
        sys.exit(1)
123
117
 
124
118
    if args.readhwpack:
125
119
        try:
126
120
            reader = HwpackReader(args.hwpacks)
127
 
            print reader.get_supported_boards()
 
121
            logger.info(reader.get_supported_boards())
128
122
            sys.exit(0)
129
123
        except HwpackReaderError as e:
130
 
            print >> sys.stderr, "\nError:", e.value
 
124
            logger.error(e.value)
131
125
            sys.exit(1)
132
126
 
133
127
    try:
134
128
        check_required_args(args)
135
129
    except MissingRequiredOption as e:
136
130
        parser.print_help()
137
 
        print >> sys.stderr, "\nError:", e.value
 
131
        logger.error(e.value)
138
132
        sys.exit(1)
139
133
 
140
134
    board_config = board_configs[args.dev]
147
141
 
148
142
    if media.is_block_device:
149
143
        if not board_config.supports_writing_to_mmc:
150
 
            print ("The board '%s' does not support the --mmc option. "
151
 
                    "Please use --image_file to create an image file for this "
152
 
                    "board." % args.dev)
 
144
            logger.error("The board '%s' does not support the --mmc option. "
 
145
                         "Please use --image_file to create an image file for "
 
146
                         "this board." % args.dev)
153
147
            sys.exit(1)
154
148
        if not confirm_device_selection_and_ensure_it_is_ready(
155
149
                args.device, args.nocheck_mmc):
156
150
            sys.exit(1)
157
151
    elif not args.should_format_rootfs or not args.should_format_bootfs:
158
 
        print ("Do not use --no-boot or --no-part in conjunction with "
159
 
               "--image_file.")
 
152
        logger.error("Do not use --no-boot or --no-part in conjunction with "
 
153
                     "--image_file.")
160
154
        sys.exit(1)
161
155
    else:
162
156
        # All good, move on.
170
164
    BIN_DIR = os.path.join(TMP_DIR, 'rootfs')
171
165
    os.mkdir(BIN_DIR)
172
166
 
 
167
    logger.info('Searching correct rootfs path')
173
168
    # Identify the correct path for the rootfs
174
169
    filesystem_dir = ''
175
170
    if path_in_tarfile_exists('binary/etc', args.binary):
212
207
 
213
208
    if args.rootfs == 'btrfs':
214
209
        if not extract_kpkgs:
215
 
            print ("Desired rootfs type is 'btrfs', trying to auto-install "
216
 
                   "the 'btrfs-tools' package")
 
210
            logger.info("Desired rootfs type is 'btrfs', trying to "
 
211
                        "auto-install the 'btrfs-tools' package")
217
212
            install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools")
218
213
        else:
219
 
            print ("Desired rootfs type is 'btrfs', please make sure the "
220
 
                   "rootfs also includes 'btrfs-tools'")
 
214
            logger.info("Desired rootfs type is 'btrfs', please make sure the "
 
215
                        "rootfs also includes 'btrfs-tools'")
221
216
 
222
217
    boot_partition, root_partition = setup_partitions(
223
218
        board_config, media, args.image_size, args.boot_label, args.rfs_label,
248
243
            board_config.mmc_device_id, board_config.mmc_part_offset,
249
244
            board_config)
250
245
 
251
 
    print "Done creating Linaro image on %s" % media.path
 
246
    logger.info("Done creating Linaro image on %s" % media.path)