Esempio n. 1
0
 def test_copytree_common(self):
     utils.copytree(self.content, self.output)
     files = [".hidden.txt", "hellosimiki.md", "zen_of_python.txt",
              "simiki.md"]
     assert(utils.check_path_exists(self.output))
     for f in files:
         assert(utils.check_path_exists(os.path.join(self.output, f)))
     assert(not os.path.islink(os.path.join(self.output, "simiki.md")))
Esempio n. 2
0
 def test_copytree_common(self):
     utils.copytree(self.content, self.output)
     files = [
         ".hidden.txt", "hellosimiki.md", "zen_of_python.txt", "simiki.md"
     ]
     assert (utils.check_path_exists(self.output))
     for f in files:
         assert (utils.check_path_exists(os.path.join(self.output, f)))
     assert (not os.path.islink(os.path.join(self.output, "simiki.md")))
Esempio n. 3
0
 def test_all_files_exist(self):
     all_fd = self.files + self.dirs + [\
             "content/intro/gettingstarted.md",\
             "themes/simple"\
             ]
     for fd in all_fd:
         assert check_path_exists(fd)
Esempio n. 4
0
 def setUp(self):
     os.chdir(os.path.dirname(__file__))
     self.content = "sample"
     self.output = "output"
     if utils.check_path_exists(self.output):
         utils.emptytree(self.output)
         os.rmdir(self.output)
Esempio n. 5
0
 def setUp(self):
     os.chdir(os.path.dirname(__file__))
     self.content = "sample"
     self.output = "output"
     if utils.check_path_exists(self.output):
         utils.emptytree(self.output)
         os.rmdir(self.output)
Esempio n. 6
0
 def __init__(self, config_file):
     self.config_file = config_file
     if not check_path_exists(self.config_file):
         logging.error("{} not exists".format(self.config_file))
         sys.exit(1)
     self.configs = parse_configs(self.config_file)
     self.current_dir = os.getcwd()
Esempio n. 7
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. 8
0
 def test_all_files_exist(self):
     all_fd = self.files + self.dirs + [\
             "content/intro/gettingstarted.md",\
             "themes/simple"\
             ]
     for fd in all_fd:
         assert check_path_exists(fd)
Esempio n. 9
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. 10
0
 def get_conf(self):
     dst_config_file = osp.join(self.current_dir, "_config.yml")
     if check_path_exists(dst_config_file):
         logging.warning("{} already exists! if you want overwrite it, " \
                     "please remove it first".format(dst_config_file))
     try:
         shutil.copyfile(self.config_file, dst_config_file)
         logging.info("Creating config file: {}".format(dst_config_file))
     except (shutil.Error, IOError), e:
         logging.error(str(e))
Esempio n. 11
0
 def __init__(self, config_file):
     self.config_file = config_file
     if not check_path_exists(self.config_file):
         logging.error("{} not exists".format(self.config_file))
         sys.exit(1)
     try:
         self.configs = parse_configs(self.config_file)
     except Exception as e:
         logging.error(str(e))
     self.current_dir = os.getcwd()
Esempio n. 12
0
 def __init__(self, config_file, target_path):
     self.config_file = config_file
     if not check_path_exists(self.config_file):
         logging.error("{} not exists".format(self.config_file))
         sys.exit(1)
     try:
         self.configs = parse_configs(self.config_file)
     except Exception as e:
         logging.error(str(e))
     self.source_path = os.path.dirname(__file__)
     self.target_path = target_path
Esempio n. 13
0
 def get_fabfile(self):
     src_fabfile = osp.join(osp.dirname(__file__), "conf_templates/fabfile.py")
     dst_fabfile = osp.join(self.current_dir, "fabfile.py")
     if check_path_exists(dst_fabfile):
         logging.warning("{} already exists! if you want overwrite it, " \
                     "please remove it first".format(dst_fabfile))
     try:
         shutil.copyfile(src_fabfile, dst_fabfile)
         logging.info("Creating config file: {}".format(dst_fabfile))
     except (shutil.Error, IOError), e:
         logging.error(str(e))
Esempio n. 14
0
 def __init__(self, config_file, target_path):
     self.config_file = config_file
     if not check_path_exists(self.config_file):
         logging.error("{} not exists".format(self.config_file))
         sys.exit(1)
     try:
         self.configs = parse_configs(self.config_file)
     except Exception as e:
         logging.error(str(e))
     self.source_path = os.path.dirname(__file__)
     self.target_path = target_path
Esempio n. 15
0
 def output_to_file(self, html):
     """Write generated html to file"""
     category, mdown = self.get_category_and_mdown(self.mdown_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
         )
         os.mkdir(output_category_path)
     mdown_name = osp.splitext(mdown)[0]
     output_file = osp.join(output_category_path, mdown_name+".html")
     with codecs.open(output_file, "wb", "utf-8") as fd:
         fd.write(html)
