Ejemplo n.º 1
0
    def get_default_theme(self, theme_path):
        src_theme = os.path.join(self.source_path, "themes")
        if os.path.exists(theme_path):
            shutil.rmtree(theme_path)

        copytree(src_theme, theme_path)
        logging.info("Copying default theme to: {0}".format(theme_path))
Ejemplo n.º 2
0
 def copy_attach(self):
     """Copy attach directory under root path to destination directory"""
     src_p = os.path.join(self.target_path, self.config['attach'])
     dest_p = os.path.join(self.target_path, self.config["destination"],
                           self.config['attach'])
     if os.path.exists(src_p):
         copytree(src_p, dest_p)
Ejemplo n.º 3
0
 def copy_attach(self):
     """Copy attach directory under root path to destination directory"""
     src_p = os.path.join(self.target_path, self.config['attach'])
     dest_p = os.path.join(self.target_path, self.config["destination"],
                           self.config['attach'])
     if os.path.exists(src_p):
         copytree(src_p, dest_p)
Ejemplo n.º 4
0
    def get_default_theme(self, theme_path):
        src_theme = osp.join(os.path.dirname(__file__), "themes")
        if osp.exists(theme_path):
            shutil.rmtree(theme_path)

        copytree(src_theme, theme_path)
        logging.info("Copying default theme to: {}".format(theme_path))
Ejemplo n.º 5
0
    def setUp(self):
        self.args = deepcopy(INIT_ARGS)
        self.wiki_path = os.path.join(test_path, "mywiki_for_cli")
        self.output_path = os.path.join(self.wiki_path, "output")

        if os.path.exists(self.output_path):
            emptytree(self.output_path)

        config_file_tpl = os.path.join(base_path, "simiki", "conf_templates", "_config.yml.in")
        self.config_file_dst = os.path.join(self.wiki_path, "_config.yml")
        shutil.copyfile(config_file_tpl, self.config_file_dst)

        s_themes_path = os.path.join(base_path, "simiki", "themes")
        self.d_themes_path = os.path.join(self.wiki_path, "themes")
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)

        self.drafts = [os.path.join(self.output_path, "intro", "my_draft.html")]
        self.files = [
            os.path.join(self.output_path, "index.html"),
            os.path.join(self.output_path, "intro", "gettingstarted.html"),
        ]
        self.dirs = [self.output_path, os.path.join(self.output_path, "intro")]
        self.attach = [os.path.join(self.output_path, "attach", "images", "linux", "opstools.png")]
        self.static = [os.path.join(self.output_path, "static", "css", "style.css")]
        os.chdir(self.wiki_path)
Ejemplo n.º 6
0
    def get_default_theme(self, theme_path):
        src_theme = os.path.join(self.source_path, "themes")
        if os.path.exists(theme_path):
            shutil.rmtree(theme_path)

        copytree(src_theme, theme_path)
        logging.info("Copying default theme to: {0}".format(theme_path))
Ejemplo n.º 7
0
 def test_copytree_common(self):
     utils.copytree(self.content, self.output)
     files = [".hidden.txt", "hellosimiki.md", "zen_of_python.txt",
              "simiki.md"]
     assert(os.path.exists(self.output))
     for f in files:
         assert(os.path.exists(os.path.join(self.output, f)))
     assert(not os.path.islink(os.path.join(self.output, "simiki.md")))
Ejemplo n.º 8
0
 def get_default_theme(self, theme_path):
     default_theme_name = self.config["theme"]
     src_theme = os.path.join(self.source_path, self.config["themes_dir"], default_theme_name)
     dst_theme = os.path.join(theme_path, default_theme_name)
     if os.path.exists(dst_theme):
         logging.warning("{0} exists".format(dst_theme))
     else:
         copytree(src_theme, dst_theme)
         logging.info("Copying default theme '{0}' to: {1}".format(default_theme_name, theme_path))
Ejemplo n.º 9
0
 def test_copytree_common(self):
     utils.copytree(self.content, self.output)
     files = [
         ".hidden.txt", "hellosimiki.md", "zen_of_python.txt", "simiki.md"
     ]
     assert (os.path.exists(self.output))
     for f in files:
         assert (os.path.exists(os.path.join(self.output, f)))
     assert (not os.path.islink(os.path.join(self.output, "simiki.md")))
