Example #1
0
    def _remove_old_updates(self):
        # Removes old updates from cache. Patch updates
        # start from currently installed version.

        # ToDo: Better filename comparison
        #       Please chime in if this is sufficient
        #       Will remove todo if so...
        temp = os.listdir(self.update_folder)
        try:
            filename = self._get_filename(self.name, self.version)
        except KeyError:
            filename = u'0.0.0'

        try:
            current_version_str = get_version_number(filename)
        except UtilsError:
            log.debug(u'Cannot parse version info')
            current_version_str = u'0.0.0'

        current_version = version_string_to_tuple(current_version_str)
        with ChDir(self.update_folder):
            for t in temp:
                try:
                    t_versoin_str = get_version_number(t)
                except UtilsError:
                    log.debug(u'Cannot parse version info')
                    t_versoin_str = u'0.0.0'
                t_version = version_string_to_tuple(t_versoin_str)

                if self.name in t and t_version < current_version:
                    log.debug(u'Removing old update: {}'.format(t))
                    os.remove(t)
Example #2
0
    def _remove_old_updates(self):
        # Removes old updates from cache. Patch updates
        # start from currently installed version.

        # ToDo: Better filename comparison
        #       Please chime in if this is sufficient
        #       Will remove todo if so...
        temp = os.listdir(self.update_folder)
        try:
            filename = self._get_filename(self.name, self.version)
        except KeyError:
            filename = u'0.0.0'

        try:
            current_version_str = get_version_number(filename)
        except UtilsError:
            log.debug(u'Cannot parse version info')
            current_version_str = u'0.0.0'

        current_version = version_string_to_tuple(current_version_str)
        with ChDir(self.update_folder):
            for t in temp:
                try:
                    t_versoin_str = get_version_number(t)
                except UtilsError:
                    log.debug(u'Cannot parse version info')
                    t_versoin_str = u'0.0.0'
                t_version = version_string_to_tuple(t_versoin_str)

                if self.name in t and t_version < current_version:
                    log.debug(u'Removing old update: {}'.format(t))
                    os.remove(t)
Example #3
0
    def update_check(self, name, version):
        """
        Will try to patch binary if all check pass.  IE hash verified
        signature verified.  If any check doesn't pass then falls back to
        full update

        Args:
            name (str): Name of file to update

            version (str): Current version number of file to update

        Returns:
            (bool) Meanings::

                True - Update Successful

                False - Update Failed
        """
        self.name = name
        self.version = version
        if self.ready is False:
            log.debug('No update manifest found')
            return False
        if FROZEN is True and self.name == self.app_name:
            self._archive_installed_binary()

        # Checking if version file is verified before
        # processing data contained in the version file.
        # This was done by self._get_update_manifest()
        if not self.verified:
            log.debug('Failed version file verification')
            return False
        log.debug(u'Checking for {} updates...'.format(name))

        # If None is returned self._get_highest_version could
        # not find the supplied name in the version file
        latest = self._get_highest_version(name)
        if latest is None:
            return False
        if version_string_to_tuple(latest) <= \
                version_string_to_tuple(version):
            log.debug(u'{} already updated to the latest version'.format(name))
            log.debug(u'Already up-to-date')
            return False
        # Hey, finally made it to the bottom!
        # Looks like its time to do some updating
        log.debug(u'Update available')
        self.ready_to_update = True
        return True
Example #4
0
    def update_check(self, name, version):
        """
        Will try to patch binary if all check pass.  IE hash verified
        signature verified.  If any check doesn't pass then falls back to
        full update

        Args:
            name (str): Name of file to update

            version (str): Current version number of file to update

        Returns:
            (bool) Meanings::

                True - Update Successful

                False - Update Failed
        """
        self.name = name
        self.version = version
        if self.ready is False:
            log.debug('No update manifest found')
            return False
        if FROZEN is True and self.name == self.app_name:
            self._archive_installed_binary()

        # Checking if version file is verified before
        # processing data contained in the version file.
        # This was done by self._get_update_manifest()
        if not self.verified:
            log.debug('Failed version file verification')
            return False
        log.debug(u'Checking for {} updates...'.format(name))

        # If None is returned self._get_highest_version could
        # not find the supplied name in the version file
        latest = self._get_highest_version(name)
        if latest is None:
            return False
        if version_string_to_tuple(latest) <= \
                version_string_to_tuple(version):
            log.debug(u'{} already updated to the latest version'.format(name))
            log.debug(u'Already up-to-date')
            return False
        # Hey, finally made it to the bottom!
        # Looks like its time to do some updating
        log.debug(u'Update available')
        self.ready_to_update = True
        return True
Example #5
0
    def _get_required_patches(self, name):
        needed_patches = []
        versions = []
        try:
            u_versions = map(version_string_to_tuple,
                             self.json_data[u'updates'][name].keys())
            versions.extend(u_versions)
        except KeyError:
            log.debug(u'No updates found in updates dict')

        # Sorted here because i may forget to leave it when i delete
        # the list/set down below.
        # How i envisioned it: sorted(list(set(needed_patches)))
        versions = sorted(versions)
        log.debug(u'getting required patches')
        for i in versions:
            if i > version_string_to_tuple(self.current_version):
                needed_patches.append(i)
        # Used to guarantee patches are only added once
        return list(set(needed_patches))
Example #6
0
    def _get_required_patches(self, name):
        needed_patches = []
        versions = []
        try:
            u_versions = map(version_string_to_tuple,
                             self.json_data[u'updates'][name].keys())
            versions.extend(u_versions)
        except KeyError:
            log.debug(u'No updates found in updates dict')

        # Sorted here because i may forget to leave it when i delete
        # the list/set down below.
        # How i envisioned it: sorted(list(set(needed_patches)))
        versions = sorted(versions)
        log.debug(u'getting required patches')
        for i in versions:
            if i > version_string_to_tuple(self.current_version):
                needed_patches.append(i)
        # Used to guarantee patches are only added once
        return list(set(needed_patches))
Example #7
0
def check_version(options):
    try:
        version = options.version_num
    except:
        raise ArchiverError('You must pass -v option with version # of update',
                            expected=True)

    if version is None:
        raise ArchiverError('You must pass version number')

    try:
        version = get_version_number(version)
    except:
        raise ArchiverError('Can not parse version number', expected=True)

    try:
        version_tuple = version_string_to_tuple(version)
    except:
        raise ArchiverError('Version not in correct format. eg. "0.0.1"',
                            expected=True)

    if len(version_tuple) != 3:
        raise ArchiverError('Version must be MAJOR.MINOR.PATCH', expected=True)
    return version
    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)
Example #9
0
def test_string_to_tuple():
    assert (1, 2, 3) == version_string_to_tuple('1.2.3')
Example #10
0
    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)