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
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()
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">'</span>(.*?)<span class="pl-pds">'</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
def change(userid): ''' \b Change your user. \b Common usage: \b * Configure change your user $ scf configure change ''' uc = UserConfig() userlist = uc.get_all_user() userlist = sorted(userlist) # 如果没有传入编号,则进入交互 if not userid: curruser = uc.section_map[UserConfig.OTHERS]['curr_user'] Operation('Your current user is %s' % curruser).process() Operation('%-10s %-15s %-15s %-15s %-15s %-10s' % ('UserId', 'AppId', 'region', 'secret_id', 'secret_key', 'using_cos')).process() for user in userlist: userinfo = uc.get_user_info(user) secret_id = ("*" * 3 + userinfo['secret_id'][32:] ) if userinfo['secret_id'] != 'None' else 'None' secret_key = ("*" * 3 + userinfo['secret_key'][28:] ) if userinfo['secret_key'] != 'None' else 'None' Operation( '%-10s %-15s %-15s %-15s %-15s %-10s' % (user.strip('USER_'), userinfo['appid'], userinfo['region'], secret_id, secret_key, userinfo['using_cos'][:5])).process() v = click.prompt(text="Please choice UserId to change", show_default=False) v = userid if userid else v if ('USER_' + v) in userlist: uc.changeuser(('USER_' + v)) uc.flush() Operation('Your current user has switched to %s' % ('USER_' + v)).success() else: Operation('error No').warning()
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
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()
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()
def set(**kwargs): uc = UserConfig() uc.set_attrs(kwargs) uc.flush()
def add(**kwargs): ''' \b Add a user. \b Common usage: \b * Add a user. $ scf configure add ''' 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.section_map[ UserConfig.USER_QCLOUD_CONFIG]['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 = {} skip_attr = {'using_cos'} for attr in sorted(attrs): if attr not in skip_attr: while True: v = click.prompt(text="TencentCloud {}".format(attr), default=None, 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 user = uc.add_user(data=kwargs) uc.flush() Operation('Add User %s success!' % user).success() Operation(user).process() Operation('%-10s %-15s %-15s %-15s %-15s %-10s' % ('UserId', 'AppId', 'region', 'secret_id', 'secret_key', 'using_cos')).process() userinfo = uc.get_user_info(user) secret_id = ("*" * 3 + userinfo['secret_id'][32:] ) if userinfo['secret_id'].upper() != 'NONE' else 'None' secret_key = ("*" * 3 + userinfo['secret_key'][28:] ) if userinfo['secret_key'].upper() != 'NONE' else 'None' Operation('%-10s %-15s %-15s %-15s %-15s %-10s' % (user.strip('USER_'), userinfo['appid'], userinfo['region'], secret_id, secret_key, userinfo['using_cos'][:5])).process() Operation('You can use `scf configure change -u %s` to switch user.' % (user.strip('USER_'))).process()