Example #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
Example #2
0
def set(**kwargs):
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()
    values = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        config = {}
        for attr in sorted(attrs):
            attr_value = attrs[attr]
            if attr == "secret-id":
                attr_value = "*" * 32 + attr_value[32:]
            elif attr == "secret-key":
                attr_value = "*" * 28 + attr_value[28:]
            v = click.prompt(text="TencentCloud {}({})".format(
                attr, attr_value),
                             default=attrs[attr],
                             show_default=False)
            config[attr] = v
        kwargs = config
    uc.set_attrs(kwargs)
    uc.flush()
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        v = click.prompt(
            text="Allow report information to help us optimize scfcli(Y/n)",
            default="y",
            show_default=False)
        if v in ["y", "Y"]:
            client = ScfReportClient()
            client.report()
Example #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
Example #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
Example #5
0
def set(**kwargs):
    '''
        \b
        Configure your account parameters.
        \b
        Common usage:
            \b
            * Configure your account parameters
              $ scf configure set
            \b
            * Modify a configuration item
              $ scf configure set --region ap-shanghai
    '''
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()

    using_cos_true = "False (By default, it isn't deployed by COS.)"
    using_cos_false = "True (By default, it is deployed by COS.)"

    if "region" in kwargs and kwargs["region"]:
        if kwargs["region"] not in REGIONS:
            Operation("The region must in %s." %
                      (", ".join(REGIONS))).warning()
            kwargs["region"] = uc.region
            return

    if "using_cos" in kwargs and kwargs["using_cos"]:
        kwargs["using_cos"] = using_cos_true if kwargs["using_cos"] not in [
            "y", "Y"
        ] else using_cos_false

    values = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        config = {}
        for attr in sorted(attrs):
            if attr != "using-cos":
                while True:
                    attr_value = attrs[attr]
                    if attr == "secret-id":
                        attr_value = "*" * 32 + attr_value[32:]
                    elif attr == "secret-key":
                        attr_value = "*" * 28 + attr_value[28:]

                    v = click.prompt(text="TencentCloud {}({})".format(
                        attr, attr_value),
                                     default=attrs[attr],
                                     show_default=False)
                    config[attr] = v

                    if attr != "region":
                        break
                    else:
                        if v in REGIONS:
                            break
                        else:
                            Operation("The region must in %s." %
                                      (", ".join(REGIONS))).warning()

        v = click.prompt(
            text="Deploy SCF function by COS, it will be faster. (y/n)",
            default="y" if str(attrs["using-cos"]).startswith("True") else "n",
            show_default=False)

        if v:
            config["using_cos"] = using_cos_true if v not in [
                "y", "Y"
            ] else using_cos_false
        else:
            config["using_cos"] = attrs["using-cos"]

        kwargs = config

    uc.set_attrs(kwargs)
    uc.flush()

    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        v = click.prompt(
            text="Allow report information to help us optimize scfcli. (y/n)",
            default="y",
            show_default=False)
        if v in ["y", "Y"]:
            client = ScfReportClient()
            client.report()
Example #6
0
def set(**kwargs):
    '''
        \b
        Configure your account parameters.
        \b
        Common usage:
            \b
            * Configure your account parameters
              $ scf configure set
            \b
            * Modify a configuration item
              $ scf configure set --region ap-shanghai
    '''
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()

    using_cos_true = "True (By default, it is deployed by COS.)"
    using_cos_false = "False (By default, it isn't deployed by COS.)"

    if "region" in kwargs and kwargs["region"]:
        if kwargs["region"] not in REGIONS:
            Operation("The region must in %s." %
                      (", ".join(REGIONS))).warning()
            kwargs["region"] = uc.region
            return

    if "using_cos" in kwargs and kwargs["using_cos"]:
        kwargs["using_cos"] = using_cos_false if kwargs["using_cos"] not in [
            "y", "Y"
        ] else using_cos_true

    if "allow_report" in kwargs and kwargs["allow_report"]:
        kwargs["allow_report"] = 'False' if kwargs["allow_report"] not in [
            "y", "Y"
        ] else 'True'
        if kwargs["allow_report"] == "True":
            Operation(
                '当前已开启数据收集,详情请参考 https://cloud.tencent.com/document/product/583/37766'
            ).out_infor()

    if "no_color" in kwargs and kwargs["no_color"]:
        kwargs["no_color"] = 'False' if kwargs["no_color"] not in [
            "y", "Y"
        ] else 'True'

    values = [v for k, v in kwargs.items()]
    config = {}
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        skip_attr = {
            'using_cos', 'python2_path', 'python3_path', 'no_color',
            'allow_report'
        }
        for attr in sorted(attrs):
            if attr not in skip_attr:
                while True:
                    attr_value = attrs[attr]
                    if attr == "secret_id":
                        attr_value = "*" * 32 + attr_value[32:]
                    elif attr == "secret_key":
                        attr_value = "*" * 28 + attr_value[28:]

                    v = click.prompt(text="TencentCloud {}({})".format(
                        attr.replace('_', '-'), attr_value),
                                     default=attrs[attr],
                                     show_default=False)
                    config[attr] = v

                    if attr != "region":
                        break
                    else:
                        if v in REGIONS:
                            break
                        else:
                            Operation("The region must in %s." %
                                      (", ".join(REGIONS))).warning()

        #
        v1 = click.prompt(
            text=("Show the command information without color(cur:%s). (y/n)")
            % attrs["no_color"][:5],
            default="y"
            if str(attrs["no_color"]).upper().startswith("TRUE") else "n",
            show_default=False)
        if v1:
            config["no_color"] = "False" if v1 not in ["y", "Y"] else "True"
        else:
            config["no_color"] = attrs["no_color"]

        v2 = click.prompt(text=(
            "Deploy SCF function by COS, it will be faster(cur:%s).  (y/n)") %
                          attrs["using_cos"][:5],
                          default="y"
                          if str(attrs["using_cos"]).upper().startswith("TRUE")
                          else "n",
                          show_default=False)
        if v2:
            config["using_cos"] = using_cos_false if v2 not in [
                "y", "Y"
            ] else using_cos_true
        else:
            config["using_cos"] = attrs["using_cos"]

        #v3 = click.prompt(text=("Allow report information to help us optimize scfcli(cur:%s). (y/n)") % attrs["allow_report"][:5],
        #                  default="y" if str(attrs["allow_report"]).upper().startswith("TRUE") else "n",
        #                  show_default=False)
        #if v3:
        #    config["allow_report"] = "False" if v3 not in ["y", "Y"] else "True"
        #else:
        #    config["allow_report"] = attrs["allow_report"]

        # if uc.section_map[UserConfig.OTHERS]['allow_report'].upper() == 'TRUE':
        #     Operation('当前已开启数据收集,详情请参考 https://cloud.tencent.com/document/product/583/37766').out_infor()

        kwargs = config

    uc.set_attrs(kwargs)
    uc.flush()
Example #7
0
def set(**kwargs):
    uc = UserConfig()
    uc.set_attrs(kwargs)
    uc.flush()