~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to virt-convert

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-01 15:40:11 UTC
  • mfrom: (1.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110201154011-op0nusgc240xajvb
Tags: 0.500.5-1ubuntu1
* Merge from debian experimental. Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Updated to add maverick and natty to OS list and enable virtio
       for them.
  - debian/patches/9003-fix-path-to-hvmloader-in-testsuite.patch: adjust
    testsuite for 0001-fix-path-to-hvmloader.patch and
    0002-Fix-path-to-pygrub.patch. (refreshed)
  - debian/control: added acl package to depends.
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin
* Removed patches:
  - debian/patches/9002-libvirt_disk_format.patch: Upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from optparse import OptionGroup
29
29
 
30
30
import virtinst.cli as cli
31
 
from virtinst.cli import fail
 
31
from virtinst.cli import fail, print_stdout, print_stderr
32
32
import virtinst.util as util
33
33
import virtconv.formats as formats
34
34
import virtconv.vmcfg as vmcfg
82
82
 
83
83
    misc = OptionGroup(opts, "Miscellaneous Options")
84
84
    misc.add_option("-q", "--quiet", action="store_true", dest="quiet",
85
 
                    help=_("Don't be verbose"))
 
85
                    help=_("Suppress non-error output"))
86
86
    misc.add_option("-d", "--debug", action="store_true", dest="debug",
87
87
                    help=_("Print debugging information"))
88
88
    opts.add_option_group(misc)
90
90
 
91
91
    (options, args) = opts.parse_args()
92
92
 
93
 
    cli.setupLogging("virt-convert", options.debug)
 
93
    cli.setupLogging("virt-convert", options.debug, options.quiet)
94
94
 
95
95
    if len(args) < 1:
96
96
        opts.error(_("You need to provide an input VM definition"))
140
140
    if os.path.isdir(args[0]):
141
141
        (options.input_file, ignore) = formats.find_input(args[0],
142
142
            options.input_format)
143
 
        options.input_dir =  args[0]
 
143
        options.input_dir = args[0]
144
144
    else:
145
145
        options.input_file = args[0]
146
146
        options.input_dir = os.path.dirname(os.path.realpath(args[0]))
147
147
 
148
148
    return options
149
149
 
150
 
def verbose(options, msg):
151
 
    """Output a message if --quiet is not set."""
152
 
    if not options.quiet:
153
 
        print msg
154
 
 
155
150
def cleanup(msg, options, vmdef, paths):
156
151
    """
157
152
    After failure, clean up anything we created.
175
170
    sys.exit(1)
176
171
 
177
172
def main():
 
173
    cli.earlyLogging()
178
174
    options = parse_args()
179
175
 
180
176
    inp = formats.parser_by_name(options.input_format)
225
221
    logging.debug("output_file: %s" % options.output_file)
226
222
    logging.debug("output_dir: %s" % options.input_dir)
227
223
 
228
 
    verbose(options, _("Generating output in '%(format)s' format to %(dir)s/") %
 
224
    print_stdout(options,
 
225
        _("Generating output in '%(format)s' format to %(dir)s/") %
229
226
        {"format": options.output_format, "dir": options.output_dir})
230
227
 
231
 
 
232
228
    try:
233
229
        for d in vmdef.disks.values():
234
230
            dformat = options.disk_format
246
242
                    dformat = "raw"
247
243
 
248
244
            if d.path and dformat != "none":
249
 
                verbose(options, _("Converting disk '%(path)s' to type "
250
 
                                   "%(format)s...") % {"path": d.path,
 
245
                print_stdout(options, _("Converting disk '%(path)s' to type "
 
246
                                      "%(format)s...") % {"path": d.path,
251
247
                                                       "format": dformat})
252
248
 
253
249
            d.convert(options.input_dir, options.output_dir, dformat)
265
261
        cleanup(_("Couldn't export to file \"%s\": %s") %
266
262
            (options.output_file, e), options, vmdef, clean)
267
263
 
268
 
    verbose(options, "Done.")
 
264
    print_stdout(options, "Done.")
269
265
 
270
266
 
271
267
if __name__ == "__main__":
274
270
    except SystemExit, sys_e:
275
271
        sys.exit(sys_e.code)
276
272
    except KeyboardInterrupt:
277
 
        print >> sys.stderr, _("Aborted at user request")
 
273
        print_stderr(_("Aborted at user request"))
278
274
    except Exception, main_e:
279
 
        logging.exception(main_e)
280
 
        sys.exit(1)
281
 
 
 
275
        fail(main_e)