Esempio n. 1
0
    def init(self, ask=False, **kwargs):
        content_path = os.path.join(self.target_path, self.config["source"])
        output_path = os.path.join(self.target_path,
                                   self.config["destination"])
        theme_path = os.path.join(self.target_path, self.config['themes_dir'])
        for path in (content_path, output_path, theme_path):
            if os.path.exists(path):
                logging.warning("{0} exists".format(path))
            else:
                mkdir_p(path)
                logging.info("Creating directory: {0}".format(path))

        self.get_config_file()
        self.get_fabfile()
        self.get_demo_page()
        self.get_default_theme(theme_path)

        if ask is True:
            try:
                _ans = raw_input('Create Dockerfile? (y/N) ')
                if _ans.lower() in yes_answer:
                    self.get_dockerfile()
            except (KeyboardInterrupt, SystemExit):
                print()  # newline with Ctrl-C
        elif ask is False and kwargs.get('dockerfile', False):
            self.get_dockerfile()
Esempio n. 2
0
def create_new_wiki(category, title, filename):
    if not filename:
        # `/` can't exists in filename
        _title = title.replace(os.sep, " slash ").lower()
        filename = "{0}.{1}".format(_title.replace(' ', '-'),
                                    config["default_ext"])
    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    meta = "\n".join([
        "---",
        "title: \"{0}\"".format(title),
        "date: {0}".format(now),
        "---",
    ]) + "\n\n"

    category_path = os.path.join(config["source"], category)
    if not os.path.exists(category_path):
        mkdir_p(category_path)
        logger.info("Creating category: {0}.".format(category))

    fn = os.path.join(category_path, filename)
    if os.path.exists(fn):
        logger.warning("File exists: {0}".format(fn))
    else:
        logger.info("Creating wiki: {0}".format(fn))
        with io.open(fn, "wt", encoding="utf-8") as fd:
            fd.write(meta)
Esempio n. 3
0
def create_new_wiki(category, title, filename):
    if not filename:
        # `/` can't exists in filename
        _title = title.replace(os.sep, " slash ").lower()
        filename = "{0}.{1}".format(_title.replace(' ', '-'),
                                    config["default_ext"])
    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    meta = "\n".join([
        "---",
        "title: \"{0}\"".format(title),
        "date: {0}".format(now),
        "---",
    ]) + "\n\n"

    category_path = os.path.join(config["source"], category)
    if not os.path.exists(category_path):
        mkdir_p(category_path)
        logger.info("Creating category: {0}.".format(category))

    fn = os.path.join(category_path, filename)
    if os.path.exists(fn):
        logger.warning("File exists: {0}".format(fn))
    else:
        logger.info("Creating wiki: {0}".format(fn))
        with io.open(fn, "wt", encoding="utf-8") as fd:
            fd.write(meta)
Esempio n. 4
0
 def test_mkdir_p(self):
     path = os.path.join(self.output, "dir1/dir2/dir3")
     utils.mkdir_p(path)
     assert os.path.exists(path)
     path = os.path.join(self.content)
     utils.mkdir_p(path)
     assert os.path.exists(path)
     path = os.path.join(self.content, u"Simiki介绍.md")
     self.assertRaises(OSError, lambda: utils.mkdir_p(path))
Esempio n. 5
0
 def write_file(content, output_fname):
     """Write content to output file."""
     output_dir, _ = os.path.split(output_fname)
     if not os.path.exists(output_dir):
         logging.debug("The output directory %s not exists, create it",
                       output_dir)
         mkdir_p(output_dir)
     with io.open(output_fname, "wt", encoding="utf-8") as fd:
         fd.write(content)
Esempio n. 6
0
 def test_mkdir_p(self):
     path = os.path.join(self.output, "dir1/dir2/dir3")
     utils.mkdir_p(path)
     assert os.path.exists(path)
     path = os.path.join(self.content)
     utils.mkdir_p(path)
     assert os.path.exists(path)
     path = os.path.join(self.content, u"Simiki介绍.md")
     self.assertRaises(OSError, lambda: utils.mkdir_p(path))
