How to use _select method in pom

Best Python code snippet using pom_python

list_printer.py

Source:list_printer.py Github

copy

Full Screen

1# Copyright 2014 Google Inc. All Rights Reserved.2"""List printer for Cloud Platform resources."""3from googlecloudsdk.core.util import attrpath4from googlecloudsdk.core.util import console_io5def PrintResourceList(collection, items):6 """Print a list of cloud resources.7 Args:8 collection: str, The name of the collection to which the items belong.9 items: iterable, A list or otherwise iterable object that generates the10 rows of the list.11 """12 console_io.PrintExtendedList(items, COLLECTION_COLUMNS[collection])13def _Select(path, transform=None):14 """Get a column fetcher for the given attr path and transform.15 Args:16 path: str, The attr path that keys into the resource.17 transform: func(str)->str, A func that takes something found by the path18 and maps it to some other strip.19 Returns:20 func(obj)->str, A func that takes an object and returns the value21 for a particular column.22 """23 getter = attrpath.Selector(path)24 if transform is None:25 return getter26 def GetAndTransform(obj):27 return transform(getter(obj))28 return GetAndTransform29def _NameOnly(value):30 """Get only the last token from a longer path, usually the name.31 Intended to be a selector transform for URLs.32 Args:33 value: str, The value whose last token will be returned.34 Returns:35 str, The name from value.36 """37 if value:38 return value.split('/')[-1]39 return value40def _CommaList(default=None):41 def Transform(items):42 if not items:43 return default44 return ', '.join(items)45 return Transform46def _DiskSize(value):47 """Returns a human readable string representation of the disk size.48 Args:49 value: str, Disk size represented as number of bytes.50 Returns:51 A human readable string representation of the disk size.52 """53 size = float(value)54 the_unit = 'TB'55 for unit in ['bytes', 'KB', 'MB', 'GB']:56 if size < 1024.0:57 the_unit = unit58 break59 size = float(size) / 1024.060 if size == int(size):61 return '%d %s' % (size, the_unit)62 else:63 return '%3.1f %s' % (size, the_unit)64def _ScreenResolution(model):65 """Build a human readable string representation of a screen resolution.66 Args:67 model: a Test_v1.AndroidModel message (from ApiTools)68 Returns:69 Returns a human readable string representation of a screen resolution.70 """71 return '{y} x {x}'.format(y=model.screenY, x=model.screenX)72# Guidelines for choosing your resource columns:73# - Column headers are ANGRY_SNAKE_CASE, just like user input in usage. This74# casing has a side effect in that column headers will never be confused for75# fields in the API responses, which are camelCase.76# - Fields that are URL parameters (that is, they disambiguate your77# resource) go first, starting at the end of the URL. So, often the first78# column will be NAME. PROJECT is an exception: no PROJECT column unless the79# resource being listed can be in a different project than the one found in80# the project property.81# - If your resource has a STATUS column or something similar, put it last.82# - Aim for an 80-char-wide table, but if someone has a 70-char NAME it's not83# your fault.84def _Default(default):85 def Transform(item):86 return default if item is None else item87 return Transform88def _SelectTime(path):89 return _Select(path, transform=lambda x: x and x.isoformat())90def _FormatOperationErrors(errs):91 if not errs:92 return None93 else:94 return '\n'.join(['[%s: %s]' % (e.code, e.message) for e in errs])95def _FormatResourceErrors(errs):96 if not errs:97 return None98 else:99 return '\n'.join(['[%s]' % e for e in errs])100COLLECTION_COLUMNS = {101 # APPENGINE102 'app.module_versions': (103 ('MODULE', _Select('module')),104 ('VERSION', _Select('version')),105 ('IS_DEFAULT', _Select('is_default',106 transform=lambda x: '*' if x else '-')),107 ),108 # AUTOSCALER109 'autoscaler.instances': (110 ('NAME', _Select('name')),111 ('DESCRIPTION', _Select('description')),112 ('STATE', _Select('state')),113 ('STATE_DETAILS', _Select('state_details')),114 ),115 # BIGQUERY116 'bigquery.datasets': (117 ('DATASET_ID', _Select('datasetReference.datasetId')),118 ),119 'bigquery.jobs.describe': (120 ('JOB_TYPE', _Select('job_type')),121 ('STATE', _Select('state')),122 ('START_TIME', _Select('start_time')),123 ('DURATION', _Select('duration')),124 ('BYTES_PROCESSED', _Select('bytes_processed')),125 ),126 'bigquery.jobs.list': (127 ('JOB_ID', _Select('job_id')),128 ('JOB_TYPE', _Select('job_type')),129 ('STATE', _Select('state')),130 ('START_TIME', _Select('start_time')),131 ('DURATION', _Select('duration')),132 ),133 'bigquery.jobs.wait': (134 ('JOB_TYPE', _Select('job_type')),135 ('STATE', _Select('state')),136 ('START_TIME', _Select('start_time')),137 ('DURATION', _Select('duration')),138 ('BYTES_PROCESSED', _Select('bytes_processed')),139 ),140 'bigquery.projects': (141 ('PROJECT_ID', _Select('projectReference.projectId')),142 ('FRIENDLY_NAME', _Select('friendlyName')),143 ),144 'bigquery.tables.list': (145 ('ID', _Select('id')),146 ('TABLE_OR_VIEW', _Select('type')),147 ),148 # COMPUTE149 'compute.instances': (150 ('NAME', _Select('name')),151 ('ZONE', _Select('zone', _NameOnly)),152 ('MACHINE_TYPE', _Select('machineType', _NameOnly)),153 ('INTERNAL_IP', _Select('networkInterfaces[0].networkIP')),154 ('EXTERNAL_IP', _Select('networkInterfaces[0].accessConfigs[0].natIP')),155 ('STATUS', _Select('status')),156 ),157 # CONTAINER V1BETA1158 # TODO(user): remove this once v1 is fully rolled out159 'containerv1beta1.projects.zones.clusters': (160 ('NAME', _Select('name')),161 ('ZONE', _Select('zone')),162 ('CLUSTER_API_VERSION', _Select('clusterApiVersion')),163 ('MASTER_IP', _Select('endpoint')),164 ('MACHINE_TYPE', _Select(165 'nodeConfig', transform=166 lambda x: '%s, %s' % (x.machineType, _NameOnly(x.sourceImage)))),167 ('NODES', _Select('numNodes')),168 ('STATUS', _Select('status')),169 ),170 'containerv1beta1.projects.zones.operations': (171 ('NAME', _Select('name')),172 ('TYPE', _Select('operationType')),173 ('ZONE', _Select('zone')),174 ('TARGET', _Select('target')),175 ('ERROR_MESSAGE', _Select('errorMessage')),176 ('STATUS', _Select('status')),177 ),178 # CONTAINER179 'container.projects.zones.clusters': (180 ('NAME', _Select('name')),181 ('ZONE', _Select('zone')),182 ('MASTER_VERSION', _Select('currentMasterVersion')),183 ('MASTER_IP', _Select('endpoint')),184 ('MACHINE_TYPE', _Select(185 'nodeConfig', transform=lambda x: '%s' % (x.machineType))),186 ('STATUS', _Select('status')),187 ),188 'container.projects.zones.operations': (189 ('NAME', _Select('name')),190 ('TYPE', _Select('operationType')),191 ('ZONE', _Select('zone')),192 ('TARGET', _Select('targetLink', _NameOnly)),193 ('STATUS_MESSAGE', _Select('statusMessage')),194 ('STATUS', _Select('status')),195 ),196 # DATAFLOW197 'dataflow.jobs': (198 ('ID', _Select('job_id')),199 ('NAME', _Select('job_name')),200 ('TYPE', _Select('job_type')),201 ('CREATION_TIME', _Select('creation_time')),202 ('STATUS', _Select('status')),203 ),204 # DNS205 'dns.changes': (206 ('ID', _Select('id')),207 ('START_TIME', _Select('startTime')),208 ('STATUS', _Select('status')),209 ),210 'dns.managedZones': (211 ('NAME', _Select('name')),212 ('DNS_NAME', _Select('dnsName')),213 ('DESCRIPTION', _Select('description')),214 ),215 'dns.resourceRecordSets': (216 ('NAME', _Select('name')),217 ('TYPE', _Select('type')),218 ('TTL', _Select('ttl')),219 ('DATA', _Select('rrdatas', _CommaList(''))),220 ),221 # TODO(user): Remove this section when dm-v2 is removed from preview.222 # DEPLOYMENTMANAGER V2BETA1223 'deploymentmanager.deployments': (224 ('NAME', _Select('name')),225 ('ID', _Select('id')),226 ('DESCRIPTION', _Select('description')),227 ('MANIFEST', _Select('manifest')),228 ),229 'deploymentmanager.operations': (230 ('NAME', _Select('name')),231 ('TYPE', _Select('operationType')),232 ('STATUS', _Select('status')),233 ('TARGET_LINK', _Select('targetLink')),234 ('ERRORS', _Select('error.errors')),235 ),236 'deploymentmanager.resources': (237 ('NAME', _Select('name')),238 ('TYPE', _Select('type')),239 ('ID', _Select('id')),240 ('STATE', _Select('state')),241 ('ERRORS', _Select('errors')),242 ),243 # DEPLOYMENTMANAGER V2BETA2244 'deploymentmanagerv2beta2.deployments': (245 ('NAME', _Select('name')),246 ('STATE', _Select('state')),247 ('INTENT', _Select('intent')),248 ('ID', _Select('id')),249 ('DESCRIPTION', _Select('description')),250 ('MANIFEST', _Select('manifest', transform=251 lambda x: x.split('/')[-1] if x else None)),252 ('ERRORS', _Select('update.errors', transform=_FormatResourceErrors)),253 ),254 'deploymentmanagerv2beta2.operations': (255 ('NAME', _Select('name')),256 ('TYPE', _Select('operationType')),257 ('STATUS', _Select('status')),258 ('TARGET', _Select('targetLink', transform=259 lambda x: x.split('/')[-1] if x else None)),260 ('ERRORS', _Select('error.errors', transform=_FormatOperationErrors)),261 ),262 'deploymentmanagerv2beta2.resources': (263 ('NAME', _Select('name')),264 ('TYPE', _Select('type')),265 ('ID', _Select('id')),266 ('UPDATE_STATE', _Select('update.state', transform=267 lambda x: 'COMPLETED' if x is None else x)),268 ('ERRORS', _Select('update.errors', transform=_FormatResourceErrors)),269 ),270 # GENOMICS271 'genomics.datasets': (272 ('ID', _Select('id')),273 ('NAME', _Select('name')),274 ),275 # SQL276 'sql.backupRuns': (277 ('DUE_TIME', _SelectTime('dueTime')),278 ('ERROR', _Select('error.code')),279 ('STATUS', _Select('status')),280 ),281 'sql.flags': (282 ('NAME', _Select('name')),283 ('TYPE', _Select('type')),284 ('ALLOWED_VALUES', _Select('allowedStringValues', _CommaList(''))),285 ),286 'sql.instances': (287 ('NAME', _Select('instance')),288 ('REGION', _Select('region')),289 ('TIER', _Select('settings.tier')),290 ('ADDRESS', _Select('ipAddresses[0].ipAddress')),291 ('STATUS', _Select('state')),292 ),293 'sql.operations': (294 ('OPERATION', _Select('operation')),295 ('TYPE', _Select('operationType')),296 ('START', _SelectTime('startTime')),297 ('END', _SelectTime('endTime')),298 ('ERROR', _Select('error[0].code')),299 ('STATUS', _Select('state')),300 ),301 'sql.sslCerts': (302 ('NAME', _Select('commonName')),303 ('SHA1_FINGERPRINT', _Select('sha1Fingerprint')),304 ('EXPIRATION', _Select('expirationTime')),305 ),306 'sql.tiers': (307 ('TIER', _Select('tier')),308 ('AVAILABLE_REGIONS', _Select('region', _CommaList(''))),309 ('RAM', _Select('RAM', _DiskSize)),310 ('DISK', _Select('DiskQuota', _DiskSize)),311 ),312 # projects313 'cloudresourcemanager.projects': (314 ('PROJECT_ID', _Select('projectId')),315 ('NAME', _Select('name')),316 ('PROJECT_NUMBER', _Select('projectNumber')),317 ),318 # source319 'source.jobs.list': (320 ('REPO_NAME', _Select('name', _Default('default'))),321 ('PROJECT_ID ', _Select('projectId')),322 ('VCS', _Select('vcs')),323 ('STATE', _Select('state')),324 ('CREATE_TIME', _Select('createTime')),325 ),326 # Cloud Updater327 'replicapoolupdater.rollingUpdates': (328 ('ID', _Select('id')),329 ('GROUP_NAME', _Select('instanceGroupManager', _NameOnly)),330 ('TEMPLATE_NAME', _Select('instanceTemplate', _NameOnly)),331 ('STATUS', _Select('status')),332 ('STATUS_MESSAGE', _Select('statusMessage')),333 ),334 'replicapoolupdater.rollingUpdates.instanceUpdates': (335 ('INSTANCE_NAME', _Select('instance', _NameOnly)),336 ('STATUS', _Select('status')),337 ),338 # TEST339 'test.android.devices': (340 ('DEVICE_ID', _Select('id')),341 ('MAKE', _Select('manufacturer')),342 ('MODEL', _Select('name')),343 ('FORM', _Select('form')),344 ('SCREEN_RES', _ScreenResolution),345 ('OS_VERSION_IDS', _Select('supportedVersionIds', _CommaList('none'))),346 ('TAGS', _Select('tags', _CommaList('')))347 ),348 'test.run.outcomes': (349 ('OUTCOME', _Select('outcome')),350 ('STEP', _Select('step_name')),351 ('TEST_AXIS_VALUE', _Select('axis_value')),352 ),353 # Cloud Logging354 'logging.logs': (355 ('NAME', _Select('name')),356 ),357 'logging.sinks': (358 ('NAME', _Select('name')),359 ('DESTINATION', _Select('destination')),360 ),361 'logging.typedSinks': (362 ('NAME', _Select('name')),363 ('DESTINATION', _Select('destination')),364 ('TYPE', _Select('type')),365 ),366 'logging.metrics': (367 ('NAME', _Select('name')),368 ('DESCRIPTION', _Select('description')),369 ('FILTER', _Select('filter')),370 ),371 # Service Management (Inception)372 'servicemanagement-v1.services': (373 ('NAME', _Select('serviceName')),374 ('TITLE', _Select('serviceConfig.title')),375 ),...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful