Skip to content
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
14 changes: 8 additions & 6 deletions planet/api/_fatomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def atomic_open(filename, mode, *args, **kwargs):
dir=os.path.dirname(filename),
suffix='.tmp',
delete=False)
_discard = [False]
# track: explicitly discarded, normal/abnormal completion
_discard = [None]
try:
if mode[0] == 'a':
try:
Expand All @@ -63,17 +64,18 @@ def atomic_open(filename, mode, *args, **kwargs):
pass

def discard(self, _discard=_discard):
# explicit discard
_discard[0] = True
f.discard = types.MethodType(discard, f)
yield f
# ischneider addition to fatomic - catch/raise any exception thrown in with
# normal completion
if not _discard[0]:
_discard[0] = False
# block and force discarding
except:
_discard = [True]
raise
finally:
f.close()
if _discard[0]:
# if we didn't complete or were aborted, delete
if _discard[0] is None or _discard[0]:
os.unlink(f.name)
else:
_replace_file(f.name, filename)
2 changes: 1 addition & 1 deletion planet/api/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from planet.api.exceptions import RequestCancelled
try:
import Queue as queue
except:
except ImportError:
# renamed in 3
import queue

Expand Down
18 changes: 7 additions & 11 deletions planet/scripts/item_asset_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# In case the API fails to respond or takes too long.
DEFAULT_ITEM_TYPES = [
"PSScene4Band", "PSScene3Band", "REScene", "SkySatScene",
"REOrthoTile", "Sentinel2L1C", "PSOrthoTile", "Landsat8L1G"]
"REOrthoTile", "Sentinel2L1C", "PSOrthoTile", "Landsat8L1G", "Sentinel1"]

DEFAULT_ASSET_TYPES = [
"analytic", "analytic_b1", "analytic_b10", "analytic_b11", "analytic_b12",
Expand Down Expand Up @@ -43,20 +43,16 @@ def _get_json_or_raise(url, timeout=0.7):
def get_item_types():
global _item_types
if _item_types is None:
try:
data = _get_json_or_raise(ITEM_TYPE_URL)
_item_types = [it['id'] for it in data['item_types']]
except:
_item_types = DEFAULT_ITEM_TYPES
_item_types = DEFAULT_ITEM_TYPES
data = _get_json_or_raise(ITEM_TYPE_URL)
_item_types = [it['id'] for it in data['item_types']]
return _item_types


def get_asset_types():
global _asset_types
if _asset_types is None:
try:
data = _get_json_or_raise(ASSET_TYPE_URL)
_asset_types = [a['id'] for a in data['asset_types']]
except:
_asset_types = DEFAULT_ASSET_TYPES
_asset_types = DEFAULT_ASSET_TYPES
data = _get_json_or_raise(ASSET_TYPE_URL)
_asset_types = [a['id'] for a in data['asset_types']]
return _asset_types
2 changes: 1 addition & 1 deletion tests/test_atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def assert_content_is(expected):
with atomic_open(outfile, 'w') as fp:
fp.write('bazzy')
raise Exception('drat')
except:
except Exception:
assert_content_is('bar')
else:
assert False
Expand Down
3 changes: 2 additions & 1 deletion tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_item_type():
check('all', get_item_types())
check('psscene', ['PSScene3Band', 'PSScene4Band'])
check('Sentinel2L1C', ['Sentinel2L1C'])
check('psscene,sent', ['PSScene3Band', 'PSScene4Band', 'Sentinel2L1C'])
check('psscene,sent', ['PSScene3Band', 'PSScene4Band',
'Sentinel1', 'Sentinel2L1C'])

with pytest.raises(Exception) as e:
ItemType().convert('x', None, None)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_v1_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def assert_success(result, expected_output, exit_code=0):
pass
try:
assert json.loads(result.output) == expected_output
except:
except ValueError:
assert result.output == expected_output


Expand Down