From 08a4697cf72b6375fef77e8218ad363a7e9a92bc Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sun, 21 Feb 2016 17:24:35 +0100 Subject: [PATCH] [WIP] NAS: Moved action='count' in dlc --- nas_server.py | 20 +------------------- other/dlc.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/nas_server.py b/nas_server.py index 0dde5b1..3f735ec 100644 --- a/nas_server.py +++ b/nas_server.py @@ -252,25 +252,7 @@ class NasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): return if action == "count": - if post["gamecd"] in dlc.gamecodes_return_random_file: - ret = "1" - else: - count = 0 - - if os.path.exists(dlcpath): - count = len(os.listdir(dlcpath)) - - if os.path.isfile(dlcpath + "/_list.txt"): - attr1 = post.get("attr1", None) - attr2 = post.get("attr2", None) - attr3 = post.get("attr3", None) - - dlcfi = dlc.safeloadfi(dlcpath, "_list.txt") - lst = dlc.filter_list(dlcfi, - attr1, attr2, attr3) - count = dlc.get_file_count(lst) - - ret = "%d" % count + ret = dlc.download_count(dlc_path, post) if action == "list": num = post.get("num", None) diff --git a/other/dlc.py b/other/dlc.py index f04cefd..c0d6e5a 100644 --- a/other/dlc.py +++ b/other/dlc.py @@ -141,3 +141,23 @@ def safeloadfi(dlc_path, name, mode='rb'): """ with open(os.path.join(dlc_path, name), mode) as f: return f.read() + + +def download_count(dlc_path, post): + """Handle download count request.""" + if post["gamecd"] in gamecodes_return_random_file: + return "1" + elif os.path.exists(dlc_path): + if os.path.isfile(os.path.join(dlc_path, "_list.txt")): + attr1 = post.get("attr1", None) + attr2 = post.get("attr2", None) + attr3 = post.get("attr3", None) + + dlc_file = safeloadfi(dlc_path, "_list.txt") + ls = filter_list(dlc_file, attr1, attr2, attr3) + count = get_file_count(ls) + else: + count = len(os.listdir(dlc_path)) + return "%d" % count + else: + return "0"