本文整理汇总了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)
示例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()