Пример #1
0
        def process(package, output, dynamic):
            plugin = self.get_plugin(package.name)
            if dynamic:
                plugin_subdir = path("plugins")
                plugin_dir = output_dir / plugin_subdir
                if not plugin_dir.isdir():
                    plugin_dir.makedirs()
                plugin_filename = package.name + ".js"
                plugin_location = plugin_subdir / plugin_filename
                self._created_javascript.add(plugin_location)
                combine_output_path = plugin_dir / plugin_filename
                combine_output = combine_output_path.open("w")
            else:
                plugin_location = None
                combine_output = output

            combiner.write_metadata(output, plugin, plugin_location)

            combiner.combine_files(combine_output,
                                   css_file,
                                   plugin,
                                   plugin.location,
                                   exclude_tests=exclude_tests,
                                   image_path_prepend="resources/%s/" %
                                   plugin.name)
            if dynamic:
                combine_output.write("bespin.tiki.script(%s);" %
                                     dumps(plugin_filename))
Пример #2
0
        def process(package, output, dynamic):
            plugin = self.get_plugin(package.name)
            if dynamic:
                plugin_subdir = path("plugins")
                plugin_dir = output_dir / plugin_subdir
                if not plugin_dir.isdir():
                    plugin_dir.makedirs()
                plugin_filename = package.name + ".js"
                plugin_location = plugin_subdir / plugin_filename
                self._created_javascript.add(plugin_location)
                combine_output_path = plugin_dir / plugin_filename
                combine_output = combine_output_path.open("w")
            else:
                plugin_location = None
                combine_output = output

            combiner.write_metadata(output, plugin, plugin_location)
            
            combiner.combine_files(combine_output, css_file, plugin,
                                   plugin.location,
                                   exclude_tests=exclude_tests,
                                   image_path_prepend="resources/%s/"
                                                      % plugin.name)
            if dynamic:
                combine_output.write("bespin.tiki.script(%s);" %
                    dumps(plugin_filename))
Пример #3
0
def main(args=None):
    if args is None:
        args = sys.argv

    print "dryice: the Bespin build tool"
    parser = optparse.OptionParser(
        description="""Builds fast-loading JS and CSS packages.""")
    parser.add_option(
        "-j",
        "--jscompressor",
        dest="jscompressor",
        help="path to Closure Compiler to compress the JS output")
    parser.add_option("-c",
                      "--csscompressor",
                      dest="csscompressor",
                      help="path to YUI Compressor to compress the CSS output")
    parser.add_option(
        "-D",
        "--variable",
        dest="variables",
        action="append",
        help=
        "override values in the manifest (use format KEY=VALUE, where VALUE is JSON)"
    )
    parser.add_option(
        "-s",
        "--server",
        dest="server",
        help="starts a server on [address:]port. example: -s 8080")
    options, args = parser.parse_args(args)

    overrides = {}
    if options.variables:
        for setting in options.variables:
            key, value = setting.split("=")
            overrides[key] = loads(value)

    if len(args) > 1:
        filename = args[1]
    else:
        filename = "manifest.json"

    filename = path(filename)
    if not filename.exists():
        raise BuildError("Build manifest file (%s) does not exist" %
                         (filename))

    print "Using build manifest: ", filename

    if options.server:
        start_server(filename, options, overrides)
    else:
        do_build(filename, options, overrides)
Пример #4
0
 def compress_css(self, compressor):
     """Compress the CSS using YUI Compressor."""
     print "Compressing CSS with YUI Compressor"
     compressor = path(compressor).abspath()
     subprocess.call("java -jar %s"
         " --type css -o BespinEmbedded.compressed.css"
         " BespinEmbedded.css" % compressor, shell=True,
         cwd=self.output_dir)
     uncompressed = self.output_dir / "BespinEmbedded.css"
     compressed = self.output_dir / "BespinEmbedded.compressed.css"
     if not compressed.exists():
         raise BuildError("Unable to compress the css file at " + uncompressed)
     uncompressed.rename(self.output_dir / "BespinEmbedded.uncompressed.css")
     compressed.rename(uncompressed)
