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_extrasources.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
8KB
|
372 lines
/**
* File: clients/inst_extrasources.ycp
* Package: yast2-installation
* Summary: Add extra installation sources from content file
* Authors: Ladislav Slezák <lslezak@suse.cz>
*
* Assumptions:
* - the sources have been initialized
* - the sources will be saved afterwards
* (this means that running this client alone will not work)
*
* $Id$
*/
{
textdomain "installation";
import "GetInstArgs";
import "Popup";
import "SourceManager";
import "Label";
import "Mode";
import "String";
import "Internet";
// editUrl()
include "packager/inst_source_dialogs.ycp";
// the tag providing location of the additional sources in content file
string content_file_tag = "EXTRAURLS";
string optional_tag = "OPTIONALURLS";
/**
* Show a confirmation dialog with list of the extra sources.
* @param urls list of URLs
* @return boolean true if the user wants to register the sources
*/
list<string> ConfirmExtraSources(map<string,boolean> urls)
{
list<term> items = [];
// display the enabled sources at the beginning of the list
foreach(string url, boolean deflt, urls,
{
if (deflt)
{
items = add(items, `item(`id(url), url, deflt));
}
}
);
foreach(string url, boolean deflt, urls,
{
if (!deflt)
{
items = add(items, `item(`id(url), url, deflt));
}
}
);
integer width = 76;
integer height = 8;
term popup = `HBox(
`HSpacing(1),
`VBox(
`VSpacing(0.2),
// heading in a popup window
`Heading(_("Additional Installation Sources")),
`VSpacing(0.2),
`VBox(
`HSpacing(width),
`HBox(
`VSpacing(height),
// label
`MultiSelectionBox(`id(`multi), _("Sources to Register"), items)
)
),
`VSpacing(0.2),
// label - use more lines for the translated message (no more than about 60 characters per line)
`Label(_("Later you can install additional software from these external sources.\nRegister the sources now?")),
`VSpacing(0.5),
`HBox(
`HStretch(),
`PushButton(`id(`yes), `opt(`default, `key_F10), Label::YesButton()),
`HSpacing(2),
`PushButton(`id(`no), `opt(`key_F9), Label::NoButton()),
`HStretch()
),
`VSpacing(0.5)
),
`HSpacing(1)
);
UI::OpenDialog(`opt(`decorated), popup);
symbol ui = (symbol)UI::UserInput();
y2milestone("Extra sources confirmed: %1", ui);
list<string> selected_items = (list<string>) UI::QueryWidget(`id(`multi), `SelectedItems);
y2milestone("Selected items: %1", selected_items);
UI::CloseDialog();
return (ui == `yes) ? selected_items : [];
}
/**
* Temporarily start the network
* @return map The network status before starting
*/
define map<string,boolean> NetworkStart()
{
// network connection status
boolean already_up = false;
// flag: demand has been changed
boolean i_set_demand = false;
if (!Mode::test())
already_up = Internet::Status();
if (!already_up)
{
// label - text in a popup window, progress indicator
UI::OpenDialog(`opt(`decorated), `Label(_("Testing the Internet Connection...")));
// this code is from inst_you.ycp
if (!Internet::demand)
{
Internet::SetDemand (true);
i_set_demand = true;
}
Internet::Start ("");
integer i = 150;
while (i > 0)
{
if (!Internet::Status ())
break;
if (Internet::Connected ())
break;
// ping anything (www.suse.com) to trigger dod connections
//
// This ping should only set the network up,
// The IP now is different to the current www.suse.com's IP
// but it doesn't matter, what we need is just a network traffic.
SCR::Execute (.target.bash_background,
"/bin/ping -c 1 -w 1 213.95.15.200");
sleep (1000);
}
UI::CloseDialog();
}
return $["already_up" : already_up, "i_set_demand" : i_set_demand];
}
/**
* Restore the network status
* @param original_status original status before starting the network
*/
define void NetworkStop(map<string,boolean> original_status)
{
if (!original_status["already_up"]:false)
{
Internet::Stop("");
if (original_status["i_set_demand"]:false)
{
Internet::SetDemand(false);
}
}
}
/**
* Dowload and parse content files from current installation sources
* @param registered
* @return map Extra URLs for each source: $[ string source_url : list<string> extra_urls ]
*/
define map<string,boolean> GetExtraURLs(list<string> registered)
{
map<string,boolean> extra_urls = $[];
list<map> products = Pkg::ResolvableProperties("", `product, "");
y2milestone("Products: %1", products);
foreach(map product, products,
{
// get the extra sources
list<string> extra = (list<string>)product["extra_urls"]:[];
list<string> optional = (list<string>)product["optional_urls"]:[];
if (size(extra) > 0)
{
foreach(string url, extra,
{
// is the URL already registered?
if (!contains(registered, url))
{
extra_urls = add(extra_urls, url, true);
}
else
{
y2milestone("Source %1 is already registered", url);
}
}
);
}
if (size(optional) > 0)
{
foreach(string url, optional,
{
// is the URL already registered?
if (!contains(registered, url))
{
extra_urls = add(extra_urls, url, false);
}
else
{
y2milestone("Source %1 is already registered", url);
}
}
);
}
}
);
y2milestone("Extra sources: %1", extra_urls);
return extra_urls;
}
/**
* Register the installation sources
* @param url_list list of the sources to register
* @return list<integer> list of created source IDs
*/
define list<integer> RegisterSources(list<string> url_list)
{
list<integer> ret = [];
foreach(string new_url, url_list,
{
boolean again = true;
while (again)
{
integer srcid = Pkg::SourceCreate(new_url, "/");
y2milestone ("Created source %1: %2", srcid, new_url);
if (srcid == -1)
{
// popup message
if (Popup::YesNo (_("An error occurred while creating the installation source.") + "\n"
// popup message
+ _("Details:") + "\n" + Pkg::LastError() + "\n" + _("Try again?")))
{
new_url = editUrl (new_url);
}
else
{
again = false;
}
}
else
{
// disable the source
Pkg::SourceSetEnabled(srcid, false);
// remember the ID
ret = add (ret, srcid);
again = false;
}
}
}
);
return ret;
}
list<string> RegisteredUrls()
{
list<string> ret = [];
// get all registered installation sources
list<integer> srcs = Pkg::SourceGetCurrent(false);
foreach(integer src, srcs,
{
map general = Pkg::SourceGeneralData(src);
string url = general["url"]:"";
if (url != nil && url != "")
{
ret = add(ret, url);
}
}
);
// remove duplicates
ret = toset(ret);
y2milestone("Registered sources: %1", ret);
return ret;
}
//////////////////////////////////////////
if ( GetInstArgs::going_back()) // going backwards?
{
return `auto; // don't execute this once more
}
// autoyast mode, user cannot be asked
if (Mode::autoinst())
{
y2milestone("Skipping extra source configuration in autoyast mode");
return `auto;
}
// remember the original network status
map<string,boolean> net_config = NetworkStart();
if (!Internet::Connected())
{
y2warning("Cannot connect to the internet, skipping extra source configuration");
NetworkStop(net_config);
return `auto;
}
list<string> already_registered = RegisteredUrls();
// $[ string url : boolean default ]
map<string,boolean> register_url = GetExtraURLs(already_registered);
// any confirmed source to register?
if (size(register_url) > 0)
{
list<string> confirmed_sources = ConfirmExtraSources(register_url);
{
// register (create) the sources
list<integer> added_ids = RegisterSources(confirmed_sources);
// synchronize the sources if any source has been added
if (size(added_ids) > 0)
{
// reload (disable) the resolvables
Pkg::SourceLoad();
y2milestone ("syncing to zmd");
boolean synced = SourceManager::SyncAddedAndDeleted (added_ids, []);
y2milestone ("sync status: %1", synced);
}
}
}
// restore the network status
NetworkStop(net_config);
return `auto;
/* EOF */
}