Daniel Dehennin <daniel.dehen...@ac-caen.fr> writes: > Hello,
Hello, > I'm working on wpkg.js as you saw, I know Rainer Meier want to > restructure the code for 1.2 and before going forward I want to submit > my TODO list for review. Ok, I just did 1.2 and fix my TODO list for 1.3 and I'm wondering if it's better or not to define setHostInfo and getHostInfo instead of direct array access? I attach 2 patches. NB: I'm tracking my changes in bzr repositories, you can follow them with: - basic layout: mkdir wpkg/{,upstream,branches} bzr --init-repository --2a wpkg - upstream 1.1: bzr branch http://www.baby-gnu.org/~nebu/archives/wpkg/upstream/1.1 wpkg/upstream/1.1 - extended host (useless as it's the base of the following one): bzr branch http://www.baby-gnu.org/~nebu/archives/wpkg/branches/extended-hosts wpkg/branches/extended-hosts - my developpement branch (based on extended-hosts): bzr branch http://www.baby-gnu.org/~nebu/archives/wpkg/branches/dad wpkg/branches/dad -- Daniel Dehennin RAIP de l'Orne
=== modified file 'wpkg.js' --- wpkg.js 2010-05-17 07:02:40 +0000 +++ wpkg.js 2010-05-19 12:08:42 +0000 @@ -433,10 +433,11 @@ var packagesRemoved = new Array(); /** host properties used within script */ -var hostname = null; -var domainname = null; -var ipaddresses = null; -var hostgroups = null; +var host = new Array(); +host.name = null; +host.domainname = null; +host.ipaddresses = null; +host.groups = null; /** FS object where the settings are stored */ var settings_file = null; @@ -1605,15 +1606,15 @@ * be overwritten by the /host:<hostname> switch. */ function getHostname() { - if (hostname == null) { + if (host.name == null) { var WshNetwork = WScript.CreateObject("WScript.Network"); setHostname(WshNetwork.ComputerName.toLowerCase()); } - return hostname; + return host.name; } function getDomainName() { - if (domainname == null) { + if (host.domainname == null) { var strComputer = getHostname() ; var WMIServiceStr = "winmgmts:{impersonationLevel=impersonate}!\\\\" @@ -1629,17 +1630,17 @@ } else { var First = items.item(); - domainname = First.Domain.toLowerCase(); - dinfo("Domain Name: " + domainname); + host.domainname = First.Domain.toLowerCase(); + dinfo("Domain Name: " + host.domainname); } } - return domainname; + return host.domainname; } function getHostGroups() { - if (hostgroups == null) { + if (host.groups == null) { try { - hostgroups = new Array(); + host.groups = new Array(); var HostName = getHostname(); var DomainName = getDomainName(); var obj = GetObject("WinNT://"+DomainName+"/"+HostName+"$,user") ; @@ -1647,14 +1648,14 @@ for (var item =new Enumerator(Groups); !item.atEnd(); item.moveNext() ) { var group = item.item(); dinfo("Found computer group: " + group.Name); - hostgroups.push(group.Name); + host.groups.push(group.Name); } } catch (e) { dinfo("Message: Error fetching computer groups."); } } - return hostgroups; + return host.groups; } /** @@ -1725,7 +1726,6 @@ // get properties of machine running this script (some can // also be defined by command line switches) - var host = new Array(); host.name = getHostname(); host.ipaddresses = getIPAddresses(); host.domainname = getDomainName(); @@ -4464,7 +4464,7 @@ * @param newHostname host name to be used */ function setHostname(newHostname) { - hostname = newHostname; + host.name = newHostname; } /** @@ -5653,15 +5653,15 @@ } if (argn("ip") != null) { - ipaddresses = new Array(argn("ip")); + host.ipaddresses = new Array(argn("ip")); } if (argn("domainname") != null) { - domainname = argn("domainname"); + host.domainname = argn("domainname"); } if (argn("group") != null) { - hostgroups = new Array (argn("group")); + host.hostgroups = new Array (argn("group")); } // Process log file pattern @@ -6361,8 +6361,8 @@ * @return array of IP address strings, array can be of length 0 */ function getIPAddresses() { - if (ipaddresses == null) { - ipaddresses = new Array(); + if (host.ipaddresses == null) { + host.ipaddresses = new Array(); var shell = new ActiveXObject("WScript.Shell"); @@ -6385,7 +6385,7 @@ // read DHCP address var dhcpIP = getRegistryValue(regBase + "DhcpIPAddress"); if (dhcpIP != null && dhcpIP != "") { - ipaddresses.push(dhcpIP); + host.ipaddresses.push(dhcpIP); dinfo("Found DHCP address: " + dhcpIP); } } else { @@ -6398,7 +6398,7 @@ if (fixedIPs[j] != null && fixedIPs[j] != "" && fixedIPs[j] != "0.0.0.0") { - ipaddresses.push(fixedIPs[j]); + host.ipaddresses.push(fixedIPs[j]); dinfo("Found fixed IP address: " + fixedIPs[j]); } } @@ -6408,7 +6408,7 @@ } } } - return ipaddresses; + return host.ipaddresses; } /**
=== modified file 'wpkg.js' --- wpkg.js 2010-05-19 12:08:42 +0000 +++ wpkg.js 2010-05-19 13:00:03 +0000 @@ -1658,6 +1658,19 @@ return host.groups; } +/* + * Gather all the computer informations in one pass + * + * @return the host associative array + */ +function gatherHostInfos() { + getHostname(); + getIPAddresses(); + getDomainName(); + getHostGroups(); + return host; +} + /** * Returns a list of attribute/value pair associated to the host * definition in hosts.xml. @@ -1726,11 +1739,6 @@ // get properties of machine running this script (some can // also be defined by command line switches) - host.name = getHostname(); - host.ipaddresses = getIPAddresses(); - host.domainname = getDomainName(); - host.groups = getHostGroups(); - if(host.name == null) { // Error! Lack of host name. throw new Error("Error! Lack of host name!"); @@ -5263,6 +5271,9 @@ dinfo("Base directory is '" + base + "'."); dinfo("Log level is " + getLogLevel()); + dinfo("Gather all computer informations:"); + gatherHostInfos(); + var packages_file; var profiles_file; var hosts_file;
pgp1PyuKZztyN.pgp
Description: PGP signature
------------------------------------------------------------------------- wpkg-users mailing list archives >> http://lists.wpkg.org/pipermail/wpkg-users/ _______________________________________________ wpkg-users mailing list wpkg-users@lists.wpkg.org http://lists.wpkg.org/mailman/listinfo/wpkg-users