Пример #5
0
 def compress_css(self, compressor):
     """Compress the CSS using YUI Compressor."""
     print "Compressing CSS with YUI Compressor"
     compressor = path(compressor).abspath()
     subprocess.call("java -jar %s"
                     " --type css -o BespinEmbedded.compressed.css"
                     " BespinEmbedded.css" % compressor,
                     shell=True,
                     cwd=self.output_dir)
     uncompressed = self.output_dir / "BespinEmbedded.css"
     compressed = self.output_dir / "BespinEmbedded.compressed.css"
     if not compressed.exists():
         raise BuildError("Unable to compress the css file at " +
                          uncompressed)
     uncompressed.rename(self.output_dir /
                         "BespinEmbedded.uncompressed.css")
     compressed.rename(uncompressed)
Пример #6
0
    def _find_plugins(self):
        self._plugin_catalog = dict(
            (p.name, p) for p in plugins.find_plugins(self.search_path))

        if self.jquery == "global":
            self._plugin_catalog['jquery'] = plugins.Plugin(
                "jquery",
                path(__file__).dirname() / "globaljquery.js",
                dict(name="thirdparty"))

        errors = []

        worker_plugins = []

        for plugin in self.dynamic_plugins:
            try:
                plugin_obj = self.get_plugin(plugin)
            except KeyError:
                errors.append("Plugin %s not found" % plugin)
                continue

        # note that we need to copy self.plugins because
        # we're going to be removing items from the list
        for plugin in list(self.plugins):
            try:
                plugin_obj = self.get_plugin(plugin)
            except KeyError:
                errors.append("Plugin %s not found" % plugin)
                continue
            env = plugin_obj.metadata.get("environments")
            if not env:
                continue
            is_worker = env.get("worker", False)
            if is_worker:
                worker_plugins.append(plugin)
                is_main = env.get("main", False)
                if not is_main:
                    self.plugins.remove(plugin)

        self.worker_plugins = worker_plugins
        return errors
Пример #7
0
def main(args=None):
    if args is None:
        args = sys.argv

    print "dryice: the Bespin build tool"
    parser = optparse.OptionParser(
        description="""Builds fast-loading JS and CSS packages.""")
    parser.add_option("-j", "--jscompressor", dest="jscompressor",
        help="path to Closure Compiler to compress the JS output")
    parser.add_option("-c", "--csscompressor", dest="csscompressor",
        help="path to YUI Compressor to compress the CSS output")
    parser.add_option("-D", "--variable", dest="variables",
        action="append",
        help="override values in the manifest (use format KEY=VALUE, where VALUE is JSON)")
    parser.add_option("-s", "--server", dest="server",
        help="starts a server on [address:]port. example: -s 8080")
    options, args = parser.parse_args(args)

    overrides = {}
    if options.variables:
        for setting in options.variables:
            key, value = setting.split("=")
            overrides[key] = loads(value)

    if len(args) > 1:
        filename = args[1]
    else:
        filename = "manifest.json"

    filename = path(filename)
    if not filename.exists():
        raise BuildError("Build manifest file (%s) does not exist" % (filename))

    print "Using build manifest: ", filename
    
    if options.server:
        start_server(filename, options, overrides)
    else:
        do_build(filename, options, overrides)
Пример #8
0
    def _find_plugins(self):
        self._plugin_catalog = dict((p.name, p) for p in plugins.find_plugins(self.search_path))
        
        if self.jquery == "global":
            self._plugin_catalog['jquery'] = plugins.Plugin("jquery",
                path(__file__).dirname() / "globaljquery.js",
                dict(name="thirdparty"))

        errors = []
        
        worker_plugins = []
        
        for plugin in self.dynamic_plugins:
            try:
                plugin_obj = self.get_plugin(plugin)
            except KeyError:
                errors.append("Plugin %s not found" % plugin)
                continue
        
        # note that we need to copy self.plugins because
        # we're going to be removing items from the list
        for plugin in list(self.plugins):
            try:
                plugin_obj = self.get_plugin(plugin)
            except KeyError:
                errors.append("Plugin %s not found" % plugin)
                continue
            env = plugin_obj.metadata.get("environments")
            if not env:
                continue
            is_worker = env.get("worker", False)
            if is_worker:
                worker_plugins.append(plugin)
                is_main = env.get("main", False)
                if not is_main:
                    self.plugins.remove(plugin)
        
        self.worker_plugins = worker_plugins
        return errors
