Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-16-2019, 05:26 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
Read Terminal Emulation File via python

I want to read and set the custom terminal emulation file using python. (Session Options > Terminal > Emulation)
I have reason to believe this fragment of code is relevant:

Code:
objTab = crt.GetScriptTab()
szSessionName = objTab.Session.Path
szSessionBLAH = objTab.Session.Config.GetOption("??????")
This is I think the GetOption method applied to the relevant SessionConfiguration object.
The question is what string do I identify the terminal emulation file field with? What do I put instead of "??????"

Many thanks for any reply
Reply With Quote
  #2  
Old 04-16-2019, 11:31 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 211
Hi slouw,

You will need to specify the name of the session.ini option that you are trying to get/set in the string field.

The following example shows how to check to see what Terminal Emulation Type is set using GetOption, and then sets the Terminal Type to "VT100" using the SetOption:

Code:
# $language = "Python"
# $interface = "1.0"

objTab = crt.GetScriptTab()
objConfig = objTab.Session.Config
strCurEmulation = objConfig.GetOption("Emulation")
crt.Dialog.MessageBox("Current Emulation Type is set to: " + strCurEmulation)
strNewEmulation = "VT100"
objConfig.SetOption("Emulation", strNewEmulation)
strNewEmulation = objConfig.GetOption("Emulation")
crt.Dialog.MessageBox("New Emulation Type is set to: " + strNewEmulation)
Is this example helpful?
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-16-2019, 03:25 PM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
thank you for reply
You script gets and sets this parameter I think:
Session Options > Terminal > Emulation > Terminal
This is label 1 in the screenshot.


I want to set the parameter shown in label2 in the screenshot.
Depending on the vendor (cisco, Huawei, juniper etc) I want to set a custom keyboard emulation.

Reply With Quote
  #4  
Old 04-16-2019, 04:40 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 211
Hi slouw,

In order to achieve the desired configuration, you will need to set "Use Alternate Keyboard" to "00000001", "Keymap Name" to "Custom" and "Keymap Filename V2" to the "C:\path\to\the\keymap\file.key".

All of these options are in the session.ini file. If you would like to be able to determine which option(s) to set you can do a comparison of the session.ini file before and after making the manual changes in SecureCRT.

Is this information helpful?
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 04-17-2019, 04:37 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
What is wrong with this script?
The first part which is identical to the script provided above, works fine.
The second part, relating to
GetOption("Use Alternate Keyboard")
gives me all manner of errors.
Grateful for any comments/ideas
Thank you

Code:
# $language = "python"
# $interface = "1.0"
import time
import datetime

crt.Session.SetStatusText("00100 Start")

def writeB(stringB):
   crt.Session.SetStatusText(stringB)
   fp.write(stringB + "\n")
   return

#writeB "Time in seconds since the epoch: %s" %time.time()
yymmdd = str(datetime.date.today().strftime("%Y")) + "-" \
+ str(datetime.date.today().strftime("%m")) + "-"        \
+ str(datetime.date.today().strftime("%d"))
#
hhmmss = str(datetime.datetime.now().strftime("%H")) + "h" \
+ str(datetime.datetime.now().strftime("%M")) + "m"        \
+ str(datetime.datetime.now().strftime("%S"))


#Open LogFile
fileMode = "w"
fp = file("C:\Users\shaunl\Dropbox\Data\Python\\" + yymmdd + " " + hhmmss + "SConf_LogFile_timestamped2_Generic_vandyke_3_py.log", fileMode)
fp.write("00000 LogFile_timestamped2.py START\n")
fp.write("\n")

#Start of Script
writeB("00200 Start of Script")

crt_GetScriptTab = crt.GetScriptTab()
crt_GetScriptTab_Session = crt_GetScriptTab.Session.Config
#

crt_GetScriptTab_Session_GetOption_Emulation = crt_GetScriptTab_Session.GetOption("Emulation")
writeB("00300 Current Emulation               : " + crt_GetScriptTab_Session_GetOption_Emulation)
strNewEmulation = "VT100"
crt_GetScriptTab_Session.SetOption("Emulation", strNewEmulation)
strNewEmulation = crt_GetScriptTab_Session.GetOption("Emulation")
writeB("00310 New Emulation Type              : " + strNewEmulation)
writeB("00320 Script works fine to this point")

