from __future__ import print_function

import os
import re


def glowscript_version():
    """
    Extract the Glowscript version from the javascript in the data directory.
    """
    data_name = 'data'
    glowscript_name = 'glow.2.1.min.js'
    this_dir = os.path.dirname(os.path.abspath(__file__))
    data_dir = os.path.join(this_dir, data_name)

    with open(os.path.join(data_dir, glowscript_name)) as f:
        contents = f.read()

    # Use the non-greedy form of "+" below to ensure we get the shortest
    # possible match.
    result = re.search('var glowscript=\{version:"(.+?)"\}', contents)
    if result:
        gs_version = result.group(1)
    else:
        raise RuntimeError("Could not determine glowscript version.")

    return gs_version

@@ -42,16 +42,38 @@
 port os%0A
+from glob import glob%0A
 import r
@@ -223,48 +223,9 @@
 ta'%0A
-    glowscript_name = 'glow.2.1.min.js'
 %0A
+
     
@@ -336,17 +336,30 @@
     
-with open
+glowscript_file = glob
 (os.
@@ -382,59 +382,67 @@
 ir, 
-glowscript_name)) as f:%0A        contents = f.read()
+'glow.*.min.js'))%0A%0A    glowscript_name = glowscript_file%5B0%5D
 %0A%0A  
@@ -562,53 +562,46 @@
 ch('
-var glowscript=%5C%7Bversion:%22(.+?)%22%5C%7D', contents
+glow%5C.(.+?)%5C.min%5C.js', glowscript_name
 )%0A  

Determine glowscript version from file name