Skip to content

Commit

Permalink
deploy pdfs in other tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
mli committed May 31, 2021
1 parent dfcb4e5 commit f5e1ccf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 4 additions & 1 deletion d2lbook/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ def pdf(self):

script = self.config.pdf['post_latex']
process_latex(self.config.tex_fname, script)
run_cmd(['cd', self.config.pdf_dir, '&& make'])
run_cmd(['cd', self.config.pdf_dir, '&& make'])
if self.config.tab != self.config.default_tab:
p = self.config.project['name']
run_cmd(['cd', self.config.pdf_dir, '&& cp ', p+'.pdf', p+'-'+self.config.tab+'.pdf' ])

This comment has been minimized.

Copy link
@astonzhang

astonzhang Sep 22, 2021

Member

Should we use cp -> mv to rename rather than copy, e.g., d2l-en.pdf -> d2l-en-pytorch.pdf


@_once
def pkg(self):
Expand Down
5 changes: 2 additions & 3 deletions d2lbook/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ def __init__(self, tab=None, config_fname='config.ini'):
self.set_tab(self.tab)
# Sanity checks.
self.sanity_check()

def _set_target(self):
# Some targets names.
self.pdf_fname = os.path.join(self.pdf_dir, self.project['name']+'.pdf')
# Some targets names.
self.tex_fname = os.path.join(self.pdf_dir, self.project['name']+'.tex')
self.pkg_fname = os.path.join(self.tgt_dir, self.project['name']+'.zip')

Expand Down
24 changes: 21 additions & 3 deletions d2lbook/deploy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import sys
import logging
import argparse
Expand All @@ -8,6 +9,7 @@
from d2lbook import colab
from d2lbook import sagemaker
from d2lbook import slides
import glob

__all__ = ['deploy']

Expand Down Expand Up @@ -68,6 +70,20 @@ def slides(self):
self.config.iter_tab(lambda: slides.Slides(self.config).deploy())
self.config.set_tab(tab)

def _get_pdfs(self):
# get all generated pdfs
pdfs = list(glob.glob(self.config.tgt_dir+'/pdf*/'+self.config.project['name']+'*.pdf'))
rets = []
for p in pdfs:
p = pathlib.Path(p)
tks = p.parent.name.split('_')
if len(tks) > 1:
tab = tks[1]
if p.with_suffix('').name.split('-')[-1] != tab:
continue
rets.append(str(p))
return rets

class GithubDeployer(Deployer):
def __init__(self, config):
super(GithubDeployer, self).__init__(config)
Expand All @@ -79,7 +95,8 @@ def html(self):
run_cmd(['cp -r', os.path.join(self.config.html_dir, '*'), self.git_dir])

def pdf(self):
shutil.copy(self.config.pdf_fname, self.git_dir)
for pdf in self._get_pdfs():
shutil.copy(pdf, self.git_dir)

def pkg(self):
shutil.copy(self.config.pkg_fname, self.git_dir)
Expand All @@ -100,8 +117,9 @@ def pdf(self):
url = self.config.deploy['s3_bucket']
if not url.endswith('/'):
url += '/'
logging.info('cp %s to %s', self.config.pdf_fname, url)
run_cmd(['aws s3 cp', self.config.pdf_fname, url, "--acl 'public-read' --quiet"])
for pdf in self._get_pdfs():
logging.info('cp %s to %s', pdf, url)
run_cmd(['aws s3 cp', pdf, url, "--acl 'public-read' --quiet"])

def _deploy_other_files(self, tgt_url):
other_urls = self.config.deploy['other_file_s3urls'].split()
Expand Down

0 comments on commit f5e1ccf

Please sign in to comment.