Ejemplo n.º 1
0
def execute(args):
    global config

    logging_init(logging.DEBUG)

    target_path = args['-p'] if args['-p'] else os.getcwdu()

    if args["init"]:
        init_site(target_path)
        return

    config_file = os.path.join(target_path, "_config.yml")
    try:
        config = parse_config(config_file)
    except (Exception, YAMLError) as e:
        # always in debug mode when parse config
        logging.exception("Parse config with error:")
        sys.exit(1)
    level = logging.DEBUG if config["debug"] else logging.INFO
    logging_init(level)   # reload logger

    if args["generate"]:
        generator = Generator(target_path)
        generator.generate()
    elif args["new"]:
        create_new_wiki(args["-c"], args["-t"], args["-f"])
    elif args["preview"]:
        args['--port'] = int(args['--port'])
        preview(config["destination"], config['root'],
                args["--host"], args["--port"])
    else:
        # docopt itself will display the help info.
        pass
Ejemplo n.º 2
0
def execute(args):
    logging_init(logging.DEBUG)

    target_path = args['-p'].decode('utf-8') if args['-p'] else os.getcwdu()

    if args["init"]:
        default_config_file = os.path.join(os.path.dirname(__file__),
                                           "conf_templates",
                                           "_config.yml.in")
        try:
            init_site = InitSite(default_config_file, target_path)
            init_site.init_site()
            default_config = parse_config(default_config_file)
            install_theme(target_path, default_config["themes_dir"],
                          default_config["theme"],
                          default_config["destination"])
        except Exception as e:
            logging.exception("Init site: {0}\n{1}"
                              .format(unicode(e), traceback.format_exc()))
            sys.exit(1)
    else:
        config_file = os.path.join(target_path, "_config.yml")
        try:
            config = parse_config(config_file)
        except (Exception, YAMLError) as e:
            logging.exception("Parse config: {0}\n{1}"
                              .format(unicode(e), traceback.format_exc()))
            sys.exit(1)
        level = logging.DEBUG if config["debug"] else logging.INFO
        logging_init(level)   # reload logger

        if args["generate"]:
            if args["--ignore-root"]:
                config.update({u"root": u"/"})
            generator = Generator(config)
            generator.generate(args["--delete"], args["--update-theme"])
        elif args["new"]:
            pocw = param_of_create_wiki(args["-t"], args["-c"], args["-f"],
                                        config["default_ext"])
            create_new_wiki(config["source"], *pocw)
        elif args["preview"]:
            preview(config["destination"])
        else:
            # docopt itself will display the help info.
            pass

    logger.info("Done.")
Ejemplo n.º 3
0
    def setUp(self):
        self.config_file = os.path.join(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
            "simiki/conf_templates/_config.yml.in")

        self.config = parse_config(self.config_file)

        self.base_path = os.path.dirname(__file__)
Ejemplo n.º 4
0
    def setUp(self):
        self.config_file = os.path.join(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
            "simiki/conf_templates/_config.yml.in"
        )

        self.config = parse_config(self.config_file)

        self.base_path = os.path.dirname(__file__)
Ejemplo n.º 5
0
 def test_parse_config(self):
     config = parse_config(self.config_file)
     self.expected_config.pop('time')
     _date = config.pop('time')
     if hasattr(unittest.TestCase, 'assertIsInstance'):
         self.assertIsInstance(_date, datetime.datetime)
     else:
         assert isinstance(_date, datetime.datetime), \
                '%s is not an instance of %r' % \
                (repr(_date), datetime.datetime)
     self.assertEqual(config, self.expected_config)
Ejemplo n.º 6
0
 def test_parse_config(self):
     config = parse_config(self.config_file)
     self.expected_config.pop("time")
     _date = config.pop("time")
     if hasattr(unittest.TestCase, "assertIsInstance"):
         self.assertIsInstance(_date, datetime.datetime)
     else:
         assert isinstance(_date, datetime.datetime), "%s is not an instance of %r" % (
             repr(_date),
             datetime.datetime,
         )
     self.assertEqual(config, self.expected_config)
Ejemplo n.º 7
0
 def test_parse_config(self):
     config = parse_config(self.config_file)
     self.expected_config.pop('time')
     _date = config.pop('time')
     if hasattr(unittest.TestCase, 'assertIsInstance'):
         self.assertIsInstance(_date, datetime.datetime)
     else:
         assert isinstance(_date, datetime.datetime), \
                '%s is not an instance of %r' % \
                (repr(_date), datetime.datetime)
     self.assertEqual(
         config,
         self.expected_config
     )
