• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.makedirs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nikola.utils.makedirs函数的典型用法代码示例。如果您正苦于以下问题:Python makedirs函数的具体用法?Python makedirs怎么用?Python makedirs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了makedirs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: process_tree

 def process_tree(self, src, dst):
     """Processes all images in a src tree and put the (possibly) rescaled
     images in the dst folder."""
     ignore = set([".svn"])
     base_len = len(src.split(os.sep))
     for root, dirs, files in os.walk(src, followlinks=True):
         root_parts = root.split(os.sep)
         if set(root_parts) & ignore:
             continue
         dst_dir = os.path.join(dst, *root_parts[base_len:])
         utils.makedirs(dst_dir)
         for src_name in files:
             if src_name in (".DS_Store", "Thumbs.db"):
                 continue
             if not src_name.lower().endswith(tuple(self.image_ext_list)) and not src_name.upper().endswith(
                 tuple(self.image_ext_list)
             ):
                 continue
             dst_file = os.path.join(dst_dir, src_name)
             src_file = os.path.join(root, src_name)
             thumb_file = ".thumbnail".join(os.path.splitext(dst_file))
             yield {
                 "name": dst_file,
                 "file_dep": [src_file],
                 "targets": [dst_file, thumb_file],
                 "actions": [(self.process_image, (src_file, dst_file, thumb_file))],
                 "clean": True,
             }
开发者ID:habilain,项目名称:nikola,代码行数:28,代码来源:scale_images.py


示例2: _execute

    def _execute(self, options, args):
        """Given a swatch name and a parent theme, creates a custom theme."""
        name = options['name']
        swatch = options['swatch']
        if not swatch:
            LOGGER.error('The -s option is mandatory')
            return 1
        parent = options['parent']
        version = ''

        # See if we need bootswatch for bootstrap v2 or v3
        themes = utils.get_theme_chain(parent)
        if 'bootstrap3' not in themes and 'bootstrap3-jinja' not in themes:
            version = '2'
        elif 'bootstrap' not in themes and 'bootstrap-jinja' not in themes:
            LOGGER.warn('"bootswatch_theme" only makes sense for themes that use bootstrap')
        elif 'bootstrap3-gradients' in themes or 'bootstrap3-gradients-jinja' in themes:
            LOGGER.warn('"bootswatch_theme" doesn\'t work well with the bootstrap3-gradients family')

        LOGGER.info("Creating '{0}' theme from '{1}' and '{2}'".format(name, swatch, parent))
        utils.makedirs(os.path.join('themes', name, 'assets', 'css'))
        for fname in ('bootstrap.min.css', 'bootstrap.css'):
            url = 'https://bootswatch.com'
            if version:
                url += '/' + version
            url = '/'.join((url, swatch, fname))
            LOGGER.info("Downloading: " + url)
            data = requests.get(url).text
            with open(os.path.join('themes', name, 'assets', 'css', fname),
                      'wb+') as output:
                output.write(data.encode('utf-8'))

        with open(os.path.join('themes', name, 'parent'), 'wb+') as output:
            output.write(parent.encode('utf-8'))
        LOGGER.notice('Theme created.  Change the THEME setting to "{0}" to use it.'.format(name))
开发者ID:jjconti,项目名称:nikola,代码行数:35,代码来源:bootswatch_theme.py


示例3: run

    def run(self):
        if matplotlib is None:
            msg = req_missing(['matplotlib'], 'use the plot directive', optional=True)
            return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]

        if not self.arguments and not self.content:
            raise self.error('The plot directive needs either an argument or content.')

        if self.arguments and self.content:
            raise self.error('The plot directive needs either an argument or content, not both.')

        if self.arguments:
            plot_path = self.arguments[0]
            with io.open(plot_path, encoding='utf-8') as fd:
                data = fd.read()
        elif self.content:
            data = '\n'.join(self.content)
            plot_path = md5(data).hexdigest()

        # Always reset context
        plt.close('all')
        matplotlib.rc_file_defaults()
        # Run plot
        exec(data)

        out_path = os.path.join(self.out_dir, plot_path + '.svg')
        plot_url = '/' + os.path.join('pyplots', plot_path + '.svg').replace(os.sep, '/')

        figures = [manager.canvas.figure for manager in matplotlib._pylab_helpers.Gcf.get_all_fig_managers()]
        for figure in figures:
            makedirs(os.path.dirname(out_path))
            figure.savefig(out_path, format='svg')  # Yes, if there's more than one, it's overwritten, sucks.
        self.arguments = [plot_url]
        return super(PyPlot, self).run()
开发者ID:ChillarAnand,项目名称:plugins,代码行数:34,代码来源:pyplots.py


示例4: _execute

    def _execute(self, options, args):
        """Given a swatch name and a parent theme, creates a custom theme."""
        if requests is None:
            utils.req_missing(['requests'], 'install Bootswatch themes')

        name = options['name']
        swatch = options['swatch']
        parent = options['parent']
        version = ''

        # See if we need bootswatch for bootstrap v2 or v3
        themes = utils.get_theme_chain(parent)
        if 'bootstrap3' not in themes:
            version = '2'
        elif 'bootstrap' not in themes:
            LOGGER.warn('"bootswatch_theme" only makes sense for themes that use bootstrap')

        LOGGER.notice("Creating '{0}' theme from '{1}' and '{2}'".format(name, swatch, parent))
        utils.makedirs(os.path.join('themes', name, 'assets', 'css'))
        for fname in ('bootstrap.min.css', 'bootstrap.css'):
            url = '/'.join(('http://bootswatch.com', version, swatch, fname))
            LOGGER.notice("Downloading: " + url)
            data = requests.get(url).text
            with open(os.path.join('themes', name, 'assets', 'css', fname),
                      'wb+') as output:
                output.write(data.encode('utf-8'))

        with open(os.path.join('themes', name, 'parent'), 'wb+') as output:
            output.write(parent.encode('utf-8'))
        LOGGER.notice('Theme created. Change the THEME setting to "{0}" to use '
                      'it.'.format(name))
开发者ID:AndreaCrotti,项目名称:nikola,代码行数:31,代码来源:bootswatch_theme.py


示例5: create_code_css

 def create_code_css():
     from pygments.formatters import get_formatter_by_name
     formatter = get_formatter_by_name('html', style=kw["code_color_scheme"])
     utils.makedirs(os.path.dirname(code_css_path))
     with codecs.open(code_css_path, 'wb+', 'utf8') as outf:
         outf.write(formatter.get_style_defs('pre.code'))
         outf.write("table.codetable { width: 100%;} td.linenos {text-align: right; width: 4em;}")
开发者ID:Liessae,项目名称:nikola,代码行数:7,代码来源:copy_assets.py


示例6: create_code_css

 def create_code_css():
     from pygments.formatters import get_formatter_by_name
     formatter = get_formatter_by_name('html', style=kw["code_color_scheme"])
     utils.makedirs(os.path.dirname(code_css_path))
     with codecs.open(code_css_path, 'wb+', 'utf8') as outf:
         outf.write(formatter.get_style_defs(kw["code.css_selectors"]))
         outf.write(kw["code.css_close"])
开发者ID:osama-afifi,项目名称:nikola,代码行数:7,代码来源:copy_assets.py


示例7: do_install

    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.info("Downloading '{0}'".format(data[name]))
            zip_file = io.BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.info("Extracting '{0}' into themes/".format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join(self.output_dir, name)
        else:
            dest_path = os.path.join(self.output_dir, name)
            try:
                theme_path = utils.get_theme_path(name)
                LOGGER.error("Theme '{0}' is already installed in {1}".format(name, theme_path))
            except Exception:
                LOGGER.error("Can't find theme {0}".format(name))

            return False

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice('This theme has a sample config file.  Integrate it with yours in order to make this theme work!')
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(utils.indent(pygments.highlight(
                        fh.read(), PythonLexer(), TerminalFormatter()),
                        4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return True
开发者ID:habilain,项目名称:nikola,代码行数:31,代码来源:install_theme.py


示例8: compile

    def compile(self, source, dest, is_two_file=True, post=None, lang=None):
        """Compile the source file into HTML and save as dest."""
        makedirs(os.path.dirname(dest))
        if ODF2XHTML is None:
            req_missing(['odfpy'], 'build this site (compile odt)')
        odhandler = ODF2XHTML(True, False)
        data = odhandler.odf2xhtml(source)

        # Take the CSS from the head and put it in body
        doc = etree.fromstring(data)
        body = doc.find('{http://www.w3.org/1999/xhtml}body')

        for style in doc.findall('*//{http://www.w3.org/1999/xhtml}style'):
            style.getparent().remove(style)

            # keep only classes:
            filtered = []
            for line in style.text.splitlines():
                if line and line[0] in '.\t}':
                    filtered.append(line)
            style.text = ''.join(filtered)

            body.insert(0, style)

        with io.open(dest, 'w+', encoding='utf-8') as outf:
            outf.write(etree.tostring(body, encoding='unicode'))
开发者ID:getnikola,项目名称:plugins,代码行数:26,代码来源:odt.py


示例9: create_redirect

def create_redirect(src, dst):
    utils.makedirs(os.path.dirname(src))
    with io.open(src, "w+", encoding="utf8") as fd:
        fd.write('<!DOCTYPE html><head><title>Redirecting...</title>'
                 '<meta name="robots" content="noindex">'
                 '<meta http-equiv="refresh" content="0; '
                 'url={0}"></head><body><p>Page moved <a href="{0}">here</a></p></body>'.format(dst))
开发者ID:asp49,项目名称:nikola,代码行数:7,代码来源:redirect.py


示例10: generate_css

        def generate_css():
            # Compass compile
            for theme_name in self.site.THEMES:

                theme_root = os.path.abspath(utils.get_theme_path(theme_name))
                compass_root = os.path.abspath(os.path.join(theme_root, 'style'))
                tmp_dir = os.path.abspath(os.path.join(theme_root, '_tmp'))

                if os.path.exists(compass_root):

                    LOGGER.notice("PYGMENTS CSS CODE")
                    create_code_css(self.site.config['CODE_COLOR_SCHEME'],
                                    os.path.join(compass_root, 'css', 'code.css'))


                    LOGGER.notice("COMPASS COMPILE")
                    run('compass clean', cwd=compass_root)
                    run('compass compile', cwd=compass_root)

                    LOGGER.notice("AUTOPREFIXER")
                    LOGGER.notice("CWD: {}".format(theme_root))
                    run('autoprefixer -o _tmp/all.pre.css _tmp/all.css', cwd=theme_root)

                    LOGGER.notice("CSSO (CSS optimizer)")
                    LOGGER.notice("CWD: {}".format(theme_root))
                    run('csso _tmp/all.pre.css _tmp/all.min.css', cwd=theme_root)


                    LOGGER.notice("Move CSS to output")
                    css_output_dir = os.path.join(os.path.abspath(self.site.config['OUTPUT_FOLDER']), 'assets', 'css')
                    utils.makedirs(css_output_dir)
                    shutil.copy2(os.path.join(tmp_dir, 'all.min.css'), css_output_dir)
开发者ID:jlesquembre,项目名称:blog,代码行数:32,代码来源:compilecss.py


示例11: compile_html

    def compile_html(self, source, dest, is_two_file=True):
        """Compile reSt into HTML."""

        if not has_docutils:
            req_missing(['docutils'], 'build this site (compile REST')
        makedirs(os.path.dirname(dest))
        error_level = 100
        with codecs.open(dest, "w+", "utf8") as out_file:
            with codecs.open(source, "r", "utf8") as in_file:
                data = in_file.read()
                if not is_two_file:
                    data = data.split('\n\n', 1)[-1]
                output, error_level, deps = rst2html(
                    data, settings_overrides={
                        'initial_header_level': 2,
                        'record_dependencies': True,
                        'stylesheet_path': None,
                        'link_stylesheet': True,
                        'syntax_highlight': 'short',
                        'math_output': 'mathjax',
                    })
                out_file.write(output)
            deps_path = dest + '.dep'
            if deps.list:
                with codecs.open(deps_path, "wb+", "utf8") as deps_file:
                    deps_file.write('\n'.join(deps.list))
            else:
                if os.path.isfile(deps_path):
                    os.unlink(deps_path)
        if error_level == 2:
            LOGGER.warning('Docutils reports warnings on {0}'.format(source))
        if error_level < 3:
            return True
        else:
            return False
开发者ID:DDevine,项目名称:nikola,代码行数:35,代码来源:__init__.py


示例12: _execute

    def _execute(self, options, args):
        """Install theme into current site."""
        if requests is None:
            utils.LOGGER.error('This command requires the requests package be installed.')
            return False

        listing = options['list']
        url = options['url']
        if args:
            name = args[0]
        else:
            name = None

        if name is None and not listing:
            utils.LOGGER.error("This command needs either a theme name or the -l option.")
            return False
        data = requests.get(url).text
        data = json.loads(data)
        if listing:
            print("Themes:")
            print("-------")
            for theme in sorted(data.keys()):
                print(theme)
            return True
        else:
            if name in data:
                utils.makedirs('themes')
                utils.LOGGER.notice('Downloading: ' + data[name])
                zip_file = BytesIO()
                zip_file.write(requests.get(data[name]).content)
                utils.LOGGER.notice('Extracting: {0} into themes'.format(name))
                utils.extract_all(zip_file)
            else:
                utils.LOGGER.error("Can't find theme " + name)
                return False
开发者ID:verbalshadow,项目名称:nikola,代码行数:35,代码来源:install_theme.py


示例13: create_post

    def create_post(self, path, **kw):
        content = kw.pop('content', None)
        onefile = kw.pop('onefile', False)
        # is_page is not needed to create the file
        kw.pop('is_page', False)

        makedirs(os.path.dirname(path))
        if onefile:
            raise Exception('The one-file format is not supported by this compiler.')
        with io.open(path, "w+", encoding="utf8") as fd:
            if not content.startswith("Write your"):
                fd.write(content)
            else:
                fd.write("""{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}""")
开发者ID:Drooids,项目名称:nikola,代码行数:35,代码来源:__init__.py


示例14: create_archive_redirect

def create_archive_redirect(src, dst):
    if os.path.exists(src): return 
    utils.makedirs(os.path.dirname(src))
    with codecs.open(src, "wb+", "utf8") as fd:
        fd.write('<!DOCTYPE html><head><title>Redirecting...</title>'
                 '<meta http-equiv="refresh" content="0; '
                 'url={0}"></head>'.format(dst))
开发者ID:sunxu,项目名称:sunxu.me,代码行数:7,代码来源:redirect_directories.py


示例15: compile_html

 def compile_html(self, source, dest, is_two_file=True):
     makedirs(os.path.dirname(dest))
     try:
         subprocess.check_call(('asciidoc', '-f', 'html', '-s', '-o', dest, source))
     except OSError as e:
         if e.strreror == 'No such file or directory':
             req_missing(['asciidoc'], 'build this site (compile with asciidoc)', python=False)
开发者ID:DoctorMalboro,项目名称:nikola,代码行数:7,代码来源:asciidoc.py


示例16: compile_html

 def compile_html(self, source, dest, is_two_file=True):
     makedirs(os.path.dirname(dest))
     try:
         subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])
     except OSError as e:
         if e.strreror == 'No such file or directory':
             req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False)
