Skip to content

Commit

Permalink
fix convert error when threshold is none (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoYangyang0403 authored Aug 23, 2023
1 parent e52cabe commit b1ec5b0
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lyrebird/db/database_server.py
Original file line number Diff line number Diff line change
@@ -222,17 +222,21 @@ def get_page_count(self, channel_rules, page_size=20, search_str=''):

def get_database_info(self):
database_path = str(self.database_uri)
threshold_str = application._cm.config.get('event.file_size_threshold')
threshold_byte = convert_size_to_byte(threshold_str)
size = self.database_uri.stat().st_size
readable_size = convert_size(size)
oversized = threshold_byte and size > threshold_byte
database_info = {
'path': database_path,
'threshold': threshold_str,
'size': readable_size,
'oversized': oversized
'oversized': False
}

threshold_str = application._cm.config.get('event.file_size_threshold')
if threshold_str is not None:
threshold_byte = convert_size_to_byte(threshold_str)
oversized = threshold_byte and size > threshold_byte
database_info['threshold'] = threshold_str
database_info['oversized'] = oversized

return database_info

def reset(self):
2 changes: 1 addition & 1 deletion lyrebird/utils.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ def convert_size(size_bytes):
return "%s %s" % (s, size_name[i])


def convert_size_to_byte(size_str):
def convert_size_to_byte(size_str: str):
size_str = size_str.strip().upper()
match = re.match(r'^(\d+\.?\d*)\s*([KMGTPEZY]?[B])$', size_str)
if not match:

0 comments on commit b1ec5b0

Please sign in to comment.