Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EdosL0Util
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SIPS
EdosL0Util
Commits
e8b46f71
Commit
e8b46f71
authored
9 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
Handle PacketTooShort in PacketStream
parent
2a78625f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
edosl0util/stream.py
+34
-5
34 additions, 5 deletions
edosl0util/stream.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
35 additions
and
6 deletions
edosl0util/stream.py
+
34
−
5
View file @
e8b46f71
...
...
@@ -36,7 +36,7 @@ class PacketTooShort(Error):
class
NonConsecutiveSeqId
(
Error
):
"""
Non-consecutive sequence numbers encounterd for apid.
Non-consecutive sequence numbers encounterd for apid
, i.e., packet gap
.
"""
...
...
@@ -70,8 +70,8 @@ class BasicStream(object):
raise
StopIteration
()
if
len
(
buf
)
!=
size
:
raise
PacketTooShort
(
'
expected to read {:d} bytes, got {:d}
'
.
format
(
size
,
len
(
buf
)
)
)
'
expected to read {:d} bytes, got
{:d} at offset
{:d}
'
.
format
(
size
,
len
(
buf
)
,
self
.
_offset
),
self
.
file
)
self
.
_offset
+=
size
return
buf
...
...
@@ -155,7 +155,20 @@ class Packet(object):
class
PacketStream
(
object
):
SEQID_NOTSET
=
-
1
def
__init__
(
self
,
data_stream
,
fail_on_missing
=
False
):
def
__init__
(
self
,
data_stream
,
fail_on_missing
=
False
,
fail_on_tooshort
=
False
):
"""
:param data_stream: An interable of ``Tracker`` objects
:keyword fail_on_missing:
Raise a ``NonConsecutiveSeqId`` error when sequence id gaps are
found. If this is False sequence id gaps are ignored.
:keyword fail_on_tooshort:
Raise a ``PacketTooShort`` error when a packet is encountered for
which less bytes can be read than are expected according to the
packet headers. Most of the this would be due to a truncated file
with an incomplete packet at the end. If this is False a
``StopIteration`` will be raised which will effectively truncate
the file.
"""
self
.
_stream
=
data_stream
self
.
_seek_cache
=
deque
()
self
.
_first
=
None
...
...
@@ -165,6 +178,7 @@ class PacketStream(object):
'
last_seqid
'
:
self
.
SEQID_NOTSET
,
'
num_missing
'
:
0
})
self
.
_fail_on_missing
=
fail_on_missing
self
.
_fail_on_tooshort
=
fail_on_tooshort
def
__repr__
(
self
):
filepath
=
getattr
(
self
.
file
,
'
name
'
,
None
)
...
...
@@ -182,13 +196,24 @@ class PacketStream(object):
return
self
.
_stream
.
file
def
push_back
(
self
,
packet
):
"""
Put a packet back such that it is the next file provided when
``next`` is called.
"""
self
.
_seek_cache
.
append
(
packet
)
def
next
(
self
):
# return any items on the seek cache before reading more
if
len
(
self
.
_seek_cache
):
return
self
.
_seek_cache
.
popleft
()
h1
,
h2
,
data_size
,
offset
,
data
=
self
.
_stream
.
next
()
try
:
h1
,
h2
,
data_size
,
offset
,
data
=
self
.
_stream
.
next
()
except
PakcetTooShort
as
err
:
if
self
.
_fail_on_tooshort
:
raise
LOG
.
error
(
'
Packet too short, aborting stream: {:s}
'
,
err
)
# The result of this is essentially a file truncation
raise
StopIteration
()
packet
=
Packet
(
h1
,
h2
,
data
,
data_size
=
data_size
,
offset
=
offset
)
have_missing
=
self
.
_update_info
(
packet
)
if
have_missing
and
self
.
_fail_on_missing
:
...
...
@@ -197,6 +222,10 @@ class PacketStream(object):
return
packet
def
_update_info
(
self
,
packet
):
"""
Handle gap detection and first/last. Returns whether any missing
packets were detected.
"""
have_missing
=
False
apid
=
self
.
_apid_info
[
packet
.
apid
]
if
packet
.
stamp
:
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
e8b46f71
...
...
@@ -5,7 +5,7 @@ setup(
author
=
'
Bruce Flynn
'
,
author_email
=
'
brucef@ssec.wisc.edu
'
,
description
=
'
Utilities for working with EDOS L0 PDS files
'
,
version
=
'
0.6.
1
'
,
version
=
'
0.6.
2
'
,
zip_safe
=
False
,
packages
=
find_packages
(),
pyver
=
True
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment