Skip to content

Commit e6a5523

Browse files
committed
update report
1 parent 39e81e1 commit e6a5523

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

nsfc/bin/report.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import tempfile
34

45
import click
@@ -17,18 +18,19 @@
1718

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

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

3335

3436
if __name__ == "__main__":

nsfc/src/official.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ def get_conclusion_report(cls, ratify_number, tmpdir='tmp', pdf=True, outfile=No
107107
cls.logger.debug(f'save png: {png}')
108108

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

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

117119
@classmethod
118120
def get_conclusion_report_images(cls, projectid):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ openpyxl
44
requests
55
sqlalchemy
66
prettytable
7+
human-readable
78
webrequests
89
simple-loggers

0 commit comments

Comments
 (0)