示例#1
0
def index_processor(config, source_path, target_path):
    config = configurate(source_path, config)
    categories_name = config['name']

    folder_config = config.copy()
    folder_config['target_name'] = categories_name
    folder_config['name'] = categories_name
    folder_config['type'] = config['default_folder_type']
    folder = build_node(folder_config, os.path.dirname(source_path),
                        target_path, categories_name)[0]
    categories_folder_target_path = os.path.join(target_path, categories_name)

    config['dont_inherit'] = [
        key for key in config['dont_inherit'] if key != 'title'
    ]
    index_config = config.copy()
    index_config['target_name'] = config['index.html']
    index_config['name'] = 'index'
    configurate(os.path.join(source_path, config['index.html']), index_config)
    index_node = JinjaNode(index_config, source_path,
                           categories_folder_target_path)
    folder.append(index_node)
    CategoryDetail.index_node = index_node

    # attach Processor node - this is the class that will scan the pages for
    # the `category` property:
    folder.append(
        CategoryFolderProcesser(config, categories_folder_target_path))
    return (folder, )
示例#2
0
文件: main.py 项目: dmr/StrangeCase
def strange_case(config):
    # pull out important values.
    site_path = config["site_path"]
    deploy_path = config["deploy_path"]

    # look for files in content/
    if not os.path.isdir(site_path):
        raise IOError('Could not find site_path folder "%s"' % site_path)

    # this is the one folder that *doesn't* get processed by processers.build_page_tree,
    # so it needs special handling here.
    # config_path = os.path.join(deploy_path, config['config_file'])
    # config.update(check_for_config(config_path))
    config.setdefault("type", "root")
    root_node = build_node(config, site_path, deploy_path, "")[0]

    root_node.generate()
示例#3
0
def index_processor(config, source_path, target_path):
    config = configurate(source_path, config)
    categories_name = config['name']

    folder_config = config.copy()
    folder_config['target_name'] = categories_name
    folder_config['name'] = categories_name
    folder_config['type'] = config['default_folder_type']
    folder = build_node(folder_config, os.path.dirname(source_path), target_path, categories_name)[0]
    categories_folder_target_path = os.path.join(target_path, categories_name)

    config['dont_inherit'] = [key for key in config['dont_inherit'] if key != 'title']
    index_config = config.copy()
    index_config['target_name'] = config['index.html']
    index_config['name'] = 'index'
    configurate(os.path.join(source_path, config['index.html']), index_config)
    index_node = JinjaNode(index_config, source_path, categories_folder_target_path)
    folder.append(index_node)
    CategoryDetail.index_node = index_node

    # attach Processor node - this is the class that will scan the pages for
    # the `category` property:
    folder.append(CategoryFolderProcesser(config, categories_folder_target_path))
    return (folder, )
示例#4
0
def strange_case(config):
    # pull out important values.
    site_path = config['site_path']
    deploy_path = config['deploy_path']

    # look for files in content/
    if not os.path.isdir(site_path):
        raise IOError('Could not find site_path folder "%s"' % site_path)

    # this is the one folder that *doesn't* get processed by processors.build_page_tree,
    # so it needs special handling here.
    config.setdefault('type', 'root')
    Node.files_written = []
    root_node = build_node(config, site_path, deploy_path, '')[0]
    Registry.set('root', root_node)

    remove_stale_files = config['remove_stale_files']
    dont_remove = config['dont_remove']
    existing_files = []
    if os.path.isdir(deploy_path):
        existing_files = __scan(deploy_path)
    else:
        os.makedirs(deploy_path, 0755)
    root_node.generate()

    # create timestamps file
    timestamps = {}
    for file_tracked in Node.files_tracked:
        f = os.path.abspath(file_tracked)
        timestamps[f] = os.stat(file_tracked).st_mtime
    timestamps_file = os.path.join(config['project_path'], '.timestamps')
    pickle.dump(timestamps, open(timestamps_file, 'w'))

    if remove_stale_files and existing_files:
        paths = []
        for f in existing_files:
            if f not in Node.files_written:
                f = os.path.abspath(f)
                f_rel = os.path.relpath(f)
                if any(pattern for pattern in dont_remove if fnmatch(f, pattern)):
                    sys.stderr.write("\033[32mignoring\033[0m \033[1m" + f_rel + "\033[0m\n")
                    continue

                if os.path.isdir(f):
                    paths.insert(0, f)
                else:
                    sys.stderr.write("\033[31mrm\033[0m \033[1m" + f_rel + "\033[0m\n")
                    os.remove(f)
        # filter out directories that are not empty
        paths = [p for p in paths if not os.listdir(p)]
        for p in paths:
            p_rel = os.path.relpath(p)
            sys.stderr.write("\033[31mrmdir\033[0m \033[1m" + p_rel + "\033[0m\n")
            os.removedirs(p)

    if notifier:
        try:
            growl = notifier.GrowlNotifier(
                applicationName="StrangeCase",
                notifications=["New Messages"],
                defaultNotifications=["New Messages"],
            )
            growl.register()

            # Send one message
            growl.notify(
                noteType="New Messages",
                title="StrangeCase site generated",
                description="site is available at:\n"
                    "{config[deploy_path]}"\
                    .format(config=config),
            )
        except socket.error:
            pass