Beispiel #1
0
def daily_task():
    try:
        version = platform.python_version()

        if version >= '3':
            import urllib.request as openurl
        else:
            import urllib2 as openurl

        socket.setdefaulttimeout(1.2)
        ssl._create_default_https_context = ssl._create_unverified_context

        try:

            uc = UserConfig()

            now_time = time.strftime("%Y-%m-%d")  # day
            version_time = uc.version_time
            allow_report = uc.section_map[UserConfig.OTHERS]['allow_report']
            #print allow_report
            if now_time != version_time:
                url = "https://service-qgphxt7y-1253970226.gz.apigw.tencentcs.com/release/client_daily_task"
                post_data = None
                if allow_report.upper() == 'TRUE':
                    statistics = StatisticsConfigure()
                    statistics.read_data()
                    post_data = statistics.get_data()
                    statistics.delete_data()
                # print post_data
                if not post_data:
                    post_data = {}
                post_data["appid"] = uc.appid
                post_data["version"] = __version__
                post_data = json.dumps(post_data) if post_data else "{}"
                request = openurl.Request(
                    data=post_data.encode("utf-8")
                    if version >= '3' else post_data,
                    url=url) if version >= '3' else openurl.Request(
                        url, data=post_data)
                # print openurl.urlopen(request).read()
                response = json.loads(
                    json.loads(
                        openurl.urlopen(request).read().decode("utf-8")))
                release_version = response["version"]
                message = response["message"]
                release_version_list = release_version.split(".")
                local_version_list = __version__.split(".")
                for i in range(0, len(release_version_list)):
                    if int(release_version_list[i]) > int(
                            local_version_list[i]):
                        output_msg(__version__, release_version, message)
                        break
                uc.set_attrs({'version_time': now_time})
                uc.flush()
        except Exception as e:
            # print e
            pass

    except Exception as e:
        pass
Beispiel #2
0
def get_version():
    version = platform.python_version()

    if version >= '3':
        import urllib.request as openurl
    else:
        import urllib2 as openurl

    socket.setdefaulttimeout(1.2)
    ssl._create_default_https_context = ssl._create_unverified_context

    url = "https://service-qgphxt7y-1253970226.gz.apigw.tencentcs.com/release/client_daily_task"
    post_data = "{}"
    request = openurl.Request(
        data=post_data.encode("utf-8") if version >= '3' else post_data,
        url=url) if version >= '3' else openurl.Request(url, data=post_data)
    response = json.loads(
        json.loads(openurl.urlopen(request).read().decode("utf-8")))
    release_version = response["version"]
    message = response["message"]
    release_version_list = release_version.split(".")
    local_version_list = __version__.split(".")
    for i in range(0, len(release_version_list)):
        if int(release_version_list[i]) > int(local_version_list[i]):
            return {"version": release_version, "message": message}

    return {}
Beispiel #3
0
def check_version():
    try:
        version = platform.python_version()

        if version >= '3':
            import urllib.request
        else:
            import urllib2

        socket.setdefaulttimeout(1)
        ssl._create_default_https_context = ssl._create_unverified_context

        try:

            uc = UserConfig()

            # this_time = time.strftime("%W") # week
            this_time = time.strftime("%Y-%m-%d")  # day
            that_time = uc.version_time

            if this_time != that_time:
                url = "https://github.com/tencentyun/scfcli/blob/master/tcfcli/cmds/cli/__init__.py"
                temp_data = urllib.request.urlopen(
                    url) if version >= '3' else urllib2.urlopen(url)
                temp_data = temp_data.read().decode("utf-8")
                regex_str = '<span class="pl-pds">&#39;</span>(.*?)<span class="pl-pds">&#39;</span></span>'
                r_version = re.findall(regex_str, temp_data)[0]
                version_list = __version__.split(".")
                r_version_list = r_version.split(".")
                for i in range(0, len(version_list)):
                    if r_version_list[i] > version_list[i]:
                        uc.set_attrs({'version_time': this_time})
                        uc.flush()
                        click.secho(
                            click.style(
                                """    ----------------------------------------------------
    |                  Upgrade reminder                |
    | Latest version:%s   ,  Your version:   %s |
    | If you want to upgrade, you can use the command: |
    |""" % (r_version, __version__),
                                fg="green") +
                            click.style(
                                "                 pip install -U scf               ",
                                fg="yellow") + click.style('''|
    ----------------------------------------------------''',
                                                           fg="green"))
                        break
        except Exception as e:
            pass
    except Exception as e:
        pass
Beispiel #4
0
def check_version():
    try:
        version = platform.python_version()

        if version >= '3':
            import urllib.request
        else:
            import urllib2

        socket.setdefaulttimeout(1)
        ssl._create_default_https_context = ssl._create_unverified_context

        try:

            uc = UserConfig()

            # this_time = time.strftime("%W") # week
            this_time = time.strftime("%Y-%m-%d")  # day
            that_time = uc.version_time

            if this_time != that_time:
                url = "https://service-qgphxt7y-1253970226.gz.apigw.tencentcs.com/test/check_version"
                temp_data = urllib.request.urlopen(url) if version >= '3' else urllib2.urlopen(url)
                r_version = temp_data.read().decode("utf-8")[1:-1]
                print(r_version)
                r_version_list = r_version.split(".")
                version_list = __version__.split(".")
                for i in range(0, len(version_list)):
                    if int(r_version_list[i]) > int(version_list[i]):
                        click.secho(click.style("""    ----------------------------------------------------
    |                  Upgrade reminder                |
    | Latest version:%7s  , Your version: %7s |
    | If you want to upgrade, you can use the command: |
    |""" % (r_version, __version__), fg="green") +
                                    click.style("                 pip install -U scf               ", fg="yellow") +
                                    click.style('''|
    ----------------------------------------------------''', fg="green"))
                        break
                uc.set_attrs({'version_time': this_time})
                uc.flush()
        except Exception as e:
            pass
    except Exception as e:
        pass