예제 #1
0
def rollout(engine):

    return 'theme', {
        'content/sample-entry.txt': copy('sample-entry.txt'),
        'theme/': [
            'base.html',
            'main.html',
            'entry.html',
            'articles.html',
            copy(engine + '/atom.xml'),
            copy(engine + '/rss.xml'),
            copy('html5/style.css')],
    }
예제 #2
0
파일: init.py 프로젝트: kenkeiras/acrylamid
def resolve(options, theme, files):
    """Takes a files dictionary and yields src and full destination path.

    :param options: Argparse namespace object
    :param theme: theme directory name
    :param files: {'/path/': [item, ...]}"""

    if 'conf.py' not in files:
        conf = string.Template(defaults.copy('conf.py').read().decode('utf-8'))
        files['conf.py'] = io.BytesIO(conf.substitute(engine=options.engine,
                                                      theme=theme).encode('utf-8'))

    for path, items in files.iteritems():
        path = join(options.dest, path)

        if isinstance(items, (basestring, io.IOBase)):
            items = [items, ]

        for obj in items:
            if hasattr(obj, 'read'):
                dest = join(path, basename(obj.name)) if path.endswith('/') else path
                yield obj, dest
            else:
                obj = join(dirname(defaults.__file__), options.theme, options.engine, obj)
                yield obj, join(dirname(path), basename(obj))
예제 #3
0
def rollout(engine):

    return 'shadowplay', {
        'conf.py': 'conf.py',
        'content/': [
            'content/about.txt', 'content/lorem.txt',
            'content/ipsum.txt', 'content/shadowplay.txt'
        ],
        'shadowplay/': [
            'shadowplay.css',
            'base.html', 'main.html', 'entry.html', 'articles.html',
            copy('jinja2/atom.xml'),
            copy('jinja2/rss.xml')
        ],
        'shadowplay/img/': [
            'img/arrow.png', 'img/back.png', 'img/link.png', 'img/logo.png'
        ]
    }
예제 #4
0
def init(env, options):
    """Subcommand: init -- create the base structure of an Acrylamid blog
    or restore individual files and folders.

    If the destination directory is empty, it will create a new blog. If the
    destination  directory is not empty it won't overwrite anything unless
    you supply -f, --force to re-initialize the whole theme.

    If you need to restore single files, remove the existing file and run::

        $ acrylamid init path/to/blog/

    and all missing files are automatically re-created."""

    if not options.engine:
        try:
            import jinja2

            options.engine = "jinja2"
        except ImportError:
            options.engine = "mako"

    root = options.dest
    theme, files = rollout(options.theme, options.engine)

    # remember whether we are restore an existing theme
    restore = isfile(join(root, "conf.py"))

    if isfile(root):
        raise AcrylamidException("%s already exists!" % root)

    if isdir(root) and len(os.listdir(root)) > 0 and not options.overwrite:
        if not restore and raw_input("Destination directory not empty! Continue? [yn]: ") != "y":
            sys.exit(1)

    if "conf.py" not in files:
        conf = string.Template(defaults.copy("conf.py").read())
        files["conf.py"] = io.BytesIO(conf.substitute(engine=options.engine, theme=theme).encode("utf-8"))

    for dest, items in files.iteritems():
        dest = join(root, dest)

        if not isdir(dirname(dest)):
            os.makedirs(dirname(dest))

        if isinstance(items, (basestring, io.IOBase)):
            items = [items]

        for obj in items:
            if hasattr(obj, "read"):
                path = join(dirname(dest), basename(obj.name)) if dest.endswith("/") else dest
                if options.overwrite or not exists(path):
                    with io.open(path, "wb") as fp:
                        fp.write(obj.read())
                    event.create(path)
                else:
                    event.skip(path)
            else:
                src = join(dirname(defaults.__file__), options.theme, options.engine, obj)
                if options.overwrite or not exists(join(dest, basename(src))):
                    shutil.copy(src, dest)
                    event.create(dest if basename(dest) else join(dest, obj))
                else:
                    event.skip(dest)

    if not restore:
        log.info("Created your fresh new blog at %r. Enjoy!", root)