Mercurial > hg > cc > cirrus_home
annotate bin/plinks.py @ 11:b0d9fe66ce8a
give up on mpiexec_mpt
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 25 Feb 2020 18:33:22 +0000 |
parents | a33db8e3f51c |
children | 3bc1d24363a1 |
rev | line source |
---|---|
0 | 1 #!/lustre/sw/miniconda3/bin/python3 |
7 | 2 import sys,pdfx,traceback,os |
3 from datetime import datetime | |
1
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
4 from os import path |
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
5 |
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
6 def run(file): |
0 | 7 global pdf |
10 | 8 pdf=pdfx.PDFx(file,limit=60) |
9 return (pdf.get_references_as_dict(),pdf.limited) | |
0 | 10 |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
11 tarnum=sys.argv[1] |
7 | 12 print(tarnum, sys.argv, os.getcwd(),file=sys.stderr) |
13 gf=0 | |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
14 with open('badpdfs_%s'%tarnum,'w') as bf: |
1
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
15 for l in sys.stdin: |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
16 (fno,f)=l.split() |
1
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
17 try: |
10 | 18 (links,limited)=run(f) |
19 if limited: | |
20 print("%s\t%s\tProcessing limited after timeout"%( | |
21 datetime.now().isoformat(),fno),file=bf) | |
11 | 22 bf.flush() |
4
462179da7dc2
try harder not to write empty links files
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
2
diff
changeset
|
23 if bool(links) and (links.get('scrape',False) or |
462179da7dc2
try harder not to write empty links files
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
2
diff
changeset
|
24 links.get('annot',False)): |
7 | 25 gf+=1 |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
26 with open('links_%s_%s'%(tarnum,fno),'w') as of: |
3
cbd13beb0922
only create links file if there are some
Henry Thompson <ht@markup.co.uk>
parents:
2
diff
changeset
|
27 for k in links.keys(): |
cbd13beb0922
only create links file if there are some
Henry Thompson <ht@markup.co.uk>
parents:
2
diff
changeset
|
28 for l in links[k]: |
cbd13beb0922
only create links file if there are some
Henry Thompson <ht@markup.co.uk>
parents:
2
diff
changeset
|
29 print("%s\t%s"%(k,l),file=of) |
1
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
30 except Exception as e: |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
31 if str(e)=='Unexpected EOF': |
7 | 32 print("%s:\t%s\t%s\t%s"%(datetime.now().isoformat(), |
33 tarnum,fno,e),file=bf) | |
11 | 34 bf.flush() |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
35 else: |
7 | 36 print("%s: "%(datetime.now().isoformat()),end='',file=bf) |
6
0f494c76a887
refactor to address tarred-up pdfs
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
5
diff
changeset
|
37 traceback.print_exc(file=bf) |
11 | 38 bf.flush() |
39 if path.exists('stopJob'): | |
7 | 40 print("%s: Quiting early: %s %s"%(datetime.now().isoformat(),tarnum,fno), |
41 file=sys.stderr) | |
11 | 42 sys.stderr.flush() |
1
a4b0359456bc
switch to file loop inside python, assume file index integer in pipe as well as filename, check /dev/shm/stopJob
Henry Thompson <ht@markup.co.uk>
parents:
0
diff
changeset
|
43 exit(1) |
7 | 44 now=datetime.now().isoformat() |
45 print('%s: exiting from %s having found %s files with links out of %s'%(now, | |
46 tarnum, | |
47 gf, | |
48 fno)) |