Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-22-2020, 10:33 AM
pjano1 pjano1 is offline
Registered User
 
Join Date: Mar 2020
Posts: 7
Using YAML in Python with SecureCRT

I'm trying to extract and parse a YAML config file on a Windows system, but I'm unable to successfully import yaml from within a SecureCRT python script. The weird thing is, I'm able to do this no problem on a Linux system. I realize part of this might be because YAML isn't included with SecureCRT's python, but what I don't understand is why it works in Linux but not Windows. Any suggestions?

Last edited by pjano1; 06-22-2020 at 11:29 AM.
Reply With Quote
  #2  
Old 06-22-2020, 11:47 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Hello "pjano1",

Because python is not natively available on a stock Windows machine, SecureCRT for Windows provides a limited Python environment; it's not a comprehensive Python distribution.

Additionally, external third-party Python modules cannot be imported into this limited Python environment within SecureCRT on Windows.

I've added a feature request for the ability to include the yaml library/module you want in SecureCRT's limited Python environment.

I've also added a feature request for the ability to use a completely separate Python environment, rather than the limited Python environment that is currently shipping with SecureCRT, in case you wanted to go with a third-party Python environment on your Windows machine.

I don't yet have any ETA for when or even if these might ever become available, but if either does we can post here for notification.
If you prefer direct email notification, send an email to support@vandyke.com with a subject of Please notify: Feature Requests - Forum Thread #14215.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 06-22-2020, 12:30 PM
pjano1 pjano1 is offline
Registered User
 
Join Date: Mar 2020
Posts: 7
Hi Jake,

Thanks for both of the feature requests.

For now I could probably switch to a format other than YAML that could still work with the limited Python environment. But, YAML is my preference so if either of those features become available in the future that would be huge.

To add on to my original question, I am able to work with YAML in SecureCRT for Linux. Is this because this version of SecureCRT has a more robust Python environment than Windows?
Reply With Quote
  #4  
Old 06-22-2020, 01:27 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by pjano1 View Post
I am able to work with YAML in SecureCRT for Linux. Is this because this version of SecureCRT has a more robust Python environment than Windows?
If by "more robust", you mean "present with a stock install of the OS", you're spot on.

SecureCRT for mac/Linux environments uses the Python engine/environment that is natively installed and available on stock installs of supported operating systems.
  • SecureCRT for mac/Linux doesn't ship with (include as part of its installer) any python engine/environment on supported mac/Linux platforms because supported mac/Linux platforms are expected to already have a native python environment in place.

  • Conversely, python is not natively available on a stock Windows machine, so SecureCRT for Windows provides (as part of the SecureCRT installation) a limited Python environment -- one that is pre-compiled with the objective to facilitate SecureCRT automation, rather than one designed to provide a "robust" or complete Python environment for all possible Python activities. The Python environment that comes with SecureCRT for Windows is not user-customizable.
Therefore, as a matter of what's available natively vs. what SecureCRT for Windows includes with its installer, one could say that the Python environment available to SecureCRT on supported Linux/Mac operating systems is more expansive ("robust", perhaps?) than the python environment that is included with SecureCRT for Windows.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 07-24-2020, 03:52 PM
gregg gregg is offline
Registered User
 
Join Date: Oct 2010
Posts: 75
I was able to get yaml working in Windows 10 x64, SecureCRT v8.7.1 by downloading the yaml source and setting the path to it.

Specifically:
From https://pyyaml.org/wiki/PyYAML I downloaded the TAR.GZ package:
http://pyyaml.org/download/pyyaml/PyYAML-5.3.1.tar.gz

Unpacked it somewhere.

My test(**) SecureCRT script looks like this:

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

import sys

# tell Python where to also look for libraries (**)
yaml_path = "D:\\dev\\PyYAML-5.3.1\\lib"
if yaml_path not in sys.path:
    sys.path.append(yaml_path)

crt.Dialog.MessageBox("\n".join(sys.path))

import yaml

data = yaml.load("""
name: Vorlin Laruknuzum
sex: Male
class: Priest
title: Acolyte
hp: [32, 71]
sp: [1, 13]
gold: 423
inventory:
- a Holy Book of Prayers (Words of Wisdom)
- an Azure Potion of Cure Light Wounds
- a Silver Wand of Wonder""")

crt.Dialog.MessageBox(data['name'])
crt.Dialog.MessageBox(data['inventory'][1])
*Note1: minor testing, but this parsing script worked.
**Note2: It looks like SecureCRT also loads libraries from a few places by default, so you could probably put the "yaml" directory in one of these places also:

C:\Program Files\VanDyke Software\SecureCRT\PythonLibraries
-or-
C:\Program Files\VanDyke Software\SecureCRT\SitePackages
of course, depends on your install path and you might need to make the final directory.
In which case you won't need to mess with sys.path.
Reply With Quote
  #6  
Old 07-24-2020, 04:25 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
Hi Gregg,

Thanks for sharing your workaround with the forum community!

Please note that we have not tested this out, and since this support is not available natively we will not be able to troubleshoot any issues that may arise as a result of this implementation.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 09-30-2020, 04:22 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by pjano1 View Post
I'm trying to extract and parse a YAML config file on a Windows system, but I'm unable to successfully import yaml from within a SecureCRT python script. The weird thing is, I'm able to do this no problem on a Linux system. I realize part of this might be because YAML isn't included with SecureCRT's python, but what I don't understand is why it works in Linux but not Windows. Any suggestions?
pjano1,

SecureCRT version 9.0 for Windows now supports the use of a separate python engine/environment.

If you want to try it out to see if it will better meet your needs, you can read more about using Python 3 in SecureCRT 9.0 in this forum post.

Is that something you would be willing to explore?
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply

Tags
python , python import

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 06:54 PM.