Ejemplo n.º 1
0
def main():
    args = docopt(__doc__, version="Simiki {}".format(__version__))

    if args["init"]:
        logging_init(logging.DEBUG)
        default_config_file = osp.join(os.path.dirname(__file__),
                                       "conf_templates/_config.yml.in")
        isite = InitSite(default_config_file)
        isite.init_site()
        return

    config_file = osp.join(os.getcwd(), "_config.yml")
    configs = parse_configs(config_file)
    level = logging.DEBUG if configs["debug"] else logging.INFO
    logging_init(level)

    if args["generate"]:
        gen = Generator(configs)
        gen.generate(args["--delete"])
    elif args["new"] and args["-t"]:
        pocw = param_of_create_wiki(args["-t"], args["-c"], args["-f"])
        create_new_wiki(configs["source"], *pocw)
    elif args["preview"]:
        preview(configs["destination"])
    else:
        # docopt itself will display the help info.
        pass

    logger.info("Done.")
Ejemplo n.º 2
0
def main():
    args = docopt(__doc__, version="Simiki {}".format(__version__))
    target_path = os.getcwd()
    if args["-p"]:
        target_path = args["-p"]

    if args["init"]:
        logging_init(logging.DEBUG)
        default_config_file = os.path.join(os.path.dirname(__file__),
                                           "conf_templates",
                                           "_config.yml.in")
        isite = InitSite(default_config_file, target_path)
        isite.init_site()
        return

    config_file = os.path.join(os.getcwd(), "_config.yml")
    configs = parse_configs(config_file)
    level = logging.DEBUG if configs["debug"] else logging.INFO
    logging_init(level)

    if args["generate"]:
        gen = Generator(configs)
        gen.generate(args["--delete"])
    elif args["new"] and args["-t"]:
        pocw = param_of_create_wiki(args["-t"], args["-c"], args["-f"])
        create_new_wiki(configs["source"], *pocw)
    elif args["preview"]:
        preview(configs["destination"])
    else:
        # docopt itself will display the help info.
        pass

    logger.info("Done.")
Ejemplo n.º 3
0
def main():
    args = docopt(__doc__, version="Simiki {}".format(__version__))

    if args["init"]:
        logging_init(logging.DEBUG)
        default_config_file = osp.join(os.path.dirname(__file__), 
                                        "conf_templates/_config.yml.in")
        isite = InitSite(default_config_file)
        isite.init_site()
        sys.exit(1)

    config_file = osp.join(os.getcwd(), "_config.yml")
    configs = parse_configs(config_file)
    level = logging.DEBUG if configs["debug"] else logging.INFO
    logging_init(level)
    simiki = Simiki(configs)

    if args["generate"]:
        simiki.generate()
    elif args["new"] and args["-t"]:
        pocw = param_of_create_wiki(args["-t"], args["-c"], args["-f"])
        simiki.create_new_wiki(*pocw)
    elif args["preview"]:
        simiki.preview()
    else:
        # docopt itself will display the help info.
        pass

    logger.info("Done.")
Ejemplo n.º 4
0
 def setUp(self):
     BASE_DIR = osp.dirname(osp.dirname(osp.abspath(__file__)))
     config_file = osp.join(BASE_DIR, "simiki/conf_templates/_config.yml.in")
     i = InitSite(config_file)
     i.init_site()
     self.files = ["_config.yml", "fabfile.py"]
     self.dirs = ["content", "output", "themes"]
Ejemplo n.º 5
0
    def test_target_invalid(self):
        """ test InitSite target path invalid, raise OSError
        """

        target_error = "/foo/bar/why/not"
        i = InitSite(self.config_file, target_error)
        self.assertRaises(OSError, lambda: i.init_site())
Ejemplo n.º 6
0
 def setUp(self):
     BASE_DIR = osp.dirname(osp.dirname(osp.abspath(__file__)))
     config_file = osp.join(BASE_DIR,
                            "simiki/conf_templates/_config.yml.in")
     i = InitSite(config_file)
     i.init_site()
     self.files = ["_config.yml", "fabfile.py"]
     self.dirs = ["content", "output", "themes"]
