示例#1
0
def s3_include_debug():
    """
    Generates html to include:
        the js scripts listed in ../static/scripts/tools/sahana.js.cfg
        the css listed in ../static/scripts/tools/sahana.css.cfg
    """
    # Disable printing
    class dummyStream:
        """ dummyStream behaves like a stream but does nothing. """
        def __init__(self): pass
        def write(self,data): pass
        def read(self,data): pass
        def flush(self): pass
        def close(self): pass
    save_stdout = sys.stdout    
    # redirect all print deals
    sys.stdout = dummyStream()
    
    scripts_dir_path = "applications/%s/static/scripts" % request.application

    # Get list of script files
    sys.path.append( "%s/tools" % scripts_dir_path)    
    import mergejs    

    configDictCore = {
        "web2py": scripts_dir_path,
        "T2":     scripts_dir_path,
        "S3":     scripts_dir_path
    }
    configFilename = "%s/tools/sahana.js.cfg"  % scripts_dir_path
    (fs, files) = mergejs.getFiles(configDictCore, configFilename)
    
    # Enable print
    sys.stdout = save_stdout
    
    include = ""
    for file in files:
        include = '%s\n<script src="/%s/static/scripts/%s" type="text/javascript"></script>' \
            % ( include,
                request.application,
                file)

    include = "%s\n <!-- CSS Syles -->" % include            
    f = open("%s/tools/sahana.css.cfg" % scripts_dir_path, "r")
    files = f.readlines()
    for file in files[:-1]:
        include = '%s\n<link href="/%s/static/styles/%s" rel="stylesheet" type="text/css" />' \
            % ( include, 
                request.application,
                file[:-1]
               )
    f.close()

    return XML(include)
示例#2
0
def dojs(dogis = False):
    """ Minifies the js"""
    # Define which files we want to include
    # also need to amend sahana.js.cfg
    configDictCore = {
        "web2py":                       "..",
        "T2":                           "..",
        "S3":                           ".."
    }


    configFilename = "sahana.js.cfg"
    outputFilename = "S3.min.js"

    # Merge JS files
    print "Merging Core libraries."
    (files, order) = mergejs.getFiles(configDictCore, configFilename)
    merged = mergejs.run(files, order)

    # Compress JS files
    print "Compressing - JS"
    minimized = jsmin.jsmin(merged)

    # Add license
    print "Adding license file."
    minimized = file("license.txt").read() + minimized

    # Print to output files
    print "Writing to %s." % outputFilename
    file(outputFilename, "w").write(minimized)

    # Remove old JS files
    print "Deleting %s." % outputFilename
    try:
        os.remove("../S3/%s" % outputFilename)
    except:
        pass

    # Move new JS files
    print "Moving new JS files"
    shutil.move("S3.min.js", "../S3")

    if dogis:

        # also need to amend sahana.js.gis.cfg
        configDictGIS = {
            "gis":                          ".."
        }
        configDictGeoExt = {
            "GeoExt.js":                "../gis/GeoExt/lib",
            "GeoExt":                   "../gis/GeoExt/lib",
            "ux":                       "../gis/GeoExt"
        }
        configDictOpenLayers = {
            "OpenLayers.js":                "../gis/openlayers/lib",
            "OpenLayers":                   "../gis/openlayers/lib",
            "Rico":                         "../gis/openlayers/lib",
            "Gears":                        "../gis/openlayers/lib"
        }
        configDictGlobalGIS = {}
        configDictGlobalGIS.update(configDictOpenLayers)
        configDictGlobalGIS.update(configDictGIS)
        configFilenameGIS = "sahana.js.gis.cfg"
        configFilenameGeoExt = "geoext.js.gis.cfg"
        outputFilenameGIS = "OpenLayers.js"
        outputFilenameGeoExt = "GeoExt.js"
        
        # Merge GIS JS Files
        print "Merging GIS libraries."
        (files, order) = mergejs.getFiles(configDictGlobalGIS, configFilenameGIS)
        mergedGIS = mergejs.run(files, order)

        print "Merging GeoExt libraries."
        (files, order) = mergejs.getFiles(configDictGeoExt, configFilenameGeoExt)
        mergedGeoExt = mergejs.run(files, order)

        # Compress JS files
        print "Compressing - GIS JS"
        minimizedGIS = jsmin.jsmin(mergedGIS)

        print "Compressing - GeoExt JS"
        minimizedGeoExt = jsmin.jsmin(mergedGeoExt)

        # Add license
        minimizedGIS = file("license.gis.txt").read() + minimizedGIS

        # Print to output files
        print "Writing to %s." % outputFilenameGIS
        file(outputFilenameGIS, "w").write(minimizedGIS)

        print "Writing to %s." % outputFilenameGeoExt
        file(outputFilenameGeoExt, "w").write(minimizedGeoExt)

        # Move new JS files
        print "Deleting %s." % outputFilenameGIS
        try:
            os.remove("../gis/%s" % outputFilenameGIS)
        except:
            pass
        print "Moving new GIS JS files"
        shutil.move("OpenLayers.js", "../gis")
        
        print "Deleting %s." % outputFilenameGeoExt
        try:
            os.remove("../gis/%s" % outputFilenameGeoExt)
        except:
            pass
        print "Moving new GeoExt JS files"
        shutil.move("GeoExt.js", "../gis")
