Mercurial > hg > cc > cirrus_home
comparison bin/plinks.py @ 1:a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Tue, 18 Feb 2020 21:33:35 +0000 |
parents | 65a56c0d1c1f |
children | 83ed7c5846b2 |
comparison
equal
deleted
inserted
replaced
0:65a56c0d1c1f | 1:a4b0359456bc |
---|---|
1 #!/lustre/sw/miniconda3/bin/python3 | 1 #!/lustre/sw/miniconda3/bin/python3 |
2 import sys,pdfx,traceback | 2 import sys,pdfx,traceback |
3 def run(): | 3 from os import path |
4 | |
5 def run(file): | |
4 global pdf | 6 global pdf |
5 try: | 7 pdf=pdfx.PDFx(file) |
6 pdf=pdfx.PDFx(sys.argv[1]) | 8 return pdf.get_references_as_dict() |
7 links=pdf.get_references_as_dict() | |
8 except: | |
9 traceback.print_exc() | |
10 print("\nFailed: %s"%sys.argv[1],file=sys.stderr) | |
11 exit(1) | |
12 for k in links.keys(): | |
13 for l in links[k]: | |
14 print("%s\t%s"%(k,l)) | |
15 | 9 |
16 if sys.argv[1]=='-t': | 10 me=sys.argv[1] |
17 import timeit | 11 with open('/dev/shm/x/badpdfs_%s'%me,'w') as bf: |
18 sys.argv.pop(1) | 12 for l in sys.stdin: |
19 n=sys.argv[1] | 13 (fno,f)=l.rstrip().split() |
20 sys.argv.pop(1) | 14 try: |
21 print(timeit.timeit("run()",number=int(n), | 15 links=run(file) |
22 setup="from __main__ import run"),file=sys.stderr) | 16 with open('/dev/shm/x/links_%s'%fno,'w') as of: |
23 else: | 17 for k in links.keys(): |
24 run() | 18 for l in links[k]: |
19 print("%s\t%s\t%s"%(k,l),file=of) | |
20 except Exception as e: | |
21 print("%s\t%s\t%s"%(fno,e),file=bf) | |
22 if (path.exists('/dev/shm/stopJob')): | |
23 print("Quiting early: %s %s"%(me,fno),file=sys.stderr) | |
24 exit(1) |