本文整理匯總了Python中src.tools.path.Path.chdir方法的典型用法代碼示例。如果您正苦於以下問題:Python Path.chdir方法的具體用法?Python Path.chdir怎麽用?Python Path.chdir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類src.tools.path.Path
的用法示例。
在下文中一共展示了Path.chdir方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_single_html_book
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create_single_html_book(self, book_package):
title = book_package.get_title()
if not title:
# 電子書題目為空時自動跳過
# 否則會發生『rm -rf / 』的慘劇
return
Path.reset_path()
Path.chdir(Path.result_path)
Path.rmdir(u'./' + title)
Path.mkdir(u'./' + title)
Path.chdir(u'./' + title)
page = []
for book in book_package.book_list:
page += book.page_list
content = u' \r\n '.join([Match.html_body(x.content) for x in page]).replace(u'../images/', u'./images/')
with open(TemplateConfig.content_base_uri) as html:
content = html.read().format(title=title, body=content).replace(u'../style/', u'./')
with open(title + u'.html', 'w') as html:
html.write(content)
Path.copy(Path.html_pool_path + u'/../{}/OEBPS/images'.format(title), u'./images')
Path.copy(Path.www_css + u'/customer.css', u'./customer.css')
Path.copy(Path.www_css + u'/markdown.css', u'./markdown.css')
Path.copy(Path.www_css + u'/normalize.css', u'./normalize.css')
Path.reset_path()
return
示例2: create
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create(self):
self.image_container.set_save_path(Path.image_pool_path)
self.image_container.start_download()
title = "_".join([book.property.epub.title for book in self.book_list])
title = title.strip()
Path.chdir(Path.base_path + u"/知乎電子書臨時資源庫/")
epub = Book(title, 27149527)
html_tmp_path = Path.html_pool_path + "/"
image_tmp_path = Path.image_pool_path + "/"
for book in self.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, "w") as html:
html.write(page.content)
epub.createChapter(html_tmp_path + page.filename, ExtraTools.get_time(), page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, "w") as html:
html.write(page.content)
epub.addHtml(html_tmp_path + page.filename, page.title)
for image in self.book["image_list"]:
epub.addImg(image_tmp_path + image["filename"])
epub.addLanguage("zh-cn")
epub.addCreator("ZhihuHelp1.7.0")
epub.addDesc(u"該電子書由知乎助手生成,知乎助手是姚澤源為知友製作的僅供個人使用的簡易電子書製作工具,源代碼遵循WTFPL,希望大家能認真領會該協議的真諦,為飛麵事業做出自己的貢獻 XD")
epub.addRight("CC")
epub.addPublisher("ZhihuHelp")
Debug.logger.debug(u"當前目錄為")
Path.pwd()
epub.addCss(Path.base_path + u"/epubResource/markdown.css")
epub.addCss(Path.base_path + u"/epubResource/front.css")
epub.buildingEpub()
return
示例3: create_book
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create_book(self, book_package):
book_package.image_container.set_save_path(Path.image_pool_path)
book_package.image_container.start_download()
title = book_package.get_title()
if not title:
# 電子書題目為空時自動跳過
# 否則會發生『rm -rf / 』的慘劇
return
Path.chdir(Path.base_path + u'/知乎電子書臨時資源庫/')
epub = Epub(title)
html_tmp_path = Path.html_pool_path + u'/'
image_tmp_path = Path.image_pool_path + u'/'
epub.set_creator(u'ZhihuHelp1.7.0')
epub.set_book_id()
epub.set_output_path(Path.result_path)
epub.add_css(Path.base_path + u'/www/css/markdown.css')
epub.add_css(Path.base_path + u'/www/css/customer.css')
epub.add_css(Path.base_path + u'/www/css/normalize.css')
for book in book_package.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, u'w') as html:
html.write(page.content)
epub.create_chapter(html_tmp_path + page.filename, page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, u'w') as html:
html.write(page.content)
epub.add_html(html_tmp_path + page.filename, page.title)
epub.finish_chapter()
for image in book_package.image_list:
epub.add_image(image_tmp_path + image['filename'])
epub.create()
Path.reset_path()
return
示例4: create_book
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create_book(self):
# 確定文件信息
title = Match.fix_filename(self.book_title)
if self.is_split:
title = self.book_title + u'_卷{}'.format(self.chapter_no)
# 先切換到電子書臨時資源目錄下
Path.chdir(Path.book_pool_path)
epub = Epub(title)
for task_result in self.task_result_list:
chapter_src = ''
# info_page
if task_result.task.task_type == Type.question:
chapter_src = self.generate_question_info_page(task_result.info_page)
elif task_result.task.task_type == Type.answer:
chapter_src = self.generate_question_info_page(task_result.info_page)
elif task_result.task.task_type == Type.collection:
chapter_src = self.generate_collection_info_page(task_result.info_page)
elif task_result.task.task_type == Type.topic:
chapter_src = self.generate_topic_info_page(task_result.info_page)
elif task_result.task.task_type == Type.author:
chapter_src = self.generate_author_info_page(task_result.info_page)
elif task_result.task.task_type == Type.column:
chapter_src = self.generate_column_info_page(task_result.info_page)
elif task_result.task.task_type == Type.article:
chapter_src = self.generate_article_info_page(task_result.info_page)
epub.create_chapter(chapter_src, task_result.get_title())
for question in task_result.question_list:
# 添加圖片文件
for filename in question.img_filename_list:
epub.add_image(Path.image_pool_path + '/' + filename)
question_src = self.generate_question_page(question)
epub.add_html(question_src, question.question_info.title)
for column in task_result.column_list:
# 添加圖片文件
for filename in column.img_filename_list:
epub.add_image(Path.image_pool_path + '/' + filename)
for article in column.article_list:
article_src = self.generate_article_page(article)
epub.add_html(article_src, article.title)
epub.finish_chapter()
epub.set_creator(u'ZhihuHelp1.8.0')
epub.set_language(u'zh-cn')
epub.set_book_id()
epub.set_output_path(Path.result_path)
epub.add_css(Path.base_path + u'/www/css/markdown.css')
epub.add_css(Path.base_path + u'/www/css/customer.css')
epub.add_css(Path.base_path + u'/www/css/normalize.css')
epub.add_css(Path.base_path + u'/www/css/bootstrap.css')
epub.create()
Path.reset_path()
return
示例5: init_epub_path
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def init_epub_path(work_path):
u"""
設置工作地址,根據該路徑進行創建文件夾,生成epub,壓縮等操作
"""
EpubPath.set_work_path(work_path)
Path.mkdir(EpubPath.meta_inf_path)
Path.mkdir(EpubPath.oebps_path)
Path.chdir(EpubPath.oebps_path)
Path.mkdir(EpubPath.html_path)
Path.mkdir(EpubPath.image_path)
Path.mkdir(EpubPath.style_path)
return
示例6: create_book
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create_book(self, book_package):
book_package.image_container.set_save_path(Path.image_pool_path)
book_package.image_container.start_download()
title = book_package.get_title()
Debug.logger.debug(u"title of the e-book:" + str(title))
if not title:
# 電子書題目為空時自動跳過
# 否則會發生『rm -rf / 』的慘劇
return
Path.chdir(Path.in_base_path + u'/e-books_tmp_source')
epub = Epub(title)
html_tmp_path = Path.html_pool_path + u'/'
image_tmp_path = Path.image_pool_path + u'/'
epub.set_creator(u'EEBookV0-1')
epub.set_language(u'zh')
epub.set_book_id()
epub.set_output_path(Path.result_path)
epub.add_css(Path.in_base_path + u'/www/css/markdown.css')
epub.add_css(Path.in_base_path + u'/www/css/customer.css')
epub.add_css(Path.in_base_path + u'/www/css/normalize.css')
epub.add_css(Path.in_base_path + u'/www/css/bootstrap.css')
# epub.add_css(Path.in_base_path + u'/www/css/article.css') # TODO: 來自新浪,需要精簡
for book in book_package.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, 'w') as html:
html.write(page.content)
if '_' in page.title:
page.title = ''.join(page.title.split('_')[1:]) # 刪除章節前綴
epub.create_chapter(html_tmp_path + page.filename, page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, 'w') as html:
html.write(page.content)
epub.add_html(html_tmp_path + page.filename, page.title)
epub.finish_chapter()
for image in book_package.image_list:
epub.add_image(image_tmp_path + image['filename'])
epub.create()
Path.reset_path()
return
示例7: create_single_html_book
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create_single_html_book(self):
title = '_'.join([book.epub.title for book in self.book_list])
title = title.strip()[:128] # 避開window文件名長度限製
title = ExtraTools.fix_filename(title) # 移除特殊字符
Path.reset_path()
Path.chdir(Path.result_path)
Path.rmdir(u'./' + title)
Path.mkdir(u'./' + title)
Path.chdir(u'./' + title)
page = []
for book in self.book_list:
page += book.page_list
content = ' \r\n<hr /> \r\n '.join([Match.html_body(x.content) for x in page]).replace('../images/', './images/')
with open(Path.base_path + '/src/template/content/single_html.html') as html:
template = html.read().format(title=title, content=content)
with open(title + u'.html', 'w') as html:
html.write(template)
shutil.copytree(Path.html_pool_path + u'/../{}/OEBPS/images'.format(title), './images')
shutil.copy(Path.www_css + '/front.css' , './front.css')
shutil.copy(Path.www_css + '/markdown.css' , './markdown.css')
Path.reset_path()
return
示例8: create
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def create(self):
self.image_container.set_save_path(Path.image_pool_path)
self.image_container.start_download()
title = '_'.join([book.epub.title for book in self.book_list])
title = title.strip()[:128] # 避開window文件名長度限製
title = ExtraTools.fix_filename(title) # 移除特殊字符
if not title:
# 電子書題目為空時自動跳過
# 否則會發生『rm -rf / 』的慘劇。。。
return
Path.chdir(Path.base_path + u'/知乎電子書臨時資源庫/')
epub = Book(title, 27149527)
html_tmp_path = Path.html_pool_path + '/'
image_tmp_path = Path.image_pool_path + '/'
for book in self.book_list:
page = book.page_list[0]
with open(html_tmp_path + page.filename, 'w') as html:
html.write(page.content)
#epub.createChapter(html_tmp_path + page.filename, ExtraTools.get_time(), page.title)
epub.addInfoPage(html_tmp_path + page.filename, page.title)
for page in book.page_list[1:]:
with open(html_tmp_path + page.filename, 'w') as html:
html.write(page.content)
epub.addHtml(html_tmp_path + page.filename, page.title)
for image in self.book.image_list:
epub.addImg(image_tmp_path + image['filename'])
epub.addLanguage('zh-cn')
epub.addCreator('ZhihuHelp1.7.0')
epub.addDesc(u'該電子書由知乎助手生成,知乎助手是姚澤源為知友製作的僅供個人使用的簡易電子書製作工具,源代碼遵循WTFPL,希望大家能認真領會該協議的真諦,為飛麵事業做出自己的貢獻 XD')
epub.addRight('CC')
epub.addPublisher('ZhihuHelp')
epub.addCss(Path.base_path + u'/www/css/markdown.css')
epub.addCss(Path.base_path + u'/www/css/front.css')
epub.buildingEpub()
Path.reset_path()
return
示例9: init_path
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def init_path(self):
Path.rmdir(u'./' + self.title)
Path.mkdir(u'./' + self.title)
Path.chdir(u'./' + self.title)
EpubPath.init_epub_path(Path.get_pwd())
return
示例10: reset_path
# 需要導入模塊: from src.tools.path import Path [as 別名]
# 或者: from src.tools.path.Path import chdir [as 別名]
def reset_path():
Path.chdir(EpubPath.work_path)
return