当前位置: 首页>>代码示例>>Python>>正文


Python Directory.rm方法代码示例

本文整理汇总了Python中mynt.fs.Directory.rm方法的典型用法代码示例。如果您正苦于以下问题:Python Directory.rm方法的具体用法?Python Directory.rm怎么用?Python Directory.rm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mynt.fs.Directory的用法示例。


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

示例1: Mynt

# 需要导入模块: from mynt.fs import Directory [as 别名]
# 或者: from mynt.fs.Directory import rm [as 别名]
class Mynt(object):
    defaults = {
        'archive_layout': None,
        'archives_url': '/',
        'assets_url': '/assets/',
        'base_url': '/',
        'date_format': '%A, %B %d, %Y',
        'domain': None,
        'include': [],
        'locale': None,
        'markup': 'markdown',
        'parser': 'misaka',
        'posts_url': '/<year>/<month>/<day>/<title>/',
        'pygmentize': True,
        'renderer': 'jinja',
        'tag_layout': None,
        'tags_url': '/',
        'version': __version__
    }
    
    _parser = None
    _renderer = None
    
    archives = OrderedDict()
    config = {}
    pages = []
    posts = []
    tags = OrderedDict()
    
    
    def __init__(self, args = None):
        self._start = time()
        
        self.opts = self._get_opts(args)
        
        logger.setLevel(getattr(logging, self.opts['level'], logging.INFO))
        
        self.opts['func']()
    
    
    def _archive(self, posts):
        archives = OrderedDict()
        
        for post in posts:
            year, month = datetime.utcfromtimestamp(post['timestamp']).strftime('%Y %B').decode('utf-8').split()
            
            if year not in archives:
                archives[year] = {
                    'months': OrderedDict({month: [post]}),
                    'url': self._get_archive_url(year),
                    'year': year
                }
            elif month not in archives[year]['months']:
                archives[year]['months'][month] = [post]
            else:
                archives[year]['months'][month].append(post)
        
        return archives
    
    def _get_archive_url(self, year):
        format = self._get_url_format(self.config['archives_url'].endswith('/'))
        
        return format.format(self.config['archives_url'], year)
    
    def _get_opts(self, args):
        opts = {}
        
        parser = ArgumentParser(description = 'A static blog generator.')
        sub = parser.add_subparsers()
        
        level = parser.add_mutually_exclusive_group()
        
        level.add_argument('-l', '--level', default = b'INFO', type = str.upper, choices = [b'DEBUG', b'INFO', b'WARNING', b'ERROR'], help = 'Sets %(prog)s\'s log level.')
        level.add_argument('-q', '--quiet', action = 'store_const', const = 'ERROR', dest = 'level', help = 'Sets %(prog)s\'s log level to ERROR.')
        level.add_argument('-v', '--verbose', action = 'store_const', const = 'DEBUG', dest = 'level', help = 'Sets %(prog)s\'s log level to DEBUG.')
        
        parser.add_argument('-V', '--version', action = 'version', version = '%(prog)s v{0}'.format(__version__), help = 'Prints %(prog)s\'s version and exits.')
        
        gen = sub.add_parser('gen')
        
        gen.add_argument('src', nargs = '?', default = '.', metavar = 'source', help = 'The directory %(prog)s looks in for source files.')
        gen.add_argument('dest', metavar = 'destination', help = 'The directory %(prog)s outputs to.')
        
        gen.add_argument('--base-url', help = 'Sets the site\'s base URL overriding the config setting.')
        gen.add_argument('--locale', help = 'Sets the locale used by the renderer.')
        
        force = gen.add_mutually_exclusive_group()
        
        force.add_argument('-c', '--clean', action = 'store_true', help = 'Forces generation by deleting the destination if it exists.')
        force.add_argument('-f', '--force', action = 'store_true', help = 'Forces generation by emptying the destination if it exists.')
        
        gen.set_defaults(func = self.generate)
        
        init = sub.add_parser('init')
        
        init.add_argument('dest', metavar = 'destination', help = 'The directory %(prog)s outputs to.')
        
        init.add_argument('--bare', action = 'store_true', help = 'Initializes a new site without using a theme.')
        init.add_argument('-f', '--force', action = 'store_true', help = 'Forces initialization by deleting the destination if it exists.')
        init.add_argument('-t', '--theme', default = 'dark', help = 'Sets which theme will be used.')
#.........这里部分代码省略.........
开发者ID:geerk,项目名称:mynt,代码行数:103,代码来源:core.py

示例2: Mynt

# 需要导入模块: from mynt.fs import Directory [as 别名]
# 或者: from mynt.fs.Directory import rm [as 别名]
class Mynt(object):
    defaults = {
        'archive_layout': None,
        'archives_url': '/',
        'assets_url': '/assets/',
        'figures_url': '/figures/',
        'base_url': '/',
        'containers': {},
        'date_format': '%A, %B %d, %Y',
        'domain': None,
      # 'parser': 'misaka',
        'include': [],
        'locale': None,
        'posts_order': 'desc',
        'posts_sort': 'timestamp',
        'posts_url': '/<year>/<month>/<day>/<slug>/',
        'pygmentize': True,
        'renderer': 'jinja',
        'tag_layout': None,
        'tags_url': '/',
        'version': __version__
    }

    container_defaults = {
        'archive_layout': None,
        'archives_url': '/',
        'order': 'desc',
        'sort': 'timestamp',
        'tag_layout': None,
        'tags_url': '/'
    }


    def __init__(self, args = None):
        self._reader = None
        self._writer = None

        self.config = None
        self.posts = None
        self.containers = None
        self.data = {}
        self.pages = None

        self.opts = self._get_opts(args)

        logger.setLevel(getattr(logging, self.opts['level'], logging.INFO))

        self.opts['func']()


    def _get_opts(self, args):
        opts = {}

        parser = ArgumentParser(description = 'A static blog generator.')
        sub = parser.add_subparsers()

        level = parser.add_mutually_exclusive_group()

        level.add_argument('-l', '--level',
            default = b'INFO', type = str.upper, choices = [b'DEBUG', b'INFO', b'WARNING', b'ERROR'],
            help = 'Sets %(prog)s\'s log level.')
        level.add_argument('-q', '--quiet',
            action = 'store_const', const = 'ERROR', dest = 'level',
            help = 'Sets %(prog)s\'s log level to ERROR.')
        level.add_argument('-v', '--verbose',
            action = 'store_const', const = 'DEBUG', dest = 'level',
            help = 'Sets %(prog)s\'s log level to DEBUG.')

        parser.add_argument('-V', '--version',
            action = 'version', version = '%(prog)s v{0}'.format(__version__),
            help = 'Prints %(prog)s\'s version and exits.')

        gen = sub.add_parser('gen')

        gen.add_argument('src',
            nargs = '?', default = '.', metavar = 'source',
            help = 'The directory %(prog)s looks in for source files.')
        gen.add_argument('dest',
            metavar = 'destination',
            help = 'The directory %(prog)s outputs to.')

        gen.add_argument('--base-url',
            help = 'Sets the site\'s base URL overriding the config setting.')
        gen.add_argument('--locale',
            help = 'Sets the locale used by the renderer.')

        force = gen.add_mutually_exclusive_group()

        force.add_argument('-c', '--clean',
            action = 'store_true',
            help = 'Forces generation by deleting the destination if it exists.')
        force.add_argument('-f', '--force',
            action = 'store_true',
            help = 'Forces generation by emptying the destination if it exists.')

        gen.set_defaults(func = self.generate)

        init = sub.add_parser('init')

        init.add_argument('dest',
#.........这里部分代码省略.........
开发者ID:shamansir,项目名称:mynt,代码行数:103,代码来源:core.py

示例3: Mynt

# 需要导入模块: from mynt.fs import Directory [as 别名]
# 或者: from mynt.fs.Directory import rm [as 别名]
class Mynt(object):
    config = {
        'archive_layout': None,
        'archives_url': '/',
        'assets_url': '/assets',
        'base_url': '/',
        'date_format': '%A, %B %d, %Y',
        'markup': 'markdown',
        'parser': 'misaka',
        'posts_url': '/<year>/<month>/<day>/<title>/',
        'pygmentize': True,
        'renderer': 'jinja',
        'tag_layout': None,
        'tags_url': '/',
        'version': __version__
    }
    
    _parser = None
    _renderer = None
    
    archives = OrderedDict()
    pages = []
    posts = []
    tags = OrderedDict()
    
    
    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})
    
    
    def _get_archives_url(self, year):
        format = self._get_url_format(self.config['tags_url'].endswith('/'))
        
        return format.format(self.config['archives_url'], year)
    
    def _get_opts(self, args):
        opts = {}
        
        parser = ArgumentParser(description = 'A static blog generator.')
        
        parser.add_argument('src', nargs = '?', default = '.', metavar = 'source', help = 'The location %(prog)s looks for source files.')
        parser.add_argument('dest', metavar = 'destination', help = 'The location %(prog)s outputs to.')
        
        level = parser.add_mutually_exclusive_group()
        
        level.add_argument('-l', '--level', default = b'INFO', type = str.upper, choices = ['DEBUG', 'INFO', 'WARNING', 'ERROR'], help = 'Sets %(prog)s\'s log level.')
        level.add_argument('-q', '--quiet', action = 'store_const', const = 'ERROR', dest = 'level', help = 'Sets %(prog)s\'s log level to ERROR.')
        level.add_argument('-v', '--verbose', action = 'store_const', const = 'DEBUG', dest = 'level', help = 'Sets %(prog)s\'s log level to DEBUG.')
        
        parser.add_argument('--base-url', help = 'Sets the site\'s base URL.')
        parser.add_argument('-f', '--force', action = 'store_true', help = 'Forces generation deleting the destination if it already exists.')
        
        parser.add_argument('-V', '--version', action = 'version', version = '%(prog)s v{0}'.format(__version__), help = 'Prints %(prog)s\'s version and exits.')
        
        for option, value in vars(parser.parse_args(args)).iteritems():
            if value is not None:
                if isinstance(option, str):
                    option = option.decode('utf-8')
                
                if isinstance(value, str):
                    value = value.decode('utf-8')
                
                opts[option] = value
        
#.........这里部分代码省略.........
开发者ID:dogonwheels,项目名称:mynt,代码行数:103,代码来源:core.py


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