Ejemplo 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()
Ejemplo 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)
Ejemplo 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)
Ejemplo 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))
Ejemplo 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)
Ejemplo 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))
Ejemplo 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))
Ejemplo 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))
Ejemplo 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))
Ejemplo 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))
Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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))
Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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))
Ejemplo 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)
Ejemplo 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))
Ejemplo 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))