Is there any way to batch export TLS States with additional files? - traffic

From https://sumo.dlr.de/docs/Simulation/Output/Traffic_Lights.html#tls_states , I know that I can use command <timedEvent type="SaveTLSStates" source="<TLS_ID>" dest="<OUTPUT_FILE>"/> in additional file to output the state of the traffic light, whose ID is "TLS_ID" defined in .net.xml file. However I wonder that if I use this way to output the TLS, do I have to enter this command for each ID of the traffic light? Is there a statement that can output the state of all traffic light defined in .net.xml?

No, but you can write a small python script to achieve that:
import sumolib
net = sumolib.net.readNet("net.net.xml")
states_xml = sumolib.xml.create_document("additional")
for tls in net.getTrafficLights():
event = states_xml.addChild("timedEvent")
event.setAttribute("type", "SaveTLSStates")
event.setAttribute("source", tls.getID())
event.setAttribute("dest", "states.xml")
with open("output.add.xml", 'w') as out:
out.write(states_xml.toXML())
Please be aware that I did not test the code above.

Related

Chef recipes - use node name in attributes

In a chef recipe I have the following code:
if (node['server1']['PT1'] == true)
setup('PT1')
elsif (node['server1']['PT2'] == true)
setup('PT2')
end
I am checking my attributes to see if the value equals true for either PT1 or PT2. This works correctly if i hardcode server1 into the code but I want to know do it dynamically depending on the server running this. How would I replace node['server1'] with something like node.name to find different servers in the attribute file. An example of my attributes is:
default['server1'][...]...
default['server2'][...]...
default['server3'][...]...
default['server4'][...]...
If I can dynamically look at the different servers, that'd be the ideal result.
Depends on your naming convention. It doesn't look like ohai gathers the node name information automatically but it does gather up a lot of information.
If you have a standard around your node names, such as using their hostname or fqdn as the node name, then you can simply query for that.
node['hostname']...
node['fqdn']...
If you use a more esoteric method to name your nodes that have nothing to do with your host information you can still query the client.rb located on your node, which is how your node knows what to identify itself as to the Chef server. On windows it's located at C:/chef/client.rb, on UNIX its at /etc/chef/client.rb. I'll leave the parsing of the file up to you.
To view the full extent of what ohai (everything available under node) log onto a bootstrapped machine and type ohai into your shell. Its quite a bit so you might want to output to a text file and use an editor to scroll/search through it.
EDIT1:
In test kitchen the location changes. It becomes <your kitchen cache location>\client.rb> EX, if you use vagrant with windows and its defaults it becomes c:\users\vagrant\appdata\local\temp\kitchen\client.rb
EDIT2:
To bring it back to your original example, if the contents of your node['server'] can either be PT1 or PT2 then you can do the following
setup(node['server'])
and you can control the contents of what server is through any variety of mechanisms. If you are controlling it through hostname then you could do
attributes/default.rb
...
node['server']= node['hostname']
or more simply, if your standards are such that allow for it
recipes/default.rb
...
setup(node['hostname'])
Although normally you'd control what is being setup in separate recipes defined in your runlist.
You can make this totally dynamic even:
node['whatever'][node.name].each do |key, value|
setup(key) if value == true
end

OpenEdge 10.2A - INPUT THROUGH set does not work after Windows Update 1703 on Windows 10

We were using below code to get the name of the computer.
def new shared var cHost as char format "x(40)" no-undo.
INPUT THROUGH hostname NO-ECHO.
SET cHost.
INPUT CLOSE.
DISPLAY chost.
After we have updated our computers (Windows 10 - 1703), it no longer works. It seems SET cHost is the part where it fails. I have tried IMPORT UNFORMATTED cHost but it does not work.
PS: I can get computer name using OS-GETENV("COMPUTERNAME") but I have to do it using INPUT THROUGH statement.
Edit: It seems that it is not only a problem with 10.2A but a more general one. Also it is not just related to hostname but all console applications and ms-dos commands. Now I will try to replace INPUT THROUGH statement with another Progress command if there is any, or try to communicate with existing console applications with some other method.
The first thing I would do is to verify that the 'hostname' command is still working properly from a command window.
Assuming that it is I would code your snippet something like this:
INPUT THROUGH VALUE( "hostname" ).
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
DISPLAY cHOST format "x(60)".
Which might reveal a more useful error message than "it no longer works".
Since COMPUTERNAME meets your needs but you must use INPUT THROUGH for some very mysterious reason you might also try:
INPUT THROUGH VALUE( "echo %COMPUTERNAME%" ).
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
DISPLAY cHOST format "x(60)".
It seems the problem may not be limited to Openedge version 10. I am running a windows 10 winver 1703 device for development, using Progress/Openedge 8.3 and I am no longer able to execute this.
def var a as char format "x(70)".
input through "echo %cd%" no-echo.
import unformatted a.
input close.
message a. pause.
This runs on a windows server 2012 R2, using progress/openedge 8.3.
Where is no longer works, it just exits from within the program when it hits the import command.
Since it seems as a bug, until someone comes up with a better solution, this is how I will change my codes:
DEF VAR cHost AS CHAR FORMAT "x(40)" NO-UNDO.
OS-CREATE-DIR VALUE("c:\temp").
OS-COMMAND SILENT VALUE("hostname >c:\temp\hostname.txt").
INPUT FROM VALUE("c:\temp\hostname.txt").
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
MESSAGE cHost.
This code can be used for other ms-dos commands and console applications as well.
DEF VAR cHost AS CHAR FORMAT "x(40)" NO-UNDO.
OS-CREATE-DIR VALUE("c:\temp").
OS-COMMAND SILENT VALUE("ECHO %cd% >c:\temp\result.txt").
INPUT FROM VALUE("c:\temp\result.txt").
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
MESSAGE cHost.
Thanks for your help.

validating ip address in datastage

I have a source file that contains two fields: IP_ADDRESS and USER_NAME. I want to check whether the IP address is correct or not before loading it to the datawarehouse using DATASTAGE. How do I do this?
I was browsing Stack Overflow and think I might have a solution to your question. If you create a job to grab all of the IP_ADDRESS's from the file and send them to a BASIC transformer (search for BASIC transformer in DataStage. It is NOT the one that is normally on the palette). From there, set the Stage Variables as 'SetUserStatus() and write out the column name to a peek stage (You don't need the output at all. The SetUserStatus is the important part). This will now allow you to pass up the Command Output (list of IP Addresses) to a Sequence. From the Sequence, start with the job you just created (BASIC transformer job) and link that to a User Variables Activity. In the User Variables Activity stage, Set the name to something like 'IP Address' and Expression as IP_ADDRESS.$UserStatus. You can then use a Loop to take that output that is now a List and send each individual IP Address to an Execute Stage with a Ping command to see if it returns a valid IP Address. If it does return a valid IP then have your job that writes the USER_NAME and IP_ADDRESS to do a 'Select' statement where the IP_ADDRESS = the valid IP_ADDRESS. For the ones that aren't valid, you can send them down a different path and have them write out to '.txt' file somewhere so you know which ones weren't valid. I'm sure you will need a few more steps in there but that should be the gist of it.
Hope my quick stab at your issue helps.
Yes, you can use a transformer or a transformer and a filter to do that, depending on the version of Datastage you're using. If you're using PX, just encode the validation logic in a transformer stage, and then, on the output link set up a filter that doesn't allow the rows to pass forward if they didn't pass the validation logic.

return information using pexpect

I am learning how to use pexpect and i had a question. I am trying to find the version number of a remote server and based on that version number I want to choose the right driver number. I am not entirely sure how should I go about doing this. Something along the lines of a getline function. Let me know if there are any functions I could use
The child .before and .after properties contain the stdout before resp. after the matched expectation.
import pexpect
child = pexpect.spawn('cat /etc/issue')
child.expect('Ubuntu.*')
print(child.after)
Which of the commands requires input? If it is the driver installation you could use fabric & fexpect:
from ilogue.fexpect import expect, expecting, run
output = run('get-system-version')
prompts = []
prompts += expect('Which driver version do you want to install?',output)
with expecting(prompts):
run('install-driver-command')

VBScript and presenting an input box

I am writing a script to capture the login time. In the final production, there would be no input from any user. However I am testing it and I wanted to know how I add extra code to determine that
If its in 'debug' mode AND
The user that is logging in is me (lets say my username is joe.smith on the domain called EXAMPLE)
then present an input box to allow me to type the date, time for logging in.
All other users would never see this and it would capture today with the system time.
I would also like to hide the code so if the script is opened by the wrong person, they wouldnt be able to make heads or tails of whats going on.
You can use a command line parameter as Matt says to set the script into debug mode, eg
dim isdebug: isdebug = WScript.Arguments.Named.Exists("debug")
WScript.Echo("in debug mode: " & isdebug)
Which you can invoke with
wscript debugscript.vbs /debug
To get the current user name, you can use either the WMI Service or the WScript.Network object.
Once you have the username, you can conditionally throw up an InputBox and collect the value returned:
dim date_: date_ = Now()
if isdebug and username = "me" then
dim value: value = CDate(InputBox("enter the date and time (dd/mm/yyyy hh:mm:ss)", "please", Now()))
' validate the input here
date_ = CDate(value)
end if
And finally, to obfuscate your code you could use the Scripting.Encoder although it looks like this doesn't seem to be supported on Vista or Windows 7. There does seem to be a few hits on googling the phrase obfuscating vbscript, anyway.
Most of this sounds like it can be resolved by the logic of the script.
Have a command line parameter (debug is an appropriate name) and then have some if logic in the code to do as you wish (present the input box).
For the code obfuscation, I don't know how this could be done in vbscript. Windows scripting host works with JavaScript as well though and there are plenty of tools on the web for making JS harder to read. Maybe you want to look a using JS...
HTH,
Matt
I think you can check the property App.LogMode to see if you are in 'debug' mode or not. If it is 0 then you are running debug mode and if it is 1 you are not.

Resources