示例#1
0
def copy_required_js_files():
    """Documentation"""
    generated_path = "%sgenerated/client/templates/" % loader.root_path()

    logging.info("Copying required files...")
    jsutil_file = "%s/../tools/closure-templates/soyutils_usegoog.js" % loader.root_path()
    logging.info("\t" + jsutil_file)
    shutil.copy(jsutil_file, generated_path)
示例#2
0
def prepare_generated_directory():
    """Documentation"""
    generated_path = "%sgenerated/client/templates/" % loader.root_path()
    try:
        shutil.rmtree(generated_path)
        os.makedirs(generated_path)
    except OSError:
        pass  # no such file or dir, dir already exists
示例#3
0
def calculate_test_deps(js_test_file_path):
    """
    Calculates the dependancy files for the test
    """
    logging.info(js_test_file_path)
    js = js_test_file_path.replace(loader.root_path(), "/") + ".js"
    css_deps, js_deps = calculate_deps(js_test_file_path.replace("_test", "_test.js"))

    return css_deps, ["/%s" % path for path in js_deps] + [js]
示例#4
0
    def run(self, build_path):
        files = [x for x in loader.locate("entrypoint.js")]
        css_deps, js_deps = calculate_deps(files[0])

        file = open("%s/%s" % (build_path, "generated/index.html"), "w")
        vars = {
            "entrypoint": loader._get_module_name(files[0]),
            "js_deps": ["/generated/client/compiled.js"],
            "css_deps": css_deps,
        }
        file.write(template.render("%stic/web/templates/index_compiled.html" % loader.root_path(), vars))
示例#5
0
 def _watch(self):
     """
     TODOC 
     """
     logging.info('Watching directry for changes...')
     def f(created, changed, removed):
         for f in created:
             logging.info('created:%s', f)
         for f in changed:
             logging.info('changed:%s', f)
         for f in removed:
             logging.info('removed:%s', f)
         return True
             
     watch_directories([loader.root_path()], f, 1)
示例#6
0
 def run(self):
   '''run '''
   directory_watcher = DirectoryWatcher(self.compmgr)
   directory_watcher.watch(loader.root_path())
示例#7
0
 def watch(self, path, delay=1):
     """
     starts watching the provided path
     """
     p = threading.Thread(target=watch_directories, args=([loader.root_path()],self.__watcher__,delay))
     p.start()
示例#8
0
def compile_soy_templates(templates=None):
    """
  Compiles the soy files
  TODO: cannot do this in appengine dev server since os.popen is not defined
  so a better approach would be to run a deamon that that monitors the file
  system and generates all needed stuff JIT
  """

    if templates == None:
        logging.info("Scanning for soy template files...")
        template_files = set()
        for template_file in loader.locate("*.soy"):
            template_files.add(template_file)
            logging.info(template_file)

        if not template_files:
            logging.info("No templates found.")
            return
    else:
        template_files = set(templates)

    if not template_files:
        return

    generated_path = "%sgenerated/client/templates/" % loader.root_path()
    SoyToJsSrcCompiler_path = "%s/../tools/closure-templates/SoyToJsSrcCompiler.jar" % loader.root_path()

    logging.info("Found %s template(s)" % len(template_files))

    logging.info("compiling ...")
    a = os.popen(
        "java -jar %(soy_to_js_compiler)s --outputPathFormat %(generated_path)s%(tmp)s{INPUT_DIRECTORY}{INPUT_FILE_NAME_NO_EXT}.js %(options)s %(templates)s"
        % {
            "soy_to_js_compiler": SoyToJsSrcCompiler_path,
            "generated_path": generated_path,
            "tmp": "tmp",
            "templates": " ".join(template_files),
            "options": " ".join(["--shouldGenerateJsdoc", "--shouldProvideRequireSoyNamespaces"]),
        }
    )
    if a.close():
        logging.info("Failed to compile... check error message")
        return

    #    logging.info('Generated files:')
    #    for fname in os.listdir(generated_path):
    #        logging.info('\t%s%s' % (generated_path, fname))

    #  src = '%stmp%s' % (generated_path, loader.root_path())
    #  for directory in os.listdir(src):
    #    shutil.move('%s%s' % (src,directory), generated_path)

    src_root = "%stmp" % generated_path
    for f in template_files:
        l = len(loader.root_path().split("/"))
        filename = "".join([".".join(f.split("/")[l - 1 :]).rstrip(".soy").strip("."), ".js"])
        src = "".join([src_root, f.rstrip(".soy"), ".js"])
        dst = "".join([generated_path, filename])
        logging.info(filename)
        logging.info(src)
        logging.info(dst)
        shutil.copy2(src, dst)

    #    shutil.move(directory, generated_path)

    shutil.rmtree("%stmp" % generated_path)

    logging.info("Done.")
    return template_files
示例#9
0
 def __init__(self):
     self.generated_path = "%sgenerated/client/closure/" % loader.root_path()
示例#10
0
import commands
import os
import logging
from tic import loader
from tic.core import Component, implements
from tic.development.admin.api import IAdminCommandProvider
from tic.development.tools.api import IRunServerTask

#TODO: Move to settings
NODE_EXECUTABLE = 'node'
NODE_SCRIPT = os.path.join(loader.root_path(),__name__.replace('.', '/'), 'main.js')
INSTRUMENTED_CODE_PATH = os.path.join(loader.root_path(), 'instrumented')

def generate_instrumented_file(js_file):
    logging.info('Generating instrumentation code for [%s]' % js_file)
    command = ' '.join([NODE_EXECUTABLE, NODE_SCRIPT, js_file])
    instrumented = commands.getoutput(command)
    
    destination, filename = os.path.join(INSTRUMENTED_CODE_PATH, 
                                     loader.get_relative_path(js_file)).rsplit('/',1)
    
    if not os.path.exists(destination):
        os.makedirs(destination)
    
    file = open(os.path.join(destination, filename), 'w')
    file.write(instrumented)
    file.close()
    logging.info('done...')

class CoverageCommand(Component):