Starting to use project_config values

This commit is contained in:
2014-11-05 16:05:45 +01:00
parent 8c127b9045
commit 8dafe01a0e
2 changed files with 24 additions and 10 deletions

View File

@@ -50,6 +50,7 @@ class bam_config:
def find_basedir(cwd=None): def find_basedir(cwd=None):
""" """
Return the config path (or None when not found) Return the config path (or None when not found)
Actually should raise an error?
""" """
import os import os
@@ -73,7 +74,8 @@ class bam_config:
return None return None
@staticmethod @staticmethod
def load(id_, cwd=None): def load(id_="config", cwd=None):
import os
basedir = bam_config.find_basedir(cwd=cwd) basedir = bam_config.find_basedir(cwd=cwd)
filepath = os.path.join(basedir, id_) filepath = os.path.join(basedir, id_)
@@ -112,8 +114,10 @@ class bam_utils:
@staticmethod @staticmethod
def session_request_url(req_path): def session_request_url(req_path):
# TODO, get from config # TODO, get from config
project_config = bam_config.load()
BAM_SERVER = bam_utils.session_find_url() BAM_SERVER = bam_utils.session_find_url()
result = "%s/%s" % (BAM_SERVER, req_path) result = "%s/%s" % (project_config['url'], req_path)
return result return result
@staticmethod @staticmethod
@@ -143,6 +147,7 @@ class bam_utils:
}, },
cwd=bam_folder) cwd=bam_folder)
print("Project %s initialized" % project_directory_name) print("Project %s initialized" % project_directory_name)
@staticmethod @staticmethod
@@ -151,6 +156,9 @@ class bam_utils:
import os import os
import requests import requests
# Load project configuration
project_config = bam_config.load()
# TODO(cam) multiple paths # TODO(cam) multiple paths
path = paths[0] path = paths[0]
del paths del paths
@@ -166,7 +174,7 @@ class bam_utils:
r = requests.get( r = requests.get(
bam_utils.session_request_url("file"), bam_utils.session_request_url("file"),
params=payload, params=payload,
auth=("bam", "bam"), auth=(project_config['user'], project_config['password']),
stream=True, stream=True,
) )
@@ -228,6 +236,9 @@ class bam_utils:
import requests import requests
from bam_utils.system import sha1_from_file from bam_utils.system import sha1_from_file
# Load project configuration
project_config = bam_config.load()
# TODO(cam) ignore files # TODO(cam) ignore files
# TODO(cam) multiple paths # TODO(cam) multiple paths
@@ -294,7 +305,7 @@ class bam_utils:
r = requests.put( r = requests.put(
bam_utils.session_request_url("file"), bam_utils.session_request_url("file"),
params=payload, params=payload,
auth=('bam', 'bam'), auth=(project_config['user'], project_config['password']),
files=files) files=files)
print("Return is:", r.text) print("Return is:", r.text)
@@ -306,6 +317,9 @@ class bam_utils:
import sys import sys
import requests import requests
# Load project configuration
project_config = bam_config.load()
# TODO(cam) multiple paths # TODO(cam) multiple paths
path = paths[0] path = paths[0]
del paths del paths
@@ -316,7 +330,7 @@ class bam_utils:
r = requests.get( r = requests.get(
bam_utils.session_request_url("file_list"), bam_utils.session_request_url("file_list"),
params=payload, params=payload,
auth=("bam", "bam"), auth=(project_config['user'], project_config['password']),
stream=True, stream=True,
) )

View File

@@ -71,7 +71,7 @@ class FilesListAPI(Resource):
args = parser.parse_args() args = parser.parse_args()
super(FilesListAPI, self).__init__() super(FilesListAPI, self).__init__()
def get(self): def get(self, project_name):
path = request.args['path'] path = request.args['path']
if not path: if not path:
@@ -130,7 +130,7 @@ class FileAPI(Resource):
super(FileAPI, self).__init__() super(FileAPI, self).__init__()
def get(self): def get(self, project_name):
filepath = request.args['filepath'] filepath = request.args['filepath']
command = request.args['command'] command = request.args['command']
@@ -191,7 +191,7 @@ class FileAPI(Resource):
else: else:
return jsonify(message="Command unknown") return jsonify(message="Command unknown")
def put(self): def put(self, project_name):
command = request.args['command'] command = request.args['command']
arguments = '' arguments = ''
if 'arguments' in request.args: if 'arguments' in request.args:
@@ -271,6 +271,6 @@ class FileAPI(Resource):
filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS'] filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
api.add_resource(FilesListAPI, '/file_list', endpoint='file_list') api.add_resource(FilesListAPI, '/<project_name>/file_list', endpoint='file_list')
api.add_resource(FileAPI, '/file', endpoint='file') api.add_resource(FileAPI, '/<project_name>/file', endpoint='file')