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

Python utils.normpath函数代码示例

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

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



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

示例1: _generate

 def _generate(self):
     logger.debug('>> Initializing\n..  src:  {0}\n..  dest: {1}'.format(self.src.path, self.dest.path))
     
     self._update_config()
     
     for opt in ('base_url',):
         if opt in self.opts:
             self.config[opt] = self.opts[opt]
     
     self.renderer.register({'site': self.config})
     
     self._render()
     
     logger.info('>> Generating')
     
     assets_src = Directory(normpath(self.src.path, '_assets'))
     assets_dest = Directory(normpath(self.dest.path, *self.config['assets_url'].split('/')))
     
     if self.dest.exists:
         if self.opts['force']:
             self.dest.empty()
         else:
             self.dest.rm()
     else:
         self.dest.mk()
     
     for page in self.pages:
         page.mk()
     
     if assets_src.exists:
         for asset in assets_src:
             asset.cp(asset.path.replace(assets_src.path, assets_dest.path))
     
     logger.info('Completed in {0:.3f}s'.format(time() - self._start))
开发者ID:jag3773,项目名称:mynt,代码行数:34,代码来源:core.py


示例2: _generate

    def _generate(self):
        self._initialize()
        self._parse()
        self._render()

        logger.info('>> Generating')

        assets_src = Directory(normpath(self.src.path, '_assets'))
        assets_dest = Directory(normpath(self.dest.path, *self.config['assets_url'].split('/')))

        figures_src = Directory(normpath(self.src.path, '_figures'))
        figures_dest = Directory(normpath(self.dest.path, *self.config['figures_url'].split('/')))

        if self.dest.exists:
            if self.opts['force']:
                self.dest.empty()
            else:
                self.dest.rm()
        else:
            self.dest.mk()

        for page in self.pages:
            page.mk()

        assets_src.cp(assets_dest.path)
        figures_src.cp(figures_dest.path)

        for pattern in self.config['include']:
            for path in iglob(normpath(self.src.path, pattern)):
                dest = path.replace(self.src.path, self.dest.path)

                if op.isdir(path):
                    Directory(path).cp(dest, False)
                elif op.isfile(path):
                    File(path).cp(dest)
开发者ID:shamansir,项目名称:mynt,代码行数:35,代码来源:core.py


示例3: _update_config

 def _update_config(self):
     self.config = deepcopy(self.defaults)
     
     logger.debug('>> Searching for config')
     
     for ext in ('.yml', '.yaml'):
         f = File(normpath(self.src.path, 'config' + ext))
         
         if f.exists:
             logger.debug('..  found: %s', f.path)
             
             try:
                 self.config.update(Config(f.content))
             except ConfigException as e:
                 raise ConfigException(e.message, 'src: {0}'.format(f.path))
             
             self.config['locale'] = self.opts.get('locale', self.config['locale'])
             
             self.config['assets_url'] = absurl(self.config['assets_url'], '')
             self.config['base_url'] = absurl(self.opts.get('base_url', self.config['base_url']), '')
             
             for setting in ('archives_url', 'posts_url', 'tags_url'):
                 self.config[setting] = absurl(self.config[setting])
             
             for setting in ('archives_url', 'assets_url', 'base_url', 'posts_url', 'tags_url'):
                 if re.search(r'(?:^\.{2}/|/\.{2}$|/\.{2}/)', self.config[setting]):
                     raise ConfigException('Invalid config setting.', 'setting: {0}'.format(setting), 'path traversal is not allowed')
             
             for pattern in self.config['include']:
                 if op.commonprefix((self.src.path, normpath(self.src.path, pattern))) != self.src.path:
                     raise ConfigException('Invalid include path.', 'path: {0}'.format(pattern), 'path traversal is not allowed')
             
             break
     else:
         logger.debug('..  no config file found')
开发者ID:geerk,项目名称:mynt,代码行数:35,代码来源:core.py


