aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-06 22:24:40 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-06 22:24:40 +0900
commitacf58f7b50aa39e613891ca4ff216c47adb8b738 (patch)
treec42adb0f2e7a0a315962330d6a5327e909402cf8
parentMerge branch 'master' of https://github.com/aliceinwire/elivepatch (diff)
downloadelivepatch-acf58f7b50aa39e613891ca4ff216c47adb8b738.tar.gz
elivepatch-acf58f7b50aa39e613891ca4ff216c47adb8b738.tar.bz2
elivepatch-acf58f7b50aa39e613891ca4ff216c47adb8b738.zip
Unified send file function
-rw-r--r--elivepatch_client/client/checkers.py43
-rw-r--r--elivepatch_client/client/cli.py3
-rw-r--r--elivepatch_client/client/restful.py8
-rw-r--r--elivepatch_server/elivepatch12
-rw-r--r--elivepatch_server/resources/dispatcher.py76
5 files changed, 32 insertions, 110 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py
index 1a7db40..931d4ab 100644
--- a/elivepatch_client/client/checkers.py
+++ b/elivepatch_client/client/checkers.py
@@ -38,7 +38,7 @@ class Kernel(object):
def set_patch(self, patch_path):
self.patch = patch_path
- def send_config(self):
+ def send_files(self):
# debug print
print('conifg path: '+ str(self.config) + 'server url: ' + str(self. url))
print (os.path.basename(self.config))
@@ -56,6 +56,8 @@ class Kernel(object):
self.rest_manager.set_kernel_version(self.kernel_version)
print(self.rest_manager.get_kernel_version())
+ path, patch_file = (os.path.split(self.patch))
+
# check userID
data_store = shelve.open('userid')
@@ -68,7 +70,7 @@ class Kernel(object):
print('no UserID')
# send only uncompressed config
- replay = self.rest_manager.send_file(self.config, file, '/elivepatch/api/v1.0/config')
+ replay = self.rest_manager.send_file(self.config, self.patch, file, patch_file, '/elivepatch/api/v1.0/get_files')
# get userid returned from the server
userid = replay['get_config']['UserID']
@@ -84,43 +86,6 @@ class Kernel(object):
except:
pass
- def send_patch(self):
- print("self.patch: "+ self.patch + ' url: '+ self.url)
- path, file = (os.path.split(self.patch))
- print('file :'+ file)
-
- data_store = shelve.open('userid')
-
- # get old userid if present
- try:
- old_userid = data_store['UserID']
- except:
- old_userid = None
- print('no UserID')
-
- # send only uncompressed config
- replay = self.rest_manager.send_file(self.patch, file, '/elivepatch/api/v1.0/patch')
-
- print(replay)
- # get userid returned from the server
- userid = replay['get_patch']['UserID']
-
- # get old userid if present
- try:
- old_userid = data_store['UserID']
- except:
- print('no UserID')
-
- if userid:
- try:
- if userid != old_userid:
- self.rest_manager.set_user_id(userid)
- print(userid)
- data_store['UserID'] = userid
- data_store.close()
- except:
- pass
-
def build_livepatch(self):
self.rest_manager.build_livepatch()
diff --git a/elivepatch_client/client/cli.py b/elivepatch_client/client/cli.py
index 556b122..6823344 100644
--- a/elivepatch_client/client/cli.py
+++ b/elivepatch_client/client/cli.py
@@ -34,8 +34,7 @@ class Main(object):
current_kernel = Kernel(config.url)
current_kernel.set_config(config.config)
current_kernel.set_patch(config.patch)
- current_kernel.send_config()
- current_kernel.send_patch()
+ current_kernel.send_files()
current_kernel.build_livepatch()
current_kernel.get_livepatch()
elif config.version:
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py
index 8dff862..5f7a291 100644
--- a/elivepatch_client/client/restful.py
+++ b/elivepatch_client/client/restful.py
@@ -33,7 +33,7 @@ class ManaGer(object):
print(r.text)
print(r.json())
- def send_file(self, send_file, name_file, api):
+ def send_file(self, config_send_file, patch_send_file, config_file_name, patch_file_name, api):
url = self.server_url+ api
# we are sending the file and the UserID
# The server is dividing user by UserID
@@ -43,7 +43,9 @@ class ManaGer(object):
'KernelVersion' : self.kernel_version,
'UserID': self.user_id
}
- files = {'file': (name_file, open(send_file, 'rb'), 'multipart/form-data', {'Expires': '0'})}
+ files = {'patch': (patch_file_name, open(patch_send_file, 'rb'), 'multipart/form-data', {'Expires': '0'}),
+ 'config': (config_file_name, open(config_send_file, 'rb'), 'multipart/form-data', {'Expires': '0'})}
+ print(str(files))
r = requests.post(url, files=files, headers=headers)
print('send file: ' + str(r.json()))
r_dict = r.json()
@@ -62,7 +64,7 @@ class ManaGer(object):
def get_livepatch(self):
from io import BytesIO
- url = self.server_url+'/elivepatch/api/v1.0/get_livepatch'
+ url = self.server_url+'/elivepatch/api/v1.0/send_livepatch'
payload = {
'KernelVersion': self.kernel_version,
'UserID' : self.user_id
diff --git a/elivepatch_server/elivepatch b/elivepatch_server/elivepatch
index bd77565..e1913c2 100644
--- a/elivepatch_server/elivepatch
+++ b/elivepatch_server/elivepatch
@@ -32,17 +32,13 @@ def create_app():
endpoint='build_livepatch')
# where to retrieve the live patch when ready
- api.add_resource(dispatcher.GetLivePatch,
- '/elivepatch/api/v1.0/get_livepatch',
- endpoint='get_livepatch')
+ api.add_resource(dispatcher.SendLivePatch,
+ '/elivepatch/api/v1.0/send_livepatch',
+ endpoint='send_livepatch')
# where to receive the config file
- api.add_resource(dispatcher.GetConfig, '/elivepatch/api/v1.0/config',
+ api.add_resource(dispatcher.GetFiles, '/elivepatch/api/v1.0/get_files',
endpoint='config')
-
- # where to receive the patch file
- api.add_resource(dispatcher.GetPatch, '/elivepatch/api/v1.0/patch',
- endpoint='patch')
return app
if __name__ == '__main__':
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index 2261092..ed724f3 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -89,7 +89,7 @@ class BuildLivePatch(Resource):
return {'build_livepatch': marshal(pack, pack_fields)}, 201
-class GetLivePatch(Resource):
+class SendLivePatch(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser()
@@ -99,7 +99,7 @@ class GetLivePatch(Resource):
self.reqparse.add_argument('UserID', type=str, required=False,
help='No task title provided',
location='json')
- super(GetLivePatch, self).__init__()
+ super(SendLivePatch, self).__init__()
pass
def get(self):
@@ -124,7 +124,7 @@ class GetLivePatch(Resource):
patches you are looking for'}), 403)
-class GetConfig(Resource):
+class GetFiles(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser()
@@ -134,7 +134,7 @@ class GetConfig(Resource):
self.reqparse.add_argument('UserID', type=str, required=False,
help='No task title provided',
location='headers')
- super(GetConfig, self).__init__()
+ super(GetFiles, self).__init__()
pass
def get(self):
@@ -143,81 +143,41 @@ class GetConfig(Resource):
def post(self):
args = self.reqparse.parse_args()
- #print("json get config: " + str(args))
if not args['UserID']:
args['UserID'] = str(id_generate())
else:
print('UserID: ' + str(args['UserID']))
parse = reqparse.RequestParser()
- parse.add_argument('file', type=werkzeug.datastructures.FileStorage,
+ parse.add_argument('patch', type=werkzeug.datastructures.FileStorage,
+ location='files')
+ parse.add_argument('config', type=werkzeug.datastructures.FileStorage,
location='files')
file_args = parse.parse_args()
- #print("file get config: " + str(file_args))
- configFile = file_args['file']
- configFile_name = file_args['file'].filename
+ print("file get config: " + str(file_args))
+ configFile = file_args['config']
+ configFile_name = file_args['config'].filename
- # debug filename
- #print('configfile_name: '+ str(configFile_name))
- #print('configfile: '+ str(configFile))
+ patchFile = file_args['patch']
+ patchFile_name = file_args['patch'].filename
configFile_name = os.path.join('/tmp','elivepatch-' + args['UserID'], configFile_name)
if not os.path.exists('/tmp/elivepatch-' + args['UserID']):
os.makedirs('/tmp/elivepatch-' + args['UserID'])
configFile.save(configFile_name)
lpatch.set_config(configFile_name)
- pack = {
- 'id': packs['id'] + 1,
- 'KernelVersion': None,
- 'UserID' : args['UserID']
- }
- return {'get_config': marshal(pack, pack_fields)}, 201
-
-
-class GetPatch(Resource):
-
- def __init__(self):
- self.reqparse = reqparse.RequestParser()
- self.reqparse.add_argument('KernelVersion', type=str, required=False,
- help='No task title provided',
- location='json')
- self.reqparse.add_argument('UserID', type=str, required=False,
- help='No task title provided',
- location='headers')
- super(GetPatch, self).__init__()
- pass
- def get(self):
- return make_response(jsonify({'message': 'These are not the \
- patches you are looking for'}), 403)
-
- def post(self):
- args = self.reqparse.parse_args()
- print("get patch: " + str(args))
- if not args['UserID']:
- args['UserID'] = str(id_generate())
- else:
- print('UserID: ' + str(args['UserID']))
-
- # parse file request information's
- parse = reqparse.RequestParser()
- parse.add_argument('file', type=werkzeug.datastructures.FileStorage,
- location='files')
- file_args = parse.parse_args()
- patchFile = file_args['file']
- patchFile_name = file_args['file'].filename
- #print(audioFile_name)
- #print(audioFile)
- patchFile_name = os.path.join('/tmp', 'elivepatch-' + args['UserID'], patchFile_name)
- if not os.path.exists('/tmp/elivepatch-'+args['UserID']):
- os.makedirs('/tmp/elivepatch-'+args['UserID'])
+ patchFile_name = os.path.join('/tmp','elivepatch-' + args['UserID'], patchFile_name)
+ if not os.path.exists('/tmp/elivepatch-' + args['UserID']):
+ os.makedirs('/tmp/elivepatch-' + args['UserID'])
patchFile.save(patchFile_name)
lpatch.set_patch(patchFile_name)
+
pack = {
- 'id': packs['id'] + 1,
+ 'id': packs['id'] + 1,
'KernelVersion': None,
'UserID' : args['UserID']
}
- return {'get_patch': marshal(pack, pack_fields)}, 201
+ return {'get_config': marshal(pack, pack_fields)}, 201
class GetID(Resource):