Ejemplo n.º 8
0
    def setUp(self):
        self.wiki_path = os.path.join(test_path, 'mywiki_for_generator')

        os.chdir(self.wiki_path)

        self.config_file = os.path.join(base_path, 'simiki', 'conf_templates',
                                        '_config.yml.in')

        self.config = parse_config(self.config_file)

        s_themes_path = os.path.join(base_path, 'simiki', 'themes')
        self.d_themes_path = os.path.join('./', 'themes')
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)
Ejemplo n.º 9
0
    def setUp(self):
        self.wiki_path = os.path.join(test_path, 'mywiki_for_generator')

        os.chdir(self.wiki_path)

        self.config_file = os.path.join(base_path, 'simiki',
                                        'conf_templates', '_config.yml.in')

        self.config = parse_config(self.config_file)

        s_themes_path = os.path.join(base_path, 'simiki', 'themes')
        self.d_themes_path = os.path.join('./', 'themes')
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)
Ejemplo n.º 10
0
    def setUp(self):
        self.default_config = get_default_config()

        self.wiki_path = os.path.join(test_path, 'mywiki_for_generator')

        os.chdir(self.wiki_path)

        self.config_file = os.path.join(base_path, 'simiki', 'conf_templates',
                                        '_config.yml.in')

        self.config = parse_config(self.config_file)

        s_themes_path = os.path.join(base_path, 'simiki',
                                     self.default_config['themes_dir'])
        self.d_themes_path = os.path.join('./',
                                          self.default_config['themes_dir'])
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)

        self.pages = {
            'content/other/page1.md': {
                'content': '',
                'collection': 'mycoll',
                'date': '2016-06-02 00:00',
                'layout': 'page',
                'title': 'Page 1'
            },
            'content/other/page2.md': {
                'content': '',
                'date': '2016-06-02 00:00',
                'layout': 'page',
                'title': 'Page 2'
            },
            'content/other/page3.md': {
                'content': '',
                'collection': 'mycoll',
                'date': '2016-06-02 00:00',
                'layout': 'page',
                'title': 'Page 3'
            },
        }

        self.generator = CatalogGenerator(self.config, self.wiki_path,
                                          self.pages)
Ejemplo n.º 11
0
    def setUp(self):
        self.default_config = get_default_config()

        self.wiki_path = os.path.join(test_path, "mywiki_for_generator")

        os.chdir(self.wiki_path)

        self.config_file = os.path.join(base_path, "simiki", "conf_templates", "_config.yml.in")

        self.config = parse_config(self.config_file)

        s_themes_path = os.path.join(base_path, "simiki", self.default_config["themes_dir"])
        self.d_themes_path = os.path.join("./", self.default_config["themes_dir"])
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)

        self.generator = PageGenerator(self.config, self.wiki_path)
Ejemplo n.º 12
0
    def setUp(self):
        self.default_config = get_default_config()

        self.wiki_path = os.path.join(test_path, 'mywiki_for_generator')

        os.chdir(self.wiki_path)

        self.config_file = os.path.join(base_path, 'simiki',
                                        'conf_templates', '_config.yml.in')

        self.config = parse_config(self.config_file)

        s_themes_path = os.path.join(base_path, 'simiki',
                                     self.default_config['themes_dir'])
        self.d_themes_path = os.path.join('./',
                                          self.default_config['themes_dir'])
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)

        self.pages = {
            'content/other/page1.md':
                {'content': '',
                 'collection': 'mycoll',
                 'date': '2016-06-02 00:00',
                 'layout': 'page',
                 'title': 'Page 1'},
            'content/other/page2.md':
                {'content': '',
                 'date': '2016-06-02 00:00',
                 'layout': 'page',
                 'title': 'Page 2'},
            'content/other/page3.md':
                {'content': '',
                 'collection': 'mycoll',
                 'date': '2016-06-02 00:00',
                 'layout': 'page',
                 'title': 'Page 3'},
        }

        self.generator = CatalogGenerator(self.config, self.wiki_path,
                                          self.pages)
Ejemplo n.º 13
0
def main(args=None):
    global config

    if not args:
        args = docopt(__doc__, version="Simiki {0}".format(__version__))
    unicode_docopt(args)

    logging_init(logging.DEBUG)

    target_path = args['-p'] if args['-p'] else getcwdu()

    if args["init"]:
        init_site(target_path)
    else:
        config_file = os.path.join(target_path, "_config.yml")
        try:
            config = parse_config(config_file)
        except (Exception, YAMLError):
            # always in debug mode when parse config
            logging.exception("Parse config with error:")
            sys.exit(1)
        level = logging.DEBUG if config["debug"] else logging.INFO
        logging_init(level)   # reload logger

        if args["generate"] or args["g"]:
            generator = Generator(target_path)
            generator.generate(include_draft=args['--draft'])
        elif args["new"] or args["n"]:
            create_new_wiki(args["-c"], args["-t"], args["-f"])
        elif args["preview"] or args["p"]:
            args['--port'] = int(args['--port'])
            preview_site(args['--host'], args['--port'], config['destination'],
                         config['root'], args['-w'])
        elif args["update"]:
            update_builtin(themes_dir=config['themes_dir'])
        else:
            # docopt itself will display the help info.
            pass

    logger.info("Done.")
