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


Python Path.mtime方法代码示例

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


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

示例1: objects

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mtime [as 别名]
def objects():

    Project = rt.models.tickets.Project
    Ticket = rt.models.tickets.Ticket
    TicketStates = rt.models.tickets.TicketStates

    prj = Project(name="Lino")
    yield prj

    settings.SITE.loading_from_dump = True

    for ln in TICKETS.splitlines():
        ln = ln.strip()
        if ln:
            a = ln.split(':')
            state = TicketStates.accepted
            a2 = []
            for i in a:
                if '[closed]' in i:
                    state = TicketStates.closed
                i = i.replace('[closed]', '')
                a2.append(i.strip())
            num = a2[0][1:]
            title = a2[1]

            import lino
            fn = Path(lino.__file__).parent.parent.child('docs', 'tickets')
            fn = fn.child(num + '.rst')
            kw = dict()
            kw.update(created=datetime.datetime.fromtimestamp(fn.ctime()))
            kw.update(modified=datetime.datetime.fromtimestamp(fn.mtime()))
            kw.update(id=int(num), summary=title, project=prj, state=state)
            logger.info("%s %s", fn, kw['modified'])
            kw.update(description=fn.read_file())
            # fd = open(fn)
            yield Ticket(**kw)
开发者ID:lino-framework,项目名称:noi,代码行数:38,代码来源:linotickets.py

示例2: SubtitleDownload

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import mtime [as 别名]
class SubtitleDownload(object):
    def __init__(self, path):
        self.path = Path(path)
        self.name = self.path.stem
        self.download_dir = self.path.parent

    def __unicode__(self):
        return self.name

    @lazy
    def time_since_modified(self):
        mtime_datetime = datetime.fromtimestamp(self.path.mtime())
        return datetime.now() - mtime_datetime

    def subtitle_exist(self):
        if (Path(self.download_dir, '{}.srt'.format(self.name)).exists() or
                Path(self.download_dir, '{}.sub'.format(self.name)).exists()):
            return True
        else:
            return False

    def search_download_subtitle(self):
        """Search subtitle services and download subtitle"""

        subscene_downloaded_zip = self.subscene_download()
        if subscene_downloaded_zip:
            self.process_zip(subscene_downloaded_zip)

    def subscene_download(self):
        subscene = Subscene(self.name)

        if not subscene.search_match():
            log.info('No Subscene match for {}'.format(self.name))
            return False

        return subscene.download_zip(self.download_dir)

    def process_zip(self, zip_file_path):
        """Process the subtitle zip and extract all files with a valid file
        extension. Remove the zip file when done.
        """

        # Make sure the downloaded zip file is valid
        if not zipfile.is_zipfile(zip_file_path):
            log.info('Invalid zip file {}'.format(
                SubtitleDownloader.relative_path(zip_file_path,
                                                 self.download_dir)))
            zip_file_path.remove()
            return False

        zip_file = zipfile.ZipFile(zip_file_path)
        for file in zip_file.namelist():
            file = Path(file)

            # Check file extension
            if not file.ext.lower() in ('.srt'):
                log.debug('Invalid subtitle file extension {}, '
                          'skipping'.format(file))
                continue

            # Name of unpacked subtitle file and the renamed subtitle file
            unpacked_subtitle_file = Path(self.download_dir, file)
            renamed_subtitle_file = Path(self.download_dir, '{}{}'.format(
                self.name, unpacked_subtitle_file.ext.lower()))

            # Skip the subtitle file if it's already exists
            if renamed_subtitle_file.exists():
                log.info('{} already exists'.format(
                    SubtitleDownloader.relative_path(renamed_subtitle_file,
                                                     self.download_dir)))
                continue

            # Extract the file to unpack dir and then move it to match the name
            # of the subtitle search
            log.info('Found subtitle, extracting subtitle file {}'.format(
                SubtitleDownloader.relative_path(renamed_subtitle_file,
                                                 self.download_dir)))
            zip_file.extract(file, self.download_dir)
            unpacked_subtitle_file.move(renamed_subtitle_file)

        # Remove the zip file
        zip_file_path.remove()
开发者ID:dnxxx,项目名称:subtitledownloader,代码行数:84,代码来源:subtitledownloader.py


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