コード例 #1
0
ファイル: builder.py プロジェクト: dimitriepirghie/PyUpdater
    def _build(self, spec_file_path):
        try:
            Version(self.args.app_version)
        except VersionError:
            log.error("Version format incorrect: %s", self.args.app_version)
            log.error("""Valid version numbers: 0.10.0, 1.1b, 1.2.1a3

        Visit url for more info:

            http://semver.org/
                      """)
            sys.exit(1)
        build_args = []
        if self.args.clean is True:
            build_args.append("--clean")

        if self.args.pyi_log_info is False:
            build_args.append("--log-level=ERROR")

        build_args.append("--distpath={}".format(self.new_dir))
        build_args.append("--workpath={}".format(self.work_dir))
        build_args.append("-y")
        build_args.append(spec_file_path)

        log.debug("Build cmd: %s", " ".join([b for b in build_args]))
        build_args = [str(x) for x in build_args]
        pyi_build(build_args)
コード例 #2
0
    def extract_info(self, package):
        """Gets version number, platform & hash for package.

        Args:

            package (str): filename
        """
        package_basename = os.path.basename(package)

        if not os.path.exists(package):
            msg = "{} does not exist".format(package)
            log.debug(msg)
            self.info["reason"] = msg
            return
        if package_basename in self.ignored_files:
            msg = "Ignored file: {}".format(package_basename)
            log.debug(msg)
            self.info["reason"] = msg
            return
        if (
            os.path.splitext(package_basename)[1].lower()
            not in self.supported_extensions
        ):
            msg = "Not a supported archive format: {}".format(package_basename)
            self.info["reason"] = msg
            log.debug(msg)
            return

        log.debug("Extracting update archive info for: %s", package_basename)
        try:
            v = Version(package_basename)
            self.channel = v.channel
            self.version = str(v)
        except VersionError:
            msg = "Package version not formatted correctly: {}"
            self.info["reason"] = msg.format(package_basename)
            log.error(msg)
            return
        log.debug("Got version info")

        try:
            self.platform = parse_platform(package_basename)
        except PackageHandlerError:
            msg = "Package platform not formatted correctly"
            self.info["reason"] = msg
            log.error(msg)
            return
        log.debug("Got platform info")

        self.name = self._parse_package_name(package_basename)
        assert self.name is not None
        log.debug("Got name of update: %s", self.name)
        self.info["status"] = True
        log.debug("Info extraction complete")
コード例 #3
0
ファイル: updates.py プロジェクト: vvarp/PyUpdater
def _get_highest_version(name, plat, channel, easy_data):
    """Parses version file and returns the highest version number.

        Args:

           name (str): name of file to search for updates

           plat (str): the platform we are requesting for

           channel (str): the release channel

           easy_data (dict): data file to search

        Returns:

           (str) Highest version number
    """
    # We grab all keys and return the version corresponding to the
    # channel passed to this function
    version_key_alpha = '{}*{}*{}*{}'.format('latest', name, 'alpha', plat)
    version_key_beta = '{}*{}*{}*{}'.format('latest', name, 'beta', plat)
    version_key_stable = '{}*{}*{}*{}'.format('latest', name, 'stable', plat)
    version = None

    alpha = easy_data.get(version_key_alpha)
    if alpha is None:
        alpha = '0.0'

    beta = easy_data.get(version_key_beta)
    if beta is None:
        beta = '0.0'

    stable = easy_data.get(version_key_stable)

    if channel == 'alpha':
        # Setting the latest alpha version
        version = alpha
        if Version(version) < Version(stable):
            version = stable
        if Version(version) < Version(beta):
            version = beta

    if channel == 'beta':
        # Setting the latest beta version
        version = beta
        if Version(version) < Version(stable):
            version = stable

    if stable is not None and channel == 'stable':
        # Setting the latest stable version
        version = stable

    if version is not None:
        log.debug('Highest version: %s', version)
    else:
        log.error('No updates for "%s" on %s exists', name, plat)

    return version
