示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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')
示例#4
0
 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)
示例#5
0
 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')
示例#6
0
 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)