Best Python code snippet using slash
app.py
Source:app.py
...27def app(args):28 if args['create']:29 name = args['--name']30 process = args['--process']31 platform = Config.get_default_config(space='paaws', key='platform') if args['--platform'] is None else args['--platform']32 env = Config.get_default_config(space='paaws', key='env') if args['--env'] is None else args['--env']33 instance_class = Config.get_default_config(space='autoscale', key='instance-class') if args['--instance-class'] is None else args['--instance-class']34 desired_capacity = Config.get_default_config(space='autoscale', key='desired-capacity') if args['--desired-capacity'] is None else args['--desired-capacity']35 region = Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region']36 if args['--scale-name'] is not None:37 asg = Scale(38 old_method=True,39 scale_name=args['--scale-name'],40 instance_class=instance_class,41 desired_capacity=desired_capacity,42 region=region,43 minimum=0 if args['--min'] is None else args['--min'],44 maximum=2 if args['--min'] is None else args['--max'],45 elb=args['--elb'],46 )47 print(asg.create())48 else:49 if args['--elb']:50 loadbalancer = ElasticLoadBalancer(51 name=name,52 process=process,53 platform=platform,54 env=env,55 region=region,56 domain=args['--domain'] if args['--domain'] is not None else None,57 public=args['--public']58 )59 loadbalancer = loadbalancer.get_or_create()60 loadbalancer_name = loadbalancer.name61 else:62 loadbalancer_name = None63 asg = Scale(64 name=name,65 process=process,66 platform=platform,67 env=env,68 region=region,69 instance_class=instance_class,70 desired_capacity=desired_capacity,71 minimum=0 if args['--min'] is None else args['--min'],72 maximum=4 if args['--min'] is None else args['--max'],73 elb=loadbalancer_name,74 public=args['--public-instances']75 )76 autoscaling_group = asg.create()77 autoscaling_data = {78 "Name": [name],79 "Process": [process],80 "Platform": [platform],81 "Region": [region],82 "Endpoint": [loadbalancer.dns_name] if args['--elb'] else [" -- "],83 "Instance Class": [instance_class],84 "Desired Capacity": [desired_capacity]85 }86 print(to_table(autoscaling_data))87 elif args['scale']:88 if args['--scale-name'] is not None:89 asg = Scale(90 old_method=True,91 autoscale_update=True,92 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],93 scale_name=args['--scale-name'],94 desired_capacity=args['--desired-capacity'],95 )96 print(asg.update())97 else:98 asg = Scale(99 name=args['--name'],100 process=args['--process'],101 platform=Config.get_default_config(space='paaws', key='platform') if args['--platform'] is None else args['--platform'],102 env=Config.get_default_config(space='paaws', key='env') if args['--env'] is None else args['--env'],103 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],104 autoscale_update=True,105 desired_capacity=args['--desired-capacity'],106 )107 print(asg.update())108 elif args['update']:109 if args['--scale-name'] is not None:110 kwargs = {111 'old_method': True,112 'launchconfig_update': True,113 'scale_name': args['--scale-name'],114 'region': Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],115 'instance_class': args['--instance-class'],116 'ami_id': args['--ami-id'],117 }118 kwargs = {key: value for (key, value) in kwargs.iteritems() if value is not None}119 asg = Scale(**kwargs)120 print(asg.update())121 else:122 kwargs = {123 'name': args['--name'],124 'process': args['--process'],125 'platform': Config.get_default_config(space='paaws', key='platform') if args['--platform'] is None else args['--platform'],126 'env': Config.get_default_config(space='paaws', key='env') if args['--env'] is None else args['--env'],127 'region': Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],128 'launchconfig_update': True,129 'instance_class': args['--instance-class'],130 'ami_id': args['--ami-id'],131 }132 kwargs = {key: value for (key, value) in kwargs.iteritems() if value is not None}133 asg = Scale(**kwargs)134 print(asg.update())135 elif args['deploy']:136 if args['--scale-name'] is not None:137 asg = Scale(138 old_method=True,139 scale_name=args['--scale-name'],140 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],141 )142 autoscaling_group = asg.get_scale()143 deploy(144 autoscaling_group=autoscaling_group,145 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],146 revision=args['--revision']147 )148 else:149 instance_ips = []150 if args['--process'] is None:151 if raw_input(red("You are running without specifying a process (including LB), are you sure? [y/N] ")) != 'y':152 sys.exit(0)153 else:154 instance_data = get_instances_data(155 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],156 instance_ids=[],157 list_instances=True,158 name=args['--name'],159 platform=args['--platform'],160 env=args['--env']161 )162 for ip in instance_data['IP']:163 instance_ips.append(ip)164 else:165 processes = args['--process'].split(", ")166 for process in processes:167 instance_data = get_instances_data(168 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],169 instance_ids=[],170 list_instances=True,171 name=args['--name'],172 process=process,173 platform=args['--platform'],174 env=args['--env']175 )176 for ip in instance_data['IP']:177 instance_ips.append(ip)178 deploy(179 instances_ips=instance_ips,180 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],181 revision=args['--revision']182 )183 elif args['cmd']:184 if args['--scale-name'] is not None:185 asg = Scale(186 old_method=True,187 scale_name=args['--scale-name'],188 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],189 )190 autoscaling_group = asg.get_scale()191 cmd(192 autoscaling_group=autoscaling_group,193 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],194 is_sudo=args['--sudo'], command=args['<command>']195 )196 else:197 instance_ips = []198 if args['--process'] is None:199 if raw_input(red("You are running without specifying a process (including LB), are you sure? [y/N] ")) != 'y':200 sys.exit(0)201 else:202 instance_data = get_instances_data(203 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],204 instance_ids=[],205 list_instances=True,206 name=args['--name'],207 platform=args['--platform'],208 env=args['--env']209 )210 for ip in instance_data['IP']:211 instance_ips.append(ip)212 else:213 processes = args['--process'].split(", ")214 for process in processes:215 instance_data = get_instances_data(216 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],217 instance_ids=[],218 list_instances=True,219 name=args['--name'],220 process=process,221 platform=args['--platform'],222 env=args['--env']223 )224 for ip in instance_data['IP']:225 instance_ips.append(ip)226 cmd(227 instances_ips=instance_ips,228 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],229 is_sudo=args['--sudo'], command=args['<command>']230 )231 elif args['ps']:232 if args['--scale-name'] is not None:233 print(to_table(describe_group(name=args['--scale-name'], old_method=True)))234 if args['--more']:235 instances = describe_group_instances(name=args['--scale-name'])236 instance_data = get_instances_data(237 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],238 instance_ids=instances,239 list_instances=True,240 )241 print(to_table(instance_data))242 else:243 asg = Scale(244 name=args['--name'],245 process=args['--process'],246 platform=Config.get_default_config(space='paaws', key='platform') if args['--platform'] is None else args['--platform'],247 env=Config.get_default_config(space='paaws', key='env') if args['--env'] is None else args['--env'],248 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],249 )250 autoscaling_group = asg.get_scale()251 print(to_table(describe_group(name=autoscaling_group.name)))252 if args['--more']:253 instance_data = get_instances_data(254 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'],255 instance_ids=[],256 list_instances=True,257 name=args['--name'],258 process=args['--process'],259 platform=args['--platform'],260 env=args['--env']261 )262 print(to_table(instance_data))263 elif args['ls']:264 print(to_table(list_all_groups(region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region'])))265 elif args['link']:266 link = link_app_resources(267 resource_connection=args['--resource-connection'],268 name=args['--name'],269 platform=Config.get_default_config(space='paaws', key='platform') if args['--platform'] is None else args['--platform'],270 env=Config.get_default_config(space='paaws', key='env') if args['--env'] is None else args['--env'],271 region=Config.get_default_config(space='paaws', key='region') if args['--region'] is None else args['--region']272 )273 print(link)274 else:...
ThinkMysql.py
Source:ThinkMysql.py
...9 g_lock = threading.Lock()10 g_dictConnPool = {}11 @classmethod12 def get_conn_pool_ex(cls, szGroup="mysql"):13 return cls.get_conn_pool(host=ThinkConfig.get_default_config().get(szGroup, "host")14 , port=int(ThinkConfig.get_default_config().get(szGroup, "port"))15 , user=ThinkConfig.get_default_config().get(szGroup, "user")16 , password=ThinkConfig.get_default_config().get(szGroup, "password")17 , db=ThinkConfig.get_default_config().get(szGroup, "db")18 , mincached=int(ThinkConfig.get_default_config().get_int(szGroup, "maxconnections") / 2)19 , maxcached=int(ThinkConfig.get_default_config().get_int(szGroup, "maxconnections"))20 , maxconnections=int(ThinkConfig.get_default_config().get(szGroup, "maxconnections"))21 , charset="utf8"22 , use_unicode=True)23 @classmethod24 def get_conn_pool(cls25 , host=ThinkConfig.get_default_config().get("mysql", "host")26 , port=int(ThinkConfig.get_default_config().get("mysql", "port"))27 , user=ThinkConfig.get_default_config().get("mysql", "user")28 , password=ThinkConfig.get_default_config().get("mysql", "password")29 , db=ThinkConfig.get_default_config().get("mysql", "db")30 , mincached = int(ThinkConfig.get_default_config().get_int("mysql", "maxconnections") / 2)31 , maxcached = int(ThinkConfig.get_default_config().get_int("mysql", "maxconnections"))32 , maxconnections=int(ThinkConfig.get_default_config().get("mysql", "maxconnections"))33 , charset = "utf8"34 , use_unicode = True):35 szHostPortDb = "{}:{}-{}".format(host, port, db)36 if cls.g_dictConnPool.get(szHostPortDb) is None:37 with cls.g_lock:38 if cls.g_dictConnPool.get(szHostPortDb) is None:39 conn_pool = PooledDB(mysql40 , mincached = mincached41 , maxcached = maxcached42 , host=host43 , user=user44 , password=password45 , db=db46 , port=port...
ThinkAioMysql.py
Source:ThinkAioMysql.py
...10 g_dictConnPool = {}11 g_rwlock = aiorwlock.RWLock()12 @classmethod13 async def get_conn_pool_ex(cls, szGroup="mysql" ):14 ret = await cls.get_conn_pool(host=ThinkConfig.get_default_config().get(szGroup, "host")15 , port=int(ThinkConfig.get_default_config().get(szGroup, "port"))16 , user=ThinkConfig.get_default_config().get(szGroup, "user")17 , password=ThinkConfig.get_default_config().get(szGroup, "password")18 , db=ThinkConfig.get_default_config().get(szGroup, "db")19 , mincached=int(ThinkConfig.get_default_config().get_int(szGroup, "maxconnections") / 2)20 , maxcached=int(ThinkConfig.get_default_config().get_int(szGroup, "maxconnections"))21 , maxconnections=int(ThinkConfig.get_default_config().get(szGroup, "maxconnections"))22 , charset="utf8"23 , use_unicode=True)24 return ret25 @classmethod26 async def get_conn_pool(cls27 , host=ThinkConfig.get_default_config().get("mysql", "host")28 , port=int(ThinkConfig.get_default_config().get("mysql", "port"))29 , user=ThinkConfig.get_default_config().get("mysql", "user")30 , password=ThinkConfig.get_default_config().get("mysql", "password")31 , db=ThinkConfig.get_default_config().get("mysql", "db")32 , mincached=int(ThinkConfig.get_default_config().get_int("mysql", "maxconnections") / 2)33 , maxcached=int(ThinkConfig.get_default_config().get_int("mysql", "maxconnections"))34 , maxconnections=int(ThinkConfig.get_default_config().get("mysql", "maxconnections"))35 , charset="utf8"36 , use_unicode=True):37 szHostPortDb = "{}:{}-{}".format(host, port, db)38 if cls.g_dictConnPool.get(szHostPortDb) is None:39 async with cls.g_rwlock.writer:40 if cls.g_dictConnPool.get(szHostPortDb) is None:41 connPool = await aiomysql.create_pool(42 minsize=mincached43 , maxsize=maxcached44 , host=host45 , user=user46 , password=password47 , db=db48 , port=port...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!