[WIP] NAS: Moved action='count' in dlc

This commit is contained in:
Sepalani 2016-02-21 17:24:35 +01:00
parent 9148578223
commit 08a4697cf7
2 changed files with 21 additions and 19 deletions

View File

@ -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)

View File

@ -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"