示例4: init

    def init(self):
        Timer.start()

        self.src = Directory(self._get_theme(self.opts['theme']))
        self.dest = Directory(self.opts['dest'])

        if not self.src.exists:
            raise OptionException('Theme not found.')
        elif self.dest.exists and not self.opts['force']:
            raise OptionException('Destination already exists.',
                'the -f flag must be passed to force initialization by deleting the destination')

        logger.info('>> Initializing')

        if self.opts['bare']:
            self.dest.rm()

            for d in ('_assets/css', '_assets/images', '_assets/js', '_templates', '_posts'):
                Directory(normpath(self.dest.path, d)).mk()

            File(normpath(self.dest.path, 'config.yml')).mk()
        else:
            self.src.cp(self.dest.path, False)

        logger.info('Completed in %.3fs', Timer.stop())
开发者ID:shamansir,项目名称:mynt,代码行数:25,代码来源:core.py


示例5: _generate

    def _generate(self):
        logger.debug('>> Initializing\n..  src:  {0}\n..  dest: {1}'.format(self.src.path, self.dest.path))

        self._update_config()

        for opt in ('base_url',):
            if opt in self.opts:
                self.config[opt] = self.opts[opt]

        self.renderer.register({'site': self.config})

        self._render()

        logger.info('>> Generating')

        assets_src = Directory(normpath(self.src.path, '_assets'))
        assets_dest = Directory(normpath(self.dest.path, *self.config['assets_url'].split('/')))

        if self.dest.exists:
            if self.opts['force']:
                self.dest.empty()
            else:
                self.dest.rm()
        else:
            self.dest.mk()

        for page in self.pages:
            page.mk()

        if assets_src.exists:
            for asset in assets_src:
                asset.cp(asset.path.replace(assets_src.path, assets_dest.path))


        # cbr - v0.8 - 2013-01-25
        robots_src = File(normpath(self.src.path, 'robots.txt' ))
        favicon_src = File(normpath(self.src.path, 'favicon.ico' ))

        if robots_src.exists:
            logger.debug('..  found: {0}'.format(robots_src.path))
            robots_src_dest = robots_src.path.replace(robots_src.path, self.dest.path)
            robots_src.cp(robots_src_dest + '/robots.txt')
        else:
            logger.debug('..  no robots file found: {0}'.format(robots_src.path))

        # cbr - v0.8 - 2013-01-25
        if favicon_src.exists:
            logger.debug('..  found: {0}'.format(favicon_src.path))
            favicon_file_dest = favicon_src.path.replace(favicon_src.path, self.dest.path)
            favicon_src.cp(favicon_file_dest + '/favicon.ico')
        else:
            logger.debug('..  no favicon found at: {0}'.format(favicon_src.path))

        logger.info('Completed in {0:.3f}s'.format(time() - self._start))
开发者ID:cblte,项目名称:mynt,代码行数:54,代码来源:core.py


示例6: _get_path

 def _get_path(self, url):
     parts = [self.dest.path] + url.split('/')
     
     if url.endswith('/'):
         parts.append('index.html')
     
     return normpath(*parts)
开发者ID:geerk,项目名称:mynt,代码行数:7,代码来源:core.py


示例7: setup

 def setup(self):
     self.config.update(self.options)
     self.config['loader'] = _PrefixLoader(OrderedDict([
         (op.sep, FileSystemLoader(self.path)),
         ('', FileSystemLoader(normpath(self.path, '_templates')))
     ]), None)
     
     self.environment = Environment(**self.config)
     
     self.environment.filters['absolutize'] = self._absolutize
     self.environment.filters['date'] = self._date
     self.environment.filters['items'] = self._items
     self.environment.filters['values'] = self._values
     
     self.environment.globals.update(self.globals)
     self.environment.globals['get_asset'] = self._get_asset
     self.environment.globals['get_url'] = self._get_url
     
     if 'extensions' in self.config and 'jinja2.ext.i18n' in self.config['extensions']:
         try:
             langs = [locale.getlocale(locale.LC_MESSAGES)[0].decode('utf-8')]
         except AttributeError:
             langs = None
         
         self.environment.install_gettext_translations(gettext.translation(gettext.textdomain(), normpath(self.path, '_locales'), langs, fallback = True))
开发者ID:belebulu,项目名称:mynt,代码行数:25,代码来源:jinja.py


示例8: _parse

 def _parse(self):
     logger.info('>> Parsing')
     
     path = Directory(normpath(self.src.path, '_posts'))
     
     logger.debug('..  src: %s', path)
     
     for f in path:
         post = Post(f)
         
         content = self.parser.parse(self.renderer.from_string(post.bodymatter, post.frontmatter))
         excerpt = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)
         
         try:
             data = {
                 'content': content,
                 'date': post.date.strftime(self.config['date_format']).decode('utf-8'),
                 'excerpt': excerpt,
                 'tags': [],
                 'timestamp': timegm(post.date.utctimetuple()),
                 'url': self._get_post_url(post.date, post.slug)
             }
         except PageException:
             raise PageException('Invalid post slug.', 'src: {0}'.format(post.path))
         
         data.update(post.frontmatter)
         data['tags'].sort(key = unicode.lower)
         
         self.posts.append(data)
         
         for tag in data['tags']:
             if tag not in self.tags:
                 self.tags[tag] = []
             
             self.tags[tag].append(data)
开发者ID:geerk,项目名称:mynt,代码行数:35,代码来源:core.py


示例9: _update_config

    def _update_config(self):
        self.config = deepcopy(self.defaults)

        logger.debug('>> Searching for config')

        for ext in ('.yml', '.yaml'):
            f = File(normpath(self.src.path, 'config' + ext))

            if f.exists:
                logger.debug('..  found: {0}'.format(f.path))

                try:
                    self.config.update(Config(f.content))
                except ConfigException as e:
                    raise ConfigException(e.message, 'src: {0}'.format(f.path))

                break
        else:
            logger.debug('..  no config file found')

        # suport for the time_locale
        if self.config['time_locale']:
            # ascii-encoding is fallback for: http://bugs.python.org/issue3067
            time_locale = self.config['time_locale'].encode('ascii')
            logger.debug('.. chaning time locale to ' + time_locale)
            try:
                locale.setlocale(locale.LC_TIME, (time_locale, b'utf-8'))
            except ValueError:
                logger.error('Wrong time locale format: {0} ({1})'.format(time_locale, type(time_locale)))
开发者ID:cblte,项目名称:mynt,代码行数:29,代码来源:core.py


示例10: __init__

 def __init__(self, name, src, config):
     self._pages = None
     
     self.name = name
     self.src = src
     self.path = Directory(normpath(self.src.path, '_containers', self.name))
     self.config = config
     self.data = Data([], OrderedDict(), OrderedDict())
开发者ID:NaPs,项目名称:mynt,代码行数:8,代码来源:containers.py


示例11: _render

 def _render(self):
     self._process()
     
     logger.info('>> Rendering')
     
     self.renderer.register({
         'archives': self.archives,
         'posts': self.posts,
         'tags': self.tags
     })
     
     logger.debug('..  posts')
     
     for post in self.posts:
         try:
             self.pages.append(Page(
                 self._get_path(post['url']),
                 self._pygmentize(self.renderer.render(post['layout'], {'post': post}))
             ))
         except RendererException as e:
             raise RendererException(e.message, '{0} in post \'{1}\''.format(post['layout'], post['title']))
     
     logger.debug('..  pages')
     
     for f in self.src:
         if f.extension not in ('.html', '.htm', '.xml'):
             continue
         
         template = f.path.replace(self.src.path, '')
         
         self.pages.append(Page(
             normpath(self.dest.path, template),
             self._pygmentize(self.renderer.render(template))
         ))
     
     if self.config['tag_layout'] and self.tags:
         logger.debug('..  tags')
         
         for name, data in self.tags:
             self.pages.append(Page(
                 self._get_path(data['url']),
                 self._pygmentize(self.renderer.render(self.config['tag_layout'], {'tag': data}))
             ))
             self.pages.append(Page(
                 self._get_path(data['url']).replace('index.html', self.config['tag_feed_layout']),
                 self._pygmentize(self.renderer.render(self.config['tag_feed_layout'], {'tag': data}))
             ))
     
     if self.config['archive_layout'] and self.archives:
         logger.debug('..  archives')
         
         for year, data in self.archives:
             self.pages.append(Page(
                 self._get_path(data['url']),
                 self._pygmentize(self.renderer.render(self.config['archive_layout'], {'archive': data}))
             ))
开发者ID:jag3773,项目名称:mynt,代码行数:56,代码来源:core.py


示例12: _generate

 def _generate(self):
     logger.debug('>> Initializing\n..  src:  %s\n..  dest: %s', self.src.path, self.dest.path)
     
     self._update_config()
     
     if self.config['locale']:
         try:
             locale.setlocale(locale.LC_ALL, (self.config['locale'], 'utf-8'))
         except locale.Error:
             raise ConfigException('Locale not available.', 'run `locale -a` to see available locales')
     
     self.renderer.register({'site': self.config})
     
     self._render()
     
     logger.info('>> Generating')
     
     assets_src = Directory(normpath(self.src.path, '_assets'))
     assets_dest = Directory(normpath(self.dest.path, *self.config['assets_url'].split('/')))
     
     if self.dest.exists:
         if self.opts['force']:
             self.dest.empty()
         else:
             self.dest.rm()
     else:
         self.dest.mk()
     
     for page in self.pages:
         page.mk()
     
     assets_src.cp(assets_dest.path)
     
     for pattern in self.config['include']:
         for path in iglob(normpath(self.src.path, pattern)):
             dest = path.replace(self.src.path, self.dest.path)
             
             if op.isdir(path):
                 Directory(path).cp(dest, False)
             elif op.isfile(path):
                 File(path).cp(dest)
     
     logger.info('Completed in %.3fs', time() - self._start)
开发者ID:geerk,项目名称:mynt,代码行数:43,代码来源:core.py


示例13: __iter__

 def __iter__(self):
     for root, dirs, files in walk(self.path):
         for d in dirs[:]:
             if d.startswith(('.', '_')):
                 dirs.remove(d)
         
         for f in files:
             if f.startswith(('.', '_')):
                 continue
             
             yield File(normpath(root, f))
开发者ID:NaPs,项目名称:mynt,代码行数:11,代码来源:fs.py


示例14: init

 def init(self):
     self.src = Directory(self._get_theme(self.opts['theme']))
     self.dest = Directory(self.opts['dest'])
     
     if not self.src.exists:
         raise OptionException('Theme not found.')
     elif self.dest.exists and not self.opts['force']:
         raise OptionException('Destination already exists.', 'the -f option must be used to force initialization by deleting the destination')
     
     logger.info('>> Initializing')
     
     if self.opts['bare']:
         for d in ['_assets/css', '_assets/images', '_assets/js', '_templates', '_posts']:
             Directory(normpath(self.dest.path, d)).mk()
         
         File(normpath(self.dest.path, 'config.yml')).mk()
     else:
         self.src.cp(self.dest.path)
     
     logger.info('Completed in {0:.3f}s'.format(time() - self._start))
开发者ID:jag3773,项目名称:mynt,代码行数:20,代码来源:core.py


示例15: _get_path

 def _get_path(self, url):
     parts = [self.dest.path] + url.split('/')
     
     if url.endswith('/'):
         parts.append('index.html')
     
     path = normpath(*parts)
     
     if op.commonprefix((self.dest.path, path)) != self.dest.path:
         raise ConfigException('Invalid URL.', 'url: {0}'.format(url), 'path traversal is not allowed')
     
     return path
开发者ID:NaPs,项目名称:mynt,代码行数:12,代码来源:processors.py


示例16: setup

 def setup(self):
     self.config.update(self.options)
     self.config['loader'] = _PrefixLoader(OrderedDict([
         ('/', FileSystemLoader(self.path)),
         ('', FileSystemLoader(normpath(self.path, '_templates')))
     ]), None)
     
     self.environment = Environment(**self.config)
     
     self.environment.filters['date'] = self._date
     self.environment.filters['needed'] = self._needed
     
     self.environment.globals.update(self.globals)
     self.environment.globals['get_asset'] = self._get_asset
     self.environment.globals['get_url'] = self._get_url
开发者ID:dogonwheels,项目名称:mynt,代码行数:15,代码来源:jinja.py


示例17: generate

    def generate(self):
        self._render()

        logger.info('>> Generating')
        
        assets_src = Directory(normpath(self.src.path, '_assets'))
        assets_dest = Directory(normpath(self.dest.path, *self.config['assets_url'].split('/')))
        
        if self.dest.exists:
            if not self.opts['force']:
                raise OptionException('Destination already exists.', 'the -f option must be used to force generation by deleting the destination')
            
            self.dest.rm()
        
        self.dest.mk()
        
        for page in self.pages:
            page.mk()
        
        if assets_src.exists:
            for asset in assets_src:
                asset.cp(asset.path.replace(assets_src.path, assets_dest.path))
        
        logger.info('Completed in {0:.3f}s'.format(time() - self._start))
开发者ID:dogonwheels,项目名称:mynt,代码行数:24,代码来源:core.py


示例18: _parse

    def _parse(self):
        logger.info('>> Parsing')

        path = Directory(normpath(self.src.path, '_posts'))

        logger.debug('..  src: {0}'.format(path))

        for f in path:
            post = Post(f)

            postdate = post.date.strftime(self.config['date_format']).decode('utf-8')

            logger.debug('.. .. postdate: {0}'.format(postdate))

            content = self.parser.parse(self.renderer.from_string(post.bodymatter, post.frontmatter))
            excerpt = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)

            if self.config['check_more']:
                # check for the more tag if set, then check the posts for it
                # because if set in config, use it for the posts
                # do nothing if not found
                logger.debug('.. checking the <!--more--> tag')
                more_excerpt = re.search(r'(\A.*?)(?:<!--more-->).*', content, re.M | re.S)
                if more_excerpt != None:
                    excerpt = more_excerpt.group(1)

            data = {
                'content': content,
                'date': post.date.strftime(self.config['date_format']).decode('utf-8'),
                'excerpt': excerpt,
                'tags': [],
                'timestamp': timegm(post.date.utctimetuple()),
                'url': self._get_post_url(post.date, post.slug)
            }

            data.update(post.frontmatter)
            data['tags'].sort(key = unicode.lower)

            self.posts.append(data)

            for tag in data['tags']:
                if tag not in self.tags:
                    self.tags[tag] = []

                self.tags[tag].append(data)
开发者ID:cblte,项目名称:mynt,代码行数:45,代码来源:core.py


示例19: _update_config

 def _update_config(self):
     self.config = deepcopy(self.defaults)
     
     logger.debug('>> Searching for config')
     
     for ext in ('.yml', '.yaml'):
         f = File(normpath(self.src.path, 'config' + ext))
         
         if f.exists:
             logger.debug('..  found: {0}'.format(f.path))
             
             try:
                 self.config.update(Config(f.content))
             except ConfigException as e:
                 raise ConfigException(e.message, 'src: {0}'.format(f.path))
             
             break
     else:
         logger.debug('..  no config file found')
开发者ID:jag3773,项目名称:mynt,代码行数:19,代码来源:core.py


示例20: __init__

 def __init__(self, args = None):
     self._start = time()
     
     self.opts = self._get_opts(args)
     
     self.src = Directory(self.opts['src'])
     self.dest = Directory(self.opts['dest'])
     
     logger.setLevel(getattr(logging, self.opts['level'], logging.INFO))
     logger.debug('>> Initializing\n..  src:  {0}\n..  dest: {1}'.format(self.src, self.dest))
     
     if self.src == self.dest:
         raise OptionException('Source and destination must differ.')
     elif self.src.path in ('/', '//') or self.dest.path in ('/', '//'):
         raise OptionException('Root is not a valid source or destination.')
     
     logger.debug('>> Searching for config')
     
     for ext in ('.yml', '.yaml'):
         f = File(normpath(self.src.path, 'config' + ext))
         
         if f.exists:
             logger.debug('..  found: {0}'.format(f.path))
             
             try:
                 self.config.update(Config(f.content))
             except ConfigException as e:
                 raise ConfigException(e.message, 'src: {0}'.format(f.path))
             
             break
     else:
         logger.debug('..  no config file found')
     
     for opt in ('base_url',):
         if opt in self.opts:
             self.config[opt] = self.opts[opt]
     
     self.renderer.register({'site': self.config})
开发者ID:dogonwheels,项目名称:mynt,代码行数:38,代码来源:core.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python myo.init函数代码示例发布时间:2022-05-27
下一篇:
Python fs.Directory类代码示例发布时间: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