Ejemplo n.º 14
0
def main(args=None):
    global config

    if not args:
        args = docopt(__doc__, version="Simiki {0}".format(__version__))
    unicode_docopt(args)

    logging_init(logging.DEBUG)

    target_path = args['-p'] if args['-p'] else getcwdu()

    if args["init"]:
        init_site(target_path)
    else:
        config_file = os.path.join(target_path, "_config.yml")
        try:
            config = parse_config(config_file)
        except (Exception, YAMLError):
            # always in debug mode when parse config
            logging.exception("Parse config with error:")
            sys.exit(1)
        level = logging.DEBUG if config["debug"] else logging.INFO
        logging_init(level)  # reload logger

        if args["generate"] or args["g"]:
            generator = Generator(target_path)
            generator.generate()
        elif args["new"] or args["n"]:
            create_new_wiki(args["-c"], args["-t"], args["-f"])
        elif args["preview"] or args["p"]:
            args['--port'] = int(args['--port'])
            preview_site(args['--host'], args['--port'], config['destination'],
                         config['root'], args['-w'])
        elif args["update"]:
            update_builtin()
        else:
            # docopt itself will display the help info.
            pass

    logger.info("Done.")
Ejemplo n.º 15
0
    def setUp(self):
        self.default_config = get_default_config()

        self.wiki_path = os.path.join(test_path, "mywiki_for_generator")

        os.chdir(self.wiki_path)

        self.config_file = os.path.join(base_path, "simiki", "conf_templates", "_config.yml.in")

        self.config = parse_config(self.config_file)

        s_themes_path = os.path.join(base_path, "simiki", self.default_config["themes_dir"])
        self.d_themes_path = os.path.join("./", self.default_config["themes_dir"])
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)

        self.pages = {
            "content/other/page1.md": {
                "content": "",
                "collection": "mycoll",
                "date": "2016-06-02 00:00",
                "layout": "page",
                "title": "Page 1",
            },
            "content/other/page2.md": {"content": "", "date": "2016-06-02 00:00", "layout": "page", "title": "Page 2"},
            "content/other/page3.md": {
                "content": "",
                "collection": "mycoll",
                "date": "2016-06-02 00:00",
                "layout": "page",
                "title": "Page 3",
            },
        }

        self.generator = CatalogGenerator(self.config, self.wiki_path, self.pages)
Ejemplo n.º 16
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, absolute_import, with_statement

import os
import sys
import ftplib
import getpass
from fabric.api import env, local, task, settings
from fabric.colors import blue, red
import fabric.contrib.project as project
from simiki import config

# XXX must run fab in root path of wiki
configs = config.parse_config('_config.yml')

env.colorize_errors = True
SUPPORTED_DEPLOY_TYPES = ('rsync', 'git', 'ftp')


def do_exit(msg):
    print(red(msg))
    print(blue('Exit!'))
    sys.exit()


def get_rsync_configs():
    if 'deploy' in configs:
        for item in configs['deploy']:
            if item['type'] == 'rsync':
Ejemplo n.º 17
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, with_statement

import os
import sys
import ftplib
import getpass
from fabric.api import env, local, task, settings, lcd
from fabric.colors import blue, red
import fabric.contrib.project as project
from simiki import config

# XXX must run fab in root path of wiki
configs = config.parse_config('_config.yml')

env.colorize_errors = True
SUPPORTED_DEPLOY_TYPES = ('rsync', 'git', 'ftp')


def do_exit(msg):
    print(red(msg))
    print(blue('Exit!'))
    sys.exit()


def get_rsync_configs():
    if 'deploy' in configs:
        for item in configs['deploy']:
            if item['type'] == 'rsync':
                return item
Ejemplo n.º 18
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, absolute_import, with_statement

import os
import sys
import ftplib
import getpass
from fabric.api import env, local, task, settings
from fabric.colors import blue, red
import fabric.contrib.project as project
from simiki import config

# XXX must run fab in root path of wiki
configs = config.parse_config("_config.yml")

env.colorize_errors = True
SUPPORTED_DEPLOY_TYPES = ("rsync", "git", "ftp")


def do_exit(msg):
    print(red(msg))
    print(blue("Exit!"))
    sys.exit()


def get_rsync_configs():
    if "deploy" in configs:
        for item in configs["deploy"]:
            if item["type"] == "rsync":
Ejemplo n.º 19
0
 def test_parse_config_not_exist(self):
     not_exist_config_file = os.path.join(self.config_file, "not_exist")
     self.assertRaises(Exception, lambda: parse_config(not_exist_config_file))
Ejemplo n.º 20
0
 def __init__(self, config_file, target_path):
     self.config_file = config_file
     self.config = parse_config(self.config_file)
     self.source_path = os.path.dirname(__file__)
     self.target_path = target_path
Ejemplo n.º 21
0
 def test_parse_config_not_exist(self):
     not_exist_config_file = os.path.join(self.config_file, "not_exist")
     self.assertRaises(Exception,
                       lambda: parse_config(not_exist_config_file))
Ejemplo n.º 22
0
 def __init__(self, config_file, target_path):
     self.config_file = config_file
     self.config = parse_config(self.config_file)
     self.source_path = os.path.dirname(__file__)
     self.target_path = target_path