开发者ID:CasAndreu,项目名称:pols_503_sp15,代码行数:7,代码来源:pandoc.py


示例17: process_tree

 def process_tree(self, src, dst):
     """Process all images in a src tree and put the (possibly) rescaled images in the dst folder."""
     thumb_fmt = self.kw['image_thumbnail_format']
     base_len = len(src.split(os.sep))
     for root, dirs, files in os.walk(src, followlinks=True):
         root_parts = root.split(os.sep)
         dst_dir = os.path.join(dst, *root_parts[base_len:])
         utils.makedirs(dst_dir)
         for src_name in files:
             if (not src_name.lower().endswith(tuple(self.image_ext_list)) and not src_name.upper().endswith(tuple(self.image_ext_list))):
                 continue
             dst_file = os.path.join(dst_dir, src_name)
             src_file = os.path.join(root, src_name)
             thumb_name, thumb_ext = os.path.splitext(src_name)
             thumb_file = os.path.join(dst_dir, thumb_fmt.format(
                 name=thumb_name,
                 ext=thumb_ext,
             ))
             yield {
                 'name': dst_file,
                 'file_dep': [src_file],
                 'targets': [dst_file, thumb_file],
                 'actions': [(self.process_image, (src_file, dst_file, thumb_file))],
                 'clean': True,
             }
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:25,代码来源:scale_images.py


