Daniel Dehennin <daniel.dehen...@ac-caen.fr> writes: > Hello,
Hello, > 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? 3 new patches for review, tell me if you prefer: - feature requests on bugzilla with patches - pushing on some SVN repository[1], if so, how? Regards. > NB: > - my developpement branch (based on extended-hosts): > bzr branch http://www.baby-gnu.org/~nebu/archives/wpkg/branches/dad > wpkg/branches/dad Footnotes: [1] bzr-svn plugin do that very well for me on some projects. -- Daniel Dehennin RAIP de l'Orne
=== modified file 'wpkg.js' --- wpkg.js 2010-05-19 13:00:03 +0000 +++ wpkg.js 2010-05-19 22:15:12 +0000 @@ -1659,7 +1659,8 @@ } /* - * Gather all the computer informations in one pass + * Gather all the computer informations in one pass. + * Throw an error if none are defined. * * @return the host associative array */ @@ -1668,6 +1669,15 @@ getIPAddresses(); getDomainName(); getHostGroups(); + + if ( host.name == null ) { + throw new Error("No host name defined!"); + } + if ( host.domainname == null + && (host.ipaddresses == null || host.ipaddresses.length <= 0) + && (host.groups == null || host.groups.length <= 0) ) { + throw new Error("No host information gathered!"); + } return host; } @@ -1739,10 +1749,6 @@ // get properties of machine running this script (some can // also be defined by command line switches) - if(host.name == null) { - // Error! Lack of host name. - throw new Error("Error! Lack of host name!"); - } dinfo("Host properties:\n" + "name = " + host.name + "\n" + "ipaddresses = " + host.ipaddresses.join(", ") + "\n"
=== modified file 'wpkg.js' --- wpkg.js 2010-05-19 22:15:12 +0000 +++ wpkg.js 2010-05-19 22:29:36 +0000 @@ -1605,20 +1605,19 @@ * Returns the hostname of the machine running this script. The hostname might * be overwritten by the /host:<hostname> switch. */ -function getHostname() { +function getHostName() { if (host.name == null) { var WshNetwork = WScript.CreateObject("WScript.Network"); - setHostname(WshNetwork.ComputerName.toLowerCase()); + host.name = WshNetwork.ComputerName.toLowerCase(); } return host.name; } function getDomainName() { if (host.domainname == null) { - var strComputer = getHostname() ; var WMIServiceStr = "winmgmts:{impersonationLevel=impersonate}!\\\\" - + strComputer + "\\root\\cimv2"; + + host.name + "\\root\\cimv2"; var objWMIService = GetObject(WMIServiceStr) ; var QueryRes = objWMIService.ExecQuery("Select * from Win32_ComputerSystem where PartOfDomain=True "); @@ -1641,9 +1640,7 @@ if (host.groups == null) { try { host.groups = new Array(); - var HostName = getHostname(); - var DomainName = getDomainName(); - var obj = GetObject("WinNT://"+DomainName+"/"+HostName+"$,user") ; + var obj = GetObject("WinNT://" + host.domainname + "/" + host.name + "$,user") ; var Groups = obj.Groups(); for (var item =new Enumerator(Groups); !item.atEnd(); item.moveNext() ) { var group = item.item(); @@ -1665,7 +1662,7 @@ * @return the host associative array */ function gatherHostInfos() { - getHostname(); + getHostName(); getIPAddresses(); getDomainName(); getHostGroups(); @@ -1854,7 +1851,7 @@ } } if (applyingHostNodes.length == 0) { - throw new Error("Could not find profile for host " + getHostname() + "."); + throw new Error("Could not find profile for host " + host.name + "."); } } return applyingHostNodes; @@ -2658,7 +2655,7 @@ } if (profilesApplying.length <= 0) { - throw new Error("Could not find any profile for host " + getHostname() + "."); + throw new Error("Could not find any profile for host " + host.name + "."); } } } @@ -4472,16 +4469,6 @@ } /** - * Set a new host name which will be used by the script. This is uesful for - * debugging purposes. - * - * @param newHostname host name to be used - */ -function setHostname(newHostname) { - host.name = newHostname; -} - -/** * Sets a new profile-id attribute to the given host XML node * * @param hostNode the host XML node to modify @@ -5534,7 +5521,7 @@ second = "0" + second; } - var logFileName = getLogfilePattern().replace(new RegExp("\\[HOSTNAME\\]", "g"), getHostname()); + var logFileName = getLogfilePattern().replace(new RegExp("\\[HOSTNAME\\]", "g"), host.name); logFileName = logFileName.replace(new RegExp("\\[YYYY\\]", "g"), year); logFileName = logFileName.replace(new RegExp("\\[MM\\]", "g"), month); logFileName = logFileName.replace(new RegExp("\\[DD\\]", "g"), day); @@ -5666,7 +5653,7 @@ // IN ORDER TO ALLOW COORECT HOSTNAME REPLACEMENT IN LOGFILE PATTERN! // Set the profile from either the command line or the hosts file. if (argn("host") != null) { - setHostname(argn("host")); + host.name = argn("host"); } if (argn("ip") != null) { @@ -5998,7 +5985,7 @@ } else { // try net send method cmd += "%SystemRoot%\\System32\\NET.EXE SEND "; - cmd += getHostname(); + cmd += host.name; cmd += " \"" + message + "\""; } try {
=== modified file 'wpkg.js' --- wpkg.js 2010-05-19 22:29:36 +0000 +++ wpkg.js 2010-05-19 22:43:12 +0000 @@ -2071,61 +2071,19 @@ } /** - * Returns 'downgrade' XML node array on a given package XML node - * - * @param packageNode package XML node which contains 'downgrade' nodes - * @return Array of 'downgrade' XML nodes, returns empty array if no nodes are defined - */ -function getPackageCmdDowngrade(packageNode) { - var nodes = packageNode.selectNodes("downgrade"); - if (nodes == null) { - nodes = new Array(); - } - return nodes; -} - -/** - * Returns 'install' XML node array on a given package XML node - * - * @param packageNode package XML node which contains 'install' nodes - * @return Array of 'install' XML nodes, returns empty array if no nodes are defined - */ -function getPackageCmdInstall(packageNode) { - var nodes = packageNode.selectNodes("install"); - if (nodes == null) { - nodes = new Array(); - } - return nodes; -} - -/** - * Returns 'remove' XML node array on a given package XML node - * - * @param packageNode package XML node which contains 'remove' nodes - * @return Array of 'remove' XML nodes, returns empty array if no nodes are defined - */ -function getPackageCmdRemove(packageNode) { - var nodes = packageNode.selectNodes("remove"); - if (nodes == null) { - nodes = new Array(); - } - return nodes; -} - -/** - * Returns 'install' XML node array on a given package XML node - * - * @param packageNode package XML node which contains 'remove' nodes - * @return Array of 'remove' XML nodes, returns empty array if no nodes are defined - */ -function getPackageCmdUpgrade(packageNode) { - var nodes = packageNode.selectNodes("upgrade"); - if (nodes == null) { - nodes = new Array(); - } - return nodes; -} - + * Returns an action XML node array on a given package XML node + * + * @param packageNode package XML node which contains the action nodes + * @param action the action nodes to return + * @return Array of 'action' XML nodes, returns empty array if no nodes are defined + */ +function getPackageCmd(packageNode, action) { + var nodes = packageNode.selectNodes(action); + if (nodes == null) { + nodes = new Array(); + } + return nodes; +} /** * Returns array of package IDs which represent the package dependencies. * Returns emtpy array in case the package does not have any dependency. @@ -3315,15 +3273,15 @@ dinfo("Install type: " + installType); if (installType == typeUpgrade) { // installation is an upgrade - cmds = getPackageCmdUpgrade(packageNode); + cmds = getPackageCmd(packageNode, "upgrade"); dinfo("Fetched " + cmds.length + " upgrade command(s)."); } else if (installType == typeDowngrade) { // prepare downgrade - cmds = getPackageCmdDowngrade(packageNode); + cmds = getPackageCmd(packageNode, "downgrade"); dinfo("Fetched " + cmds.length + " downgrade command(s)."); }else { // installation is default - cmds = getPackageCmdInstall(packageNode); + cmds = getPackageCmd(packageNode, "install"); dinfo("Fetched " + cmds.length + " install command(s)."); } @@ -4104,7 +4062,7 @@ info("Removing " + packageName + " (" + packageID + ")..."); // select command lines to remove - var cmds = getPackageCmdRemove(packageNode); + var cmds = getPackageCmd(packageNode, "remove"); // stores if the package needs a reboot after removing var rebootRequired = false;
pgpPtIEWeHp5n.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