def handle(self, **options):

        if not options["watch"] and not options["initial_scan"]:
            sys.exit("--no-initial-scan option should be used with --watch.")

        scanned_dirs = get_scanned_dirs()

        verbosity = int(options["verbosity"])

        compilers = utils.get_compilers().values()

        if not options["watch"] or options["initial_scan"]:
            # Scan the watched directories and compile everything
            for scanned_dir in scanned_dirs:
                for dirname, dirnames, filenames in os.walk(scanned_dir):
                    for filename in filenames:
                        path = os.path.join(dirname,
                                            filename)[len(scanned_dir):]
                        if path.startswith("/"):
                            path = path[1:]
                        for compiler in compilers:
                            if compiler.is_supported(path):
                                try:
                                    compiler.handle_changed_file(
                                        path, verbosity=verbosity)
                                except (exceptions.StaticCompilationError,
                                        ValueError) as e:
                                    print(e)
                                break

        if options["watch"]:
            from static_precompiler.watch import watch_dirs
            watch_dirs(scanned_dirs, verbosity)
    def handle(self, **options):

        if not options["watch"] and not options["initial_scan"]:
            sys.exit("--no-initial-scan option should be used with --watch.")

        scanned_dirs = get_scanned_dirs()
        verbosity = int(options["verbosity"])
        compilers = utils.get_compilers().values()

        if not options["watch"] or options["initial_scan"]:
            # Scan the watched directories and compile everything
            for path in sorted(set(list_files(scanned_dirs))):
                for compiler in compilers:
                    if compiler.is_supported(path):
                        break
                else:
                    compiler = None

                if not compiler:
                    continue

                try:
                    compiler.handle_changed_file(path, verbosity=verbosity)
                except (exceptions.StaticCompilationError, ValueError) as e:
                    print(e)

        if options["watch"]:
            from static_precompiler.watch import watch_dirs
            watch_dirs(scanned_dirs, verbosity)
예제 #3
0
    def handle_noargs(self, **options):

        print "Watching '{0}' for changes.\nPress Control+C to exit.\n".format(
            STATIC_ROOT)

        verbosity = int(options["verbosity"])

        compilers = get_compilers()

        # Scan the root folder and compile everything
        for dirname, dirnames, filenames in os.walk(STATIC_ROOT):
            for filename in filenames:
                path = os.path.join(dirname, filename)[len(STATIC_ROOT):]
                if path.startswith("/"):
                    path = path[1:]
                for compiler in compilers:
                    if compiler.is_supported(path):
                        compiler.handle_changed_file(path)
                        break

        observer = Observer()
        observer.schedule(EventHandler(verbosity, compilers),
                          path=STATIC_ROOT,
                          recursive=True)
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()
    def handle_noargs(self, **options):

        print "Watching '{0}' for changes.\nPress Control+C to exit.\n".format(STATIC_ROOT)

        verbosity = int(options["verbosity"])

        compilers = get_compilers()

        # Scan the root folder and compile everything
        for dirname, dirnames, filenames in os.walk(STATIC_ROOT):
            for filename in filenames:
                path = os.path.join(dirname, filename)[len(STATIC_ROOT):]
                if path.startswith("/"):
                    path = path[1:]
                for compiler in compilers:
                    if compiler.is_supported(path):
                        compiler.handle_changed_file(path)
                        break

        observer = Observer()
        observer.schedule(EventHandler(verbosity, compilers), path=STATIC_ROOT, recursive=True)
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()
예제 #5
0
    def handle_noargs(self, **options):

        if not options["watch"] and not options["initial_scan"]:
            sys.exit("--no-initial-scan option should be used with --watch.")

        scanned_dirs = get_scanned_dirs()

        verbosity = int(options["verbosity"])

        compilers = utils.get_compilers().values()

        if not options["watch"] or options["initial_scan"]:
            # Scan the watched directories and compile everything
            for scanned_dir in scanned_dirs:
                for dirname, dirnames, filenames in os.walk(scanned_dir):
                    for filename in filenames:
                        path = os.path.join(dirname, filename)[len(scanned_dir):]
                        if path.startswith("/"):
                            path = path[1:]
                        for compiler in compilers:
                            if compiler.is_supported(path):
                                try:
                                    compiler.handle_changed_file(path, verbosity=options["verbosity"])
                                except (exceptions.StaticCompilationError, ValueError) as e:
                                    print(e)
                                break

        if options["watch"]:
            from static_precompiler.watch import watch_dirs
            watch_dirs(scanned_dirs, verbosity)
예제 #6
0
    def test_get_compilers(self):
        with patch("static_precompiler.utils.COMPILERS", ["invalid_classpath"]):
            self.assertRaises(ImproperlyConfigured, get_compilers)

        with patch("static_precompiler.utils.COMPILERS", ["non_existing_module.ClassName"]):
            self.assertRaises(ImproperlyConfigured, get_compilers)

        with patch("static_precompiler.utils.COMPILERS", ["static_precompiler.NonExistingClass"]):
            self.assertRaises(ImproperlyConfigured, get_compilers)

        with patch("static_precompiler.utils.COMPILERS", ["static_precompiler.compilers.CoffeeScript"]):
            compilers = get_compilers()
            self.assertEqual(len(compilers), 1)
            self.assertTrue(isinstance(compilers[0], CoffeeScript))