Пример #9
0
    def __init__(self,
                 include_tests=False,
                 plugins=None,
                 dynamic_plugins=None,
                 jquery="builtin",
                 search_path=None,
                 output_dir="build",
                 include_sample=False,
                 boot_file=None,
                 unbundled_plugins=None,
                 preamble=None,
                 loader=None,
                 worker=None,
                 config=None):

        if plugins is None:
            plugins = []

        if dynamic_plugins is None:
            dynamic_plugins = []

        self.include_tests = include_tests
        plugins.insert(0, "bespin")
        self.plugins = plugins
        self.dynamic_plugins = dynamic_plugins

        self.jquery = jquery

        if search_path is not None:
            for i in range(0, len(search_path)):
                name = search_path[i]

                # did we get handed a dict already?
                if not isinstance(name, basestring):
                    continue

                # convert to the dict format that is used by
                # the plugin module
                search_path[i] = dict(name=name, path=path(name))
        else:
            search_path = []

        # add the default plugin directory, if it exists
        plugindir = path("plugins")
        if plugindir.exists():
            for name in plugindir.glob("*"):
                if not name.isdir():
                    continue
                search_path.append(dict(name=name, path=name))

        self.search_path = search_path

        if boot_file:
            self.boot_file = path(boot_file).abspath()
        else:
            self.boot_file = _boot_file

        if not output_dir:
            raise BuildError("""Cannot run unless output_dir is set
(it defaults to 'build'). The contents of the output_dir directory
will be deleted before the build.""")
        self.output_dir = path(output_dir)

        self.include_sample = include_sample

        if unbundled_plugins:
            self.unbundled_plugins = path(unbundled_plugins).abspath()

        self.preamble = path(__file__).dirname() / "preamble.js"

        def location_of(file, default_location):
            if default_location is not None:
                return path(default_location)
            static_path = path("static") / file
            return static_path if static_path.exists() else path("lib") / file

        self.loader = location_of("tiki.js", loader)
        self.worker = location_of("BespinEmbedded.js", worker)

        # this is a bit hacky. Because of the way worker_manager works,
        # the server version of Bespin calls it "BespinEmbedded.js"
        # and the embedded customizable version has a script called
        # (more appropriately) worker.js
        # hopefully, this will clear up in the move to JavaScript tooling
        if not self.worker.exists():
            self.worker = path("lib") / "worker.js"

        self.config = config if config is not None else {}
        self._created_javascript = set()
        self._set_package_lists()
Пример #10
0
 def location_of(file, default_location):
     if default_location is not None:
         return path(default_location)
     static_path = path("static") / file
     return static_path if static_path.exists() else path("lib") / file
Пример #11
0
from dryice.path import path

from dryice import plugins, combiner


class BuildError(Exception):
    def __init__(self, message, errors=None):
        if errors:
            message += "\n"
            for e in errors:
                message += "* %s\n" % (e)
        Exception.__init__(self, message)


sample_dir = path(__file__).dirname() / "samples"
_boot_file = path(__file__).dirname() / "boot.js"
_script2loader = path(__file__).dirname() / "script2loader.js"


def ignore_css(src, names):
    return [name for name in names if name.endswith(".css")]