#
crt_GetScriptTab_Session_GetOption_Emulation = crt_GetScriptTab_Session.GetOption("Use Alternate Keyboard")
writeB("00320 Current Use Alternate Keyboard  : " + str(crt_GetScriptTab_Session_GetOption_Emulation)
L_UseAltKB = 0
crt_GetScriptTab_Session.SetOption("Use Alternate Keyboard", "00000000")
L_UseAltKB = crt_GetScriptTab_Session.GetOption("Use Alternate Keyboard")
writeB("00330 Use Alternate Keyboard Setting  : " + L_UseAltKB)

#End of Script
writeB("01200 End of Script")


#Close Log File
writeB("09101 Close Log File\n")
fp.close()
crt.Session.SetStatusText("09201 LogFile_timestamped2.py Logfile closed")
crt.Session.SetStatusText("09201 LogFile_timestamped2.py END")
Reply With Quote
  #6  
Old 04-17-2019, 07:54 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,938
Hi slouw,

Quote:
gives me all manner of errors.
What errors are you getting?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 04-17-2019, 03:06 PM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
Hi Brenda
In the current form that I have it see below.
The errors vary according to troubleshooting steps that I take

Quote:
---------------------------
SecureCRT
---------------------------
SyntaxError
Error: invalid syntax
File: C:\XXX\SecureCRT\Python Scripts\SConf_LogFile_timestamped2_Generic_vandyke_3.py

Line: 47

L_UseAltKB = 0
---------------------------
OK
---------------------------
Reply With Quote
  #8  
Old 04-17-2019, 03:25 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,938
Hi slouw,

Oldest reason in the book for one of these *weird python errors*. The issue is on the previous line, missing parentheses:
Code:
crt_GetScriptTab_Session_GetOption_Emulation = crt_GetScriptTab_Session.GetOption("Use Alternate Keyboard")
writeB("00320 Current Use Alternate Keyboard  : " + str(crt_GetScriptTab_Session_GetOption_Emulation))
L_UseAltKB = 0

And I'm not sure what you are doing here. You don't need to quote the values but you'll likely need to str the variable when you write out the results (don't forget the second close paren):
Code:
L_UseAltKB = 0
crt_GetScriptTab_Session.SetOption("Use Alternate Keyboard", 0)
L_UseAltKB = crt_GetScriptTab_Session.GetOption("Use Alternate Keyboard")
writeB("00330 Use Alternate Keyboard Setting  : " + str(L_UseAltKB))
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by bgagnon; 04-17-2019 at 03:34 PM.
Reply With Quote
  #9  
Old 04-17-2019, 05:22 PM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
Solution Script

Wonderful thank you
The complete code below works for me.
It does the following:
- Checks current terminal emulation then sets it to VT100 and confirms;
- Checks current setting of "Select an alternate keyboard emulation" then checks the checkbox



Code:
# $language = "python"
# $interface = "1.0"
import time
import datetime

crt.Session.SetStatusText("00100 Start")

def writeB(stringB):
   crt.Session.SetStatusText(stringB)
   fp.write(stringB + "\n")
   return

#writeB "Time in seconds since the epoch: %s" %time.time()
yymmdd = str(datetime.date.today().strftime("%Y")) + "-" \
+ str(datetime.date.today().strftime("%m")) + "-"        \
+ str(datetime.date.today().strftime("%d"))
#
hhmmss = str(datetime.datetime.now().strftime("%H")) + "h" \
+ str(datetime.datetime.now().strftime("%M")) + "m"        \
+ str(datetime.datetime.now().strftime("%S"))


#Open LogFile
fileMode = "w"
fp = file("C:\Python\\" + yymmdd + " " + hhmmss + "SConf_LogFile_timestamped2_Generic_vandyke_3_py.log", fileMode)
fp.write("00000 LogFile_timestamped2.py START\n")
fp.write("\n")

#Start of Script
writeB("00200 Start of Script")

crt_GetScriptTab = crt.GetScriptTab()
crt_GetScriptTab_Session_Config = crt_GetScriptTab.Session.Config
#
# Set Emulation Type to VT100
crt_GetScriptTab_Session_Config_GetOption_Emulation = crt_GetScriptTab_Session_Config.GetOption("Emulation")
writeB("00300 Current Emulation               : " + crt_GetScriptTab_Session_Config_GetOption_Emulation)
strNewEmulation = "VT100"
crt_GetScriptTab_Session_Config.SetOption("Emulation", strNewEmulation)
strNewEmulation = crt_GetScriptTab_Session_Config.GetOption("Emulation")
writeB("00310 New Emulation Type              : " + strNewEmulation)
writeB("00320 Script works fine to this point")

# Check Select Alternate Keyboard checkbox then set 1
crt_GetScriptTab_Session_Config_GetOption_Emulation = crt_GetScriptTab_Session_Config.GetOption("Use Alternate Keyboard")
writeB("00320 Current Use Alternate Keyboard  : " + str(crt_GetScriptTab_Session_Config_GetOption_Emulation))
L_UseAltKB = 1
crt_GetScriptTab_Session_Config.SetOption("Use Alternate Keyboard", L_UseAltKB)
UseAltKB = crt_GetScriptTab_Session_Config.GetOption("Use Alternate Keyboard")
writeB("00330 Use Alternate Keyboard Setting  : " + str(L_UseAltKB))

#End of Script
writeB("01200 End of Script")


#Close Log File
writeB("09101 Close Log File\n")
fp.close()
crt.Session.SetStatusText("09201 LogFile_timestamped2.py Logfile closed")
crt.Session.SetStatusText("09201 LogFile_timestamped2.py END")
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:38 PM.