def _get_patch_info(self, name): # Taking the list of needed patches and extracting the # patch data from it. If any loop fails, will return False # and start full binary update. log.debug(u'Getting patch meta-data') required_patches = self._get_required_patches(name) for p in required_patches: info = {} v_num = version_tuple_to_string(p) plat_key = '{}*{}*{}*{}'.format(u'updates', name, v_num, self.plat) plat_info = self.star_access_update_data.get(plat_key) try: info[u'patch_name'] = plat_info[u'patch_name'] info[u'patch_urls'] = self.update_urls info[u'patch_hash'] = plat_info[u'patch_hash'] self.patch_data.append(info) except KeyError: log.error(u'Missing required patch meta-data') return False return True
def _check_make_patch(self, name, version_str, platform): # Check to see if previous version is available to # make patch updates # Also calculates patch number log.debug('Checking if patch creation is possible') version = version_string_to_tuple(version_str) if bsdiff4 is None: return None src_file_path = None highest_version_str = None data_dir = os.path.join(self.files_dir, name) if os.path.exists(data_dir): with ChDir(data_dir): # getting a list of all version folders # for current app version_dirs = os.listdir(os.getcwd()) version_dirs = remove_dot_files(version_dirs) # Changing version strings into tuples fixed_version_dirs = [] for v in version_dirs: fixed_version_dirs.append(version_string_to_tuple(v)) # Can't make a patch if no source file to work with if len(fixed_version_dirs) < 1: return None # highest_version = sorted(fixed_version_dirs)[-1] # highest_version_str = version_tuple_to_string(highest_version) # # ToDo: Not sure if this is need. # # Will research later. # if highest_version > version: # return None found = False versions_hi_to_low = sorted(fixed_version_dirs, reverse=True) for v in versions_hi_to_low: if found is True: break files = os.listdir(os.path.join(data_dir, version_tuple_to_string(v))) for f in files: if platform in f: found = True highest_version_str = version_tuple_to_string(v) break if highest_version_str is None: return None # Chainging into directory to get absolute path of # source file for patch creation later target_dir = os.path.join(data_dir, highest_version_str) with ChDir(target_dir): files = remove_dot_files(os.listdir(os.getcwd())) log.debug('Files in {}:\n{}'.format(target_dir, files)) # If somehow the source file got deleted # just return if len(files) == 0: return None # Getting the correct source matches # destination platform for f in files: if highest_version_str in f and platform in f: log.debug('Found src file to create patch') log.debug('Src file: {}'.format(f)) src_file_path = os.path.abspath(f) break # if our list gets exhausted before finding # source file then just return None if src_file_path is None: return None return src_file_path, len(fixed_version_dirs)
def test_tuple_to_stirng(): assert '1.2.3' == version_tuple_to_string((1, 2, 3))
def _check_make_patch(self, name, version_str, platform): # Check to see if previous version is available to # make patch updates # Also calculates patch number log.debug('Checking if patch creation is possible') version = version_string_to_tuple(version_str) if bsdiff4 is None: return None src_file_path = None highest_version_str = None data_dir = os.path.join(self.files_dir, name) if os.path.exists(data_dir): with ChDir(data_dir): # getting a list of all version folders # for current app version_dirs = os.listdir(os.getcwd()) version_dirs = remove_dot_files(version_dirs) # Changing version strings into tuples fixed_version_dirs = [] for v in version_dirs: fixed_version_dirs.append(version_string_to_tuple(v)) # Can't make a patch if no source file to work with if len(fixed_version_dirs) < 1: return None # highest_version = sorted(fixed_version_dirs)[-1] # highest_version_str = version_tuple_to_string(highest_version) # # ToDo: Not sure if this is need. # # Will research later. # if highest_version > version: # return None found = False versions_hi_to_low = sorted(fixed_version_dirs, reverse=True) for v in versions_hi_to_low: if found is True: break files = os.listdir( os.path.join(data_dir, version_tuple_to_string(v))) for f in files: if platform in f: found = True highest_version_str = version_tuple_to_string(v) break if highest_version_str is None: return None # Chainging into directory to get absolute path of # source file for patch creation later target_dir = os.path.join(data_dir, highest_version_str) with ChDir(target_dir): files = remove_dot_files(os.listdir(os.getcwd())) log.debug('Files in {}:\n{}'.format(target_dir, files)) # If somehow the source file got deleted # just return if len(files) == 0: return None # Getting the correct source matches # destination platform for f in files: if highest_version_str in f and platform in f: log.debug('Found src file to create patch') log.debug('Src file: {}'.format(f)) src_file_path = os.path.abspath(f) break # if our list gets exhausted before finding # source file then just return None if src_file_path is None: return None return src_file_path, len(fixed_version_dirs)