Skip to content

Commit

Permalink
minor change with download folder
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksMat committed Apr 16, 2018
1 parent 5ac577f commit d80d151
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion sentinelhub/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@ def download(url, filename, redownload):
Example:
sentinelhub.download http://sentinel-s2-l1c.s3.amazonaws.com/tiles/54/H/VH/2017/4/14/0/metadata.xml home/example.xml
"""
download_list = [DownloadRequest(url=url, data_folder='', filename=filename, save_response=True, return_data=False)]
data_folder, filename = filename.rsplit('/', 1)
download_list = [DownloadRequest(url=url, data_folder=data_folder, filename=filename, save_response=True,
return_data=False)]
download_data(download_list, redownload=redownload)
4 changes: 3 additions & 1 deletion sentinelhub/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ def set_data_folder(self, data_folder):
self._set_file_location()

def _set_file_location(self):
if self.data_folder is not None and self.filename is not None:
if self.data_folder and self.filename:
self.file_location = os.path.join(self.data_folder, self.filename.lstrip('/'))
elif self.filename:
self.file_location = self.filename

def is_downloaded(self):
""" Checks if data for this request has already been downloaded and is saved to disk.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def setUpClass(cls):
os.mkdir(cls.OUTPUT_FOLDER)

compact_product_id = 'S2A_MSIL1C_20170414T003551_N0204_R016_T54HVH_20170414T003551'
cls.status += subprocess.call('sentinelhub.aws --product {} -rf ./{} -b B8A'.format(compact_product_id,
cls.OUTPUT_FOLDER),
cls.status += subprocess.call('sentinelhub.aws --product {} -rf {} -b B8A'.format(compact_product_id,
cls.OUTPUT_FOLDER),
shell=True)
old_product_id = 'S2A_OPER_PRD_MSIL1C_PDMC_20160121T043931_R069_V20160103T171947_20160103T171947'
cls.status += subprocess.call('sentinelhub.aws --product {} -i'.format(old_product_id), shell=True)
cls.status += subprocess.call('sentinelhub.aws --tile T38TML 2015-12-19 -ref {} '
'--bands B01,B10'.format(cls.OUTPUT_FOLDER), shell=True)
url = 'http://sentinel-s2-l1c.s3.amazonaws.com/tiles/54/H/VH/2017/4/14/0/metadata.xml'
cls.status += subprocess.call('sentinelhub.download {} {}/example.xml -r'.format(url, cls.OUTPUT_FOLDER),
shell=True)
cls.status += subprocess.call('sentinelhub.download {} {} '
'-r'.format(url, os.path.join(cls.OUTPUT_FOLDER, 'example.xml')), shell=True)

cls.status += subprocess.call('sentinelhub.config --show', shell=True)

Expand Down

0 comments on commit d80d151

Please sign in to comment.