Ejemplo n.º 7
0
    def generate(self, delete_output_dir=False):
        if delete_output_dir:
            logger.info("Delete all the files and dirs under output directory")
            output_dir = osp.join(os.getcwd(), self.configs["destination"])
            emptytree(output_dir)

        self.generate_all_pages()
        self.generate_catalog()
        InitSite.install_theme(os.getcwd(), self.configs["theme"])
Ejemplo n.º 8
0
    def test_target_invalid(self):
        """ test InitSite target path invalid, raise OSError
        """

        self.files = ["_config.yml", "fabfile.py"]
        self.dirs = ["content", "output", "themes"]
        target_error = "/foo/bar/why/not"
        i = InitSite(self.config_file, target_error)
        with self.assertRaises(OSError):
            i.init_site()
Ejemplo n.º 9
0
    def test_target_invalid(self):
        """ test InitSite target path invalid, raise OSError
        """

        self.files = ["_config.yml", "fabfile.py"]
        self.dirs = ["content", "output", "themes"]
        target_error = "/foo/bar/why/not"
        i = InitSite(self.config_file, target_error)
        with self.assertRaises(OSError):
            i.init_site()
Ejemplo n.º 10
0
    def test_target_exist(self):
        """ test InitSite target path exist
        """

        i = InitSite(self.config_file, self.target_path)
        i.init_site()

        for f in self.files:
            self.assertTrue(os.path.isfile(os.path.join(self.target_path, f)))

        for d in self.dirs:
            self.assertTrue(os.path.isdir(os.path.join(self.target_path, d)))
Ejemplo n.º 11
0
    def test_target_exist(self):
        """ test InitSite target path exist
        """

        i = InitSite(self.config_file, self.target_path)
        i.init_site()

        for f in self.files:
            self.assertTrue(os.path.isfile(os.path.join(self.target_path, f)))

        for d in self.dirs:
            self.assertTrue(os.path.isdir(os.path.join(self.target_path, d)))
Ejemplo n.º 12
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.º 13
0
def execute(args):
    logging_init(logging.DEBUG)

    target_path = os.getcwd()
    if args["-p"]:
        target_path = args["-p"]
    if not isinstance(target_path, unicode):
        target_path = unicode(target_path, "utf-8")

    if args["init"]:
        default_config_file = os.path.join(os.path.dirname(__file__),
                                           "conf_templates",
                                           "_config.yml.in")
        try:
            isite = InitSite(default_config_file, target_path)
            isite.init_site()
        except Exception as e:
            logging.exception("{0}\n{1}"
                              .format(str(e), traceback.format_exc()))
        return

    config_file = os.path.join(target_path, "_config.yml")
    try:
        configs = parse_configs(config_file)
    except (Exception, YAMLError) as e:
        logging.exception("{0}\n{1}".format(str(e), traceback.format_exc()))
        return
    level = logging.DEBUG if configs["debug"] else logging.INFO
    logging_init(level)

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

    logger.info("Done.")
Ejemplo n.º 14
0
def execute(args):
    logging_init(logging.DEBUG)

    target_path = os.getcwd()
    if args["-p"]:
        target_path = args["-p"]
    if not isinstance(target_path, unicode):
        target_path = unicode(target_path, "utf-8")

    if args["init"]:
        default_config_file = os.path.join(os.path.dirname(__file__),
                                           "conf_templates", "_config.yml.in")
        try:
            isite = InitSite(default_config_file, target_path)
            isite.init_site()
        except Exception as e:
            logging.exception("{0}\n{1}".format(str(e),
                                                traceback.format_exc()))
        return

    config_file = os.path.join(target_path, "_config.yml")
    try:
        configs = parse_configs(config_file)
    except (Exception, YAMLError) as e:
        logging.exception("{0}\n{1}".format(str(e), traceback.format_exc()))
        return
    level = logging.DEBUG if configs["debug"] else logging.INFO
    logging_init(level)

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

    logger.info("Done.")