Initial client

This commit is contained in:
2014-10-23 14:45:21 +02:00
parent bf7d40e098
commit 0e1a642aef
5 changed files with 94 additions and 9 deletions

6
.gitignore vendored
View File

@@ -2,3 +2,9 @@
webservice/venv/
docs/venv/
docs/build/
client/venv/
client/client/config.json
webservice/bam/config.py

24
client/client/__init__.py Normal file
View File

@@ -0,0 +1,24 @@
import requests
with open('config.json', 'r') as config:
import json
config = json.load(config)
def request_url(path):
return ('%s%s' % (config['BAM_SERVER'], path))
#payload = {'path': ''}
#r = requests.get(request_url('/files'), params=payload, auth=('bam', 'bam'))
#print (r.json())
payload = {'filepath': 'video.mp4'}
r = requests.get(request_url('/file'), params=payload, auth=('bam', 'bam'), stream=True)
local_filename = payload['filepath'].split('/')[-1]
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
print(local_filename)

View File

@@ -0,0 +1,3 @@
{
"BAM_SERVER" : "http://localhost:5000"
}

View File

@@ -16,6 +16,8 @@
#
# ***** END GPL LICENCE BLOCK *****
import os
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask.views import MethodView
from flask.ext.restful import Api, Resource, reqparse, fields, marshal
@@ -24,7 +26,8 @@ from flask.ext.httpauth import HTTPBasicAuth
app = Flask(__name__)
api = Api(app)
auth = HTTPBasicAuth()
import config
app.config.from_object(config.Development)
@api.representation('application/octet-stream')
def output_file(data, code, headers=None):
@@ -53,10 +56,44 @@ class FilesListAPI(Resource):
decorators = [auth.login_required]
def __init__(self):
parser = reqparse.RequestParser()
#parser.add_argument('rate', type=int, help='Rate cannot be converted')
parser.add_argument('path', type=str)
args = parser.parse_args()
super(FilesListAPI, self).__init__()
def get(self):
return {'message': 'Display files list'}
path = request.args['path']
if not path:
path = ''
absolute_path_root = app.config['STORAGE_PATH']
parent_path = ''
if path != '':
absolute_path_root = os.path.join(absolute_path_root, path)
parent_path = os.pardir
items_list = []
for f in os.listdir(absolute_path_root):
relative_path = os.path.join(path, f)
absolute_path = os.path.join(absolute_path_root, f)
# we are going to pick up only blend files and folders
if absolute_path.endswith('blend'):
# items[f] = relative_path
items_list.append((f, relative_path, 'blendfile'))
elif os.path.isdir(absolute_path):
items_list.append((f, relative_path, 'folder'))
project_files = dict(
parent_path=parent_path,
items_list=items_list)
return jsonify(project_files)
#return {'message': 'Display files list'}
class FileAPI(Resource):
@@ -65,18 +102,28 @@ class FileAPI(Resource):
decorators = [auth.login_required]
def __init__(self):
# self.reqparse = reqparse.RequestParser()
# self.reqparse.add_argument('path',
# type = str,
# location = 'json')
parser = reqparse.RequestParser()
#parser.add_argument('rate', type=int, help='Rate cannot be converted')
parser.add_argument('filepath', type=str)
args = parser.parse_args()
# parser = reqparse.RequestParser()
# parser.add_argument('filepath', type=str, required=True,
# help="Filepath cannot be blank!")
# args = parser.parse_args()
super(FileAPI, self).__init__()
def get(self, path):
with open(path, 'r') as f:
def get(self):
filepath = os.path.join(app.config['STORAGE_PATH'], request.args['filepath'])
print (filepath)
with open(filepath, 'r') as f:
body = f.read()
response = flask.make_response(body)
response.headers['content-type'] = 'application/octet-stream'
return response
return output_file(body, 200)
# return {'path': path}
api.add_resource(FilesListAPI, '/files', endpoint='files')
api.add_resource(FileAPI, '/file/<path:path>', endpoint='file')
api.add_resource(FileAPI, '/file', endpoint='file')

View File

@@ -0,0 +1,5 @@
class Config(object):
DEBUG=True
class Development(Config):
STORAGE_PATH='/Volumes/PROJECTS/storage'