Skip to content

Commit feafb7a

Browse files
committed
mudando caminhos de arquivos importações de módulos em epub.py
1 parent b05ec5e commit feafb7a

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed
File renamed without changes.

util/epub.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
11
#!/usr/bin/env python3
2+
23
from glob import glob
3-
from shutil import rmtree
4-
from subprocess import call
5-
from os import path, makedirs
4+
import shutil
5+
import subprocess
6+
import os
7+
8+
9+
URL_REPO = 'https://github.com/PenseAllen/PensePython2e/raw/master'
10+
611

712
def _project_path():
8-
return path.dirname(path.dirname(path.abspath(__file__)))
13+
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
914

1015

1116
def _get_path(p):
12-
return path.join(_project_path(), p)
17+
return os.path.join(_project_path(), p)
1318

1419

1520
def _fix_images_url(files, tmp_dir):
1621
""" Corrige as urls das imagens.
17-
Por algum motivo o pandoc não estava conseguindo baixar as imagens do site para embedar no epub.
18-
Com esse código eu utilizo gero arquivos temporários com as essas referências acertadas para a mesma imagem dentro do projeto.
22+
Por algum motivo o pandoc não estava conseguindo baixar as imagens
23+
do site para embedar no epub. Com esse código eu gero arquivos
24+
temporários com as essas referências acertadas para a mesma imagem
25+
dentro do projeto.
1926
"""
20-
makedirs(tmp_dir)
27+
os.makedirs(tmp_dir)
2128
fixed_files = []
22-
fixed_path = path.relpath(_project_path())
29+
fixed_path = os.path.relpath(_project_path())
2330
for fp in files:
24-
file_name = path.split(fp)[1]
25-
output = path.join(tmp_dir, file_name)
31+
file_name = os.path.split(fp)[1]
32+
output = os.path.join(tmp_dir, file_name)
2633
with open(fp) as input_file:
27-
fixed_str = input_file.read().replace('https://github.com/PenseAllen/PensePython2e/raw/master', fixed_path)
34+
fixed_str = input_file.read().replace(URL_REPO, fixed_path)
2835
with open(output, 'w') as output_file:
2936
output_file.write(fixed_str)
3037
fixed_files.append(output)
3138
return fixed_files
3239

3340

34-
3541
def main():
3642
glob_filter = _get_path('docs/*.md')
3743
capa = _get_path('img/Capa_PenseEmPython332x461-borda.png')
38-
metadata = _get_path('docs/metadata.xml')
39-
output = _get_path('docs/PenseEmPython.epub')
44+
metadata = _get_path('ebooks/metadata.xml')
45+
output = _get_path('ebooks/PenseEmPython2e.epub')
4046
files = glob(glob_filter)
4147
files.sort()
4248
files.pop()
@@ -48,9 +54,9 @@ def main():
4854
args.append('-o')
4955
args.append(output)
5056
# Executa o pandoc
51-
call(args)
57+
subprocess.call(args)
5258
# Remove arquivos temporários
53-
rmtree(tmp_dir)
59+
shutil.rmtree(tmp_dir)
5460
print('Gerado epub em', output)
5561

5662

0 commit comments

Comments
 (0)