Ejemplo n.º 10
0
    def install_theme(self):
        # TODO copy non-html files and directorys
        src_theme = osp.join(self.current_dir, "themes/{}/css".format(self.configs["theme"]))
        dst_theme = osp.join(self.current_dir, "output/css")
        if osp.exists(dst_theme):
            shutil.rmtree(dst_theme)

        copytree(src_theme, dst_theme)
        logging.info("Installing theme: {}".format(self.configs["theme"]))
Ejemplo n.º 11
0
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))
    dst_theme = osp.join(current_dir, "output/static")
    if osp.exists(dst_theme):
        shutil.rmtree(dst_theme)

    copytree(src_theme, dst_theme)
    logging.info("Installing theme: {}".format(theme_name))
Ejemplo n.º 12
0
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))
    dst_theme = osp.join(current_dir, "output/static")
    if osp.exists(dst_theme):
        shutil.rmtree(dst_theme)

    copytree(src_theme, dst_theme)
    logging.info("Installing theme: {}".format(theme_name))
Ejemplo n.º 13
0
def install_theme(current_dir, theme_dir, theme_name, dest_path):
    """Copy static directory under theme to destination directory"""
    src_theme = os.path.join(current_dir, theme_dir, theme_name, "static")
    dest_theme = os.path.join(current_dir, dest_path, "static")
    if os.path.exists(dest_theme):
        shutil.rmtree(dest_theme)

    copytree(src_theme, dest_theme)
    logging.info("Installing theme: {0}".format(theme_name))
Ejemplo n.º 14
0
def _update_dir(dirname, local_dir, original_dir, tag='directory'):
    """Update sth on a per-directory basis, such as theme
    :dirname: directory name to be updated, without parent path
    :local_path: full path of local dirname
    :original_path: full path of original dirname
    :tag: input help information
    """

    up_to_date = True

    try:
        if os.path.exists(local_dir):
            _need_update = False
            for root, dirs, files in os.walk(original_dir):
                files = [f for f in files if not f.startswith(".")]
                dirs[:] = [d for d in dirs if not d.startswith(".")]
                rel_dir = os.path.relpath(root, original_dir)

                for fn in files:
                    original_fn_md5 = get_md5(os.path.join(root, fn))

                    local_fn = os.path.join(local_dir, rel_dir, fn)
                    if not os.path.exists(local_fn):
                        _need_update = True
                        break
                    local_fn_md5 = get_md5(local_fn)
                    if local_fn_md5 != original_fn_md5:
                        _need_update = True
                        break
                if _need_update:
                    break

            if _need_update:
                up_to_date = False
                try:
                    _ans = get_input('Overwrite {0} {1}? (y/N) '.format(
                        tag, dirname))
                    if _ans.lower() in yes_answer:
                        shutil.rmtree(local_dir)
                        copytree(original_dir, local_dir)
                except (KeyboardInterrupt, SystemExit):
                    print()
        else:
            up_to_date = False
            try:
                _ans = get_input('New {0} {1}? (y/N) '.format(tag, dirname))
                if _ans.lower() in yes_answer:
                    copytree(original_dir, local_dir)
            except (KeyboardInterrupt, SystemExit):
                print()
    except Exception as e:
        logger.error(e)

    if up_to_date:
        logger.info('{0} {1} is already up to date.'.format(tag, dirname))
