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 /elivepatch_client
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
Diffstat (limited to 'elivepatch_client')
-rw-r--r--elivepatch_client/client/checkers.py43
-rw-r--r--elivepatch_client/client/cli.py3
-rw-r--r--elivepatch_client/client/restful.py8
3 files changed, 10 insertions, 44 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