@@ -25,76 +25,82 @@ import sys
2525import os
2626import logging
2727import errno
28+ import gettext , locale
2829from optparse import OptionGroup
2930
3031import virtinst .cli as cli
3132from virtinst .cli import fail
3233import virtinst .util as util
34+ import virtconv
3335import virtconv .formats as formats
3436import virtconv .vmcfg as vmcfg
3537import virtconv .diskcfg as diskcfg
3638
39+ locale .setlocale (locale .LC_ALL , '' )
40+ gettext .bindtextdomain (virtconv .gettext_app , virtconv .gettext_dir )
41+ gettext .install (virtconv .gettext_app , virtconv .gettext_dir , unicode = 1 )
42+
3743def parse_args ():
3844 """Parse and verify command line."""
3945 usage = "%prog [options] inputdir|input.vmx [outputdir|output.xml]"
4046 opts = cli .VirtOptionParser (usage = usage )
4147
4248 cong = OptionGroup (opts , "Conversion Options" )
4349 cong .add_option ("-i" , "--input-format" , action = "store" ,
44- dest = "input_format" , help = ("Input format, e.g. 'vmx'" ))
50+ dest = "input_format" , help = _ ("Input format, e.g. 'vmx'" ))
4551 cong .add_option ("-o" , "--output-format" , action = "store" ,
4652 dest = "output_format" , default = "virt-image" ,
47- help = ("Output format, e.g. 'virt-image'" ))
53+ help = _ ("Output format, e.g. 'virt-image'" ))
4854 cong .add_option ("-D" , "--disk-format" , action = "store" ,
49- dest = "disk_format" , help = ("Output disk format" ))
55+ dest = "disk_format" , help = _ ("Output disk format" ))
5056 opts .add_option_group (cong )
5157
5258 virg = OptionGroup (opts , "Virtualization Type Options" )
5359 virg .add_option ("-v" , "--hvm" , action = "store_true" , dest = "fullvirt" ,
54- help = ("This guest should be a fully virtualized guest" ))
60+ help = _ ("This guest should be a fully virtualized guest" ))
5561 virg .add_option ("-p" , "--paravirt" , action = "store_true" , dest = "paravirt" ,
56- help = ("This guest should be a paravirtualized guest" ))
62+ help = _ ("This guest should be a paravirtualized guest" ))
5763 opts .add_option_group (virg )
5864
5965 cfgg = OptionGroup (opts , "Guest Configuration Options" )
6066 cfgg .add_option ("-a" , "--arch" , type = "string" , dest = "arch" ,
6167 default = util .get_default_arch (),
62- help = ("Machine Architecture Type (i686/x86_64/ppc)" ))
68+ help = _ ("Machine Architecture Type (i686/x86_64/ppc)" ))
6369 cfgg .add_option ("" , "--os-type" , type = "string" , dest = "os_type" ,
6470 action = "callback" , callback = cli .check_before_store ,
65- help = ("The OS type for fully virtualized guests, e.g. "
66- "'linux', 'unix', 'windows'" ))
71+ help = _ ("The OS type for fully virtualized guests, e.g. "
72+ "'linux', 'unix', 'windows'" ))
6773 cfgg .add_option ("" , "--os-variant" , type = "string" , dest = "os_variant" ,
6874 action = "callback" , callback = cli .check_before_store ,
69- help = ("The OS variant for fully virtualized guests, e.g. "
70- "'fedora6', 'rhel5', 'solaris10', 'win2k', 'vista'" ))
75+ help = _ ("The OS variant for fully virtualized guests, e.g. "
76+ "'fedora6', 'rhel5', 'solaris10', 'win2k', 'vista'" ))
7177 cfgg .add_option ("" , "--noapic" , action = "store_true" , dest = "noapic" ,
72- help = ("Disables APIC for fully virtualized guest "
73- "(overrides value in os-type/os-variant db)" ),
78+ help = _ ("Disables APIC for fully virtualized guest "
79+ "(overrides value in os-type/os-variant db)" ),
7480 default = False )
7581 cfgg .add_option ("" , "--noacpi" , action = "store_true" , dest = "noacpi" ,
76- help = ("Disables ACPI for fully virtualized guest "
77- "(overrides value in os-type/os-variant db)" ),
82+ help = _ ("Disables ACPI for fully virtualized guest "
83+ "(overrides value in os-type/os-variant db)" ),
7884 default = False )
7985 opts .add_option_group (cfgg )
8086
8187 misc = OptionGroup (opts , "Miscellaneous Options" )
8288 misc .add_option ("-q" , "--quiet" , action = "store_true" , dest = "quiet" ,
83- help = ("Don't be verbose" ))
89+ help = _ ("Don't be verbose" ))
8490 misc .add_option ("-d" , "--debug" , action = "store_true" , dest = "debug" ,
85- help = ("Print debugging information" ))
91+ help = _ ("Print debugging information" ))
8692 opts .add_option_group (misc )
8793
8894
8995 (options , args ) = opts .parse_args ()
9096 if len (args ) < 1 :
91- opts .error (("You need to provide an input VM definition" ))
97+ opts .error (_ ("You need to provide an input VM definition" ))
9298 if len (args ) > 2 :
93- opts .error (("Too many arguments provided" ))
94-
99+ opts .error (_ ("Too many arguments provided" ))
100+
95101 if (options .disk_format and
96102 options .disk_format not in diskcfg .disk_formats ()):
97- opts .error ("Unknown output disk format \" %s\" " % options .disk_format )
103+ opts .error (_ ( "Unknown output disk format \" %s\" " ) % options .disk_format )
98104
99105 if len (args ) == 1 :
100106 options .output_file = None
@@ -109,28 +115,28 @@ def parse_args():
109115 options .output_dir = os .path .dirname (os .path .realpath (args [1 ]))
110116
111117 if options .output_format not in formats .formats ():
112- opts .error (("Unknown output format \" %s\" " % options .output_format ))
118+ opts .error (_ ("Unknown output format \" %s\" ) " % options .output_format ))
113119 if options .output_format not in formats .output_formats ():
114- opts .error (("No output handler for format \" %s\" "
120+ opts .error (_ ("No output handler for format \" %s\" ) "
115121 % options .output_format ))
116122
117123 if not os .access (args [0 ], os .R_OK ):
118- opts .error ("Couldn't access input argument \" %s\" \n " % args [0 ])
124+ opts .error (_ ( "Couldn't access input argument \" %s\" \n " ) % args [0 ])
119125 sys .exit (1 )
120126
121127 if not options .input_format :
122128 try :
123129 (args [0 ], options .input_format ) = formats .find_input (args [0 ])
124130 except StandardError , e :
125- opts .error ("Couldn't determine input format for \" %s\" : %s" %
131+ opts .error (_ ( "Couldn't determine input format for \" %s\" : %s" ) %
126132 (args [0 ], e ))
127133 sys .exit (1 )
128134
129135 if options .input_format not in formats .formats ():
130- opts .error (("Unknown input format \" %s\" " % options .input_format ))
136+ opts .error (_ ("Unknown input format \" %s\" ) " % options .input_format ))
131137 if options .input_format not in formats .input_formats ():
132- opts .error (("No input handler for format \" %s\" "
133- % options .input_format ))
138+ opts .error (_ ("No input handler for format \" %s\" " )
139+ % options .input_format )
134140
135141 if os .path .isdir (args [0 ]):
136142 (options .input_file , ignore ) = formats .find_input (args [0 ],
@@ -164,8 +170,8 @@ def cleanup(msg, options, vmdef, paths):
164170 elif os .path .isfile (path ):
165171 os .remove (path )
166172 except OSError , e :
167- fail ("Couldn't clean up output directory \" %s\" : %s" %
168- (options .output_dir , e .strerror ))
173+ fail (_ ( "Couldn't clean up output directory \" %s\" : %s" ) %
174+ (options .output_dir , e .strerror ))
169175
170176 sys .exit (1 )
171177
@@ -181,10 +187,10 @@ def main():
181187 try :
182188 vmdef = inp .import_file (options .input_file )
183189 except IOError , e :
184- fail ("Couldn't import file \" %s\" : %s" %
190+ fail (_ ( "Couldn't import file \" %s\" : %s" ) %
185191 (options .input_file , e .strerror ))
186192 except Exception , e :
187- fail ("Couldn't import file \" %s\" : %s" % (options .input_file , e ))
193+ fail (_ ( "Couldn't import file \" %s\" : %s" ) % (options .input_file , e ))
188194
189195 if options .paravirt :
190196 vmdef .type = vmcfg .VM_TYPE_PV
@@ -221,8 +227,8 @@ def main():
221227 logging .debug ("output_file: %s" % options .output_file )
222228 logging .debug ("output_dir: %s" % options .input_dir )
223229
224- verbose (options , "Generating output in \" %s \" format to %s/" %
225- ( options .output_format , options .output_dir ) )
230+ verbose (options , _ ( "Generating output in '%(format)s' format to %(dir) s/" ) %
231+ { "format" : options .output_format , "dir" : options .output_dir } )
226232
227233
228234 try :
@@ -240,34 +246,35 @@ def main():
240246 format = "raw"
241247
242248 if d .path and format != "none" :
243- verbose (options , "Converting disk \" %s\" to type %s..." %
244- (d .path , format ))
249+ verbose (options , _ ("Converting disk '%(path)s' to type "
250+ "%(format)s..." ) % {"path" : d .path ,
251+ "format" : format })
245252
246253 d .convert (options .input_dir , options .output_dir , format )
247254
248255 except OSError , e :
249- cleanup ("Couldn't convert disks: %s" % e .strerror ,
256+ cleanup (_ ( "Couldn't convert disks: %s" ) % e .strerror ,
250257 options , vmdef , clean )
251258 except RuntimeError , e :
252- cleanup ("Couldn't convert disks: %s" % e , options , vmdef , clean )
259+ cleanup (_ ( "Couldn't convert disks: %s" ) % e , options , vmdef , clean )
253260
254261 try :
255262 clean += [ options .output_file ]
256263 outp .export_file (vmdef , options .output_file )
257264 except ValueError , e :
258- cleanup ("Couldn't export to file \" %s\" : %s" %
265+ cleanup (_ ( "Couldn't export to file \" %s\" : %s" ) %
259266 (options .output_file , e ), options , vmdef , clean )
260267
261268 verbose (options , "Done." )
262269
263-
270+
264271if __name__ == "__main__" :
265272 try :
266273 main ()
267274 except SystemExit , sys_e :
268275 sys .exit (sys_e .code )
269276 except KeyboardInterrupt :
270- print >> sys .stderr , "Aborted at user request"
277+ print >> sys .stderr , _ ( "Aborted at user request" )
271278 except Exception , main_e :
272279 logging .exception (main_e )
273280 sys .exit (1 )
0 commit comments