Ejemplo n.º 15
0
def _update_dir(dirname, local_dir, original_dir, tag='directory'):
    '''Update sth on a per-directory basis, such as theme
    :dirname: directory name to be updated, without parent path
    :local_path: full path of local dirname
    :original_path: full path of original dirname
    :tag: input help information
    '''

    up_to_date = True

    try:
        if os.path.exists(local_dir):
            _need_update = False
            for root, dirs, files in os.walk(original_dir):
                files = [f for f in files if not f.startswith(".")]
                dirs[:] = [d for d in dirs if not d.startswith(".")]
                rel_dir = os.path.relpath(root, original_dir)

                for fn in files:
                    original_fn_md5 = get_md5(os.path.join(root, fn))

                    local_fn = os.path.join(local_dir, rel_dir, fn)
                    if not os.path.exists(local_fn):
                        _need_update = True
                        break
                    local_fn_md5 = get_md5(local_fn)
                    if local_fn_md5 != original_fn_md5:
                        _need_update = True
                        break
                if _need_update:
                    break

            if _need_update:
                up_to_date = False
                try:
                    _ans = get_input('Overwrite {0} {1}? (y/N) '
                                     .format(tag, dirname))
                    if _ans.lower() in yes_answer:
                        shutil.rmtree(local_dir)
                        copytree(original_dir, local_dir)
                except (KeyboardInterrupt, SystemExit):
                    print()
        else:
            up_to_date = False
            try:
                _ans = get_input('New {0} {1}? (y/N) '.format(tag, dirname))
                if _ans.lower() in yes_answer:
                    copytree(original_dir, local_dir)
            except (KeyboardInterrupt, SystemExit):
                print()
    except Exception as e:
        logger.error(e)

    if up_to_date:
        logger.info('{0} {1} is already up to date.'.format(tag, dirname))
Ejemplo n.º 16
0
 def get_default_theme(self, theme_path):
     default_theme_name = self.config['theme']
     src_theme = os.path.join(self.source_path, self.config['themes_dir'],
                              default_theme_name)
     dst_theme = os.path.join(theme_path, default_theme_name)
     if os.path.exists(dst_theme):
         logging.warning('{0} exists'.format(dst_theme))
     else:
         copytree(src_theme, dst_theme)
         logging.info("Copying default theme '{0}' to: {1}".format(
             default_theme_name, theme_path))
Ejemplo n.º 17
0
    def install_theme(self):
        """Copy static directory under theme to destination directory"""
        src_theme = os.path.join(self.target_path, self.config["themes_dir"],
                                 self.config["theme"], "static")
        dest_theme = os.path.join(self.target_path, self.config["destination"],
                                  "static")
        if os.path.exists(dest_theme):
            shutil.rmtree(dest_theme)

        copytree(src_theme, dest_theme)
        logging.debug("Installing theme: {0}".format(self.config["theme"]))
Ejemplo n.º 18
0
    def install_theme(self):
        """Copy static directory under theme to destination directory"""
        src_theme = os.path.join(self.target_path, self.config["themes_dir"],
                                 self.config["theme"], "static")
        dest_theme = os.path.join(self.target_path, self.config["destination"],
                                  "static")
        if os.path.exists(dest_theme):
            shutil.rmtree(dest_theme)

        copytree(src_theme, dest_theme)
        logging.debug("Installing theme: {0}".format(self.config["theme"]))
Ejemplo n.º 19
0
    def test_update_builtin_up_to_date(self):
        shutil.copyfile(self.original_fabfile, self.local_fabfile)
        utils.copytree(self.original_theme, self.local_theme)

        updater.update_builtin(**self.kwargs)

        original_fn_md5 = utils.get_md5(self.original_fabfile)
        local_fn_md5 = utils.get_md5(self.local_fabfile)
        self.assertEqual(original_fn_md5, local_fn_md5)

        original_fn_md5 = utils.get_dir_md5(self.original_theme)
        local_fn_md5 = utils.get_dir_md5(self.local_theme)
        self.assertEqual(original_fn_md5, local_fn_md5)
Ejemplo n.º 20
0
    def test_update_builtin_up_to_date(self):
        shutil.copyfile(self.original_fabfile, self.local_fabfile)
        utils.copytree(self.original_theme, self.local_theme)

        updater.update_builtin(**self.kwargs)

        original_fn_md5 = utils.get_md5(self.original_fabfile)
        local_fn_md5 = utils.get_md5(self.local_fabfile)
        self.assertEqual(original_fn_md5, local_fn_md5)

        original_fn_md5 = utils.get_dir_md5(self.original_theme)
        local_fn_md5 = utils.get_dir_md5(self.local_theme)
        self.assertEqual(original_fn_md5, local_fn_md5)
Ejemplo n.º 21
0
    def test_copytree_common(self):
        utils.copytree(self.content, self.output)
        assert os.path.exists(self.output) and os.path.isdir(self.output)

        files = [
            os.path.join('python', 'zen_of_python.md'),
            os.path.join('python', 'python文档.md'),
            os.path.join('其它', 'helloworld.markdown'),
            os.path.join('其它', '维基.md'),
            os.path.join('其它', 'hello.txt'),
            os.path.join('其它', '.hidden.md'),
        ]
        for f in files:
            assert os.path.exists(os.path.join(self.output, f))
