1 # -*- coding: utf-8 -*-
3 # Copyright 2012 GRNET S.A. All rights reserved.
5 # Redistribution and use in source and binary forms, with or
6 # without modification, are permitted provided that the following
9 # 1. Redistributions of source code must retain the above
10 # copyright notice, this list of conditions and the following
13 # 2. Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials
16 # provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
31 # The views and conclusions contained in the software and
32 # documentation are those of the authors and should not be
33 # interpreted as representing official policies, either expressed
34 # or implied, of GRNET S.A.
36 """This module implements the "expert" mode of the dialog-based version of
45 from image_creator import __version__ as version
46 from image_creator.util import MD5, FatalError
47 from image_creator.output.dialog import GaugeOutput, InfoBoxOutput
48 from image_creator.kamaki_wrapper import Kamaki, ClientError
49 from image_creator.help import get_help_file
50 from image_creator.dialog_util import SMALL_WIDTH, WIDTH, \
51 update_background_title, confirm_reset, confirm_exit, Reset, \
52 extract_image, extract_metadata_string, add_cloud, edit_cloud
54 CONFIGURATION_TASKS = [
55 ("Partition table manipulation", ["FixPartitionTable"],
56 ["linux", "windows"]),
57 ("File system resize",
58 ["FilesystemResizeUnmounted", "FilesystemResizeMounted"],
59 ["linux", "windows"]),
60 ("Swap partition configuration", ["AddSwap"], ["linux"]),
61 ("SSH keys removal", ["DeleteSSHKeys"], ["linux"]),
62 ("Temporal RDP disabling", ["DisableRemoteDesktopConnections"],
64 ("SELinux relabeling at next boot", ["SELinuxAutorelabel"], ["linux"]),
65 ("Hostname/Computer Name assignment", ["AssignHostname"],
66 ["windows", "linux"]),
67 ("Password change", ["ChangePassword"], ["windows", "linux"]),
68 ("File injection", ["EnforcePersonality"], ["windows", "linux"])
71 SYSPREP_PARAM_MAXLEN = 20
73 class MetadataMonitor(object):
74 """Monitors image metadata chages"""
75 def __init__(self, session, meta):
76 self.session = session
81 for (k, v) in self.meta.items():
84 def __exit__(self, type, value, traceback):
85 d = self.session['dialog']
90 for (k, v) in self.meta.items():
93 elif self.old[k] != v:
96 if not (len(added) or len(altered)):
99 msg = "The last action has changed some image properties:\n\n"
101 msg += "New image properties:\n"
102 for (k, v) in added.items():
103 msg += ' %s: "%s"\n' % (k, v)
106 msg += "Updated image properties:\n"
107 for (k, v) in altered.items():
108 msg += ' %s: "%s" -> "%s"\n' % (k, self.old[k], v)
111 self.session['metadata'].update(added)
112 self.session['metadata'].update(altered)
113 d.msgbox(msg, title="Image Property Changes", width=SMALL_WIDTH)
116 def upload_image(session):
117 """Upload the image to the storage service"""
118 d = session["dialog"]
119 image = session['image']
120 meta = session['metadata']
123 if "account" not in session:
124 d.msgbox("You need to select a valid cloud before you can upload "
125 "images to it", width=SMALL_WIDTH)
129 if 'upload' in session:
130 init = session['upload']
132 init = "%s.diskdump" % meta['OS']
135 (code, answer) = d.inputbox("Please provide a filename:", init=init,
138 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
141 filename = answer.strip()
142 if len(filename) == 0:
143 d.msgbox("Filename cannot be empty", width=SMALL_WIDTH)
146 kamaki = Kamaki(session['account'], None)
148 for f in (filename, "%s.md5sum" % filename, "%s.meta" % filename):
149 if kamaki.object_exists(f):
152 if len(overwrite) > 0:
153 if d.yesno("The following storage service object(s) already "
154 "exist(s):\n%s\nDo you want to overwrite them?" %
155 "\n".join(overwrite), width=WIDTH, defaultno=1):
158 session['upload'] = filename
161 gauge = GaugeOutput(d, "Image Upload", "Uploading ...")
167 if 'checksum' not in session:
169 session['checksum'] = md5.compute(image.device, size)
173 with open(image.device, 'rb') as f:
174 session["pithos_uri"] = \
175 kamaki.upload(f, size, filename,
176 "Calculating block hashes",
177 "Uploading missing blocks")
179 out.output("Uploading md5sum file ...")
180 md5str = "%s %s\n" % (session['checksum'], filename)
181 kamaki.upload(StringIO.StringIO(md5str), size=len(md5str),
182 remote_path="%s.md5sum" % filename)
185 except ClientError as e:
187 "Error in storage service client: %s" % e.message,
188 title="Storage Service Client Error", width=SMALL_WIDTH)
189 if 'pithos_uri' in session:
190 del session['pithos_uri']
197 d.msgbox("Image file `%s' was successfully uploaded" % filename,
203 def register_image(session):
204 """Register image with the compute service"""
205 d = session["dialog"]
209 if "account" not in session:
210 d.msgbox("You need to select a valid cloud before you "
211 "can register an images with it", width=SMALL_WIDTH)
214 if "pithos_uri" not in session:
215 d.msgbox("You need to upload the image to the cloud before you can "
216 "register it", width=SMALL_WIDTH)
220 (code, answer) = d.inputbox("Please provide a registration name:",
222 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
225 name = answer.strip()
227 d.msgbox("Registration name cannot be empty", width=SMALL_WIDTH)
230 ret = d.yesno("Make the image public?\\nA public image is accessible "
231 "by every user of the service.", defaultno=1,
233 if ret not in (0, 1):
236 is_public = True if ret == 0 else False
241 metadata.update(session['metadata'])
242 if 'task_metadata' in session:
243 for key in session['task_metadata']:
244 metadata[key] = 'yes'
246 img_type = "public" if is_public else "private"
247 gauge = GaugeOutput(d, "Image Registration", "Registering image ...")
249 out = session['image'].out
253 out.output("Registering %s image with the cloud ..." %
255 kamaki = Kamaki(session['account'], out)
256 result = kamaki.register(name, session['pithos_uri'], metadata,
259 # Upload metadata file
260 out.output("Uploading metadata file ...")
261 metastring = unicode(json.dumps(result, ensure_ascii=False))
262 kamaki.upload(StringIO.StringIO(metastring),
263 size=len(metastring),
264 remote_path="%s.meta" % session['upload'])
267 out.output("Sharing metadata and md5sum files ...")
268 kamaki.share("%s.meta" % session['upload'])
269 kamaki.share("%s.md5sum" % session['upload'])
271 except ClientError as e:
272 d.msgbox("Error in storage service client: %s" % e.message)
279 d.msgbox("%s image `%s' was successfully registered with the cloud as `%s'"
280 % (img_type.title(), session['upload'], name), width=SMALL_WIDTH)
284 def modify_clouds(session):
285 """Modify existing cloud accounts"""
286 d = session['dialog']
289 clouds = Kamaki.get_clouds()
291 if not add_cloud(session):
296 for (name, cloud) in clouds.items():
297 descr = cloud['description'] if 'description' in cloud else ''
298 choices.append((name, descr))
300 (code, choice) = d.menu(
301 "In this menu you can edit existing cloud accounts or add new "
302 " ones. Press <Edit> to edit an existing account or <Add> to add "
303 " a new one. Press <Back> or hit <ESC> when done.", height=18,
304 width=WIDTH, choices=choices, menu_height=10, ok_label="Edit",
305 extra_button=1, extra_label="Add", cancel="Back", help_button=1,
308 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
310 elif code == d.DIALOG_OK: # Edit button
311 edit_cloud(session, choice)
312 elif code == d.DIALOG_EXTRA: # Add button
316 def delete_clouds(session):
317 """Delete existing cloud accounts"""
318 d = session['dialog']
321 for (name, cloud) in Kamaki.get_clouds().items():
322 descr = cloud['description'] if 'description' in cloud else ''
323 choices.append((name, descr, 0))
325 if len(choices) == 0:
326 d.msgbox("No available clouds to delete!", width=SMALL_WIDTH)
329 (code, to_delete) = d.checklist("Choose which cloud accounts to delete:",
330 choices=choices, width=WIDTH)
331 to_delete = map(lambda x: x.strip('"'), to_delete) # Needed for OpenSUSE
333 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
336 if not len(to_delete):
337 d.msgbox("Nothing selected!", width=SMALL_WIDTH)
340 if not d.yesno("Are you sure you want to remove the selected cloud "
341 "accounts?", width=WIDTH, defaultno=1):
343 Kamaki.remove_cloud(i)
344 if 'cloud' in session and session['cloud'] == i:
346 if 'account' in session:
347 del session['account']
351 d.msgbox("%d cloud accounts were deleted." % len(to_delete),
356 def kamaki_menu(session):
357 """Show kamaki related actions"""
358 d = session['dialog']
359 default_item = "Cloud"
361 if 'cloud' not in session:
362 cloud = Kamaki.get_default_cloud_name()
364 session['cloud'] = cloud
365 session['account'] = Kamaki.get_account(cloud)
366 if not session['account']:
367 del session['account']
369 default_item = "Add/Edit"
372 cloud = session["cloud"] if "cloud" in session else "<none>"
373 if 'account' not in session and 'cloud' in session:
374 cloud += " <invalid>"
376 upload = session["upload"] if "upload" in session else "<none>"
378 choices = [("Add/Edit", "Add/Edit cloud accounts"),
379 ("Delete", "Delete existing cloud accounts"),
380 ("Cloud", "Select cloud account to use: %s" % cloud),
381 ("Upload", "Upload image to the cloud"),
382 ("Register", "Register image with the cloud: %s" % upload)]
384 (code, choice) = d.menu(
385 text="Choose one of the following or press <Back> to go back.",
386 width=WIDTH, choices=choices, cancel="Back", height=13,
387 menu_height=5, default_item=default_item,
388 title="Image Registration Menu")
390 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
393 if choice == "Add/Edit":
394 if modify_clouds(session):
395 default_item = "Cloud"
396 elif choice == "Delete":
397 if delete_clouds(session):
398 if len(Kamaki.get_clouds()):
399 default_item = "Cloud"
401 default_item = "Add/Edit"
403 default_item = "Delete"
404 elif choice == "Cloud":
405 default_item = "Cloud"
406 clouds = Kamaki.get_clouds()
408 d.msgbox("No clouds available. Please add a new cloud!",
410 default_item = "Add/Edit"
413 if 'cloud' not in session:
414 session['cloud'] = clouds.keys()[0]
417 for name, info in clouds.items():
418 default = 1 if session['cloud'] == name else 0
419 descr = info['description'] if 'description' in info else ""
420 choices.append((name, descr, default))
422 (code, answer) = d.radiolist("Please select a cloud:",
423 width=WIDTH, choices=choices)
424 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
427 session['account'] = Kamaki.get_account(answer)
429 if session['account'] is None: # invalid account
430 if not d.yesno("The cloud %s' is not valid! Would you "
431 "like to edit it?" % answer, width=WIDTH):
432 if edit_cloud(session, answer):
433 session['account'] = Kamaki.get_account(answer)
434 Kamaki.set_default_cloud(answer)
436 if session['account'] is not None:
437 session['cloud'] = answer
438 Kamaki.set_default_cloud(answer)
439 default_item = "Upload"
441 del session['account']
443 elif choice == "Upload":
444 if upload_image(session):
445 default_item = "Register"
447 default_item = "Upload"
448 elif choice == "Register":
449 if register_image(session):
452 default_item = "Register"
455 def add_property(session):
456 """Add a new property to the image"""
457 d = session['dialog']
460 (code, answer) = d.inputbox("Please provide a name for a new image"
461 " property:", width=WIDTH)
462 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
465 name = answer.strip()
467 d.msgbox("A property name cannot be empty", width=SMALL_WIDTH)
473 (code, answer) = d.inputbox("Please provide a value for image "
474 "property %s" % name, width=WIDTH)
475 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
478 value = answer.strip()
480 d.msgbox("Value cannot be empty", width=SMALL_WIDTH)
485 session['metadata'][name] = value
490 def modify_properties(session):
491 """Modify an existing image property"""
492 d = session['dialog']
496 for (key, val) in session['metadata'].items():
497 choices.append((str(key), str(val)))
499 (code, choice) = d.menu(
500 "In this menu you can edit existing image properties or add new "
501 "ones. Be careful! Most properties have special meaning and "
502 "alter the image deployment behaviour. Press <HELP> to see more "
503 "information about image properties. Press <BACK> when done.",
504 height=18, width=WIDTH, choices=choices, menu_height=10,
505 ok_label="Edit", extra_button=1, extra_label="Add", cancel="Back",
506 help_button=1, title="Image Properties")
508 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
511 elif code == d.DIALOG_OK:
512 (code, answer) = d.inputbox("Please provide a new value for the "
513 "image property with name `%s':" %
515 init=session['metadata'][choice],
517 if code not in (d.DIALOG_CANCEL, d.DIALOG_ESC):
518 value = answer.strip()
520 d.msgbox("Value cannot be empty!")
523 session['metadata'][choice] = value
525 elif code == d.DIALOG_EXTRA:
526 add_property(session)
528 help_file = get_help_file("image_properties")
529 assert os.path.exists(help_file)
530 d.textbox(help_file, title="Image Properties", width=70, height=40)
533 def delete_properties(session):
534 """Delete an image property"""
535 d = session['dialog']
538 for (key, val) in session['metadata'].items():
539 choices.append((key, "%s" % val, 0))
541 (code, to_delete) = d.checklist("Choose which properties to delete:",
542 choices=choices, width=WIDTH)
543 to_delete = map(lambda x: x.strip('"'), to_delete) # needed for OpenSUSE
545 # If the user exits with ESC or CANCEL, the returned tag list is empty.
547 del session['metadata'][i]
551 d.msgbox("%d image properties were deleted." % cnt, width=SMALL_WIDTH)
557 def exclude_tasks(session):
558 """Exclude specific tasks from running during image deployment"""
559 d = session['dialog']
565 if 'excluded_tasks' not in session:
566 session['excluded_tasks'] = []
568 if -1 in session['excluded_tasks']:
569 if not d.yesno("Image deployment configuration is disabled. "
570 "Do you wish to enable it?", width=SMALL_WIDTH):
571 session['excluded_tasks'].remove(-1)
575 for (msg, task, osfamily) in CONFIGURATION_TASKS:
576 if session['metadata']['OSFAMILY'] in osfamily:
577 checked = 1 if index in session['excluded_tasks'] else 0
578 choices.append((str(displayed_index), msg, checked))
579 mapping[displayed_index] = index
584 (code, tags) = d.checklist(
585 text="Please choose which configuration tasks you would like to "
586 "prevent from running during image deployment. "
587 "Press <No Config> to supress any configuration. "
588 "Press <Help> for more help on the image deployment "
589 "configuration tasks.",
590 choices=choices, height=19, list_height=8, width=WIDTH,
591 help_button=1, extra_button=1, extra_label="No Config",
592 title="Exclude Configuration Tasks")
593 tags = map(lambda x: x.strip('"'), tags) # Needed for OpenSUSE
595 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
597 elif code == d.DIALOG_HELP:
598 help_file = get_help_file("configuration_tasks")
599 assert os.path.exists(help_file)
600 d.textbox(help_file, title="Configuration Tasks",
603 elif code == d.DIALOG_EXTRA:
604 session['excluded_tasks'] = [-1]
605 session['task_metadata'] = ["EXCLUDE_ALL_TASKS"]
607 elif code == d.DIALOG_OK:
608 session['excluded_tasks'] = []
610 session['excluded_tasks'].append(mapping[int(tag)])
612 exclude_metadata = []
613 for task in session['excluded_tasks']:
614 exclude_metadata.extend(CONFIGURATION_TASKS[task][1])
616 session['task_metadata'] = map(lambda x: "EXCLUDE_TASK_%s" % x,
623 def sysprep_params(session):
624 """Collect the needed sysprep parameters"""
625 d = session['dialog']
626 image = session['image']
628 available = image.os.sysprep_params
629 needed = image.os.needed_sysprep_params
630 names = needed.keys()
638 default = available[name] if name in available else ""
639 fields.append(("%s: " % param.description, default,
640 SYSPREP_PARAM_MAXLEN))
642 txt = "Please provide the following system preparation parameters:"
643 code, output = d.form(txt, height=13, width=WIDTH, form_height=len(fields),
646 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
649 for i in range(len(fields)):
650 param = needed[names[i]]
651 if param.validator(output[i]):
652 image.os.sysprep_params[names[i]] = output[i]
654 d.msgbox("The value you provided for parameter: %s is not valid" %
655 names[i], width=SMALL_WIDTH)
661 def sysprep(session):
662 """Perform various system preperation tasks on the image"""
663 d = session['dialog']
664 image = session['image']
666 # Is the image already shrinked?
667 if 'shrinked' in session and session['shrinked']:
668 msg = "It seems you have shrinked the image. Running system " \
669 "preparation tasks on a shrinked image is dangerous."
671 if d.yesno("%s\n\nDo you really want to continue?" % msg,
672 width=SMALL_WIDTH, defaultno=1):
675 wrapper = textwrap.TextWrapper(width=WIDTH - 5)
677 syspreps = image.os.list_syspreps()
679 if len(syspreps) == 0:
680 d.msgbox("No system preparation task available to run!",
681 title="System Preperation", width=SMALL_WIDTH)
688 help_title = "System Preperation Tasks"
689 sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))
691 for sysprep in syspreps:
692 name, descr = image.os.sysprep_info(sysprep)
693 display_name = name.replace('-', ' ').capitalize()
694 sysprep_help += "%s\n" % display_name
695 sysprep_help += "%s\n" % ('-' * len(display_name))
696 sysprep_help += "%s\n\n" % wrapper.fill(" ".join(descr.split()))
697 enabled = 1 if sysprep.enabled else 0
698 choices.append((str(index + 1), display_name, enabled))
701 (code, tags) = d.checklist(
702 "Please choose which system preparation tasks you would like to "
703 "run on the image. Press <Help> to see details about the system "
704 "preparation tasks.", title="Run system preparation tasks",
705 choices=choices, width=70, ok_label="Run", help_button=1)
706 tags = map(lambda x: x.strip('"'), tags) # Needed for OpenSUSE
708 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
710 elif code == d.DIALOG_HELP:
711 d.scrollbox(sysprep_help, width=WIDTH)
712 elif code == d.DIALOG_OK:
713 # Enable selected syspreps and disable the rest
714 for i in range(len(syspreps)):
715 if str(i + 1) in tags:
716 image.os.enable_sysprep(syspreps[i])
718 image.os.disable_sysprep(syspreps[i])
720 if len([s for s in image.os.list_syspreps() if s.enabled]) == 0:
721 d.msgbox("No system preperation task is selected!",
722 title="System Preperation", width=SMALL_WIDTH)
725 if not sysprep_params(session):
728 infobox = InfoBoxOutput(d, "Image Configuration")
730 image.out.add(infobox)
732 # The checksum is invalid. We have mounted the image rw
733 if 'checksum' in session:
734 del session['checksum']
736 # Monitor the metadata changes during syspreps
737 with MetadataMonitor(session, image.os.meta):
739 image.os.do_sysprep()
741 except FatalError as e:
742 title = "System Preparation"
743 d.msgbox("System Preparation failed: %s" % e,
744 title=title, width=SMALL_WIDTH)
746 image.out.remove(infobox)
754 """Shrink the image"""
755 d = session['dialog']
756 image = session['image']
758 shrinked = 'shrinked' in session and session['shrinked']
761 d.msgbox("The image is already shrinked!", title="Image Shrinking",
765 msg = "This operation will shrink the last partition of the image to " \
766 "reduce the total image size. If the last partition is a swap " \
767 "partition, then this partition is removed and the partition " \
768 "before that is shrinked. The removed swap partition will be " \
769 "recreated during image deployment."
771 if not d.yesno("%s\n\nDo you want to continue?" % msg, width=WIDTH,
772 height=12, title="Image Shrinking"):
773 with MetadataMonitor(session, image.meta):
774 infobox = InfoBoxOutput(d, "Image Shrinking", height=4)
775 image.out.add(infobox)
780 image.out.remove(infobox)
782 session['shrinked'] = True
783 update_background_title(session)
790 def customization_menu(session):
791 """Show image customization menu"""
792 d = session['dialog']
794 choices = [("Sysprep", "Run various image preparation tasks"),
795 ("Shrink", "Shrink image"),
796 ("View/Modify", "View/Modify image properties"),
797 ("Delete", "Delete image properties"),
798 ("Exclude", "Exclude various deployment tasks from running")]
802 actions = {"Sysprep": sysprep,
804 "View/Modify": modify_properties,
805 "Delete": delete_properties,
806 "Exclude": exclude_tasks}
808 (code, choice) = d.menu(
809 text="Choose one of the following or press <Back> to exit.",
810 width=WIDTH, choices=choices, cancel="Back", height=13,
811 menu_height=len(choices), default_item=choices[default_item][0],
812 title="Image Customization Menu")
814 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
816 elif choice in actions:
817 default_item = [entry[0] for entry in choices].index(choice)
818 if actions[choice](session):
819 default_item = (default_item + 1) % len(choices)
822 def main_menu(session):
823 """Show the main menu of the program"""
824 d = session['dialog']
826 update_background_title(session)
828 choices = [("Customize", "Customize image & cloud deployment options"),
829 ("Register", "Register image to a cloud"),
830 ("Extract", "Dump image to local file system"),
831 ("Reset", "Reset everything and start over again"),
832 ("Help", "Get help for using snf-image-creator")]
834 default_item = "Customize"
836 actions = {"Customize": customization_menu, "Register": kamaki_menu,
837 "Extract": extract_image}
839 (code, choice) = d.menu(
840 text="Choose one of the following or press <Exit> to exit.",
841 width=WIDTH, choices=choices, cancel="Exit", height=13,
842 default_item=default_item, menu_height=len(choices),
843 title="Image Creator for synnefo (snf-image-creator version %s)" %
846 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
849 elif choice == "Reset":
851 d.infobox("Resetting snf-image-creator. Please wait ...",
854 elif choice == "Help":
855 d.msgbox("For help, check the online documentation:\n\nhttp://www"
856 ".synnefo.org/docs/snf-image-creator/latest/",
857 width=WIDTH, title="Help")
858 elif choice in actions:
859 actions[choice](session)
861 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :