home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / root / usr / share / YaST2 / clients / inst_evms.ycp < prev    next >
Text File  |  2006-11-29  |  9KB  |  353 lines

  1. /**
  2.  * File:
  3.  *   inst_evms.ycp
  4.  *
  5.  * Module:
  6.  *   evms
  7.  *
  8.  * Summary:
  9.  *
  10.  * Authors:
  11.  *   Thomas Fehr <fehr@suse.de>
  12.  *
  13.  *
  14.  *
  15.  * $Id: inst_evms.ycp 33372 2006-10-12 16:13:30Z fehr $
  16.  *
  17.  */
  18.  
  19. {
  20.  
  21.     textdomain "storage"; 
  22.  
  23.     import "Installation";
  24.     import "Mode";
  25.     import "Storage";
  26.     import "Wizard";
  27.     import "Label";
  28.     
  29.     include "partitioning/partition_defines.ycp";
  30.     include "partitioning/custom_part_dialogs.ycp";
  31.     include "partitioning/custom_part_lib.ycp";
  32.     include "partitioning/custom_part_check_generated.ycp";
  33.     include "partitioning/evms_lib.ycp";
  34.  
  35.     map<string,map> targetMap    = Storage::GetTargetMap();
  36.     string no_container = "-none-";
  37.     boolean changed = false;
  38.  
  39.     Storage::CreateTargetBackup("evms");
  40.  
  41.     y2milestone( "evms:%1", targetMap["/dev/evms","partitions"]:[] );
  42.     y2milestone( "evms co:%1", size(filter(string k, map e, targetMap,
  43.                     ``(e["is_container"]:false))));
  44.  
  45.     if( size(targetMap["/dev/evms","partitions"]:[])==0 )
  46.     {
  47.     Storage::ActivateEvms();
  48.     targetMap = Storage::GetTargetMap();
  49.     y2milestone( "evms:%1", targetMap["/dev/evms","partitions"]:[] );
  50.     y2milestone( "evms co:%1", size(filter(string k, map e, targetMap,
  51.                     ``(e["is_container"]:false))));
  52.     }
  53.     foreach( string k, map e, targetMap,
  54.     ``{
  55.     if( e["type"]:`CT_UNKNOWN==`CT_LVM && 
  56.         find( map p, e["partitions"]:[], ``(p["mount"]:""=="swap"))!=nil )
  57.         {
  58.         changed = true;
  59.         y2milestone( "k %1", k );
  60.         targetMap[k,"partitions"] = 
  61.         maplist( map p, e["partitions"]:[],
  62.             ``{
  63.             if( p["mount"]:""=="swap" )
  64.             p["mount"] = "";
  65.             return( p );
  66.             });
  67.         y2milestone( "k part %1", targetMap[k,"partitions"]:[] );
  68.         }
  69.     });
  70.     foreach( string k, map e, targetMap,
  71.     ``{
  72.     if( changed && e["type"]:`CT_UNKNOWN==`CT_EVMS && 
  73.         e["is_container"]:false )
  74.         {
  75.         y2milestone( "k %1", k );
  76.         targetMap[k,"partitions"] = 
  77.         maplist( map p, e["partitions"]:[],
  78.             ``{
  79.             if( Stage::initial() && p["detected_fs"]:`unknown==`swap )
  80.             {
  81.             p["mount"] = "swap";
  82.             }
  83.             return( p );
  84.             });
  85.         y2milestone( "k part %1", targetMap[k,"partitions"]:[] );
  86.         }
  87.     });
  88.     if( changed )
  89.     Storage::SetTargetMap( targetMap );
  90.     
  91.     list evms_cont = get_containers( targetMap, no_container );
  92.     list table = [];
  93.  
  94.     string  current_co = evms_cont[0]:"";
  95.  
  96.     term dlg = 
  97.     `HBox( 
  98.         `HSpacing(2.5),
  99.         `VBox(
  100.         `VSpacing(0.1),
  101.         `VWeight( 20, 
  102.             `HBox(
  103.             `VBox( 
  104.                 get_bargraph_if_possible(),
  105.                 `HBox(
  106.                 `Left(`ReplacePoint(
  107.                       `id(`rcont), 
  108.                       `ComboBox(`id(`cont), `opt(`notify),
  109.                             // button text
  110.                             _("EVMS &Container"), 
  111.                             [] ))),
  112.                 `HSpacing(2),
  113.                        // label text
  114.                 `VBox( `Left(`Label(_("Size"))),
  115.                     // label text
  116.                        `Left(`Label(_("Available")))),
  117.                 `VBox( `Left(`Label( `id(`co_size),
  118.                              `opt(`hstretch, 
  119.                                   `outputField), 
  120.                              "" )),
  121.                        `Left(`Label( `id(`co_free),
  122.                              `opt(`hstretch, 
  123.                                   `outputField), 
  124.                              "" )))
  125.                 )
  126.                 ),
  127.             `HWeight(1,`HStretch()),
  128.             `HSpacing(2),
  129.             `VCenter(`Right(
  130.                 `VBox(
  131.                 `PushButton( `id(`add_container),
  132.                          `opt(`hstretch),
  133.                          // button text
  134.                          _("C&reate Container")),
  135.                 `PushButton( `id(`edit_container),
  136.                          `opt(`hstretch),
  137.                          // button text
  138.                          _("&Edit Container")),
  139.                 `PushButton( `id(`remove_container),
  140.                          `opt(`hstretch),
  141.                          // button text
  142.                          _("&Remove Container"))
  143.                  )))
  144.             )
  145.             ),
  146.         `VSpacing(1),
  147.         `VWeight( 50, 
  148.             `VBox(
  149.             `Table( `id(`evms_table), `opt(`notify),
  150.                 // table header text
  151.                 `header(_("Device"), `Right(_(" Size")), 
  152.                         `Center(_("Format")), _(" Mount"), 
  153.                     `Center(_("Type"))), [] ),
  154.             `VSpacing(0.2),
  155.             // button text
  156.             `HBox( `PushButton(`id(`evms_add), _("A&dd")),
  157.                    // button text
  158.                    `PushButton(`id(`evms_edit), _("&Edit")),
  159.                    // button text
  160.                    `PushButton(`id(`evms_delete), _("&Remove"))
  161.                    // button text
  162.                    //`PushButton(`id(`evms_convert), _("C&onvert"))
  163.                  ),
  164.             `VSpacing(0.5)
  165.             )
  166.             )
  167.         ),
  168.         `HSpacing(2)
  169.         );
  170.  
  171.     // heading text
  172.     Wizard::SetContents( _("EVMS Configuration"), dlg, "", true, true);
  173.     Wizard::SetHelpText( getEvmsHelptext() );
  174.  
  175.     // Display current container:
  176.     new_co_list( evms_cont );
  177.     UI::ChangeWidget( `id(`cont), `Value, current_co );
  178.     map co = get_co_map( current_co, targetMap );
  179.     y2milestone( "current_co:%1 co:%2", current_co, co );
  180.     new_co_size( co );
  181.     
  182.     
  183.     //////////////////////////////////////////////////////////////////////
  184.     // mainloop
  185.     //////////////////////////////////////////////////////////////////////
  186.  
  187.     string id  =  "";
  188.     symbol ret = `next;
  189.     changed = false;
  190.     repeat
  191.     {
  192.     /////////////////////////////////////////////////////////////////
  193.     // Show the current state:
  194.     table = get_evms_volumes( targetMap );
  195.     UI::ChangeWidget( `id(`evms_table), `Items, table);
  196.  
  197.         UI::SetFocus(`id(`evms_table));
  198.  
  199.     if( id!=nil && id != "" )
  200.         {
  201.         UI::ChangeWidget( `id(`evms_table), `CurrentItem, id);
  202.         }
  203.  
  204.         /////////////////////////////////////////////////////////////////
  205.         // Wait for User input
  206.  
  207.     ret = (symbol)Wizard::UserInput();
  208.  
  209.     ////////////////////////////////////////
  210.     // user has changed the current volume group
  211.     ////////////////////////////////////////
  212.     
  213.     if( ret == `cont )
  214.         {
  215.         current_co = (string)UI::QueryWidget( `id(`cont), `Value);
  216.         y2milestone("TTT %1", current_co );
  217.         co = get_co_map( current_co, targetMap );
  218.         new_co_size( co );
  219.         }
  220.  
  221.         ////////////////////////////////////////
  222.         // Add a new container:
  223.         ////////////////////////////////////////
  224.  
  225.         if( ret == `add_container )
  226.         {
  227.             map ad = add_evms_container( targetMap );
  228.         targetMap = Storage::GetTargetMap();
  229.             // has the user cancelled the dialog?
  230.             if( ad["ok"]:false )
  231.         {
  232.         changed = true;
  233.         evms_cont = get_containers( targetMap, no_container );
  234.         new_co_list( evms_cont );
  235.         current_co = ad["name"]:"";
  236.         UI::ChangeWidget( `id(`cont), `Value, current_co );
  237.         co = get_co_map( current_co, targetMap );
  238.         new_co_size( co );
  239.         }
  240.         }
  241.     else if( ret == `edit_container && current_co!=no_container )
  242.         {
  243.             map ad = edit_evms_container( targetMap, current_co );
  244.         targetMap = Storage::GetTargetMap();
  245.             // has the user cancelled the dialog?
  246.             if( ad["ok"]:false )
  247.         {
  248.         changed = true;
  249.         evms_cont = get_containers( targetMap, no_container );
  250.         new_co_list( evms_cont );
  251.         current_co = ad["name"]:"";
  252.         UI::ChangeWidget( `id(`cont), `Value, current_co );
  253.         co = get_co_map( current_co, targetMap );
  254.         new_co_size( co );
  255.         }
  256.         }
  257.  
  258.     ////////////////////////////////////////
  259.     // Remove volume group:
  260.     ////////////////////////////////////////
  261.     
  262.     else if( ret == `remove_container && current_co!=no_container )
  263.         {
  264.         map ad = remove_evms_container( targetMap, current_co );
  265.         if( ad["ok"]:false )
  266.         {
  267.         changed = true;
  268.                 targetMap = Storage::GetTargetMap();
  269.         evms_cont = get_containers( targetMap, no_container );
  270.         new_co_list( evms_cont );
  271.         current_co = evms_cont[0]:"";
  272.         UI::ChangeWidget( `id(`cont), `Value, current_co );
  273.         co = get_co_map( current_co, targetMap );
  274.         new_co_size( co );
  275.         }
  276.         }
  277.     else if( ret == `evms_add && current_co != no_container )
  278.         {
  279.             map ad = add_evms_volume( current_co, targetMap );
  280.  
  281.             // has the user cancelled the dialog?
  282.             if( ad["ok"]:false )
  283.         {
  284.                 targetMap = Storage::GetTargetMap();
  285.         co = get_co_map( current_co, targetMap );
  286.         changed = true;
  287.         new_co_size( co );
  288.         }
  289.         }
  290.     else if( ret == `evms_edit )
  291.         {
  292.         id = (string)UI::QueryWidget(`id(`evms_table), `CurrentItem);
  293.             map ad = edit_evms_volume( id, targetMap );
  294.  
  295.             // has the user cancelled the dialog?
  296.             if( ad["ok"]:false )
  297.         {
  298.                 targetMap = Storage::GetTargetMap();
  299.         co = get_co_map( current_co, targetMap );
  300.         changed = true;
  301.         new_co_size( co );
  302.         }
  303.         }
  304.     else if( ret == `evms_delete )
  305.         {
  306.         id = (string)UI::QueryWidget(`id(`evms_table), `CurrentItem);
  307.             map ad = delete_evms_volume( id, targetMap );
  308.  
  309.             // has the user cancelled the dialog?
  310.             if( ad["ok"]:false )
  311.         {
  312.                 targetMap = Storage::GetTargetMap();
  313.         co = get_co_map( current_co, targetMap );
  314.         changed = true;
  315.         new_co_size( co );
  316.         id = "";
  317.         }
  318.         }
  319.  
  320.     ////////////////////////////////////////
  321.     // Finish this step
  322.     ////////////////////////////////////////
  323.     
  324.     if( ret == `back || ret == `cancel || ret == `abort )
  325.         {
  326.         if( changed )
  327.         {
  328.         // popup text 
  329.         string txt = _("You have changed the EVMS configuration.
  330. These changes will be lost if you exit the dialog now.
  331. Continue?
  332. ");
  333.         if( !Popup::ContinueCancel( txt ))
  334.             {
  335.             ret = `again;
  336.             }
  337.         else
  338.             {
  339.             Storage::RestoreTargetBackup("evms");
  340.             }
  341.         }
  342.         }
  343.     } 
  344.     until (ret == `next || ret == `back || ret == `cancel || ret == `abort );
  345.     if( !changed )
  346.     Storage::RestoreTargetBackup("evms");
  347.  
  348.     Storage::DisposeTargetBackup("evms");
  349.     return ret;
  350. }
  351.  
  352. // end
  353.