Skip to content

Commit

Permalink
Merge pull request #136 from developmentseed/update_join
Browse files Browse the repository at this point in the history
better handle url joins to a fix error on Windows
  • Loading branch information
Scisco committed Dec 2, 2015
2 parents b44bfcf + d04f69b commit 449762a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ after_success:
- docker login -e ${DOCKER_EMAIL} -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
- docker push developmentseed/landsat-util:travis

before_deploy:
- pip install twine

deploy:
provider: pypi
user: devseed
Expand Down
2 changes: 1 addition & 1 deletion landsat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.10b2'
__version__ = '0.10b3'
8 changes: 4 additions & 4 deletions landsat/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homura import download as fetch
import requests

from utils import check_create_folder
from utils import check_create_folder, url_builder
from mixins import VerbosityMixin
import settings

Expand Down Expand Up @@ -192,7 +192,7 @@ def google_storage_url(self, sat):
(String) The URL to a google storage file
"""
filename = sat['scene'] + '.tar.bz'
return join(self.google, sat['sat'], sat['path'], sat['row'], filename)
return url_builder([self.google, sat['sat'], sat['path'], sat['row'], filename])

def amazon_s3_url(self, sat, filename):
"""
Expand All @@ -210,7 +210,7 @@ def amazon_s3_url(self, sat, filename):
:returns:
(String) The URL to a S3 file
"""
return join(self.s3, sat['sat'], sat['path'], sat['row'], sat['scene'], filename)
return url_builder([self.s3, sat['sat'], sat['path'], sat['row'], sat['scene'], filename])

def remote_file_exists(self, url):
""" Checks whether the remote file exists.
Expand Down Expand Up @@ -284,4 +284,4 @@ def scene_interpreter(self, scene):

d = Downloader()

# d.download(['LC81990242015046LGN00', 'LC80030172015001LGN00'])
# d.download(['LC81990242015046LGN00', 'LC80030172015001LGN00'])
14 changes: 14 additions & 0 deletions landsat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,17 @@ def adjust_bounding_box(bounds1, bounds2):
new_bounds[3] = bounds1[3]

return tuple(new_bounds)


def remove_slash(value):

assert(isinstance(value, str))
return re.sub('(^\/|\/$)', '', value)


def url_builder(segments):

# Only accept list or tuple
assert((isinstance(segments, list) or isinstance(segments, tuple)))
return "/".join([remove_slash(s) for s in segments])

10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ def test_adjust_bounding_box(self):

self.assertEqual(utils.adjust_bounding_box(origin, target), origin)

def test_url_builder(self):

self.assertEqual('http://example.com/segment1/segment2',
utils.url_builder(['/http://example.com', 'segment1/', '/segment2']))

self.assertEqual('http://example.com/segment1/segment2',
utils.url_builder(('/http://example.com', 'segment1/', '/segment2',)))

with self.assertRaises(AssertionError):
utils.url_builder('example.com')

if __name__ == '__main__':
unittest.main()

0 comments on commit 449762a

Please sign in to comment.