Esempio n. 7
0
    def test_mkdir_p(self):
        path = os.path.join(self.content)
        utils.mkdir_p(path)
        assert os.path.exists(path)

        path = os.path.join(self.output, "dir1/dir2/dir3")
        utils.mkdir_p(path)
        assert os.path.exists(path)

        # test path exist, and not a directory
        path = os.path.join(self.content, '其它', 'hello.txt')
        self.assertRaises(OSError, lambda: utils.mkdir_p(path))
Esempio n. 8
0
    def test_mkdir_p(self):
        path = os.path.join(self.content)
        utils.mkdir_p(path)
        assert os.path.exists(path)

        path = os.path.join(self.output, "dir1/dir2/dir3")
        utils.mkdir_p(path)
        assert os.path.exists(path)

        # test path exist, and not a directory
        path = os.path.join(self.content, '其它', 'hello.txt')
        self.assertRaises(OSError, lambda: utils.mkdir_p(path))
Esempio n. 9
0
    def get_file(src, dst):
        if os.path.exists(dst):
            logging.warning("{0} exists".format(dst))
            return

        # Create parent directory
        dst_directory = os.path.dirname(dst)
        if not os.path.exists(dst_directory):
            mkdir_p(dst_directory)
            logging.info("Creating directory: {0}".format(dst_directory))

        shutil.copyfile(src, dst)
        logging.info("Creating file: {0}".format(dst))
Esempio n. 10
0
    def get_file(self, src, dst):
        if os.path.exists(dst):
            logging.warning("{0} exists".format(dst))
            return

        # Create parent directory
        dst_directory = os.path.dirname(dst)
        if not os.path.exists(dst_directory):
            mkdir_p(dst_directory)
            logging.info("Creating directory: {0}".format(dst_directory))

        shutil.copyfile(src, dst)
        logging.info("Creating config file: {0}".format(dst))
Esempio n. 11
0
def write_file(content, ofile, ftype="page"):
    """Write content to output file.

    :param content: content to write to ofile
    :param ofile: output file
    :param ftype: file type, "page" or "index"
    """
    if ftype == "page":
        output_category, _ = osp.split(ofile)
        if not check_path_exists(output_category):
            logging.info("The output category %s not exists, create it" %
                         output_category)
            mkdir_p(output_category)
    with codecs.open(ofile, "wb", "utf-8") as fd:
        fd.write(content)
Esempio n. 12
0
def write_file(content, ofile, ftype="page"):
    """Write content to output file.

    :param content: content to write to ofile
    :param ofile: output file
    :param ftype: file type, "page" or "index"
    """
    if ftype == "page":
        output_category, _ = os.path.split(ofile)
        if not os.path.exists(output_category):
            logging.info("The output category %s not exists, create it",
                         output_category)
            mkdir_p(output_category)
    with io.open(ofile, "wt", encoding="utf-8") as fd:
        fd.write(content)
Esempio n. 13
0
    def init(self):
        content_path = os.path.join(self.target_path, self.config["source"])
        output_path = os.path.join(self.target_path, self.config["destination"])
        theme_path = os.path.join(self.target_path, self.config["themes_dir"])
        for path in (content_path, output_path, theme_path):
            if os.path.exists(path):
                logging.warning("{0} exists".format(path))
            else:
                mkdir_p(path)
                logging.info("Creating directory: {0}".format(path))

        self.get_config_file()
        self.get_fabfile()
        self.get_demo_page()
        self.get_default_theme(theme_path)
Esempio n. 14
0
def write_file(content, ofile, ftype="page"):
    """Write content to output file.

    :param content: content to write to ofile
    :param ofile: output file
    :param ftype: file type, "page" or "index"
    """
    if ftype == "page":
        output_category, _ = os.path.split(ofile)
        if not os.path.exists(output_category):
            logging.info(
                "The output category %s not exists, create it", output_category)
            mkdir_p(output_category)
    with io.open(ofile, "wt", encoding="utf-8") as fd:
        fd.write(content)
Esempio n. 15
0
    def get_file(self, src, dst):
        if check_path_exists(dst):
            logging.warning("{} exists".format(dst))
            return

        # Create parent directory
        dst_directory = osp.dirname(dst)
        if not check_path_exists(dst_directory):
            mkdir_p(dst_directory)
            logging.info("Creating directory: {}".format(dst_directory))

        try:
            shutil.copyfile(src, dst)
            logging.info("Creating config file: {}".format(dst))
        except (shutil.Error, IOError), e:
            logging.error(str(e))
Esempio n. 16
0
    def init_site(self):
        content_path = os.path.join(self.target_path, self.config["source"])
        output_path = os.path.join(self.target_path,
                                   self.config["destination"])
        theme_path = os.path.join(self.target_path, "themes")
        for path in (content_path, output_path, theme_path):
            if os.path.exists(path):
                logging.warning("{0} exists".format(path))
            else:
                mkdir_p(path)
                logging.info("Creating directory: {0}".format(path))

        self.get_config_file()
        self.get_fabfile()
        self.get_first_page()
        self.get_default_theme(theme_path)
Esempio n. 17
0
def write_file(content, ofile, ftype="page"):
    """Write content to output file.

    :param content: content to write to ofile
    :param ofile: output file
    :param ftype: file type, "page" or "index"
    """
    if ftype == "page":
        output_category,_ = osp.split(ofile)
        if not check_path_exists(output_category):
            logging.info(
                "The output category %s not exists, create it" \
                % output_category
            )
            mkdir_p(output_category)
    with codecs.open(ofile, "wb", "utf-8") as fd:
        fd.write(content)
Esempio n. 18
0
 def output_to_file(self, html):
     """Write generated html to file"""
     category, markdown = self.get_category_and_file()
     output_category_path = osp.join(
         self.site_settings["destination"], 
         category
     )
     if not utils.check_path_exists(output_category_path):
         logging.info(
             "The output category %s not exists, create it" \
             % output_category_path
         )
         utils.mkdir_p(output_category_path)
     markdown_name = osp.splitext(markdown)[0]
     output_file = osp.join(output_category_path, markdown_name+".html")
     with codecs.open(output_file, "wb", "utf-8") as fd:
         fd.write(html)
Esempio n. 19
0
    def get_file(self, src, dst):
        if check_path_exists(dst):
            logging.warning("{} already exists! if you want overwrite it, " \
                        "please remove it first".format(dst))
            return

        # Create parent directory
        dst_directory = osp.dirname(dst)
        if not check_path_exists(dst_directory):
            mkdir_p(dst_directory)
            logging.info("Creating directory: {}".format(dst_directory))

        try:
            shutil.copyfile(src, dst)
            logging.info("Creating config file: {}".format(dst))
        except (shutil.Error, IOError), e:
            logging.error(str(e))
Esempio n. 20
0
def create_new_wiki(source, category, filename, title, date):
    meta = "\n".join([
        "---",
        "title: \"{0}\"".format(title),
        "date: {0}".format(date),
        "---",
    ]) + "\n\n"

    category_path = os.path.join(source, category)
    if not os.path.exists(category_path):
        mkdir_p(category_path)
        logger.info("Creating category {0}.".format(category))

    fn = os.path.join(category_path, filename)
    if os.path.exists(fn):
        logger.warning("wiki file exists: {0}".format(fn))
    else:
        logger.info("Creating wiki: {0}".format(fn))
        with io.open(fn, "wt", encoding="utf-8") as fd:
            fd.write(meta)
Esempio n. 21
0
 def test_mkdir_p(self):
     path = os.path.join(self.output, "dir1/dir2/dir3")
     utils.mkdir_p(path)
     assert (utils.check_path_exists(path))
Esempio n. 22
0
 def test_mkdir_p(self):
     path = os.path.join(self.output, "dir1/dir2/dir3")
     utils.mkdir_p(path)
     assert (utils.check_path_exists(path))