jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/669743 )
Change subject: [bugfix] reflinks.py: If urlobj.write fails, the file will not be closed ......................................................................
[bugfix] reflinks.py: If urlobj.write fails, the file will not be closed
Bug: T276747 Change-Id: I0c7e71715b03dc9fb94ba31482f5d34fd0d17da2 --- M scripts/reflinks.py 1 file changed, 13 insertions(+), 11 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/reflinks.py b/scripts/reflinks.py index 7226f72..4c9c43f 100755 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -464,24 +464,18 @@
def getPDFTitle(self, ref, response): """Use pdfinfo to retrieve title from a PDF.""" - pywikibot.output('PDF file.') - fd, infile = tempfile.mkstemp() - urlobj = os.fdopen(fd, 'w+') - urlobj.write(response.text) + # pdfinfo is Unix-only + pywikibot.output('Reading PDF file...')
try: + fd, infile = tempfile.mkstemp() + urlobj = os.fdopen(fd, 'w+') + urlobj.write(response.text) pdfinfo_out = subprocess.Popen([r'pdfinfo', '/dev/stdin'], stdin=urlobj, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False).communicate()[0] - for aline in pdfinfo_out.splitlines(): - if aline.lower().startswith('title'): - ref.title = ' '.join(aline.split()[1:]) - if ref.title: - pywikibot.output('title: ' + ref.title) - break - pywikibot.output('PDF done.') except ValueError: pywikibot.output('pdfinfo value error.') except OSError: @@ -489,6 +483,14 @@ except Exception: # Ignore errors pywikibot.output('PDF processing error.') pywikibot.exception() + else: + for aline in pdfinfo_out.splitlines(): + if aline.lower().startswith('title'): + ref.title = ' '.join(aline.split()[1:]) + if ref.title: + pywikibot.output('title: ' + ref.title) + break + pywikibot.output('PDF done.') finally: urlobj.close() os.unlink(infile)
pywikibot-commits@lists.wikimedia.org