Ejemplo n.º 22
0
    def test_copytree_common(self):
        utils.copytree(self.content, self.output)
        assert os.path.exists(self.output) and os.path.isdir(self.output)

        files = [
            os.path.join('python', 'zen_of_python.md'),
            os.path.join('python', 'python文档.md'),
            os.path.join('其它', 'helloworld.markdown'),
            os.path.join('其它', '维基.md'),
            os.path.join('其它', 'hello.txt'),
            os.path.join('其它', '.hidden.md'),
        ]
        for f in files:
            assert os.path.exists(os.path.join(self.output, f))
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
    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)
Ejemplo n.º 28
0
    def init_site(self):
        content_path = osp.join(self.current_dir, self.configs["source"])
        output_path = osp.join(self.current_dir, self.configs["destination"])
        theme_path = osp.join(self.current_dir, "themes")
        for path in (content_path, output_path, theme_path):
            if osp.exists(path):
                logging.warning("{} exists".format(path))
            else:
                os.mkdir(path)
                logging.info("Creating directory: {}".format(path))

        src_theme = osp.join(os.path.dirname(__file__), "themes")
        if osp.exists(theme_path):
            shutil.rmtree(theme_path)

        copytree(src_theme, theme_path)
        logging.info("Copying themes: {}".format(theme_path))

        self.get_conf()
        self.install_theme()
Ejemplo n.º 29
0
    def setUp(self):
        self.args = deepcopy(INIT_ARGS)
        self.wiki_path = os.path.join(test_path, "mywiki_for_cli")
        self.output_path = os.path.join(self.wiki_path, "output")

        if os.path.exists(self.output_path):
            emptytree(self.output_path)

        config_file_tpl = os.path.join(base_path, 'simiki', 'conf_templates',
                                       '_config.yml.in')
        self.config_file_dst = os.path.join(self.wiki_path, '_config.yml')
        shutil.copyfile(config_file_tpl, self.config_file_dst)

        s_themes_path = os.path.join(base_path, 'simiki', 'themes')
        self.d_themes_path = os.path.join(self.wiki_path, 'themes')
        if os.path.exists(self.d_themes_path):
            shutil.rmtree(self.d_themes_path)
        copytree(s_themes_path, self.d_themes_path)

        self.drafts = [
            os.path.join(self.output_path, "intro", "my_draft.html")
        ]
        self.files = [
            os.path.join(self.output_path, "index.html"),
            os.path.join(self.output_path, "intro", "gettingstarted.html")
        ]
        self.dirs = [
            self.output_path,
            os.path.join(self.output_path, "intro"),
        ]
        self.attach = [
            os.path.join(self.output_path, 'attach', 'images', 'linux',
                         'opstools.png'),
        ]
        self.static = [
            os.path.join(self.output_path, "static", "css", "style.css"),
        ]
        os.chdir(self.wiki_path)
Ejemplo n.º 30
0
    def test_update_builtin_exists_with_no(self, mock_input):
        # empty fabfile.py
        with open(self.local_fabfile, 'wb') as _fd:
            _fd.close()
        original_fn_md5 = utils.get_md5(self.original_fabfile)
        local_fn_md5 = utils.get_md5(self.local_fabfile)
        self.assertNotEqual(original_fn_md5, local_fn_md5)

        utils.copytree(self.original_theme, self.local_theme)
        with open(self.local_theme_afile, 'wb') as _fd:
            _fd.close()
        original_fn_md5 = utils.get_dir_md5(self.original_theme)
        local_fn_md5 = utils.get_dir_md5(self.local_theme)
        self.assertNotEqual(original_fn_md5, local_fn_md5)

        updater.update_builtin(**self.kwargs)

        original_fn_md5 = utils.get_md5(self.original_fabfile)
        local_fn_md5 = utils.get_md5(self.local_fabfile)
        self.assertNotEqual(original_fn_md5, local_fn_md5)

        original_fn_md5 = utils.get_dir_md5(self.original_theme)
        local_fn_md5 = utils.get_dir_md5(self.local_theme)
        self.assertNotEqual(original_fn_md5, local_fn_md5)
Ejemplo n.º 31
0
    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)
Ejemplo n.º 32
0
    def test_update_builtin_exists_with_no(self, mock_input):
        # empty fabfile.py
        with open(self.local_fabfile, 'wb') as _fd:
            _fd.close()
        original_fn_md5 = utils.get_md5(self.original_fabfile)
        local_fn_md5 = utils.get_md5(self.local_fabfile)
        self.assertNotEqual(original_fn_md5, local_fn_md5)

        utils.copytree(self.original_theme, self.local_theme)
        with open(self.local_theme_afile, 'wb') as _fd:
            _fd.close()
        original_fn_md5 = utils.get_dir_md5(self.original_theme)
        local_fn_md5 = utils.get_dir_md5(self.local_theme)
        self.assertNotEqual(original_fn_md5, local_fn_md5)

        updater.update_builtin(**self.kwargs)

        original_fn_md5 = utils.get_md5(self.original_fabfile)
        local_fn_md5 = utils.get_md5(self.local_fabfile)
        self.assertNotEqual(original_fn_md5, local_fn_md5)

        original_fn_md5 = utils.get_dir_md5(self.original_theme)
        local_fn_md5 = utils.get_dir_md5(self.local_theme)
        self.assertNotEqual(original_fn_md5, local_fn_md5)
Ejemplo n.º 33
0
 def test_emptytree(self):
     utils.copytree(self.content, self.output)
     utils.emptytree(self.output)
     assert os.path.isdir(self.output) and not os.listdir(self.output)
Ejemplo n.º 34
0
def copy_attach(current_dir, attach_dir, dest_dir):
    """Copy attach directory under root path to destination directory"""
    src_p = os.path.join(current_dir, attach_dir)
    dest_p = os.path.join(current_dir, dest_dir, attach_dir)
    if os.path.exists(src_p):
        copytree(src_p, dest_p)
Ejemplo n.º 35
0
 def test_emptytree(self):
     utils.copytree(self.content, self.output)
     utils.emptytree(self.output)
     assert os.path.isdir(self.output) and not os.listdir(self.output)
Ejemplo n.º 36
0
def update_builtin():
    '''Update builtin scripts and themes under local site'''
    # for fabfile.py
    yes_ans = ('y', 'yes')
    _fabfile_r = os.path.join(os.path.dirname(__file__), 'conf_templates',
                              'fabfile.py')
    _fabfile_l = os.path.join(os.getcwd(), 'fabfile.py')
    if os.path.exists(_fabfile_l):
        # py3 require md5 with bytes object, otherwise raise
        # TypeError: Unicode-objects must be encoded before hashing
        with open(_fabfile_r, 'rb') as _fd:
            _fabfile_r_md5 = hashlib.md5(_fd.read()).hexdigest()
        with open(_fabfile_l, 'rb') as _fd:
            _fabfile_l_md5 = hashlib.md5(_fd.read()).hexdigest()
        if _fabfile_l_md5 != _fabfile_r_md5:
            try:
                _ans = raw_input('Overwrite fabfile.py? (y/N) ')
                if _ans.lower() in yes_ans:
                    shutil.copy2(_fabfile_r, _fabfile_l)
            except (KeyboardInterrupt, SystemExit):
                print()  # newline with Ctrl-C
    else:
        try:
            _ans = raw_input('New fabfile.py? (y/N) ')
            if _ans.lower() in yes_ans:
                shutil.copy2(_fabfile_r, _fabfile_l)
        except (KeyboardInterrupt, SystemExit):
            print()

    # for themes
    _themes_r = os.path.join(os.path.dirname(__file__), 'themes')
    _themes_l = os.path.join(os.getcwd(), config['themes_dir'])
    for theme in os.listdir(_themes_r):
        _theme_r = os.path.join(_themes_r, theme)
        _theme_l = os.path.join(_themes_l, theme)
        if os.path.exists(_theme_l):
            _need_update = False
            for root, dirs, files in os.walk(_theme_r):
                files = [f for f in files if not f.startswith(".")]
                dirs[:] = [d for d in dirs if not d.startswith(".")]
                for filename in files:
                    with open(os.path.join(root, filename), 'rb') as _fd:
                        _theme_r_md5 = hashlib.md5(_fd.read()).hexdigest()
                    _dir = os.path.relpath(root, _theme_r)
                    with open(os.path.join(_theme_l, _dir, filename),
                              'rb') as _fd:
                        _theme_l_md5 = hashlib.md5(_fd.read()).hexdigest()
                    if _theme_l_md5 != _theme_r_md5:
                        _need_update = True
                        break
                if _need_update:
                    break
            if _need_update:
                try:
                    _ans = raw_input('Overwrite theme {0}? (y/N) '
                                     .format(theme))
                    if _ans.lower() in yes_ans:
                        shutil.rmtree(_theme_l)
                        copytree(_theme_r, _theme_l)
                except (KeyboardInterrupt, SystemExit):
                    print()
        else:
            try:
                _ans = raw_input('New theme {0}? (y/N) '.format(theme))
                if _ans.lower() in yes_ans:
                    copytree(_theme_r, _theme_l)
            except (KeyboardInterrupt, SystemExit):
                print()
