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
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.")
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__)
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__)
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)
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)
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 )
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)
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)
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)
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)
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.")
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.")
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)
#!/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':
#!/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
#!/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":
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))
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