Blendfile now downloads zip
This commit is contained in:
@@ -73,11 +73,15 @@ class PathHandle:
|
|||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download_from_server(path, idname):
|
def download_from_server(path, idname, file_type, local_filename=None):
|
||||||
import requests
|
import requests
|
||||||
payload = {"filepath": "/".join(path) + "/" + idname}
|
payload = {"filepath": "/".join(path) + "/" + idname}
|
||||||
r = requests.get(PathHandle.request_url("file"), params=payload, auth=("bam", "bam"), stream=True)
|
r = requests.get(PathHandle.request_url(file_type), params=payload, auth=("bam", "bam"), stream=True)
|
||||||
local_filename = payload['filepath'].split('/')[-1]
|
local_filename = payload['filepath'].split('/')[-1]
|
||||||
|
|
||||||
|
if file_type == "file_deps":
|
||||||
|
local_filename += ".zip"
|
||||||
|
|
||||||
with open(local_filename, 'wb') as f:
|
with open(local_filename, 'wb') as f:
|
||||||
for chunk in r.iter_content(chunk_size=1024):
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
if chunk: # filter out keep-alive new chunks
|
if chunk: # filter out keep-alive new chunks
|
||||||
@@ -101,7 +105,7 @@ class Application(tk.Frame):
|
|||||||
|
|
||||||
self.vsb.pack(side="right", fill="y")
|
self.vsb.pack(side="right", fill="y")
|
||||||
self.canvas.pack(side="left", fill="both", expand=True)
|
self.canvas.pack(side="left", fill="both", expand=True)
|
||||||
self.canvas.create_window((4, 4), window=self.frame, anchor="nw",
|
self.canvas.create_window((4, 4), window=self.frame, anchor="nw",
|
||||||
tags="self.frame")
|
tags="self.frame")
|
||||||
|
|
||||||
self.frame.bind("<Configure>", self.OnFrameConfigure)
|
self.frame.bind("<Configure>", self.OnFrameConfigure)
|
||||||
@@ -141,11 +145,12 @@ class Application(tk.Frame):
|
|||||||
self.repopulate()
|
self.repopulate()
|
||||||
|
|
||||||
def exec_path_file(idname):
|
def exec_path_file(idname):
|
||||||
self.path_handle.download_from_server(self.path_handle.path, idname)
|
self.path_handle.download_from_server(self.path_handle.path, idname, "file")
|
||||||
print(self.path_handle.path)
|
|
||||||
|
|
||||||
self.repopulate()
|
self.repopulate()
|
||||||
|
|
||||||
|
def exec_path_blendfile(idname):
|
||||||
|
self.path_handle.download_from_server(self.path_handle.path, idname, "file_deps")
|
||||||
|
self.repopulate()
|
||||||
|
|
||||||
js = self.path_handle.json
|
js = self.path_handle.json
|
||||||
items = js.get("items_list")
|
items = js.get("items_list")
|
||||||
@@ -177,16 +182,30 @@ class Application(tk.Frame):
|
|||||||
|
|
||||||
self.grid_members.append(but)
|
self.grid_members.append(but)
|
||||||
row += 1
|
row += 1
|
||||||
|
#
|
||||||
|
# for name_short, name_full, item_type in items:
|
||||||
|
# print(name_short, name_full, item_type)
|
||||||
|
# if item_type == "file":
|
||||||
|
# but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid")
|
||||||
|
# but.grid(row=row, column=0)
|
||||||
|
# def fn(idname=name_short): exec_path_file(idname)
|
||||||
|
# self.grid_members.append(but)
|
||||||
|
#
|
||||||
|
# but = tk.Button(self.frame, text=name_short, fg="blue", command=fn)
|
||||||
|
# but.grid(row=row, column=1, sticky="nw")
|
||||||
|
# del fn
|
||||||
|
#
|
||||||
|
# self.grid_members.append(but)
|
||||||
|
# row += 1
|
||||||
|
|
||||||
for name_short, name_full, item_type in items:
|
for name_short, name_full, item_type in items:
|
||||||
print(name_short, name_full, item_type)
|
print(name_short, name_full, item_type)
|
||||||
if item_type in {"file", "blendfile"}:
|
if item_type == "file":
|
||||||
but = tk.Label(self.frame, text="(f)", width=3, borderwidth="1", relief="solid")
|
but = tk.Label(self.frame, text="(b)", width=3, borderwidth="1", relief="solid")
|
||||||
but.grid(row=row, column=0)
|
but.grid(row=row, column=0)
|
||||||
def fn(idname=name_short): exec_path_file(idname)
|
def fn(idname=name_short): exec_path_blendfile(idname)
|
||||||
self.grid_members.append(but)
|
self.grid_members.append(but)
|
||||||
|
|
||||||
|
|
||||||
but = tk.Button(self.frame, text=name_short, fg="blue", command=fn)
|
but = tk.Button(self.frame, text=name_short, fg="blue", command=fn)
|
||||||
but.grid(row=row, column=1, sticky="nw")
|
but.grid(row=row, column=1, sticky="nw")
|
||||||
del fn
|
del fn
|
||||||
|
@@ -114,5 +114,70 @@ class FileAPI(Resource):
|
|||||||
return Response(f, direct_passthrough=True)
|
return Response(f, direct_passthrough=True)
|
||||||
|
|
||||||
|
|
||||||
|
class FileDepsAPI(Resource):
|
||||||
|
"""Downloads a file and its deps."""
|
||||||
|
|
||||||
|
decorators = [auth.login_required]
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
parser = reqparse.RequestParser()
|
||||||
|
parser.add_argument('filepath', type=str, required=True,
|
||||||
|
help="Filepath cannot be blank!")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
super(FileDepsAPI, self).__init__()
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
filepath = os.path.join(app.config['STORAGE_PATH'], request.args['filepath'])
|
||||||
|
|
||||||
|
# pack the file!
|
||||||
|
print("PACKING")
|
||||||
|
filepath_zip = self.pack_fn(filepath)
|
||||||
|
|
||||||
|
# TODO, handle fail
|
||||||
|
if filepath_zip is None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
f = open(filepath_zip, 'rb')
|
||||||
|
return Response(f, direct_passthrough=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def pack_fn(filepath):
|
||||||
|
import tempfile
|
||||||
|
filepath_zip = tempfile.mkstemp(suffix=".zip")
|
||||||
|
|
||||||
|
import os
|
||||||
|
modpath = \
|
||||||
|
os.path.normpath(
|
||||||
|
os.path.abspath(
|
||||||
|
os.path.join(
|
||||||
|
os.path.dirname(__file__),
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"packer")))
|
||||||
|
|
||||||
|
import sys
|
||||||
|
if modpath not in sys.path:
|
||||||
|
sys.path.append(modpath)
|
||||||
|
del modpath
|
||||||
|
|
||||||
|
import packer
|
||||||
|
|
||||||
|
print("AAA", filepath)
|
||||||
|
print("NNN", filepath_zip)
|
||||||
|
|
||||||
|
try:
|
||||||
|
packer.pack(filepath.encode('utf-8'), filepath_zip[-1].encode('utf-8'), mode='ZIP')
|
||||||
|
return filepath_zip[-1]
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
api.add_resource(FilesListAPI, '/file_list', endpoint='file_list')
|
api.add_resource(FilesListAPI, '/file_list', endpoint='file_list')
|
||||||
api.add_resource(FileAPI, '/file', endpoint='file')
|
api.add_resource(FileAPI, '/file', endpoint='file')
|
||||||
|
api.add_resource(FileDepsAPI, '/file_deps', endpoint='file_deps')
|
||||||
|
Reference in New Issue
Block a user