Skip to content

Commit

Permalink
Merge pull request #289 from Youwotma/master
Browse files Browse the repository at this point in the history
Make splash:get_version() return a table with version information
  • Loading branch information
kmike committed Sep 2, 2015
2 parents f910c97 + 15c96cf commit 3d131ea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
20 changes: 16 additions & 4 deletions docs/scripting-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1829,19 +1829,31 @@ splash:get_version

Get Splash major and minor version.

**Signature:** ``major, minor = splash:get_version()``
**Signature:** ``version_info = splash:get_version()``

**Returns:** two numbers corresponding to the major and minor Splash version.
**Returns:** A table with version information.

**Async:** no.

As of now, this table contains:

* ``splash`` - (string) Splash version
* ``major`` - (int) Splash major version
* ``minor`` - (int) Splash minor version
* ``python`` - (string) Python version
* ``qt`` - (string) Qt version
* ``pyqt`` - (string) PyQt version
* ``webkit`` - (string) WebKit version
* ``sip`` - (string) SIP version
* ``twisted`` - (string) Twisted version

Example:

.. code-block:: lua
function main(splash)
local major, minor = splash:get_version()
if major < 2 and minor < 8 then
local version = splash:get_version()
if version.major < 2 and version.minor < 8 then
error("Splash 1.8 or newer required")
end
end
Expand Down
16 changes: 15 additions & 1 deletion splash/qtrender_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import contextlib
import time
import sys
import sip
import twisted

import lupa
from PyQt4.QtNetwork import QNetworkRequest
from PyQt4.QtCore import PYQT_VERSION_STR, QT_VERSION_STR
from PyQt4.QtWebKit import qWebKitVersion

from splash.browser_tab import JsError
from splash.lua_runner import (
Expand Down Expand Up @@ -681,7 +685,17 @@ def res_callback(reply):
@command()
def get_version(self):
major, minor = splash_version.split('.')
return int(major), int(minor)
return {
"major": int(major),
"minor": int(minor),
"splash": splash_version,
"qt": QT_VERSION_STR,
"pyqt": PYQT_VERSION_STR,
"webkit": str(qWebKitVersion()),
"sip": sip.SIP_VERSION_STR,
"twisted": twisted.version.short(),
"python": sys.version,
}

def _error_info_to_lua(self, error_info):
if error_info is None:
Expand Down
4 changes: 2 additions & 2 deletions splash/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2500,8 +2500,8 @@ class VersionTest(BaseLuaRenderTest):
def test_version(self):
resp = self.request_lua("""
function main(splash)
local major, minor = splash:get_version()
return major .. '.' .. minor
local version = splash:get_version()
return version.major .. '.' .. version.minor
end
""")
self.assertStatusCode(resp, 200)
Expand Down

0 comments on commit 3d131ea

Please sign in to comment.