Skip to content

Commit

Permalink
update report
Browse files Browse the repository at this point in the history
  • Loading branch information
suqingdong committed Apr 13, 2021
1 parent 39e81e1 commit e6a5523
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions nsfc/bin/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
import tempfile

import click
Expand All @@ -17,18 +18,19 @@

@click.command(name='report',
epilog=__epilog__,
no_args_is_help=True,
help='download the conclusion report for given project_id')
@click.argument('project_id')
@click.option('-t', '--tmpdir', help='the temporary directory to store pngs', default=tempfile.gettempdir(), show_default=True)
@click.option('-o', '--outfile', help='the output filename of pdf')
@click.option('-k', '--keep', help='do not the temporary directory after completion', is_flag=True)
def main(**kwargs):

tmpdir = tempfile.mktemp(prefix='nsfc-report', dir=kwargs['tmpdir'])
Official.get_conclusion_report(kwargs['project_id'], tmpdir=tmpdir, outfile=kwargs['outfile'])

if not kwargs['keep']:
os.removedirs(tmpdir)
tmpdir = tempfile.mktemp(prefix='nsfc-report-', dir=kwargs['tmpdir'])
if Official.get_conclusion_report(kwargs['project_id'], tmpdir=tmpdir, outfile=kwargs['outfile']):
if not kwargs['keep']:
shutil.rmtree(tmpdir)
Official.logger.debug(f'tempdir deleted: {tmpdir}')


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions nsfc/src/official.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ def get_conclusion_report(cls, ratify_number, tmpdir='tmp', pdf=True, outfile=No
cls.logger.debug(f'save png: {png}')

if pdf:
cls.logger.debug('converting *png to pdf')
outfile = outfile or f'{ratify_number}.pdf'
with open(outfile, 'wb') as out:
out.write(img2pdf.convert(pngs))

size = human_readable.file_size(os.stat(outfile).st_size)
cls.logger.info(f'save pdf: {outfile} [{size}]')
return True

@classmethod
def get_conclusion_report_images(cls, projectid):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ openpyxl
requests
sqlalchemy
prettytable
human-readable
webrequests
simple-loggers

0 comments on commit e6a5523

Please sign in to comment.