A couple of bug fixes

This commit is contained in:
Jeff Bradberry 2021-03-17 16:46:12 -04:00
parent 0b31e771b1
commit 3568558571
3 changed files with 14 additions and 12 deletions

View File

@ -274,7 +274,10 @@ class FileSplitter(io.StringIO):
self.files = self.files[:-1]
# If we only have one file, remove the suffix
if len(self.files) == 1:
os.rename(self.files[0], self.files[0].replace('_split0', ''))
filename = self.files.pop()
new_filename = filename.replace('_split0', '')
os.rename(filename, new_filename)
self.files.append(new_filename)
return self.files
def write(self, s):
@ -302,7 +305,7 @@ def events_slicing(key, since, until):
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}')
previous_pk = last_entries.get(key) or pk_values['pk__min'] or 0
final_pk = pk_values['pk__max']
final_pk = pk_values['pk__max'] or 0
for start in range(previous_pk, final_pk + 1, step):
yield (start, min(start + step, final_pk))

View File

@ -87,24 +87,24 @@ def package(target, data, timestamp):
for name, (item, version) in data.items():
try:
if isinstance(item, str):
info = f.gettarinfo(item, arcname=f'./{name}')
f.addfile(info)
f.add(item, arcname=f'./{name}')
else:
fileobj = io.BytesIO(json.dumps(item).encode('utf-8'))
buf = json.dumps(item).encode('utf-8')
info = tarfile.TarInfo(f'./{name}')
info.size = len(fileobj.getvalue())
info.size = len(buf)
info.mtime = timestamp.timestamp()
f.addfile(info, fileobj=fileobj)
f.addfile(info, fileobj=io.BytesIO(buf))
manifest[name] = version
except Exception:
logger.exception(f"Could not generate metric {name}")
return None
try:
fileobj = io.BytesIO(json.dumps(manifest).encode('utf-8'))
buf = json.dumps(manifest).encode('utf-8')
info = tarfile.TarInfo('./manifest.json')
info.size = len(fileobj.getvalue())
info.size = len(buf)
info.mtime = timestamp.timestamp()
f.addfile(info, fileobj=fileobj)
f.addfile(info, fileobj=io.BytesIO(buf))
except Exception:
logger.exception("Could not generate manifest.json")
return None

View File

@ -48,8 +48,7 @@ class Command(BaseCommand):
if opt_ship and opt_dry_run:
self.logger.error('Both --ship and --dry-run cannot be processed at the same time.')
return
tgzfiles = analytics.gather(collection_type='manual' if opt_ship else 'dry-run',
since=since, until=until)
tgzfiles = analytics.gather(collection_type='manual' if opt_ship else 'dry-run', since=since, until=until)
if tgzfiles:
for tgz in tgzfiles:
self.logger.info(tgz)