示例#3
0
def s3_include_debug():
    """
    Generates html to include:
        the js scripts listed in ../static/scripts/tools/sahana.js.cfg
        the css listed in ../static/scripts/tools/sahana.css.cfg
    """

    # Disable printing
    class dummyStream:
        """ dummyStream behaves like a stream but does nothing. """
        def __init__(self):
            pass

        def write(self, data):
            pass

        def read(self, data):
            pass

        def flush(self):
            pass

        def close(self):
            pass

    save_stdout = sys.stdout
    # redirect all print deals
    sys.stdout = dummyStream()

    scripts_dir_path = "applications/%s/static/scripts" % request.application

    # Get list of script files
    sys.path.append("%s/tools" % scripts_dir_path)
    import mergejs

    configDictCore = {
        "web2py": scripts_dir_path,
        "T2": scripts_dir_path,
        "S3": scripts_dir_path
    }
    configFilename = "%s/tools/sahana.js.cfg" % scripts_dir_path
    (fs, files) = mergejs.getFiles(configDictCore, configFilename)

    # Enable print
    sys.stdout = save_stdout

    include = ""
    for file in files:
        include = '%s\n<script src="/%s/static/scripts/%s" type="text/javascript"></script>' \
            % ( include,
                request.application,
                file)

    include = "%s\n <!-- CSS Syles -->" % include
    f = open("%s/tools/sahana.css.cfg" % scripts_dir_path, "r")
    files = f.readlines()
    for file in files[:-1]:
        include = '%s\n<link href="/%s/static/styles/%s" rel="stylesheet" type="text/css" />' \
            % ( include,
                request.application,
                file[:-1]
               )
    f.close()

    return XML(include)
示例#4
0
    if o in ("-o", "--output"):
        outputFilename = a
    if o in ("-d", "--debug"):
        debug = True
    if o in ("-m", "--mfonly"):
        mfOnly = True

#
# Get file list
#

configDictGlobal = {}
configDictGlobal.update(configDictOpenLayers)
configDictGlobal.update(configDictMapFish)

(files, order) = mergejs.getFiles(configDictGlobal, configFilename)

# rebuild the file list and order list, based on whether a MapFish-only
# build is to be done or not
if not mfOnly:
    newfiles = files
    neworder = order
else:
    newfiles = {}
    neworder = []
    for f in files:
        keep = False
        for k in configDictMapFish:
            if f.startswith(k):
                keep = True
                break
示例#5
0
def dojs(dogis=False):
    """ Minifies the js"""
    # Define which files we want to include
    # also need to amend sahana.js.cfg
    configDictCore = {"web2py": "..", "T2": "..", "S3": ".."}

    configFilename = "sahana.js.cfg"
    outputFilename = "S3.min.js"

    # Merge JS files
    print "Merging Core libraries."
    (files, order) = mergejs.getFiles(configDictCore, configFilename)
    merged = mergejs.run(files, order)

    # Compress JS files
    print "Compressing - JS"
    minimized = jsmin.jsmin(merged)

    # Add license
    print "Adding license file."
    minimized = file("license.txt").read() + minimized

    # Print to output files
    print "Writing to %s." % outputFilename
    file(outputFilename, "w").write(minimized)

    # Remove old JS files
    print "Deleting %s." % outputFilename
    try:
        os.remove("../S3/%s" % outputFilename)
    except:
        pass

    # Move new JS files
    print "Moving new JS files"
    shutil.move("S3.min.js", "../S3")

    if dogis:

        # also need to amend sahana.js.gis.cfg
        configDictGIS = {"gis": ".."}
        configDictGeoExt = {
            "GeoExt.js": "../gis/geoext/lib",
            "GeoExt": "../gis/geoext/lib",
            "ux": "../gis/geoext"
        }
        configDictOpenLayers = {
            "OpenLayers.js": "../gis/openlayers/lib",
            "OpenLayers": "../gis/openlayers/lib",
            "Rico": "../gis/openlayers/lib",
            "Gears": "../gis/openlayers/lib"
        }
        configDictGlobalGIS = {}
        configDictGlobalGIS.update(configDictOpenLayers)
        configDictGlobalGIS.update(configDictGIS)
        configFilenameGIS = "sahana.js.gis.cfg"
        configFilenameGeoExt = "geoext.js.gis.cfg"
        outputFilenameGIS = "OpenLayers.js"
        outputFilenameGeoExt = "GeoExt.js"

        # Merge GIS JS Files
        print "Merging GIS libraries."
        (files, order) = mergejs.getFiles(configDictGlobalGIS,
                                          configFilenameGIS)
        mergedGIS = mergejs.run(files, order)

        print "Merging GeoExt libraries."
        (files, order) = mergejs.getFiles(configDictGeoExt,
                                          configFilenameGeoExt)
        mergedGeoExt = mergejs.run(files, order)

        # Compress JS files
        print "Compressing - GIS JS"
        minimizedGIS = jsmin.jsmin(mergedGIS)

        print "Compressing - GeoExt JS"
        minimizedGeoExt = jsmin.jsmin(mergedGeoExt)

        # Add license
        minimizedGIS = file("license.gis.txt").read() + minimizedGIS

        # Print to output files
        print "Writing to %s." % outputFilenameGIS
        file(outputFilenameGIS, "w").write(minimizedGIS)

        print "Writing to %s." % outputFilenameGeoExt
        file(outputFilenameGeoExt, "w").write(minimizedGeoExt)

        # Move new JS files
        print "Deleting %s." % outputFilenameGIS
        try:
            os.remove("../gis/%s" % outputFilenameGIS)
        except:
            pass
        print "Moving new GIS JS files"
        shutil.move("OpenLayers.js", "../gis")

        print "Deleting %s." % outputFilenameGeoExt
        try:
            os.remove("../gis/%s" % outputFilenameGeoExt)
        except:
            pass
        print "Moving new GeoExt JS files"
        shutil.move("GeoExt.js", "../gis")