From d8a40ecec779170518b3c184f9a7c88b884c3eb5 Mon Sep 17 00:00:00 2001 From: fumiya-kubota Date: Wed, 25 Jan 2017 13:36:47 +0900 Subject: [PATCH 1/3] =?UTF-8?q?zip=E3=81=AE=E6=A7=8B=E9=80=A0=E3=81=AB?= =?UTF-8?q?=E3=82=88=E3=81=A3=E3=81=A6upload=E3=81=AB=E5=A4=B1=E6=95=97?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db_models/datasets.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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() From 6de69d7f4c5d7168cd1451e9b37e0a62cfff6a5d Mon Sep 17 00:00:00 2001 From: fumiya-kubota Date: Fri, 14 Apr 2017 12:08:39 +0900 Subject: [PATCH 2/3] huge text stream --- src/common/utils.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common/utils.py b/src/common/utils.py index 55ec050..cfcbe3c 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) + text.decode(encoding) From ed299f66a02f378161363825b8ef6feb8914c1cb Mon Sep 17 00:00:00 2001 From: fumiya-kubota Date: Tue, 18 Apr 2017 18:36:47 +0900 Subject: [PATCH 3/3] fix return None --- src/common/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/utils.py b/src/common/utils.py index cfcbe3c..eb9b2a3 100644 --- a/src/common/utils.py +++ b/src/common/utils.py @@ -238,4 +238,4 @@ def get_text_sample(path, character_num=100): else: text = text[:character_num] encoding = nkf.guess(text) - text.decode(encoding) + return text.decode(encoding)