예제 #7
0
    def handle_noargs(self, **options):

        if not options["watch"] and not options["initial_scan"]:
            sys.exit("--no-initial-scan option should be used with --watch.")

        scanned_dirs = get_scanned_dirs()

        verbosity = int(options["verbosity"])

        compilers = get_compilers()

        if not options["watch"] or options["initial_scan"]:
            # Scan the watched directories and compile everything
            for scanned_dir in scanned_dirs:
                for dirname, dirnames, filenames in os.walk(scanned_dir):
                    for filename in filenames:
                        path = os.path.join(dirname,
                                            filename)[len(scanned_dir):]
                        if path.startswith("/"):
                            path = path[1:]
                        for compiler in compilers:
                            if compiler.is_supported(path):
                                try:
                                    compiler.handle_changed_file(path)
                                except (StaticCompilationError,
                                        ValueError) as e:
                                    print(e)
                                break

        if options["watch"]:
            print("Watching directories:")
            for scanned_dir in scanned_dirs:
                print(scanned_dir)
            print("\nPress Control+C to exit.\n")

            observer = Observer()

            for scanned_dir in scanned_dirs:
                handler = EventHandler(scanned_dir, verbosity, compilers)
                observer.schedule(handler, path=scanned_dir, recursive=True)

            observer.start()

            try:
                while True:
                    time.sleep(1)
            except KeyboardInterrupt:
                observer.stop()

            observer.join()
    def handle_noargs(self, **options):

        if not options["watch"] and not options["initial_scan"]:
            sys.exit("--no-initial-scan option should be used with --watch.")

        scanned_dirs = get_scanned_dirs()

        verbosity = int(options["verbosity"])

        compilers = get_compilers()

        if not options["watch"] or options["initial_scan"]:
            # Scan the watched directories and compile everything
            for scanned_dir in scanned_dirs:
                for dirname, dirnames, filenames in os.walk(scanned_dir):
                    for filename in filenames:
                        path = os.path.join(dirname, filename)[len(scanned_dir):]
                        if path.startswith("/"):
                            path = path[1:]
                        for compiler in compilers:
                            if compiler.is_supported(path):
                                try:
                                    compiler.handle_changed_file(path)
                                except (StaticCompilationError, ValueError) as e:
                                    print(e)
                                break

        if options["watch"]:
            print("Watching directories:")
            for scanned_dir in scanned_dirs:
                print(scanned_dir)
            print("\nPress Control+C to exit.\n")

            observer = Observer()

            for scanned_dir in scanned_dirs:
                handler = EventHandler(scanned_dir, verbosity, compilers)
                observer.schedule(handler, path=scanned_dir, recursive=True)

            observer.start()

            try:
                while True:
                    time.sleep(1)
            except KeyboardInterrupt:
                observer.stop()

            observer.join()
예제 #9
0
    def test_get_compilers(self):
        with patch("static_precompiler.utils.COMPILERS",
                   ["invalid_classpath"]):
            self.assertRaises(ImproperlyConfigured, get_compilers)

        with patch("static_precompiler.utils.COMPILERS",
                   ["non_existing_module.ClassName"]):
            self.assertRaises(ImproperlyConfigured, get_compilers)

        with patch("static_precompiler.utils.COMPILERS",
                   ["static_precompiler.NonExistingClass"]):
            self.assertRaises(ImproperlyConfigured, get_compilers)

        with patch("static_precompiler.utils.COMPILERS",
                   ["static_precompiler.compilers.CoffeeScript"]):
            compilers = get_compilers()
            self.assertEqual(len(compilers), 1)
            self.assertTrue(CoffeeScript.name in compilers)
            self.assertTrue(
                isinstance(compilers[CoffeeScript.name], CoffeeScript))
    def handle_noargs(self, **options):

        print "Watching '{0}' for changes.\nPress Control+C to exit.\n".format(STATIC_ROOT)

        verbosity = int(options["verbosity"])

        compilers = get_compilers()

        # Scan the root folder and compile everything
        for dirname, dirnames, filenames in os.walk(STATIC_ROOT):
            for filename in filenames:
                path = os.path.join(dirname, filename)[len(STATIC_ROOT):]
                if path.startswith("/"):
                    path = path[1:]
                for compiler in compilers:
                    if compiler.is_supported(path):
                        try:
                            compiler.handle_changed_file(path)
                        except (StaticCompilationError, ValueError), e:
                            print e
                        break
예제 #11
0
def watch_dirs(scanned_dirs, verbosity):
    print("Watching directories:")
    for scanned_dir in scanned_dirs:
        print(scanned_dir)
    print("\nPress Control+C to exit.\n")

    compilers = utils.get_compilers().values()
    observer = observers.Observer()

    for scanned_dir in scanned_dirs:
        handler = EventHandler(scanned_dir, verbosity, compilers)
        observer.schedule(handler, path=scanned_dir, recursive=True)

    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()
예제 #12
0
def watch_dirs(scanned_dirs, verbosity):
    print("Watching directories:")
    for scanned_dir in scanned_dirs:
        print(scanned_dir)
    print("\nPress Control+C to exit.\n")

    compilers = utils.get_compilers().values()
    observer = observers.Observer()

    for scanned_dir in scanned_dirs:
        handler = EventHandler(scanned_dir, verbosity, compilers)
        observer.schedule(handler, path=scanned_dir, recursive=True)

    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()
예제 #13
0
    def handle_noargs(self, **options):

        print "Watching '{0}' for changes.\nPress Control+C to exit.\n".format(
            STATIC_ROOT)

        verbosity = int(options["verbosity"])

        compilers = get_compilers()

        # Scan the root folder and compile everything
        for dirname, dirnames, filenames in os.walk(STATIC_ROOT):
            for filename in filenames:
                path = os.path.join(dirname, filename)[len(STATIC_ROOT):]
                if path.startswith("/"):
                    path = path[1:]
                for compiler in compilers:
                    if compiler.is_supported(path):
                        try:
                            compiler.handle_changed_file(path)
                        except (StaticCompilationError, ValueError), e:
                            print e
                        break