Giter VIP home page Giter VIP logo

ivbscript's Introduction

iVBScript

Interactive VBScript

Jupyter kernel implementation for VBScript

Installation*

git clone https://github.com/ofer1katz/ivbscript.git 
cd ivbscript
git lfs pull 
python setup.py develop

*notice:

during installation registry will be edited to allow ANSI console color

[HKEY_CURRENT_USER\Console]
"VirtualTerminalLevel"=dword:00000001

during installation com dll "tlbinf32.dll" (TLI.TLIApplication) will be registered if not registered already.

%systemroot%\SysWOW64\regsvr32.exe can be used to manually register/unregister


kernel specs will be copied to os.path.join(os.path.abspath(sys.prefix), 'share', 'jupyter', 'kernels', 'vbscript')

Usage

ivbscript

or

jupyter console --kernel vbscript

Special Commands

  • cls/clear - clear console
  • exit/exit()/quit/quit() - exit iVBScript
  • !<command> - execute a child program in a new process
  • <variable>? - inspect <variable>
  • %reset - reset console
  • %file <file_path> - read <file_path> and run the content as VBScript code
  • %paste - paste and execute

If you are having this error:

Unhandled exception in event loop:
  File "c:\users\USER\appdata\local\programs\python\python38-32\lib\asyncio\proactor_events.py", line 768, in _loop_self_reading
    f.result()  # may raise
  File "c:\users\USER\appdata\local\programs\python\python38-32\lib\asyncio\windows_events.py", line 808, in _poll
    value = callback(transferred, key, ov)
  File "c:\users\USER\appdata\local\programs\python\python38-32\lib\asyncio\windows_events.py", line 457, in finish_recv
    raise ConnectionResetError(*exc.args)

Exception [WinError 995] The I/O operation has been aborted because of either a thread exit or an application request
Press ENTER to continue...

Take a look at the following workaround: ipython/ipython#12049 (comment)

Development

Install development requirements

pip install -r requirements_dev.txt -U --upgrade-strategy eager

Tests

coverage erase
coverage run --source=. --omit="*\tests\*" -m pytest -v -s
coverage report -m

Code Analytics

prospector --strictness veryhigh
# Analyze the given Python modules and compute Cyclomatic Complexity (CC).
radon cc . --min B
# Analyze the given Python modules and compute the Maintainability Index.
radon mi . --min B
# Analyze the given Python modules and compute raw metrics.
radon raw .
# Analyze the given Python modules and compute their Halstead metrics.
radon hal .

TODO:

  • test coverage
  • using pipes instead of files for communication with vbscript
  • better implementation of exit/quit (via jupyter)
  • evaluate expressions
  • complete session's variables/functions/etc. using - Tab (do_complete)
  • use do_inspect() for inspect
  • inspect levels support - ?/??
  • paste into terminal - Ctrl + v

ivbscript's People

Contributors

ofer1katz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

oldliu001

ivbscript's Issues

[Bug] Failed to inspecting COM object

When creating a COM object from VBscript it failed to inspect the result.

In [1]: Dim fso: Set fso = CreateObject("scripting.filesystemobject")

In [2]: fso
Err.Description: Object doesn't support this property or method.
Err.Number: 438

When the output should be something like this:

Object FileSystemObject
  Sub QueryInterface(riid, ppvObj)
  Function ULong AddRef()
  Function ULong Release()
  Sub GetTypeInfoCount(pctinfo)
  Sub GetTypeInfo(itinfo, lcid, pptinfo)
  Sub GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid)
  Sub Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr)
  Function vbEmpty (uninitialized variable) Drives()
  Function vbString BuildPath(Path, Name)
  Function vbString GetDriveName(Path)
  Function vbString GetParentFolderName(Path)
  Function vbString GetFileName(Path)
  Function vbString GetBaseName(Path)
  Function vbString GetExtensionName(Path)
  Function vbString GetAbsolutePathName(Path)
  Function vbString GetTempName()
  Function vbBoolean DriveExists(DriveSpec)
  Function vbBoolean FileExists(FileSpec)
  Function vbBoolean FolderExists(FolderSpec)
  Function vbEmpty (uninitialized variable) GetDrive(DriveSpec)
  Function vbEmpty (uninitialized variable) GetFile(FilePath)
  Function vbEmpty (uninitialized variable) GetFolder(FolderPath)
  Function vbEmpty (uninitialized variable) GetSpecialFolder(SpecialFolder)
  Sub DeleteFile(FileSpec, Force)
  Sub DeleteFolder(FolderSpec, Force)
  Sub MoveFile(Source, Destination)
  Sub MoveFolder(Source, Destination)
  Sub CopyFile(Source, Destination, OverWriteFiles)
  Sub CopyFolder(Source, Destination, OverWriteFiles)
  Function vbEmpty (uninitialized variable) CreateFolder(Path)
  Function vbEmpty (uninitialized variable) CreateTextFile(FileName, Overwrite, Unicode)
  Function vbEmpty (uninitialized variable) OpenTextFile(FileName, IOMode, Create, Format)
  Function vbEmpty (uninitialized variable) GetStandardStream(StandardStreamType, Unicode)
  Function vbString GetFileVersion(FileName)

[Enhancement] Add a magic for executing a file.

It can be usefull for "importing" vbscript files, for exmaple.

In [1]: %file "stringUtilities.vbs"
In [2]: formatString("{0}:\{1}", Array("C", "Windows")) ' Imported from 'stringUtilities.vbs'.
Out[2]: C:\Windows

[enhancement] Add main file.

@ofer1katz Can you give permissions to add a new branch in order to start a pull request?

Something like this:

ivbscript\main.py

from jupyter_console.app import ZMQTerminalIPythonApp


def main():
    """ Launch iVBScript Shell """
    ZMQTerminalIPythonApp.launch_instance(argv=['--kernel', 'vbscript'])


if __name__ == '__main__':
    main()

[Bug] Failed to inspect array

Example:

In [1]: Array(1,2,3,4)
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\ipykernel\kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tornado\gen.py", line 735, in run
    value = future.result()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tornado\gen.py", line 209, in wrapper
    yielded = next(result)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\ipykernel\kernelbase.py", line 543, in execute_request
    self.do_execute(
  File "c:\git\ivbscript\ivbscript\kernel.py", line 148, in do_execute
    output = self._handle_vbscript_command(code)
  File "c:\git\ivbscript\ivbscript\kernel.py", line 132, in _handle_vbscript_command
    output = json.loads(output_file.read())
  File "C:\Program Files (x86)\Python38-32\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files (x86)\Python38-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files (x86)\Python38-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

[Bug] Got an error when calling a specific function

The scenario that raising the error:

In [1]: Function formatString(format, arguments)
      :     Dim stringBuilder: Set stringBuilder = CreateObject("System.Text.StringBuilder")
      :     Call stringBuilder.AppendFormat_4(format, (arguments))
      :     formatString = stringBuilder.ToString()
      :     stringBuilder.Length = 0
      :     Set stringBuilder = Nothing
      : End Function

In [2]: formatString("{0}:\{1}", Array("C", "Windows"))
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\ipykernel\kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tornado\gen.py", line 735, in run
    value = future.result()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tornado\gen.py", line 209, in wrapper
    yielded = next(result)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\ipykernel\kernelbase.py", line 543, in execute_request
    self.do_execute(
  File "c:\git\ivbscript\ivbscript\kernel.py", line 148, in do_execute
    output = self._handle_vbscript_command(code)
  File "c:\git\ivbscript\ivbscript\kernel.py", line 132, in _handle_vbscript_command
    output = json.loads(output_file.read())
  File "C:\Program Files (x86)\Python38-32\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files (x86)\Python38-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files (x86)\Python38-32\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 41 (char 40)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.