Skip to content

Commit

Permalink
fixes for windows: convert url to file with pathname2url, use 'b' for
Browse files Browse the repository at this point in the history
reading warcs, don't use %s for timestamp conversion (not portable)
(#56)
  • Loading branch information
ikreymer committed Jan 11, 2015
1 parent 7f52ecd commit ba853a4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pywb/warc/cdxindexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def write_multi_cdx_index(output, inputs, **options):
outpath = os.path.join(output, outpath)

with open(outpath, 'w') as outfile:
with open(fullpath, 'r') as infile:
with open(fullpath, 'rb') as infile:
write_cdx_index(outfile, infile, filename, **options)

# write to one cdx file
Expand All @@ -133,7 +133,7 @@ def write_multi_cdx_index(output, inputs, **options):

with writer_cls(outfile, options.get('cdx09')) as writer:
for fullpath, filename in iter_file_or_dir(inputs):
with open(fullpath, 'r') as infile:
with open(fullpath, 'rb') as infile:
entry_iter = create_index_iter(infile, **options)

for entry in entry_iter:
Expand Down
2 changes: 2 additions & 0 deletions pywb/warc/pathresolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pywb.utils.binsearch import iter_exact

import urlparse
import urllib
import os
import logging

Expand Down Expand Up @@ -92,6 +93,7 @@ def make_best_resolver(param):

if url_parts.scheme == 'file':
path = url_parts.path
path = urllib.url2pathname(path)

if os.path.isfile(path):
logging.debug('Adding Path Index: ' + path)
Expand Down
10 changes: 8 additions & 2 deletions pywb/warc/test/test_pathresolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
RedisResolver('redis://myhost.example.com:1234/1')
# a file
>>> r = make_best_resolver('file://' + os.path.realpath(__file__))
>>> r = make_best_resolver(to_local_url(os.path.realpath(__file__)))
>>> r.__class__.__name__
'PathIndexResolver'
# a dir
>>> path = os.path.realpath(__file__)
>>> r = make_best_resolver('file://' + os.path.dirname(path))
>>> r = make_best_resolver(to_local_url(os.path.dirname(path)))
>>> r.__class__.__name__
'PrefixResolver'
Expand All @@ -56,6 +56,7 @@
from pywb.warc.pathresolvers import make_best_resolver, make_best_resolvers
import os

from urllib import pathname2url

from fakeredis import FakeStrictRedis
from mock import patch
Expand All @@ -68,6 +69,11 @@ def init_redis_resolver():
def hset_path(filename, path):
redis_resolver.redis.hset(redis_resolver.key_prefix + filename, 'path', path)

def to_local_url(filename):
filename = os.path.abspath(filename)
res = 'file:' + pathname2url(filename)
#print(res)
return res

redis_resolver = init_redis_resolver()

Expand Down
6 changes: 5 additions & 1 deletion pywb/webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import urlparse
import logging
import time

from os import path
from itertools import imap
Expand Down Expand Up @@ -42,7 +43,10 @@ def __call__(self, func):
@template_filter
def format_ts(value, format_='%a, %b %d %Y %H:%M:%S'):
value = timestamp_to_datetime(value)
return value.strftime(format_)
if format_ == '%s':
return int(time.mktime(value.timetuple()) * 1000)
else:
return value.strftime(format_)


@template_filter('urlsplit')
Expand Down

0 comments on commit ba853a4

Please sign in to comment.