Skip to content

Commit c6b42d1

Browse files
committed
remove microseconds from filename
1 parent 9130a41 commit c6b42d1

12 files changed

Lines changed: 31 additions & 44 deletions

File tree

SatsDecoder/systems/cit_gardens_02.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

1210
from SatsDecoder.systems import common
@@ -57,8 +55,7 @@ def __init__(self, outdir):
5755

5856
def generate_fid(self, force=0, name='Gardens-02', tx_id=0, t=None):
5957
if force or not (self.current_fid and self.merge_mode):
60-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
61-
self.current_fid = f'{name}_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}_{tx_id:02X}'
58+
self.current_fid = f'{name}_{self.strftime(t)}_{tx_id:02X}'
6259
return self.current_fid
6360

6461
def push_data(self, pkt, name='Gardens-02', t=None, **kw):

SatsDecoder/systems/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def _encode(self, obj, context, path=None):
2121
return round(obj.timestamp())
2222

2323
def _decode(self, obj, context, path=None):
24-
return dt.datetime.utcfromtimestamp(obj)
24+
return dt.datetime.fromtimestamp(obj, dt.timezone.utc)
2525

2626

2727
class UNIXTimestampUsAdapter(construct.Adapter):
2828
def _encode(self, obj, context, path=None):
2929
return round(obj.timestamp() * 1000000)
3030

3131
def _decode(self, obj, context, path=None):
32-
return dt.datetime.utcfromtimestamp(obj / 1000000)
32+
return dt.datetime.fromtimestamp(obj / 1000000, dt.timezone.utc)
3333

3434

3535
class TimeDeltaAdapter(construct.Adapter):

SatsDecoder/systems/cubebel2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

1210
from SatsDecoder import utils

SatsDecoder/systems/geoscan.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
from itertools import chain
119

1210
import construct
@@ -302,11 +300,10 @@ def __init__(self, outdir):
302300

303301
def generate_fid(self, sat_num=None, t=None):
304302
if not (self.current_fid and self.merge_mode):
305-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
306303
pfx = get_sat_name(sat_num).rpartition('-')[0]
307304
hr = self._last_is_hr and '_hr' or ''
308305
fnum = (self._last_fnum > -1) and ('_N' + str(self._last_fnum)) or ''
309-
self.current_fid = f'{pfx.upper()}{hr}{fnum}_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}'
306+
self.current_fid = f'{pfx.upper()}{hr}{fnum}_{self.strftime(t)}'
310307
if fnum and self.merge_mode:
311308
self._fids[self._last_fnum] = self.current_fid
312309
return self.current_fid

SatsDecoder/systems/image_receiver.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8+
import datetime as dt
89
import math
910
import pathlib
1011
import shutil
@@ -126,6 +127,8 @@ def __init__(self, outdir, suff=None):
126127
self.merge_mode = 0
127128
self.current_fid = ''
128129
self.last_date = 0
130+
self.time_fmt = '%Y-%m-%dT%H-%M-%S'
131+
self.dated_img = 0
129132

130133
@property
131134
def cur_img(self):
@@ -151,6 +154,9 @@ def set_outdir(self, outdir):
151154
def set_merge_mode(self, val):
152155
self.merge_mode = val
153156

157+
def set_dated_img(self, val):
158+
self.dated_img = val
159+
154160
def generate_fid(self, *args, **kwargs):
155161
raise NotImplementedError
156162

@@ -160,7 +166,7 @@ def force_new(self, *args, **kwargs):
160166

161167
def new_file(self, fid):
162168
fn = self.outdir / fid
163-
if self.suff:
169+
if self.suff and not fn.suffix:
164170
fn = fn.with_suffix(self.suff)
165171

166172
# img = self.images.get(fid)
@@ -178,3 +184,7 @@ def clear(self):
178184
for i in self.images.values():
179185
i.close()
180186
self.current_fid = ''
187+
188+
def strftime(self, t=None):
189+
self.last_date = t or dt.datetime.now(dt.timezone.utc)
190+
return self.last_date.strftime(self.time_fmt)

SatsDecoder/systems/ledsat.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

1210
from SatsDecoder.systems import csp, common
@@ -150,9 +148,8 @@ def clear(self):
150148

151149
def generate_fid(self, large='', t=None):
152150
if not (self.current_fid and self.merge_mode):
153-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
154151
large = large and f'_LARGE-({",".join(large)})'
155-
self.current_fid = f'LEDSAT_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}{large}'
152+
self.current_fid = f'LEDSAT_{self.strftime(t)}{large}'
156153
return self.current_fid
157154

158155
def push_data(self, data, large='', t=None, **kw):

SatsDecoder/systems/lucky7.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

12-
from SatsDecoder import utils
1310
from SatsDecoder.systems import common
1411
from SatsDecoder.systems.image_receiver import ImageReceiver
1512

@@ -68,8 +65,7 @@ def __init__(self, outdir):
6865

6966
def generate_fid(self, t=None):
7067
if not (self.current_fid and self.merge_mode):
71-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
72-
self.current_fid = f'LUCKY7_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}'
68+
self.current_fid = f'LUCKY7_{self.strftime(t)}'
7369
return self.current_fid
7470

7571
def get_image(self, force_new=0, packets=0, t=None, **kwargs):

SatsDecoder/systems/roseycubesat.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

1210
from SatsDecoder.systems import ax25, common
@@ -71,8 +69,7 @@ def __init__(self, outdir):
7169

7270
def generate_fid(self, t=None):
7371
if not (self.current_fid and self.merge_mode):
74-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
75-
self.current_fid = f'RoseyCubesat-1_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}'
72+
self.current_fid = f'RoseyCubesat-1_{self.strftime(t)}'
7673
return self.current_fid
7774

7875
def new_file(self, fid, sz=None):

SatsDecoder/systems/sharjahsat.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

12-
from SatsDecoder import utils
1310
from SatsDecoder.systems import ax25, common
1411
from SatsDecoder.systems.image_receiver import ImageReceiver
1512

@@ -225,8 +222,7 @@ def __init__(self, outdir):
225222

226223
def generate_fid(self, t=None):
227224
if not (self.current_fid and self.merge_mode):
228-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
229-
self.current_fid = f'SharjahSat-1_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}'
225+
self.current_fid = f'SharjahSat-1_{self.strftime(t)}'
230226
return self.current_fid
231227

232228
def get_image(self, force_new=0, soi=0, pnum=0, t=None, **kwargs):

SatsDecoder/systems/usp.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8-
import datetime as dt
9-
108
import construct
119

1210
from SatsDecoder import utils
@@ -1478,16 +1476,13 @@
14781476

14791477
class UspImageReceiver(ImageReceiver):
14801478
def __init__(self, outdir):
1481-
super().__init__(outdir)
1479+
super().__init__(outdir, '.jpg')
14821480

14831481
def generate_fid(self, fname='', force=0, t=None):
14841482
if self.current_fid.startswith('unknown_') and fname:
14851483
self.rename_image(self.current_fid, fname)
14861484
elif force or not (self.current_fid and self.merge_mode):
1487-
self.last_date = now = t or dt.datetime.now(dt.timezone.utc)
1488-
if not fname:
1489-
fname = f'unknown_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}'
1490-
self.current_fid = fname
1485+
self.current_fid = fname or f'USP_unknown_{self.strftime(t)}'
14911486
return self.current_fid
14921487

14931488
def push_data(self, data, t=None, **kw):

0 commit comments

Comments
 (0)