示例18: compile_html

    def compile_html(self, source, dest, is_two_file=True):
        makedirs(os.path.dirname(dest))
        if ODF2XHTML is None:
            req_missing(["odfpy"], "build this site (compile odt)")
        odhandler = ODF2XHTML(True, False)
        data = odhandler.odf2xhtml(source)

        # Take the CSS from the head and put it in body
        doc = etree.fromstring(data)
        body = doc.find("{http://www.w3.org/1999/xhtml}body")

        for style in doc.findall("*//{http://www.w3.org/1999/xhtml}style"):
            style.getparent().remove(style)

            # keep only classes:
            filtered = []
            for line in style.text.splitlines():
                if line and line[0] in ".\t}":
                    filtered.append(line)
            style.text = "".join(filtered)

            body.insert(0, style)

        with io.open(dest, "w+", encoding="utf-8") as outf:
            outf.write(etree.tostring(body, encoding="unicode"))
开发者ID:ChillarAnand,项目名称:plugins,代码行数:25,代码来源:odt.py


示例19: do_install

    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.notice('Downloading: ' + data[name])
            zip_file = BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.notice('Extracting: {0} into themes'.format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join('themes', name)
        else:
            try:
                theme_path = utils.get_theme_path(name)
            except:
                LOGGER.error("Can't find theme " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return False

            LOGGER.notice('Copying {0} into themes'.format(theme_path))
            shutil.copytree(theme_path, dest_path)
        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice('This plugin has a sample config file.')
            print('Contents of the conf.py.sample file:\n')
            with codecs.open(confpypath, 'rb', 'utf-8') as fh:
                print(indent(pygments.highlight(
                    fh.read(), PythonLexer(), TerminalFormatter()), 4 * ' '))
            return True
开发者ID:AndreaCrotti,项目名称:nikola,代码行数:32,代码来源:install_theme.py


示例20: compile

    def compile(self, source, dest, is_two_file=True, post=None, lang=None):
        """Compile the source file into HTML and save as dest."""
        makedirs(os.path.dirname(dest))
        try:
            command = [
                'emacs', '--batch',
                '-l', join(dirname(abspath(__file__)), 'init.el'),
                '--eval', '(nikola-html-export "{0}" "{1}")'.format(
                    abspath(source), abspath(dest))
            ]

            # Dirty walkaround for this plugin to run on Windows platform.
            if os.name == 'nt':
                command[5] = command[5].replace("\\", "\\\\")

            subprocess.check_call(command)
            with io.open(dest, 'r', encoding='utf-8') as inf:
                output, shortcode_deps = self.site.apply_shortcodes(inf.read(), with_dependencies=True)
            with io.open(dest, 'w', encoding='utf-8') as outf:
                outf.write(output)
            if post is None:
                if shortcode_deps:
                    self.logger.error(
                        "Cannot save dependencies for post {0} (post unknown)",
                        source)
            else:
                post._depfile[dest] += shortcode_deps
        except OSError as e:
            import errno
            if e.errno == errno.ENOENT:
                req_missing(['emacs', 'org-mode'],
                            'use the orgmode compiler', python=False)
        except subprocess.CalledProcessError as e:
            raise Exception('Cannot compile {0} -- bad org-mode configuration (return code {1})'.format(source, e.returncode))
开发者ID:getnikola,项目名称:plugins,代码行数:34,代码来源:orgmode.py



注:本文中的nikola.utils.makedirs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.slugify函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_translation_candidate函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap