Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
7 changes: 3 additions & 4 deletions src/db_models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down