def handle(self, *args, **options): force = options.get('force', False) download = True try: lib_path = utils.get_closure_path(interactive=False) print 'Closure library found at %s' % lib_path if force: print 'Removing as requested.' shutil.rmtree(lib_path) else: download = False except ImproperlyConfigured: pass if download: utils.get_closure_path(interactive=True) download = True try: jar_path = utils.get_compiler_jar(interactive=False) print 'Closure compiler found at %s' % jar_path if force: print 'Removing as requested.' shutil.rmtree(os.path.split(jar_path)[0]) else: download = False except ImproperlyConfigured: pass if download: utils.get_compiler_jar(interactive=True)
def handle(self, *args, **options): # TODO(andi): exclude goog namespace. It doesn't make sense to # calc dependencies for it. closure_path = utils.get_closure_path(interactive=True) depswriter = os.path.join(closure_path, 'closure', 'bin', 'build', 'depswriter.py') cmd = [sys.executable, depswriter] namespaces = getattr(settings, 'GOOG_JS_NAMESPACES', {}) if not args: print 'No namespace given. Available namespaces are %s.' % ', '.join(namespaces) for ns in args: data = namespaces.get(ns, None) if data is None: print 'Skipping unknown namespace %r' % ns cwd = os.path.join(utils.get_abspath(data['path']), "../") outfile = os.path.join(cwd, '%s/deps.js' % ns) this_cmd = cmd+['--root_with_prefix', '%s/ ../%s' % (ns, ns)] if data.get('use_goog', False): this_cmd.extend(['--root_with_prefix', '%s ../goog' % (os.path.join(closure_path, 'closure', 'goog'))]) if data.get('use_goog_third_party', False): this_cmd.extend(['--root_with_prefix', '%s ../goog' % (os.path.join(closure_path, 'third_party', 'closure', 'goog'))]) this_cmd = this_cmd+['--output_file', outfile] p = subprocess.Popen(this_cmd, cwd=cwd) p.wait() if not p.returncode: print '%s written.' % outfile else: print 'ERROR: Failed to genereated deps.js for namespace %s' % ns
def handle(self, *args, **options): # closure lib found? downloadinfo = False try: lib_path = utils.get_closure_path(interactive=False) sys.stdout.write('Closure library found at %s\n' % lib_path) except ImproperlyConfigured: sys.stderr.write( self.style.ERROR('Error: Closure library not found.\n')) downloadinfo = True # compiler jar found? try: jar_path = utils.get_compiler_jar(interactive=False) sys.stdout.write('Closure compiler found at %s\n' % jar_path) except ImproperlyConfigured: sys.stderr.write( self.style.ERROR('Error: Closure compiler not found.\n')) downloadinfo = True if downloadinfo: sys.stdout.write( ' -> Run "%s googdownload" to download missing dependencies.\n' % sys.argv[0]) # namespaces up to date? namespaces = getattr(settings, 'GOOG_JS_NAMESPACES', {}) comp_needed = False comp_time = utils.get_compiled_mtime() if not namespaces: sys.stdout.write('No namespaces found.\n') else: for ns in namespaces: if utils.get_ns_mtime(ns) > comp_time: sys.stderr.write( self.style.HTTP_NOT_FOUND( 'Namespace %s has changes.\n' % ns)) comp_needed = True # js files up to date? for js, data in getattr(settings, 'GOOG_JS_FILES', {}).iteritems(): infile = utils._get_infile(data) if os.stat(infile).st_mtime > comp_time: sys.stderr.write( self.style.HTTP_NOT_FOUND('JS file %s has changes.\n' % js)) if comp_needed: sys.stdout.write(' -> Run "%s googcompile" to compile.\n' % sys.argv[0]) else: sys.stdout.write('All compiled files are up-to-date.\n') # warning about used CSS files? css_files = getattr(settings, 'GOOG_DEV_CSS', []) if css_files: sys.stderr.write( self.style.HTTP_NOT_FOUND( 'You\'re using development CSS files: %s.\n' % ', '.join(css_files))) sys.stdout.write(' -> Merge them with your static CSS files.\n')
def handle(self, *args, **options): for path in getattr(settings, 'GOOG_DEV_CSS', []): if not path.endswith('.css'): path = '%s.css' % path relpath = os.path.join('closure', 'goog', 'css', path) path = os.path.join(utils.get_closure_path(), relpath) msg = '--- Contents from %s ---' % relpath print '/* ' + '-' * len(msg) + ' */' print '/* %s */' % msg print '/* ' + '-' * len(msg) + ' */' print with open(path) as r: print r.read()
def handle(self, *args, **options): # TODO(andi) Always run googdeps before? closure_path = utils.get_closure_path(interactive=True) goog_path = os.path.join(closure_path, 'closure', 'goog') goog_td_path = os.path.join(closure_path, 'third_party', 'closure', 'goog') compiler_jar = utils.get_compiler_jar(interactive=True) calcdeps = os.path.join(closure_path, 'closure', 'bin', 'calcdeps.py') cmd = [ sys.executable, calcdeps, '-o', 'compiled', '--compiler_jar', compiler_jar, ] for flag in getattr(settings, 'GOOG_COMPILER_FLAGS', ['--compilation_level=ADVANCED_OPTIMIZATIONS']): cmd.append('--compiler_flags=%s' % flag) for key, data in getattr(settings, 'GOOG_JS_EXTERNS', {}).iteritems(): full_path = utils.get_abspath(data.get('path', '')) if full_path is None: raise ImproperlyConfigured('Missing extern JS file: %r' % data) cmd.append('--compiler_flags=--externs=%s' % full_path) # add namespaces -p path goog_included = False goog_td_included = False for key, data in getattr(settings, 'GOOG_JS_NAMESPACES', {}).iteritems(): if not goog_included and data.get('use_goog', False): cmd.extend(['-p', goog_path]) goog_included = True if not goog_td_included and data.get('use_goog_third_party', False): cmd.extend(['-p', goog_td_path]) goog_td_included = True full_path = utils.abspath_for_namespace(data, key) cmd.extend(['-p', full_path]) # iterate files and compile them for key, data in getattr(settings, 'GOOG_JS_FILES', {}).iteritems(): infile = utils._get_infile(data) if infile is None: raise ImproperlyConfigured('Missing JS file: %r' % data) outfile = utils._get_outfile(infile, data) this_cmd = cmd + ['-i', infile] p = subprocess.Popen(this_cmd, stdout=subprocess.PIPE) stdout, stderr = p.communicate() with open(outfile, 'w') as f: f.write(stdout) print 'Compiled %s (%.3fkB)' % (outfile, len(stdout) / 1024.0)
def _serve_closure(request, path, prefixes): closure_path = utils.get_closure_path() full_path = None stat = None for prefix in prefixes: full_path = os.path.join(closure_path, prefix, path) try: stat = os.stat(full_path) break except OSError: pass if full_path is None or stat is None: return HttpResponseNotFound(path) return _serve_file(request, stat, path, full_path)
def handle(self, *args, **options): # closure lib found? downloadinfo = False try: lib_path = utils.get_closure_path(interactive=False) sys.stdout.write('Closure library found at %s\n' % lib_path) except ImproperlyConfigured: sys.stderr.write(self.style.ERROR('Error: Closure library not found.\n')) downloadinfo = True # compiler jar found? try: jar_path = utils.get_compiler_jar(interactive=False) sys.stdout.write('Closure compiler found at %s\n' % jar_path) except ImproperlyConfigured: sys.stderr.write(self.style.ERROR('Error: Closure compiler not found.\n')) downloadinfo = True if downloadinfo: sys.stdout.write(' -> Run "%s googdownload" to download missing dependencies.\n' % sys.argv[0]) # namespaces up to date? namespaces = getattr(settings, 'GOOG_JS_NAMESPACES', {}) comp_needed = False comp_time = utils.get_compiled_mtime() if not namespaces : sys.stdout.write('No namespaces found.\n') else: for ns in namespaces: if utils.get_ns_mtime(ns) > comp_time: sys.stderr.write(self.style.HTTP_NOT_FOUND('Namespace %s has changes.\n' % ns)) comp_needed = True # js files up to date? for js, data in getattr(settings, 'GOOG_JS_FILES', {}).iteritems(): infile = utils._get_infile(data) if os.stat(infile).st_mtime > comp_time: sys.stderr.write(self.style.HTTP_NOT_FOUND('JS file %s has changes.\n' % js)) if comp_needed: sys.stdout.write(' -> Run "%s googcompile" to compile.\n' % sys.argv[0]) else: sys.stdout.write('All compiled files are up-to-date.\n') # warning about used CSS files? css_files = getattr(settings, 'GOOG_DEV_CSS', []) if css_files: sys.stderr.write(self.style.HTTP_NOT_FOUND('You\'re using development CSS files: %s.\n' % ', '.join(css_files))) sys.stdout.write(' -> Merge them with your static CSS files.\n')
def handle(self, *args, **options): # TODO(andi) Always run googdeps before? closure_path = utils.get_closure_path(interactive=True) goog_path = os.path.join(closure_path, 'closure', 'goog') goog_td_path = os.path.join(closure_path, 'third_party', 'closure', 'goog') compiler_jar = utils.get_compiler_jar(interactive=True) calcdeps = os.path.join(closure_path, 'closure', 'bin', 'calcdeps.py') cmd = [sys.executable, calcdeps, '-o', 'compiled', '--compiler_jar', compiler_jar,] for flag in getattr(settings, 'GOOG_COMPILER_FLAGS', ['--compilation_level=ADVANCED_OPTIMIZATIONS']): cmd.append('--compiler_flags=%s' % flag) for key, data in getattr(settings, 'GOOG_JS_EXTERNS', {}).iteritems(): full_path = utils.get_abspath(data.get('path', '')) if full_path is None: raise ImproperlyConfigured('Missing extern JS file: %r' % data) cmd.append('--compiler_flags=--externs=%s' % full_path) # add namespaces -p path goog_included = False goog_td_included = False for key, data in getattr(settings, 'GOOG_JS_NAMESPACES', {}).iteritems(): if not goog_included and data.get('use_goog', False): cmd.extend(['-p', goog_path]) goog_included = True if not goog_td_included and data.get('use_goog_third_party', False): cmd.extend(['-p', goog_td_path]) goog_td_included = True full_path = utils.abspath_for_namespace(data, key) cmd.extend(['-p', full_path]) # iterate files and compile them for key, data in getattr(settings, 'GOOG_JS_FILES', {}).iteritems(): infile = utils._get_infile(data) if infile is None: raise ImproperlyConfigured('Missing JS file: %r' % data) outfile = utils._get_outfile(infile, data) this_cmd = cmd+['-i', infile] p = subprocess.Popen(this_cmd, stdout=subprocess.PIPE) stdout, stderr = p.communicate() with open(outfile, 'w') as f: f.write(stdout) print 'Compiled %s (%.3fkB)' % (outfile, len(stdout)/1024.0)
def handle(self, *args, **options): # TODO(andi): exclude goog namespace. It doesn't make sense to # calc dependencies for it. closure_path = utils.get_closure_path(interactive=True) depswriter = os.path.join(closure_path, 'closure', 'bin', 'build', 'depswriter.py') cmd = [sys.executable, depswriter] namespaces = getattr(settings, 'GOOG_JS_NAMESPACES', {}) if not args: print 'No namespace given. Available namespaces are %s.' % ', '.join( namespaces) for ns in args: data = namespaces.get(ns, None) if data is None: print 'Skipping unknown namespace %r' % ns cwd = os.path.join(utils.get_abspath(data['path']), "../") outfile = os.path.join(cwd, '%s/deps.js' % ns) this_cmd = cmd + ['--root_with_prefix', '%s/ ../%s' % (ns, ns)] if data.get('use_goog', False): this_cmd.extend([ '--root_with_prefix', '%s ../goog' % (os.path.join(closure_path, 'closure', 'goog')) ]) if data.get('use_goog_third_party', False): this_cmd.extend([ '--root_with_prefix', '%s ../goog' % (os.path.join(closure_path, 'third_party', 'closure', 'goog')) ]) this_cmd = this_cmd + ['--output_file', outfile] p = subprocess.Popen(this_cmd, cwd=cwd) p.wait() if not p.returncode: print '%s written.' % outfile else: print 'ERROR: Failed to genereated deps.js for namespace %s' % ns