Skip to content

Commit

Permalink
Allow uploader.py to compress rlog without upload permission (#471)
Browse files Browse the repository at this point in the history
* Always Compress - Make sure uploader to bzip2 rlog once it's completed without any upload permission.
  • Loading branch information
eFiniLan authored and legonigel committed Feb 14, 2019
1 parent 03f13e6 commit 88246af
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions selfdrive/loggerd/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ def get_data_stats(self):
total_size += os.stat(fn).st_size
return dict(name_counts), total_size

def next_file_to_compress(self):
for name, key, fn in self.gen_upload_files():
if name == "rlog":
return (key, fn, 0)
return None

def next_file_to_upload(self, with_video):
# try to upload log files first
for name, key, fn in self.gen_upload_files():
if name in ["rlog", "rlog.bz2"]:
if name == "rlog.bz2":
return (key, fn, 0)

if with_video:
Expand Down Expand Up @@ -208,7 +214,7 @@ def abort_upload(self):
raise_on_thread(thread, SystemExit)
thread.join()

def upload(self, key, fn):
def compress(self, key, fn):
# write out the bz2 compress
if fn.endswith("log"):
ext = ".bz2"
Expand All @@ -221,6 +227,9 @@ def upload(self, key, fn):
key += ext
fn += ext

return (key, fn)

def upload(self, key, fn):
try:
sz = os.path.getsize(fn)
except OSError:
Expand Down Expand Up @@ -275,6 +284,12 @@ def uploader_fn(exit_event):
if exit_event.is_set():
return

d = uploader.next_file_to_compress()
if d is not None:
key, fn, _ = d
uploader.compress(key, fn)
continue

if not should_upload:
time.sleep(5)
continue
Expand Down

0 comments on commit 88246af

Please sign in to comment.