Example #1
0
def check_version(url="https://update.getghiro.org/update/check/",
                  force=False):
    """Checks version of Ghiro.
    It connects to Ghiro update website to check if a new release is available.
    You can optionally disable this via configuration file.
    @param url: update service URL
    @param force: force update check
    @return: boolean status of update available
    """

    # Do i have to check? It checks only out of a time frame.
    # Disable with "UPDATE_CHECK" option in configuration file.
    if (UpdateCheck.should_check() and settings.UPDATE_CHECK) or force:

        # Create new check entry.
        check = UpdateCheck.objects.create()

        # Format request.
        data = {"version": settings.GHIRO_VERSION}
        headers = {"User-Agent": "Ghiro update client"}
        try:
            request = requests.post(url,
                                    data=data,
                                    headers=headers,
                                    verify=True)
            response = request.text
        except requests.exceptions.RequestException as e:
            check.state = "E"
            check.save()
            raise Exception("Unable to establish connection: %s" % e)

        try:
            data = json.loads(response)
        except ValueError as e:
            check.state = "E"
            check.save()
            raise Exception("Invalid response: %s" % e)

        if data["new_release"]:
            check.state = "A"
            check.save()
            return True
        else:
            check.state = "N"
            check.save()
            return False
    else:
        return False
Example #2
0
def check_version(url="https://update.getghiro.org/update/check/", force=False):
    """Checks version of Ghiro.
    It connects to Ghiro update website to check if a new release is available.
    You can optionally disable this via configuration file.
    @param url: update service URL
    @param force: force update check
    @return: boolean status of update available
    """

    # Do i have to check? It checks only out of a time frame.
    # Disable with "UPDATE_CHECK" option in configuration file.
    if (UpdateCheck.should_check() and settings.UPDATE_CHECK) or force:

        # Create new check entry.
        check = UpdateCheck.objects.create()

        # Format request.
        data = {"version": settings.GHIRO_VERSION}
        headers = {"User-Agent": "Ghiro update client"}
        try:
            request = requests.post(url, data=data, headers=headers, verify=True)
            response = request.text
        except requests.exceptions.RequestException as e:
            check.state = "E"
            check.save()
            raise Exception("Unable to establish connection: %s" % e)

        try:
            data = json.loads(response)
        except ValueError as e:
            check.state = "E"
            check.save()
            raise Exception("Invalid response: %s" % e)

        if data["new_release"]:
            check.state = "A"
            check.save()
            return True
        else:
            check.state = "N"
            check.save()
            return False
    else:
        return False
Example #3
0
def check_version(url="http://update.getghiro.org/update/check/"):
    """Checks version of Ghiro.
    It connects to Ghiro update website to check if a new release is available.
    You can optionally disable this via configuration file.
    @param url: update service URL
    @return: boolean status of update available
    """

    # Do i have to check? It checks only out of a time frame.
    # Disable with "UPDATE_CHECK" option in configuration file.
    if UpdateCheck.should_check() and settings.UPDATE_CHECK:

        # Create new check entry.
        check = UpdateCheck.objects.create()

        # Format request.
        data = urllib.urlencode({"version": settings.GHIRO_VERSION})
        headers = {"User-Agent": "Ghiro update client"}
        try:
            request = urllib2.Request(url, data=data, headers=headers)
            response = urllib2.urlopen(request, timeout=60).read()
        except (urllib2.URLError, urllib2.HTTPError) as e:
            check.state = "E"
            check.save()
            raise Exception("Unable to establish connection: %s" % e)

        try:
            data = json.loads(response)
        except ValueError as e:
            check.state = "E"
            check.save()
            raise Exception("Invalid response: %s" % e)

        if data["new_release"]:
            check.state = "A"
            check.save()
            return True
        else:
            check.state = "N"
            check.save()
            return False
    else:
        return False