Ejemplo n.º 37
0
def update_builtin():
    '''Update builtin scripts and themes under local site'''
    # for fabfile.py
    yes_ans = ('y', 'yes')
    _fabfile_r = os.path.join(os.path.dirname(__file__), 'conf_templates',
                              'fabfile.py')
    _fabfile_l = os.path.join(os.getcwd(), 'fabfile.py')
    if os.path.exists(_fabfile_l):
        # py3 require md5 with bytes object, otherwise raise
        # TypeError: Unicode-objects must be encoded before hashing
        with open(_fabfile_r, 'rb') as _fd:
            _fabfile_r_md5 = hashlib.md5(_fd.read()).hexdigest()
        with open(_fabfile_l, 'rb') as _fd:
            _fabfile_l_md5 = hashlib.md5(_fd.read()).hexdigest()
        if _fabfile_l_md5 != _fabfile_r_md5:
            try:
                _ans = raw_input('Overwrite fabfile.py? (y/N) ')
                if _ans.lower() in yes_ans:
                    shutil.copy2(_fabfile_r, _fabfile_l)
            except (KeyboardInterrupt, SystemExit):
                print()  # newline with Ctrl-C
    else:
        try:
            _ans = raw_input('New fabfile.py? (y/N) ')
            if _ans.lower() in yes_ans:
                shutil.copy2(_fabfile_r, _fabfile_l)
        except (KeyboardInterrupt, SystemExit):
            print()

    # for themes
    _themes_r = os.path.join(os.path.dirname(__file__), 'themes')
    _themes_l = os.path.join(os.getcwd(), config['themes_dir'])
    for theme in os.listdir(_themes_r):
        _theme_r = os.path.join(_themes_r, theme)
        _theme_l = os.path.join(_themes_l, theme)
        if os.path.exists(_theme_l):
            _need_update = False
            for root, dirs, files in os.walk(_theme_r):
                files = [f for f in files if not f.startswith(".")]
                dirs[:] = [d for d in dirs if not d.startswith(".")]
                for filename in files:
                    with open(os.path.join(root, filename), 'rb') as _fd:
                        _theme_r_md5 = hashlib.md5(_fd.read()).hexdigest()
                    _dir = os.path.relpath(root, _theme_r)
                    with open(os.path.join(_theme_l, _dir, filename),
                              'rb') as _fd:
                        _theme_l_md5 = hashlib.md5(_fd.read()).hexdigest()
                    if _theme_l_md5 != _theme_r_md5:
                        _need_update = True
                        break
                if _need_update:
                    break
            if _need_update:
                try:
                    _ans = raw_input(
                        'Overwrite theme {0}? (y/N) '.format(theme))
                    if _ans.lower() in yes_ans:
                        shutil.rmtree(_theme_l)
                        copytree(_theme_r, _theme_l)
                except (KeyboardInterrupt, SystemExit):
                    print()
        else:
            try:
                _ans = raw_input('New theme {0}? (y/N) '.format(theme))
                if _ans.lower() in yes_ans:
                    copytree(_theme_r, _theme_l)
            except (KeyboardInterrupt, SystemExit):
                print()