diff bin/plinks.py @ 7:25ca3505b4d7

more logging
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 24 Feb 2020 00:44:53 +0000
parents 0f494c76a887
children 7a93e190c74d
line wrap: on
line diff
--- a/bin/plinks.py	Sun Feb 23 16:48:34 2020 +0000
+++ b/bin/plinks.py	Mon Feb 24 00:44:53 2020 +0000
@@ -1,5 +1,6 @@
 #!/lustre/sw/miniconda3/bin/python3
-import sys,pdfx,traceback
+import sys,pdfx,traceback,os
+from datetime import datetime
 from os import path
 
 def run(file):
@@ -8,6 +9,8 @@
   return pdf.get_references_as_dict()
 
 tarnum=sys.argv[1]
+print(tarnum, sys.argv, os.getcwd(),file=sys.stderr)
+gf=0
 with open('badpdfs_%s'%tarnum,'w') as bf:
   for l in sys.stdin:
     (fno,f)=l.split()
@@ -15,16 +18,25 @@
       links=run(f)
       if bool(links) and (links.get('scrape',False) or
                           links.get('annot',False)):
+        gf+=1
         with open('links_%s_%s'%(tarnum,fno),'w') as of:
           for k in links.keys():
             for l in links[k]:
               print("%s\t%s"%(k,l),file=of)
     except Exception as e:
       if str(e)=='Unexpected EOF':
-        print("%s\t%s\t%s"%(tarnum,fno,e),file=bf)
+        print("%s:\t%s\t%s\t%s"%(datetime.now().isoformat(),
+                                 tarnum,fno,e),file=bf)
       else:
+        print("%s: "%(datetime.now().isoformat()),end='',file=bf)
         traceback.print_exc(file=bf)
 
     if (path.exists('/dev/shm/stopJob')):
-      print("Quiting early: %s %s"%(tarnum,fno),file=sys.stderr)
+      print("%s: Quiting early: %s %s"%(datetime.now().isoformat(),tarnum,fno),
+            file=sys.stderr)
       exit(1)          
+now=datetime.now().isoformat()
+print('%s: exiting from %s having found %s files with links out of %s'%(now,
+                                                                        tarnum,
+                                                                        gf,
+                                                                        fno))