class Manifest(object):
    """A manifest describes what should be built."""

    unbundled_plugins = None

    def __init__(self,
                 include_tests=False,
Пример #12
0
    def __init__(self, include_tests=False, plugins=None,
        dynamic_plugins=None, jquery="builtin",
        search_path=None, output_dir="build", include_sample=False,
        boot_file=None, unbundled_plugins=None, preamble=None, loader=None,
        worker=None, config=None):
        
        if plugins is None:
            plugins = []
        
        if dynamic_plugins is None:
            dynamic_plugins = []

        self.include_tests = include_tests
        plugins.insert(0, "bespin")
        self.plugins = plugins
        self.dynamic_plugins = dynamic_plugins
        
        self.jquery = jquery

        if search_path is not None:
            for i in range(0, len(search_path)):
                name = search_path[i]

                # did we get handed a dict already?
                if not isinstance(name, basestring):
                    continue

                # convert to the dict format that is used by
                # the plugin module
                search_path[i] = dict(name=name, path=path(name))
        else:
            search_path = []

        # add the default plugin directory, if it exists
        plugindir = path("plugins")
        if plugindir.exists():
            for name in plugindir.glob("*"):
                if not name.isdir():
                    continue
                search_path.append(dict(name=name, path=name))

        self.search_path = search_path

        if boot_file:
            self.boot_file = path(boot_file).abspath()
        else:
            self.boot_file = _boot_file

        if not output_dir:
            raise BuildError("""Cannot run unless output_dir is set
(it defaults to 'build'). The contents of the output_dir directory
will be deleted before the build.""")
        self.output_dir = path(output_dir)

        self.include_sample = include_sample
        
        if unbundled_plugins:
            self.unbundled_plugins = path(unbundled_plugins).abspath()

        self.preamble = path(__file__).dirname() / "preamble.js"

        def location_of(file, default_location):
            if default_location is not None:
                return path(default_location)
            static_path = path("static") / file
            return static_path if static_path.exists() else path("lib") / file

        self.loader = location_of("tiki.js", loader)
        self.worker = location_of("BespinEmbedded.js", worker)
        
        # this is a bit hacky. Because of the way worker_manager works,
        # the server version of Bespin calls it "BespinEmbedded.js"
        # and the embedded customizable version has a script called
        # (more appropriately) worker.js
        # hopefully, this will clear up in the move to JavaScript tooling
        if not self.worker.exists():
            self.worker = path("lib") / "worker.js"
        
        self.config = config if config is not None else {}
        self._created_javascript = set()
        self._set_package_lists()
Пример #13
0
 def location_of(file, default_location):
     if default_location is not None:
         return path(default_location)
     static_path = path("static") / file
     return static_path if static_path.exists() else path("lib") / file
Пример #14
0
    from simplejson import loads, dumps

from dryice.path import path

from dryice import plugins, combiner

class BuildError(Exception):
    def __init__(self, message, errors=None):
        if errors:
            message += "\n"
            for e in errors:
                message += "* %s\n" % (e)
        Exception.__init__(self, message)
                

sample_dir = path(__file__).dirname() / "samples"
_boot_file = path(__file__).dirname() / "boot.js"
_script2loader = path(__file__).dirname() / "script2loader.js"

def ignore_css(src, names):
    return [name for name in names if name.endswith(".css")]

class Manifest(object):
    """A manifest describes what should be built."""
    
    unbundled_plugins = None
    
    def __init__(self, include_tests=False, plugins=None,
        dynamic_plugins=None, jquery="builtin",
        search_path=None, output_dir="build", include_sample=False,
        boot_file=None, unbundled_plugins=None, preamble=None, loader=None,
Пример #15
0
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

from cStringIO import StringIO
import codecs

from dryice import tool
from dryice.path import path

plugindir = path(__file__).dirname() / "plugindir"
pluginpath = [dict(name="pl", path=plugindir)]

def test_manifest_creation():
    sample = """
    {
        "include_tests": true,
        "plugins": ["text_editor"]
    }
"""
    manifest = tool.Manifest.from_json(sample)
    assert manifest.include_tests
    errors = manifest.errors
    assert errors == []

def test_manifest_overrides():