diff --git a/src/common/utils.py b/src/common/utils.py index 55ec050..eb9b2a3 100644 --- a/src/common/utils.py +++ b/src/common/utils.py @@ -54,7 +54,7 @@ def get_disk_info(): disk_info.append({ 'mount': row[mounted_on_index], 'size': calculate_human_readable_filesize(st.f_frsize * st.f_blocks), - 'used': calculate_human_readable_filesize(st.f_frsize * (st.f_blocks-st.f_bfree)), + 'used': calculate_human_readable_filesize(st.f_frsize * (st.f_blocks - st.f_bfree)), 'avail': calculate_human_readable_filesize(st.f_frsize * st.f_favail) }) return disk_info @@ -228,11 +228,14 @@ def get_images_in_random_order(path, num): return ret -def get_text_sample(path, character_num=-1): - raw_text = open(path).read() - encoding = nkf.guess(raw_text) - text = raw_text.decode(encoding) - if character_num > -1: - return text[0:character_num] - else: - return text +def get_text_sample(path, character_num=100): + text = '' + with open(path) as fp: + for row in fp: + text += row.strip() + if len(text) > character_num: + break + else: + text = text[:character_num] + encoding = nkf.guess(text) + return text.decode(encoding) diff --git a/src/db_models/datasets.py b/src/db_models/datasets.py index 026cba8..e46da9b 100644 --- a/src/db_models/datasets.py +++ b/src/db_models/datasets.py @@ -194,10 +194,9 @@ def save_uploaded_data(self, uploaded_file, save_raw_file_to, save_to): if ('__MACOSX' in file_name) or ('.DS_Store' in file_name): continue temp_path = os.path.join(extract_to, file_name) - if not os.path.basename(file_name): - if not os.path.exists(temp_path): - os.makedirs(temp_path.encode(encoding='utf-8')) - category_num += 1 + if not os.path.exists(os.path.dirname(temp_path)): + os.makedirs(temp_path.encode(encoding='utf-8')) + category_num += 1 else: temp, ext = os.path.splitext(temp_path) ext = ext.lower()