Esempio n. 16
0
def parse_configs(config_file):
    base_dir = osp.dirname(osp.dirname(osp.realpath(__file__)))

    if not utils.check_path_exists(config_file):
        sys.exit(utils.color_msg("error", "{} not exists".format(config_file)))

    try:
        with open(config_file, "rb") as fd:
            configs = yaml.load(fd)
    except yaml.YAMLError, e:
        msg = "Yaml format error in {}:\n{}".format(
                config_file,
                unicode(str(e), "utf-8")
                )
        sys.exit(utils.color_msg("error", msg))
Esempio n. 17
0
def parse_configs(config_file):
    if not check_path_exists(config_file):
        logging.error("{} not exists".format(config_file))
        sys.exit(1)

    try:
        with open(config_file, "rb") as fd:
            configs = yaml.load(fd)
    except yaml.YAMLError, e:
        msg = "Yaml format error in {}:\n{}".format(
                config_file,
                unicode(str(e), "utf-8")
            )
        logging.error(msg)
        sys.exit(1)
Esempio n. 18
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. 19
0
def parse_configs(config_file):
    default_configs = _set_default_configs()

    if not check_path_exists(config_file):
        logging.error("{} not exists".format(config_file))
        sys.exit(1)

    try:
        with open(config_file, "rb") as fd:
            configs = yaml.load(fd)
    except yaml.YAMLError, e:
        msg = "Yaml format error in {}:\n{}".format(config_file,
                                                    unicode(str(e), "utf-8"))
        logging.error(msg)
        sys.exit(1)
Esempio n. 20
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 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. 21
0
def preview(path, port=8000):
    if check_path_exists(path):
        os.chdir(path)
    else:
        logger.error("Path {} not exists".format(path))
    try:
        Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        httpd = Reuse_TCPServer(("", port), Handler)
    except OSError as e:
        logger.error("Could not listen on port {}".format(port))
        sys.exit(getattr(e, 'exitcode', 1))

    logger.info("Serving at port {}".format(port))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt as e:
        logger.info("Shutting down server")
        httpd.socket.close()
Esempio n. 22
0
def preview(path, port=8000):
    if check_path_exists(path):
        os.chdir(path)
    else:
        logger.error("Path {} not exists".format(path))
    try:
        Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        httpd = SocketServer.TCPServer(("", port), Handler)
    except OSError as e:
        logger.error("Could not listen on port {}".format(port))
        sys.exit(getattr(e, 'exitcode', 1))

    logger.info("Serving at port {}".format(port))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt as e:
        logger.info("Shutting down server")
        httpd.socket.close()
Esempio n. 23
0
 def setUp(self):
     self.content = "sample"
     self.output = "output"
     if utils.check_path_exists(self.output):
         utils.emptytree(self.output)
         os.rmdir(self.output)
Esempio n. 24
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. 25
0
 def test_listdir_nohidden(self):
     hidden_file = os.path.join(self.content, ".hidden.txt")
     assert (utils.check_path_exists(hidden_file))
Esempio n. 26
0

def create_new_wiki(source, category, filename, title, date):
    try:
        meta = "\n".join([
            "---",
            "title: \"{}\"".format(title),
            "date: {}".format(date),
            "---",
        ]) + "\n\n"
    except Exception, e:
        logger.error(str(e))
        sys.exit(1)

    category_path = osp.join(source, category)
    if not check_path_exists(category_path):
        os.mkdir(category_path)
        logger.info("Creating category {}.".format(category))

    fn = osp.join(category_path, filename)
    if check_path_exists(fn):
        logger.warning("wiki file exists: {}".format(fn))
    else:
        logger.info("Creating wiki: {}".format(fn))
        with codecs.open(fn, "wb", "utf-8") as fd:
            fd.write(meta)


def install_theme(current_dir, theme_name):
    """Copy static directory under theme to output directory"""
    src_theme = osp.join(current_dir, "themes/{}/static".format(theme_name))
Esempio n. 27
0
 def tearDown(self):
     if utils.check_path_exists(self.output):
         utils.emptytree(self.output)
         os.rmdir(self.output)
Esempio n. 28
0
 def tearDown(self):
     if utils.check_path_exists(self.output):
         utils.emptytree(self.output)
         os.rmdir(self.output)
Esempio n. 29
0
 def test_listdir_nohidden(self):
     hidden_file = os.path.join(self.content, ".hidden.txt")
     assert (utils.check_path_exists(hidden_file))
Esempio n. 30
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. 31
0

def create_new_wiki(source, category, filename, title, date):
    try:
        meta = "\n".join([
            "---",
            "title: \"{}\"".format(title),
            "date: {}".format(date),
            "---",
        ]) + "\n\n"
    except Exception, e:
        logger.error(str(e))
        sys.exit(1)

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

    fn = os.path.join(category_path, filename)
    if check_path_exists(fn):
        logger.warning("wiki file exists: {}".format(fn))
    else:
        logger.info("Creating wiki: {}".format(fn))
        with codecs.open(fn, "wb", "utf-8") as fd:
            fd.write(meta)


def install_theme(current_dir, theme_name):
    """Copy static directory under theme to output directory"""
    src_theme = os.path.join(