Пример #1
0
def start_env(basedir):
    """
    Init all needed stuff for handler testing
    """
    join_basedir_curry = join_basedir(basedir.strpath)

    inspector = ScssInspector()

    minimal_conf = {
        'SOURCES_PATH': basedir.join('sass').strpath,
        'TARGET_PATH': basedir.join('css').strpath,
        'LIBRARY_PATHS': [basedir.join('lib').strpath],
    }
    settings = Settings(initial=minimal_conf)

    watcher_opts = {
        'patterns': ['*.scss'],
        'ignore_patterns': ['*.part'],
        'ignore_directories': False,
        'case_sensitive': True,
    }
    return join_basedir_curry, inspector, settings, watcher_opts
Пример #2
0
def inspector():
    """Initialize and return SCSS inspector (scope at function level)"""
    return ScssInspector()
Пример #3
0
def watch_command(context, backend, config, poll):
    """
    Watch for change on your Sass project sources then compile them to CSS.

    Watched events are:

    \b
    * Create: when a new source file is created;
    * Change: when a source is changed;
    * Delete: when a source is deleted;
    * Move: When a source file is moved in watched dirs. Also occurs with
      editor transition file;

    Almost all errors occurring during compile won't break watcher, so you can
    resolve them and watcher will try again to compile once a new event
    occurs.

    You can stop watcher using key combo "CTRL+C" (or CMD+C on MacOSX).
    """
    logger = logging.getLogger("boussole")
    logger.info("Watching project")

    # Discover settings file
    try:
        discovering = Discover(
            backends=[SettingsBackendJson, SettingsBackendYaml])
        config_filepath, config_engine = discovering.search(
            filepath=config, basedir=os.getcwd(), kind=backend)

        project = ProjectBase(backend_name=config_engine._kind_name)
        settings = project.backend_engine.load(filepath=config_filepath)
    except BoussoleBaseException as e:
        logger.critical(six.text_type(e))
        raise click.Abort()

    logger.debug(u"Settings file: {} ({})".format(config_filepath,
                                                  config_engine._kind_name))
    logger.debug(u"Project sources directory: {}".format(
        settings.SOURCES_PATH))
    logger.debug(u"Project destination directory: {}".format(
        settings.TARGET_PATH))
    logger.debug(u"Exclude patterns: {}".format(settings.EXCLUDES))

    # Watcher settings
    watcher_templates_patterns = {
        'patterns': ['*.scss'],
        'ignore_patterns': ['*.part'],
        'ignore_directories': False,
        'case_sensitive': True,
    }

    # Init inspector instance shared through all handlers
    inspector = ScssInspector()

    if not poll:
        logger.debug(u"Using Watchdog native platform observer")
        observer = Observer()
    else:
        logger.debug(u"Using Watchdog polling observer")
        observer = PollingObserver()

    # Init event handlers
    project_handler = WatchdogProjectEventHandler(settings, inspector,
                                                  **watcher_templates_patterns)

    lib_handler = WatchdogLibraryEventHandler(settings, inspector,
                                              **watcher_templates_patterns)

    # Observe source directory
    observer.schedule(project_handler, settings.SOURCES_PATH, recursive=True)

    # Also observe libraries directories
    for libpath in settings.LIBRARY_PATHS:
        observer.schedule(lib_handler, libpath, recursive=True)

    # Start watching
    logger.warning(u"Launching the watcher, use CTRL+C to stop it")
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        logger.warning(u"CTRL+C used, stopping..")
        observer.stop()

    observer.join()
Пример #4
0
def watch_command(context, config):
    """
    Watch for change on your SASS project sources then compile them to CSS.

    Watched events are:

    \b
    * Create: when a new source file is created;
    * Change: when a source is changed;
    * Delete: when a source is deleted;
    * Move: When a source file is moved;

    Almost all errors occurring during compile won't break watcher, so you can
    resolve them and watcher will try again to compile once an a new event
    occurs.

    You can stop watcher using key combo "CTRL+C" (or CMD+C on MacOSX).
    """
    logger = context.obj['logger']
    logger.info("Watching project")

    # Load settings file
    try:
        backend = SettingsBackendJson(basedir=os.getcwd())
        settings = backend.load(filepath=config)
    except SettingsBackendError as e:
        logger.critical(e.message)
        raise click.Abort()

    logger.debug("Project sources directory: {}".format(settings.SOURCES_PATH))
    logger.debug("Project destination directory: {}".format(
        settings.TARGET_PATH))
    logger.debug("Exclude patterns: {}".format(settings.EXCLUDES))

    # Watcher settings
    watcher_templates_patterns = {
        'patterns': ['*.scss'],
        'ignore_patterns': ['*.part'],
        'ignore_directories': False,
        'case_sensitive': True,
    }

    # Init inspector instance shared through all handlers
    inspector = ScssInspector()

    # Registering event handlers to observer
    observer = Observer()
    project_handler = WatchdogProjectEventHandler(settings, logger, inspector,
                                                  **watcher_templates_patterns)

    lib_handler = WatchdogLibraryEventHandler(settings, logger, inspector,
                                              **watcher_templates_patterns)

    # Observe source directory
    observer.schedule(project_handler, settings.SOURCES_PATH, recursive=True)

    # Also observe libraries directories
    for libpath in settings.LIBRARY_PATHS:
        observer.schedule(lib_handler, libpath, recursive=True)

    # Start watching
    logger.warning("Launching the watcher, use CTRL+C to stop it")
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        logger.warning("CTRL+C used, stopping..")
        observer.stop()

    observer.join()
Пример #5
0
def inspector():
    """Initialize and return SCSS inspector"""
    return ScssInspector()