Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mechanism for generating a temporary cdxj file. #697

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ipwb/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os
import random # For generating a temp file for stdin
import string # For generating a temp file for stdin
import sys
Expand Down Expand Up @@ -44,10 +45,11 @@ def checkArgs_replay(args):
random.seed()
# Write data to temp file (sub-optimal)

tf = tempfile.NamedTemporaryFile(mode='w', suffix='.cdxj')
tf.write(cdxjIn)
args.index = tf.name
tf.close()
fh, args.index = tempfile.mkstemp(suffix='.cdxj')
os.close(fh)
with open(args.index, 'w') as f:
f.write(cdxjIn)

suppliedIndexParameter = True

proxy = None
Expand Down
19 changes: 9 additions & 10 deletions tests/testUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,23 @@ def countCDXJEntries(cdxjData):
return urimCount


def startReplay(warcFilename):
def startReplay(warc_filename):
global p
pathOfWARC = os.path.join(
path_of_warc = os.path.join(
Path(os.path.dirname(__file__)).parent,
'samples', 'warcs', warcFilename)
'samples', 'warcs', warc_filename)

tf = tempfile.NamedTemporaryFile(mode='a', suffix='.cdxj')
tempFilePath = tf.name
tf.close()
fh, tempfile_path = tempfile.mkstemp(suffix='.cdxj')
os.close(fh)

p = Process(target=replay.start, args=[tempFilePath])
p = Process(target=replay.start, args=[tempfile_path])
p.start()
sleep(5)

cdxjList = indexer.indexFileAt(pathOfWARC, quiet=True)
cdxj = '\n'.join(cdxjList)
cdxj_list = indexer.indexFileAt(path_of_warc, quiet=True)
cdxj = '\n'.join(cdxj_list)

with open(tempFilePath, 'w') as f:
with open(tempfile_path, 'w') as f:
f.write(cdxj)


Expand Down