From e984bb347eeea0e211c294c83493521105b1f23e Mon Sep 17 00:00:00 2001 From: Alice Ferrazzi Date: Sat, 12 Aug 2017 04:32:10 +0900 Subject: we are saving livepatch and patch files for incremental patches and history, but we need only to send patch. so fixing that and also fix problem on closing open temporary file for sending it. --- elivepatch_client/client/patch.py | 20 ++++++++++++++++---- elivepatch_client/client/restful.py | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/elivepatch_client/client/patch.py b/elivepatch_client/client/patch.py index fa8af75..b059540 100644 --- a/elivepatch_client/client/patch.py +++ b/elivepatch_client/client/patch.py @@ -16,7 +16,13 @@ class ManaGer(object): patch_filename = [] # search previous livepatch patch folder for (dirpath, dirnames, filenames) in os.walk(self.tmp_patch_folder): - patch_filename.extend(filenames) + if filenames and not dirnames: + for filename in filenames: + if filename.endswith('.patch'): + print('dirpath: '+str(dirpath),'filename: '+str(filename)) + incremental_patch_fullpath = os.path.join(dirpath, filename) + print(incremental_patch_fullpath) + patch_filename.append(incremental_patch_fullpath) # search eapply_user patches # local basedir=${PORTAGE_CONFIGROOT%/}/etc/portage/patches try: @@ -28,9 +34,15 @@ class ManaGer(object): kernel_patch_basedir_P = os.path.join(portage_configroot, 'sys-kernel', kernel_sources + '-' + kernel_version) basedir = [kernel_patch_basedir_PN, kernel_patch_basedir_P] - for dir in basedir: - for (dirpath, dirnames, filenames) in os.walk(dir): - patch_filename.extend(filenames) + for path in basedir: + for (dirpath, dirnames, filenames) in os.walk(path): + if filenames and not dirnames: + for filename in filenames: + if filename.endswith('.patch'): + print('dirpath: '+str(dirpath),'filename: '+str(filename)) + incremental_patch_fullpath = os.path.join(dirpath, filename) + print(incremental_patch_fullpath) + patch_filename.append(incremental_patch_fullpath) print('List of current patches:') return patch_filename diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py index 957aba9..e11d8ba 100644 --- a/elivepatch_client/client/restful.py +++ b/elivepatch_client/client/restful.py @@ -53,24 +53,26 @@ class ManaGer(object): # Static patch and config filename files=[] counter = 0 + print('incremental_patches: '+str(incremental_patches)) for incremental_patch_fullpath in incremental_patches: - read_incremental_patch = open(incremental_patch_fullpath, 'rb') - files.append(('patch', (str(counter) + '.patch', read_incremental_patch, 'multipart/form-data', {'Expires': '0'}))) - read_incremental_patch.close() - counter += 1 - files.append(('main_patch', ('main_patch', open(new_patch_fullpath, 'rb'), 'multipart/form-data', {'Expires': '0'}))) + if incremental_patch_fullpath.endswith('.patch'): + # TODO: we need to close what we open + read_incremental_patch = open(incremental_patch_fullpath, 'rb') + files.append(('patch', (str(counter) + '.patch', read_incremental_patch, 'multipart/form-data', {'Expires': '0'}))) + counter += 1 + files.append(('main_patch', ('main.patch', open(new_patch_fullpath, 'rb'), 'multipart/form-data', {'Expires': '0'}))) files.append(('config', ('config', open(temporary_config.name, 'rb'), 'multipart/form-data', {'Expires': '0'}))) print(str(files)) - temporary_config.close() try: response = requests.post(url, files=files, headers=headers) print('send file: ' + str(response.json())) response_dict = response.json() except requests.exceptions.ConnectionError as e: print('connection error: %s' % e) - sys.exit(1) - #except: - #self.catching_exceptions_exit(self.send_file) + temporary_config.close() + except: + self._catching_exceptions_exit(self.send_files) + temporary_config.close() return response_dict def build_livepatch(self): -- cgit v1.2.3-65-gdbad