コード例 #4
0
ファイル: patcher.py プロジェクト: MikaelLilja/PyUpdater
    def __init__(self, **kwargs):
        self.name = kwargs.get("name")
        self.channel = kwargs.get("channel")
        self.json_data = kwargs.get("json_data")
        self.star_access_update_data = EasyAccessDict(self.json_data)
        self.current_version = Version(kwargs.get("current_version"))
        self.latest_version = kwargs.get("latest_version")
        self.update_folder = kwargs.get("update_folder")
        self.update_urls = kwargs.get("update_urls", [])
        self.verify = kwargs.get("verify", True)
        self.max_download_retries = kwargs.get("max_download_retries")
        self.headers = kwargs.get("headers")
        self.downloader = kwargs.get("downloader")
        self.http_timeout = kwargs.get("http_timeout")

        # Progress hooks to be called
        self.progress_hooks = kwargs.get("progress_hooks", [])

        # List of dicts with urls, filename & hash of each patch
        self.patch_data = []

        # List of binary blobs of patch data
        self.patch_binary_data = []

        # binary blob of original archive to patch
        self.og_binary = None

        # Used for testing.
        self.platform = kwargs.get("platform", _PLATFORM)

        self.current_filename = kwargs.get("current_filename")

        self.current_file_hash = kwargs.get("current_file_hash")

        file_info = self._get_info(self.name,
                                   self.current_version,
                                   option="file")
        if self.current_filename is None:
            self.current_filename = file_info["filename"]
        if self.current_file_hash is None:
            self.current_file_hash = file_info["file_hash"]
コード例 #5
0
ファイル: patcher.py プロジェクト: dragandbot/PyUpdater
    def __init__(self, **kwargs):
        self.name = kwargs.get('name')
        self.json_data = kwargs.get('json_data')
        self.star_access_update_data = EasyAccessDict(self.json_data)
        self.current_version = Version(kwargs.get('current_version'))
        self.latest_version = kwargs.get('latest_version')
        self.update_folder = kwargs.get('update_folder')
        self.update_urls = kwargs.get('update_urls', [])
        self.verify = kwargs.get('verify', True)
        self.max_download_retries = kwargs.get('max_download_retries')
        self.urllib3_headers = kwargs.get('urllib3_headers')

        # Progress hooks to be called
        self.progress_hooks = kwargs.get('progress_hooks', [])

        # List of dicts with urls, filename & hash of each patch
        self.patch_data = []

        # List of binary blobs of patch data
        self.patch_binary_data = []

        # binary blob of original archive to patch
        self.og_binary = None

        # ToDo: Update tests with linux archives.
        # Used for testing.
        self.platform = kwargs.get('platform', _PLATFORM)

        self.current_filename = kwargs.get('current_filename')

        self.current_file_hash = kwargs.get('current_file_hash')

        file_info = self._get_info(self.name,
                                   self.current_version,
                                   option='file')
        if self.current_filename is None:
            self.current_filename = file_info['filename']
        if self.current_file_hash is None:
            self.current_file_hash = file_info['file_hash']
コード例 #6
0
    def _build(self, args, spec_file_path):
        try:
            Version(args.app_version)
        except VersionError:
            log.error('Version format incorrect: %s', args.app_version)
            log.error("""Valid version numbers: 0.10.0, 1.1b, 1.2.1a3

        Visit url for more info:

            http://semver.org/
                      """)
            sys.exit(1)
        build_args = []
        if args.clean is True:
            build_args.append('--clean')
        build_args.append('--distpath={}'.format(self.new_dir))
        build_args.append('--workpath={}'.format(self.work_dir))
        build_args.append('-y')
        build_args.append(spec_file_path)

        log.debug('Build cmd: %s', ' '.join([b for b in build_args]))
        build_args = [str(x) for x in build_args]
        pyi_build(build_args)
コード例 #7
0
def _get_highest_version(name, plat, channel, easy_data, strict):
    # Parses version file and returns the highest version number.
    #
    #   Args:
    #
    #      name (str): name of file to search for updates
    #
    #      plat (str): the platform we are requesting for
    #
    #      channel (str): the release channel
    #
    #      easy_data (dict): data file to search
    #
    #      strict (bool): specify whether or not to take the channel
    #                     into consideration
    #
    #   Returns:
    #
    #      (str) Highest version number

    # We grab all keys and return the version corresponding to the
    # channel passed to this function
    version_key_alpha = '{}*{}*{}*{}'.format('latest', name, 'alpha', plat)
    version_key_beta = '{}*{}*{}*{}'.format('latest', name, 'beta', plat)
    version_key_stable = '{}*{}*{}*{}'.format('latest', name, 'stable', plat)
    version = None

    version_options = []

    alpha_available = False
    alpha_str = easy_data.get(version_key_alpha)
    if alpha_str is not None:
        log.debug('Alpha str: %s', alpha_str)
        alpha = Version(alpha_str)
        version_options.append(alpha)
        alpha_available = True

    beta_available = False
    beta_str = easy_data.get(version_key_beta)
    if beta_str is not None:
        log.debug('Beta str: %s', beta_str)
        beta = Version(beta_str)
        version_options.append(beta)
        beta_available = True

    stable_str = easy_data.get(version_key_stable)
    stable_available = False
    if stable_str is not None:
        log.debug('Stable str: %s', stable_str)
        stable = Version(stable_str)
        version_options.append(stable)
        stable_available = True

    if strict is False:
        return str(max(version_options))

    if alpha_available is True and channel == 'alpha':
        version = alpha

    if beta_available is True and channel == 'beta':
        version = beta

    if stable_available is True and channel == 'stable':
        version = stable

    if version is not None:
        log.debug('Highest version: %s', version)
        return str(version)
    else:
        log.info('No updates for "%s" on %s exists', name, plat)
        return version
コード例 #8
0
def remove_previous_versions(directory, filename):
    """Removes previous version of named file"""
    if filename is None:
        log.debug('Cleanup Failed - Filename is None')
        return
    log.debug('Filename: %s', filename)

    if directory is None:
        log.debug('Cleanup Failed - Directory is None')
        return
    log.debug('Directory: %s', directory)

    try:
        current_version = Version(filename)
    except (UtilsError, VersionError):  # pragma: no cover
        log.debug('Cleanup Failed: %s - Cannot parse version info.', filename)
        return

    try:
        # We set the full path here because Package() checks if filename exists
        package_info = Package(os.path.join(directory, filename))
    except (UtilsError, VersionError):
        log.debug('Cleanup Failed: %s - Cannot parse package info.', filename)
        return

    if package_info.info['status'] is False:
        log.debug('Not an archive format: %s', package_info.name)
        return

    log.debug('Current version: %s', str(current_version))
    assert package_info.name is not None
    log.debug('Name to search for: %s', package_info.name)
    with ChDir(directory):
        temp = os.listdir(os.getcwd())
        for t in temp:
            log.debug('Checking: %s', t)
            # Only attempt to remove old files of the one we
            # are updating
            if package_info.name not in t:
                log.debug('File does not match name of current binary')
                continue
            else:
                log.debug('Found possible match')
                log.debug('Latest name: %s', package_info.name)
                log.debug('Old name: %s', t)

            try:
                old_version = Version(t)
            except (UtilsError, VersionError):  # pragma: no cover
                log.warning('Cannot parse version info')
                # Skip file since we can't parse
                continue
            log.debug('Found version: %s', str(old_version))

            if old_version < current_version:
                old_path = os.path.join(directory, t)
                log.debug('Removing old update: %s', old_path)
                remove_any(old_path)
            else:
                log.debug('Old version: %s', old_version)
                log.debug('Current version: %s', current_version)