How to use rules method in hypothesis

Best Python code snippet using hypothesis

pluralrules.js

Source:pluralrules.js Github

copy

Full Screen

1// Copyright 2012 The Closure Library Authors. All Rights Reserved2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS, WITHOUT11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12// License for the specific language governing permissions and limitations under13// the License.14/**15 * @fileoverview Plural rules.16 *17 * This file is autogenerated by script:18 * http://go/generate_pluralrules.py19 *20 * Before check in, this file could have been manually edited. This is to21 * incorporate changes before we could fix CLDR. All manual modification must be22 * documented in this section, and should be removed after those changes land to23 * CLDR.24 */25goog.provide('goog.i18n.pluralRules');26/**27 * Plural pattern keyword28 * @enum {string}29 */30goog.i18n.pluralRules.Keyword = {31 ZERO: 'zero',32 ONE: 'one',33 TWO: 'two',34 FEW: 'few',35 MANY: 'many',36 OTHER: 'other'37};38/**39 * Default plural select rule.40 * @param {number} n The count of items.41 * @return {goog.i18n.pluralRules.Keyword} Default value.42 * @private43 */44goog.i18n.pluralRules.defaultSelect_ = function(n) {45 return goog.i18n.pluralRules.Keyword.OTHER;46};47/**48 * Plural select rules for ar locale49 *50 * @param {number} n The count of items.51 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.52 * @private53 */54goog.i18n.pluralRules.arSelect_ = function(n) {55 if (n == 0) {56 return goog.i18n.pluralRules.Keyword.ZERO;57 }58 if (n == 1) {59 return goog.i18n.pluralRules.Keyword.ONE;60 }61 if (n == 2) {62 return goog.i18n.pluralRules.Keyword.TWO;63 }64 if (n == (n | 0) && n % 100 >= 3 && n % 100 <= 10) {65 return goog.i18n.pluralRules.Keyword.FEW;66 }67 if (n == (n | 0) && n % 100 >= 11 && n % 100 <= 99) {68 return goog.i18n.pluralRules.Keyword.MANY;69 }70 return goog.i18n.pluralRules.Keyword.OTHER;71};72/**73 * Plural select rules for en locale74 *75 * @param {number} n The count of items.76 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.77 * @private78 */79goog.i18n.pluralRules.enSelect_ = function(n) {80 if (n == 1) {81 return goog.i18n.pluralRules.Keyword.ONE;82 }83 return goog.i18n.pluralRules.Keyword.OTHER;84};85/**86 * Plural select rules for fil locale87 *88 * @param {number} n The count of items.89 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.90 * @private91 */92goog.i18n.pluralRules.filSelect_ = function(n) {93 if (n == 0 || n == 1) {94 return goog.i18n.pluralRules.Keyword.ONE;95 }96 return goog.i18n.pluralRules.Keyword.OTHER;97};98/**99 * Plural select rules for fr locale100 *101 * @param {number} n The count of items.102 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.103 * @private104 */105goog.i18n.pluralRules.frSelect_ = function(n) {106 if (n >= 0 && n <= 2 && n != 2) {107 return goog.i18n.pluralRules.Keyword.ONE;108 }109 return goog.i18n.pluralRules.Keyword.OTHER;110};111/**112 * Plural select rules for lv locale113 *114 * @param {number} n The count of items.115 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.116 * @private117 */118goog.i18n.pluralRules.lvSelect_ = function(n) {119 if (n == 0) {120 return goog.i18n.pluralRules.Keyword.ZERO;121 }122 if (n % 10 == 1 && n % 100 != 11) {123 return goog.i18n.pluralRules.Keyword.ONE;124 }125 return goog.i18n.pluralRules.Keyword.OTHER;126};127/**128 * Plural select rules for iu locale129 *130 * @param {number} n The count of items.131 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.132 * @private133 */134goog.i18n.pluralRules.iuSelect_ = function(n) {135 if (n == 1) {136 return goog.i18n.pluralRules.Keyword.ONE;137 }138 if (n == 2) {139 return goog.i18n.pluralRules.Keyword.TWO;140 }141 return goog.i18n.pluralRules.Keyword.OTHER;142};143/**144 * Plural select rules for ga locale145 *146 * @param {number} n The count of items.147 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.148 * @private149 */150goog.i18n.pluralRules.gaSelect_ = function(n) {151 if (n == 1) {152 return goog.i18n.pluralRules.Keyword.ONE;153 }154 if (n == 2) {155 return goog.i18n.pluralRules.Keyword.TWO;156 }157 if (n == (n | 0) && n >= 3 && n <= 6) {158 return goog.i18n.pluralRules.Keyword.FEW;159 }160 if (n == (n | 0) && n >= 7 && n <= 10) {161 return goog.i18n.pluralRules.Keyword.MANY;162 }163 return goog.i18n.pluralRules.Keyword.OTHER;164};165/**166 * Plural select rules for ro locale167 *168 * @param {number} n The count of items.169 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.170 * @private171 */172goog.i18n.pluralRules.roSelect_ = function(n) {173 if (n == 1) {174 return goog.i18n.pluralRules.Keyword.ONE;175 }176 if (n == 0 || n != 1 && n == (n | 0) && n % 100 >= 1 && n % 100 <= 19) {177 return goog.i18n.pluralRules.Keyword.FEW;178 }179 return goog.i18n.pluralRules.Keyword.OTHER;180};181/**182 * Plural select rules for lt locale183 *184 * @param {number} n The count of items.185 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.186 * @private187 */188goog.i18n.pluralRules.ltSelect_ = function(n) {189 if (n % 10 == 1 && (n % 100 < 11 || n % 100 > 19)) {190 return goog.i18n.pluralRules.Keyword.ONE;191 }192 if (n == (n | 0) && n % 10 >= 2 && n % 10 <= 9 && (n % 100 < 11 || n % 100 > 19)) {193 return goog.i18n.pluralRules.Keyword.FEW;194 }195 return goog.i18n.pluralRules.Keyword.OTHER;196};197/**198 * Plural select rules for be locale199 *200 * @param {number} n The count of items.201 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.202 * @private203 */204goog.i18n.pluralRules.beSelect_ = function(n) {205 if (n % 10 == 1 && n % 100 != 11) {206 return goog.i18n.pluralRules.Keyword.ONE;207 }208 if (n == (n | 0) && n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) {209 return goog.i18n.pluralRules.Keyword.FEW;210 }211 if (n % 10 == 0 || n == (n | 0) && n % 10 >= 5 && n % 10 <= 9 || n == (n | 0) && n % 100 >= 11 && n % 100 <= 14) {212 return goog.i18n.pluralRules.Keyword.MANY;213 }214 return goog.i18n.pluralRules.Keyword.OTHER;215};216/**217 * Plural select rules for cs locale218 *219 * @param {number} n The count of items.220 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.221 * @private222 */223goog.i18n.pluralRules.csSelect_ = function(n) {224 if (n == 1) {225 return goog.i18n.pluralRules.Keyword.ONE;226 }227 if (n == (n | 0) && n >= 2 && n <= 4) {228 return goog.i18n.pluralRules.Keyword.FEW;229 }230 return goog.i18n.pluralRules.Keyword.OTHER;231};232/**233 * Plural select rules for pl locale234 *235 * @param {number} n The count of items.236 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.237 * @private238 */239goog.i18n.pluralRules.plSelect_ = function(n) {240 if (n == 1) {241 return goog.i18n.pluralRules.Keyword.ONE;242 }243 if (n == (n | 0) && n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) {244 return goog.i18n.pluralRules.Keyword.FEW;245 }246 if (n != 1 && (n % 10 == 0 || n % 10 == 1) || n == (n | 0) && n % 10 >= 5 && n % 10 <= 9 || n == (n | 0) && n % 100 >= 12 && n % 100 <= 14) {247 return goog.i18n.pluralRules.Keyword.MANY;248 }249 return goog.i18n.pluralRules.Keyword.OTHER;250};251/**252 * Plural select rules for sl locale253 *254 * @param {number} n The count of items.255 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.256 * @private257 */258goog.i18n.pluralRules.slSelect_ = function(n) {259 if (n % 100 == 1) {260 return goog.i18n.pluralRules.Keyword.ONE;261 }262 if (n % 100 == 2) {263 return goog.i18n.pluralRules.Keyword.TWO;264 }265 if (n % 100 == 3 || n % 100 == 4) {266 return goog.i18n.pluralRules.Keyword.FEW;267 }268 return goog.i18n.pluralRules.Keyword.OTHER;269};270/**271 * Plural select rules for mt locale272 *273 * @param {number} n The count of items.274 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.275 * @private276 */277goog.i18n.pluralRules.mtSelect_ = function(n) {278 if (n == 1) {279 return goog.i18n.pluralRules.Keyword.ONE;280 }281 if (n == 0 || n == (n | 0) && n % 100 >= 2 && n % 100 <= 10) {282 return goog.i18n.pluralRules.Keyword.FEW;283 }284 if (n == (n | 0) && n % 100 >= 11 && n % 100 <= 19) {285 return goog.i18n.pluralRules.Keyword.MANY;286 }287 return goog.i18n.pluralRules.Keyword.OTHER;288};289/**290 * Plural select rules for mk locale291 *292 * @param {number} n The count of items.293 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.294 * @private295 */296goog.i18n.pluralRules.mkSelect_ = function(n) {297 if (n % 10 == 1 && n != 11) {298 return goog.i18n.pluralRules.Keyword.ONE;299 }300 return goog.i18n.pluralRules.Keyword.OTHER;301};302/**303 * Plural select rules for cy locale304 *305 * @param {number} n The count of items.306 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.307 * @private308 */309goog.i18n.pluralRules.cySelect_ = function(n) {310 if (n == 0) {311 return goog.i18n.pluralRules.Keyword.ZERO;312 }313 if (n == 1) {314 return goog.i18n.pluralRules.Keyword.ONE;315 }316 if (n == 2) {317 return goog.i18n.pluralRules.Keyword.TWO;318 }319 if (n == 3) {320 return goog.i18n.pluralRules.Keyword.FEW;321 }322 if (n == 6) {323 return goog.i18n.pluralRules.Keyword.MANY;324 }325 return goog.i18n.pluralRules.Keyword.OTHER;326};327/**328 * Plural select rules for lag locale329 *330 * @param {number} n The count of items.331 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.332 * @private333 */334goog.i18n.pluralRules.lagSelect_ = function(n) {335 if (n == 0) {336 return goog.i18n.pluralRules.Keyword.ZERO;337 }338 if (n >= 0 && n <= 2 && n != 0 && n != 2) {339 return goog.i18n.pluralRules.Keyword.ONE;340 }341 return goog.i18n.pluralRules.Keyword.OTHER;342};343/**344 * Plural select rules for shi locale345 *346 * @param {number} n The count of items.347 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.348 * @private349 */350goog.i18n.pluralRules.shiSelect_ = function(n) {351 if (n >= 0 && n <= 1) {352 return goog.i18n.pluralRules.Keyword.ONE;353 }354 if (n == (n | 0) && n >= 2 && n <= 10) {355 return goog.i18n.pluralRules.Keyword.FEW;356 }357 return goog.i18n.pluralRules.Keyword.OTHER;358};359/**360 * Plural select rules for br locale361 *362 * @param {number} n The count of items.363 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.364 * @private365 */366goog.i18n.pluralRules.brSelect_ = function(n) {367 if (n % 10 == 1 && n % 100 != 11 && n % 100 != 71 && n % 100 != 91) {368 return goog.i18n.pluralRules.Keyword.ONE;369 }370 if (n % 10 == 2 && n % 100 != 12 && n % 100 != 72 && n % 100 != 92) {371 return goog.i18n.pluralRules.Keyword.TWO;372 }373 if ((n % 10 == 3 || n % 10 == 4 || n % 10 == 9) && ((n % 100 < 10 || n % 100 > 19) && (n % 100 < 70 || n % 100 > 79) && (n % 100 < 90 || n % 100 > 99))) {374 return goog.i18n.pluralRules.Keyword.FEW;375 }376 if (n % 1000000 == 0 && n != 0) {377 return goog.i18n.pluralRules.Keyword.MANY;378 }379 return goog.i18n.pluralRules.Keyword.OTHER;380};381/**382 * Plural select rules for ksh locale383 *384 * @param {number} n The count of items.385 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.386 * @private387 */388goog.i18n.pluralRules.kshSelect_ = function(n) {389 if (n == 0) {390 return goog.i18n.pluralRules.Keyword.ZERO;391 }392 if (n == 1) {393 return goog.i18n.pluralRules.Keyword.ONE;394 }395 return goog.i18n.pluralRules.Keyword.OTHER;396};397/**398 * Plural select rules for tzm locale399 *400 * @param {number} n The count of items.401 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.402 * @private403 */404goog.i18n.pluralRules.tzmSelect_ = function(n) {405 if (n == 0 || n == 1 || n == (n | 0) && n >= 11 && n <= 99) {406 return goog.i18n.pluralRules.Keyword.ONE;407 }408 return goog.i18n.pluralRules.Keyword.OTHER;409};410/**411 * Plural select rules for gv locale412 *413 * @param {number} n The count of items.414 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.415 * @private416 */417goog.i18n.pluralRules.gvSelect_ = function(n) {418 if (n % 10 == 1 || n % 10 == 2 || n % 20 == 0) {419 return goog.i18n.pluralRules.Keyword.ONE;420 }421 return goog.i18n.pluralRules.Keyword.OTHER;422};423/**424 * Plural select rules for gd locale425 *426 * @param {number} n The count of items.427 * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value.428 * @private429 */430goog.i18n.pluralRules.gdSelect_ = function(n) {431 if (n == 1 || n == 11) {432 return goog.i18n.pluralRules.Keyword.ONE;433 }434 if (n == 2 || n == 12) {435 return goog.i18n.pluralRules.Keyword.TWO;436 }437 if (n == (n | 0) && (n >= 3 && n <= 10 || n >= 13 && n <= 19)) {438 return goog.i18n.pluralRules.Keyword.FEW;439 }440 return goog.i18n.pluralRules.Keyword.OTHER;441};442/**443 * Selected plural rules by locale.444 */445goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;446if (goog.LOCALE == 'am') {447 goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_;448}449if (goog.LOCALE == 'ar') {450 goog.i18n.pluralRules.select = goog.i18n.pluralRules.arSelect_;451}452if (goog.LOCALE == 'bg') {453 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;454}455if (goog.LOCALE == 'bn') {456 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;457}458if (goog.LOCALE == 'br') {459 goog.i18n.pluralRules.select = goog.i18n.pluralRules.brSelect_;460}461if (goog.LOCALE == 'ca') {462 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;463}464if (goog.LOCALE == 'cs') {465 goog.i18n.pluralRules.select = goog.i18n.pluralRules.csSelect_;466}467if (goog.LOCALE == 'da') {468 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;469}470if (goog.LOCALE == 'de') {471 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;472}473if (goog.LOCALE == 'de_AT' || goog.LOCALE == 'de-AT') {474 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;475}476if (goog.LOCALE == 'de_CH' || goog.LOCALE == 'de-CH') {477 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;478}479if (goog.LOCALE == 'el') {480 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;481}482if (goog.LOCALE == 'en') {483 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;484}485if (goog.LOCALE == 'en_AU' || goog.LOCALE == 'en-AU') {486 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;487}488if (goog.LOCALE == 'en_GB' || goog.LOCALE == 'en-GB') {489 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;490}491if (goog.LOCALE == 'en_IE' || goog.LOCALE == 'en-IE') {492 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;493}494if (goog.LOCALE == 'en_IN' || goog.LOCALE == 'en-IN') {495 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;496}497if (goog.LOCALE == 'en_SG' || goog.LOCALE == 'en-SG') {498 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;499}500if (goog.LOCALE == 'en_US' || goog.LOCALE == 'en-US') {501 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;502}503if (goog.LOCALE == 'en_ZA' || goog.LOCALE == 'en-ZA') {504 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;505}506if (goog.LOCALE == 'es') {507 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;508}509if (goog.LOCALE == 'et') {510 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;511}512if (goog.LOCALE == 'eu') {513 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;514}515if (goog.LOCALE == 'fa') {516 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;517}518if (goog.LOCALE == 'fi') {519 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;520}521if (goog.LOCALE == 'fil') {522 goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_;523}524if (goog.LOCALE == 'fr') {525 goog.i18n.pluralRules.select = goog.i18n.pluralRules.frSelect_;526}527if (goog.LOCALE == 'fr_CA' || goog.LOCALE == 'fr-CA') {528 goog.i18n.pluralRules.select = goog.i18n.pluralRules.frSelect_;529}530if (goog.LOCALE == 'gl') {531 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;532}533if (goog.LOCALE == 'gsw') {534 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;535}536if (goog.LOCALE == 'gu') {537 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;538}539if (goog.LOCALE == 'he') {540 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;541}542if (goog.LOCALE == 'hi') {543 goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_;544}545if (goog.LOCALE == 'hr') {546 goog.i18n.pluralRules.select = goog.i18n.pluralRules.beSelect_;547}548if (goog.LOCALE == 'hu') {549 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;550}551if (goog.LOCALE == 'id') {552 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;553}554if (goog.LOCALE == 'in') {555 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;556}557if (goog.LOCALE == 'is') {558 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;559}560if (goog.LOCALE == 'it') {561 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;562}563if (goog.LOCALE == 'iw') {564 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;565}566if (goog.LOCALE == 'ja') {567 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;568}569if (goog.LOCALE == 'kn') {570 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;571}572if (goog.LOCALE == 'ko') {573 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;574}575if (goog.LOCALE == 'ln') {576 goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_;577}578if (goog.LOCALE == 'lt') {579 goog.i18n.pluralRules.select = goog.i18n.pluralRules.ltSelect_;580}581if (goog.LOCALE == 'lv') {582 goog.i18n.pluralRules.select = goog.i18n.pluralRules.lvSelect_;583}584if (goog.LOCALE == 'ml') {585 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;586}587if (goog.LOCALE == 'mr') {588 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;589}590if (goog.LOCALE == 'ms') {591 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;592}593if (goog.LOCALE == 'mt') {594 goog.i18n.pluralRules.select = goog.i18n.pluralRules.mtSelect_;595}596if (goog.LOCALE == 'nl') {597 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;598}599if (goog.LOCALE == 'no') {600 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;601}602if (goog.LOCALE == 'or') {603 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;604}605if (goog.LOCALE == 'pl') {606 goog.i18n.pluralRules.select = goog.i18n.pluralRules.plSelect_;607}608if (goog.LOCALE == 'pt') {609 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;610}611if (goog.LOCALE == 'pt_BR' || goog.LOCALE == 'pt-BR') {612 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;613}614if (goog.LOCALE == 'pt_PT' || goog.LOCALE == 'pt-PT') {615 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;616}617if (goog.LOCALE == 'ro') {618 goog.i18n.pluralRules.select = goog.i18n.pluralRules.roSelect_;619}620if (goog.LOCALE == 'ru') {621 goog.i18n.pluralRules.select = goog.i18n.pluralRules.beSelect_;622}623if (goog.LOCALE == 'sk') {624 goog.i18n.pluralRules.select = goog.i18n.pluralRules.csSelect_;625}626if (goog.LOCALE == 'sl') {627 goog.i18n.pluralRules.select = goog.i18n.pluralRules.slSelect_;628}629if (goog.LOCALE == 'sq') {630 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;631}632if (goog.LOCALE == 'sr') {633 goog.i18n.pluralRules.select = goog.i18n.pluralRules.beSelect_;634}635if (goog.LOCALE == 'sv') {636 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;637}638if (goog.LOCALE == 'sw') {639 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;640}641if (goog.LOCALE == 'ta') {642 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;643}644if (goog.LOCALE == 'te') {645 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;646}647if (goog.LOCALE == 'th') {648 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;649}650if (goog.LOCALE == 'tl') {651 goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_;652}653if (goog.LOCALE == 'tr') {654 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;655}656if (goog.LOCALE == 'uk') {657 goog.i18n.pluralRules.select = goog.i18n.pluralRules.beSelect_;658}659if (goog.LOCALE == 'ur') {660 goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_;661}662if (goog.LOCALE == 'vi') {663 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;664}665if (goog.LOCALE == 'zh') {666 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;667}668if (goog.LOCALE == 'zh_CN' || goog.LOCALE == 'zh-CN') {669 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;670}671if (goog.LOCALE == 'zh_HK' || goog.LOCALE == 'zh-HK') {672 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;673}674if (goog.LOCALE == 'zh_TW' || goog.LOCALE == 'zh-TW') {675 goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_;...

Full Screen

Full Screen

built-in-rules-index.js

Source:built-in-rules-index.js Github

copy

Full Screen

1/**2 * @fileoverview Collects the built-in rules into a map structure so that they can be imported all at once and without3 * using the file-system directly.4 * @author Peter (Somogyvari) Metz5 */6"use strict";7/* eslint sort-keys: ["error", "asc"] */8module.exports = {9 "accessor-pairs": require("./rules/accessor-pairs"),10 "array-bracket-newline": require("./rules/array-bracket-newline"),11 "array-bracket-spacing": require("./rules/array-bracket-spacing"),12 "array-callback-return": require("./rules/array-callback-return"),13 "array-element-newline": require("./rules/array-element-newline"),14 "arrow-body-style": require("./rules/arrow-body-style"),15 "arrow-parens": require("./rules/arrow-parens"),16 "arrow-spacing": require("./rules/arrow-spacing"),17 "block-scoped-var": require("./rules/block-scoped-var"),18 "block-spacing": require("./rules/block-spacing"),19 "brace-style": require("./rules/brace-style"),20 "callback-return": require("./rules/callback-return"),21 camelcase: require("./rules/camelcase"),22 "capitalized-comments": require("./rules/capitalized-comments"),23 "class-methods-use-this": require("./rules/class-methods-use-this"),24 "comma-dangle": require("./rules/comma-dangle"),25 "comma-spacing": require("./rules/comma-spacing"),26 "comma-style": require("./rules/comma-style"),27 complexity: require("./rules/complexity"),28 "computed-property-spacing": require("./rules/computed-property-spacing"),29 "consistent-return": require("./rules/consistent-return"),30 "consistent-this": require("./rules/consistent-this"),31 "constructor-super": require("./rules/constructor-super"),32 curly: require("./rules/curly"),33 "default-case": require("./rules/default-case"),34 "dot-location": require("./rules/dot-location"),35 "dot-notation": require("./rules/dot-notation"),36 "eol-last": require("./rules/eol-last"),37 eqeqeq: require("./rules/eqeqeq"),38 "for-direction": require("./rules/for-direction"),39 "func-call-spacing": require("./rules/func-call-spacing"),40 "func-name-matching": require("./rules/func-name-matching"),41 "func-names": require("./rules/func-names"),42 "func-style": require("./rules/func-style"),43 "function-paren-newline": require("./rules/function-paren-newline"),44 "generator-star-spacing": require("./rules/generator-star-spacing"),45 "getter-return": require("./rules/getter-return"),46 "global-require": require("./rules/global-require"),47 "guard-for-in": require("./rules/guard-for-in"),48 "handle-callback-err": require("./rules/handle-callback-err"),49 "id-blacklist": require("./rules/id-blacklist"),50 "id-length": require("./rules/id-length"),51 "id-match": require("./rules/id-match"),52 "implicit-arrow-linebreak": require("./rules/implicit-arrow-linebreak"),53 indent: require("./rules/indent"),54 "indent-legacy": require("./rules/indent-legacy"),55 "init-declarations": require("./rules/init-declarations"),56 "jsx-quotes": require("./rules/jsx-quotes"),57 "key-spacing": require("./rules/key-spacing"),58 "keyword-spacing": require("./rules/keyword-spacing"),59 "line-comment-position": require("./rules/line-comment-position"),60 "linebreak-style": require("./rules/linebreak-style"),61 "lines-around-comment": require("./rules/lines-around-comment"),62 "lines-around-directive": require("./rules/lines-around-directive"),63 "lines-between-class-members": require("./rules/lines-between-class-members"),64 "max-classes-per-file": require("./rules/max-classes-per-file"),65 "max-depth": require("./rules/max-depth"),66 "max-len": require("./rules/max-len"),67 "max-lines": require("./rules/max-lines"),68 "max-lines-per-function": require("./rules/max-lines-per-function"),69 "max-nested-callbacks": require("./rules/max-nested-callbacks"),70 "max-params": require("./rules/max-params"),71 "max-statements": require("./rules/max-statements"),72 "max-statements-per-line": require("./rules/max-statements-per-line"),73 "multiline-comment-style": require("./rules/multiline-comment-style"),74 "multiline-ternary": require("./rules/multiline-ternary"),75 "new-cap": require("./rules/new-cap"),76 "new-parens": require("./rules/new-parens"),77 "newline-after-var": require("./rules/newline-after-var"),78 "newline-before-return": require("./rules/newline-before-return"),79 "newline-per-chained-call": require("./rules/newline-per-chained-call"),80 "no-alert": require("./rules/no-alert"),81 "no-array-constructor": require("./rules/no-array-constructor"),82 "no-async-promise-executor": require("./rules/no-async-promise-executor"),83 "no-await-in-loop": require("./rules/no-await-in-loop"),84 "no-bitwise": require("./rules/no-bitwise"),85 "no-buffer-constructor": require("./rules/no-buffer-constructor"),86 "no-caller": require("./rules/no-caller"),87 "no-case-declarations": require("./rules/no-case-declarations"),88 "no-catch-shadow": require("./rules/no-catch-shadow"),89 "no-class-assign": require("./rules/no-class-assign"),90 "no-compare-neg-zero": require("./rules/no-compare-neg-zero"),91 "no-cond-assign": require("./rules/no-cond-assign"),92 "no-confusing-arrow": require("./rules/no-confusing-arrow"),93 "no-console": require("./rules/no-console"),94 "no-const-assign": require("./rules/no-const-assign"),95 "no-constant-condition": require("./rules/no-constant-condition"),96 "no-continue": require("./rules/no-continue"),97 "no-control-regex": require("./rules/no-control-regex"),98 "no-debugger": require("./rules/no-debugger"),99 "no-delete-var": require("./rules/no-delete-var"),100 "no-div-regex": require("./rules/no-div-regex"),101 "no-dupe-args": require("./rules/no-dupe-args"),102 "no-dupe-class-members": require("./rules/no-dupe-class-members"),103 "no-dupe-keys": require("./rules/no-dupe-keys"),104 "no-duplicate-case": require("./rules/no-duplicate-case"),105 "no-duplicate-imports": require("./rules/no-duplicate-imports"),106 "no-else-return": require("./rules/no-else-return"),107 "no-empty": require("./rules/no-empty"),108 "no-empty-character-class": require("./rules/no-empty-character-class"),109 "no-empty-function": require("./rules/no-empty-function"),110 "no-empty-pattern": require("./rules/no-empty-pattern"),111 "no-eq-null": require("./rules/no-eq-null"),112 "no-eval": require("./rules/no-eval"),113 "no-ex-assign": require("./rules/no-ex-assign"),114 "no-extend-native": require("./rules/no-extend-native"),115 "no-extra-bind": require("./rules/no-extra-bind"),116 "no-extra-boolean-cast": require("./rules/no-extra-boolean-cast"),117 "no-extra-label": require("./rules/no-extra-label"),118 "no-extra-parens": require("./rules/no-extra-parens"),119 "no-extra-semi": require("./rules/no-extra-semi"),120 "no-fallthrough": require("./rules/no-fallthrough"),121 "no-floating-decimal": require("./rules/no-floating-decimal"),122 "no-func-assign": require("./rules/no-func-assign"),123 "no-global-assign": require("./rules/no-global-assign"),124 "no-implicit-coercion": require("./rules/no-implicit-coercion"),125 "no-implicit-globals": require("./rules/no-implicit-globals"),126 "no-implied-eval": require("./rules/no-implied-eval"),127 "no-inline-comments": require("./rules/no-inline-comments"),128 "no-inner-declarations": require("./rules/no-inner-declarations"),129 "no-invalid-regexp": require("./rules/no-invalid-regexp"),130 "no-invalid-this": require("./rules/no-invalid-this"),131 "no-irregular-whitespace": require("./rules/no-irregular-whitespace"),132 "no-iterator": require("./rules/no-iterator"),133 "no-label-var": require("./rules/no-label-var"),134 "no-labels": require("./rules/no-labels"),135 "no-lone-blocks": require("./rules/no-lone-blocks"),136 "no-lonely-if": require("./rules/no-lonely-if"),137 "no-loop-func": require("./rules/no-loop-func"),138 "no-magic-numbers": require("./rules/no-magic-numbers"),139 "no-misleading-character-class": require("./rules/no-misleading-character-class"),140 "no-mixed-operators": require("./rules/no-mixed-operators"),141 "no-mixed-requires": require("./rules/no-mixed-requires"),142 "no-mixed-spaces-and-tabs": require("./rules/no-mixed-spaces-and-tabs"),143 "no-multi-assign": require("./rules/no-multi-assign"),144 "no-multi-spaces": require("./rules/no-multi-spaces"),145 "no-multi-str": require("./rules/no-multi-str"),146 "no-multiple-empty-lines": require("./rules/no-multiple-empty-lines"),147 "no-native-reassign": require("./rules/no-native-reassign"),148 "no-negated-condition": require("./rules/no-negated-condition"),149 "no-negated-in-lhs": require("./rules/no-negated-in-lhs"),150 "no-nested-ternary": require("./rules/no-nested-ternary"),151 "no-new": require("./rules/no-new"),152 "no-new-func": require("./rules/no-new-func"),153 "no-new-object": require("./rules/no-new-object"),154 "no-new-require": require("./rules/no-new-require"),155 "no-new-symbol": require("./rules/no-new-symbol"),156 "no-new-wrappers": require("./rules/no-new-wrappers"),157 "no-obj-calls": require("./rules/no-obj-calls"),158 "no-octal": require("./rules/no-octal"),159 "no-octal-escape": require("./rules/no-octal-escape"),160 "no-param-reassign": require("./rules/no-param-reassign"),161 "no-path-concat": require("./rules/no-path-concat"),162 "no-plusplus": require("./rules/no-plusplus"),163 "no-process-env": require("./rules/no-process-env"),164 "no-process-exit": require("./rules/no-process-exit"),165 "no-proto": require("./rules/no-proto"),166 "no-prototype-builtins": require("./rules/no-prototype-builtins"),167 "no-redeclare": require("./rules/no-redeclare"),168 "no-regex-spaces": require("./rules/no-regex-spaces"),169 "no-restricted-globals": require("./rules/no-restricted-globals"),170 "no-restricted-imports": require("./rules/no-restricted-imports"),171 "no-restricted-modules": require("./rules/no-restricted-modules"),172 "no-restricted-properties": require("./rules/no-restricted-properties"),173 "no-restricted-syntax": require("./rules/no-restricted-syntax"),174 "no-return-assign": require("./rules/no-return-assign"),175 "no-return-await": require("./rules/no-return-await"),176 "no-script-url": require("./rules/no-script-url"),177 "no-self-assign": require("./rules/no-self-assign"),178 "no-self-compare": require("./rules/no-self-compare"),179 "no-sequences": require("./rules/no-sequences"),180 "no-shadow": require("./rules/no-shadow"),181 "no-shadow-restricted-names": require("./rules/no-shadow-restricted-names"),182 "no-spaced-func": require("./rules/no-spaced-func"),183 "no-sparse-arrays": require("./rules/no-sparse-arrays"),184 "no-sync": require("./rules/no-sync"),185 "no-tabs": require("./rules/no-tabs"),186 "no-template-curly-in-string": require("./rules/no-template-curly-in-string"),187 "no-ternary": require("./rules/no-ternary"),188 "no-this-before-super": require("./rules/no-this-before-super"),189 "no-throw-literal": require("./rules/no-throw-literal"),190 "no-trailing-spaces": require("./rules/no-trailing-spaces"),191 "no-undef": require("./rules/no-undef"),192 "no-undef-init": require("./rules/no-undef-init"),193 "no-undefined": require("./rules/no-undefined"),194 "no-underscore-dangle": require("./rules/no-underscore-dangle"),195 "no-unexpected-multiline": require("./rules/no-unexpected-multiline"),196 "no-unmodified-loop-condition": require("./rules/no-unmodified-loop-condition"),197 "no-unneeded-ternary": require("./rules/no-unneeded-ternary"),198 "no-unreachable": require("./rules/no-unreachable"),199 "no-unsafe-finally": require("./rules/no-unsafe-finally"),200 "no-unsafe-negation": require("./rules/no-unsafe-negation"),201 "no-unused-expressions": require("./rules/no-unused-expressions"),202 "no-unused-labels": require("./rules/no-unused-labels"),203 "no-unused-vars": require("./rules/no-unused-vars"),204 "no-use-before-define": require("./rules/no-use-before-define"),205 "no-useless-call": require("./rules/no-useless-call"),206 "no-useless-catch": require("./rules/no-useless-catch"),207 "no-useless-computed-key": require("./rules/no-useless-computed-key"),208 "no-useless-concat": require("./rules/no-useless-concat"),209 "no-useless-constructor": require("./rules/no-useless-constructor"),210 "no-useless-escape": require("./rules/no-useless-escape"),211 "no-useless-rename": require("./rules/no-useless-rename"),212 "no-useless-return": require("./rules/no-useless-return"),213 "no-var": require("./rules/no-var"),214 "no-void": require("./rules/no-void"),215 "no-warning-comments": require("./rules/no-warning-comments"),216 "no-whitespace-before-property": require("./rules/no-whitespace-before-property"),217 "no-with": require("./rules/no-with"),218 "nonblock-statement-body-position": require("./rules/nonblock-statement-body-position"),219 "object-curly-newline": require("./rules/object-curly-newline"),220 "object-curly-spacing": require("./rules/object-curly-spacing"),221 "object-property-newline": require("./rules/object-property-newline"),222 "object-shorthand": require("./rules/object-shorthand"),223 "one-var": require("./rules/one-var"),224 "one-var-declaration-per-line": require("./rules/one-var-declaration-per-line"),225 "operator-assignment": require("./rules/operator-assignment"),226 "operator-linebreak": require("./rules/operator-linebreak"),227 "padded-blocks": require("./rules/padded-blocks"),228 "padding-line-between-statements": require("./rules/padding-line-between-statements"),229 "prefer-arrow-callback": require("./rules/prefer-arrow-callback"),230 "prefer-const": require("./rules/prefer-const"),231 "prefer-destructuring": require("./rules/prefer-destructuring"),232 "prefer-named-capture-group": require("./rules/prefer-named-capture-group"),233 "prefer-numeric-literals": require("./rules/prefer-numeric-literals"),234 "prefer-object-spread": require("./rules/prefer-object-spread"),235 "prefer-promise-reject-errors": require("./rules/prefer-promise-reject-errors"),236 "prefer-reflect": require("./rules/prefer-reflect"),237 "prefer-rest-params": require("./rules/prefer-rest-params"),238 "prefer-spread": require("./rules/prefer-spread"),239 "prefer-template": require("./rules/prefer-template"),240 "quote-props": require("./rules/quote-props"),241 quotes: require("./rules/quotes"),242 radix: require("./rules/radix"),243 "require-atomic-updates": require("./rules/require-atomic-updates"),244 "require-await": require("./rules/require-await"),245 "require-jsdoc": require("./rules/require-jsdoc"),246 "require-unicode-regexp": require("./rules/require-unicode-regexp"),247 "require-yield": require("./rules/require-yield"),248 "rest-spread-spacing": require("./rules/rest-spread-spacing"),249 semi: require("./rules/semi"),250 "semi-spacing": require("./rules/semi-spacing"),251 "semi-style": require("./rules/semi-style"),252 "sort-imports": require("./rules/sort-imports"),253 "sort-keys": require("./rules/sort-keys"),254 "sort-vars": require("./rules/sort-vars"),255 "space-before-blocks": require("./rules/space-before-blocks"),256 "space-before-function-paren": require("./rules/space-before-function-paren"),257 "space-in-parens": require("./rules/space-in-parens"),258 "space-infix-ops": require("./rules/space-infix-ops"),259 "space-unary-ops": require("./rules/space-unary-ops"),260 "spaced-comment": require("./rules/spaced-comment"),261 strict: require("./rules/strict"),262 "switch-colon-spacing": require("./rules/switch-colon-spacing"),263 "symbol-description": require("./rules/symbol-description"),264 "template-curly-spacing": require("./rules/template-curly-spacing"),265 "template-tag-spacing": require("./rules/template-tag-spacing"),266 "unicode-bom": require("./rules/unicode-bom"),267 "use-isnan": require("./rules/use-isnan"),268 "valid-jsdoc": require("./rules/valid-jsdoc"),269 "valid-typeof": require("./rules/valid-typeof"),270 "vars-on-top": require("./rules/vars-on-top"),271 "wrap-iife": require("./rules/wrap-iife"),272 "wrap-regex": require("./rules/wrap-regex"),273 "yield-star-spacing": require("./rules/yield-star-spacing"),274 yoda: require("./rules/yoda")...

Full Screen

Full Screen

ordinalrules.js

Source:ordinalrules.js Github

copy

Full Screen

1// Copyright 2012 The Closure Library Authors. All Rights Reserved2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS, WITHOUT11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12// License for the specific language governing permissions and limitations under13// the License.14/**15 * @fileoverview Ordinal rules.16 *17 * This file is autogenerated by script:18 * http://go/generate_pluralrules.py19 *20 * Before check in, this file could have been manually edited. This is to21 * incorporate changes before we could fix CLDR. All manual modification must be22 * documented in this section, and should be removed after those changes land to23 * CLDR.24 */25goog.provide('goog.i18n.ordinalRules');26/**27 * Ordinal pattern keyword28 * @enum {string}29 */30goog.i18n.ordinalRules.Keyword = {31 ZERO: 'zero',32 ONE: 'one',33 TWO: 'two',34 FEW: 'few',35 MANY: 'many',36 OTHER: 'other'37};38/**39 * Default ordinal select rule.40 * @param {number} n The count of items.41 * @return {goog.i18n.ordinalRules.Keyword} Default value.42 * @private43 */44goog.i18n.ordinalRules.defaultSelect_ = function(n) {45 return goog.i18n.ordinalRules.Keyword.OTHER;46};47/**48 * Ordinal select rules for fr locale49 *50 * @param {number} n The count of items.51 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.52 * @private53 */54goog.i18n.ordinalRules.frSelect_ = function(n) {55 if (n == 1) {56 return goog.i18n.ordinalRules.Keyword.ONE;57 }58 return goog.i18n.ordinalRules.Keyword.OTHER;59};60/**61 * Ordinal select rules for hu locale62 *63 * @param {number} n The count of items.64 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.65 * @private66 */67goog.i18n.ordinalRules.huSelect_ = function(n) {68 if (n == 1 || n == 5) {69 return goog.i18n.ordinalRules.Keyword.ONE;70 }71 return goog.i18n.ordinalRules.Keyword.OTHER;72};73/**74 * Ordinal select rules for sv locale75 *76 * @param {number} n The count of items.77 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.78 * @private79 */80goog.i18n.ordinalRules.svSelect_ = function(n) {81 if ((n % 10 == 1 || n % 10 == 2) && n % 100 != 11 && n % 100 != 12) {82 return goog.i18n.ordinalRules.Keyword.ONE;83 }84 return goog.i18n.ordinalRules.Keyword.OTHER;85};86/**87 * Ordinal select rules for en locale88 *89 * @param {number} n The count of items.90 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.91 * @private92 */93goog.i18n.ordinalRules.enSelect_ = function(n) {94 if (n % 10 == 1 && n % 100 != 11) {95 return goog.i18n.ordinalRules.Keyword.ONE;96 }97 if (n % 10 == 2 && n % 100 != 12) {98 return goog.i18n.ordinalRules.Keyword.TWO;99 }100 if (n % 10 == 3 && n % 100 != 13) {101 return goog.i18n.ordinalRules.Keyword.FEW;102 }103 return goog.i18n.ordinalRules.Keyword.OTHER;104};105/**106 * Ordinal select rules for it locale107 *108 * @param {number} n The count of items.109 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.110 * @private111 */112goog.i18n.ordinalRules.itSelect_ = function(n) {113 if (n == 11 || n == 8 || n == 80 || n == 800) {114 return goog.i18n.ordinalRules.Keyword.MANY;115 }116 return goog.i18n.ordinalRules.Keyword.OTHER;117};118/**119 * Ordinal select rules for ca locale120 *121 * @param {number} n The count of items.122 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.123 * @private124 */125goog.i18n.ordinalRules.caSelect_ = function(n) {126 if (n == 1 || n == 3) {127 return goog.i18n.ordinalRules.Keyword.ONE;128 }129 if (n == 2) {130 return goog.i18n.ordinalRules.Keyword.TWO;131 }132 if (n == 4) {133 return goog.i18n.ordinalRules.Keyword.FEW;134 }135 return goog.i18n.ordinalRules.Keyword.OTHER;136};137/**138 * Ordinal select rules for mr locale139 *140 * @param {number} n The count of items.141 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.142 * @private143 */144goog.i18n.ordinalRules.mrSelect_ = function(n) {145 if (n == 1) {146 return goog.i18n.ordinalRules.Keyword.ONE;147 }148 if (n == 2 || n == 3) {149 return goog.i18n.ordinalRules.Keyword.TWO;150 }151 if (n == 4) {152 return goog.i18n.ordinalRules.Keyword.FEW;153 }154 return goog.i18n.ordinalRules.Keyword.OTHER;155};156/**157 * Ordinal select rules for gu locale158 *159 * @param {number} n The count of items.160 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.161 * @private162 */163goog.i18n.ordinalRules.guSelect_ = function(n) {164 if (n == 1) {165 return goog.i18n.ordinalRules.Keyword.ONE;166 }167 if (n == 2 || n == 3) {168 return goog.i18n.ordinalRules.Keyword.TWO;169 }170 if (n == 4) {171 return goog.i18n.ordinalRules.Keyword.FEW;172 }173 if (n == 6) {174 return goog.i18n.ordinalRules.Keyword.MANY;175 }176 return goog.i18n.ordinalRules.Keyword.OTHER;177};178/**179 * Ordinal select rules for bn locale180 *181 * @param {number} n The count of items.182 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.183 * @private184 */185goog.i18n.ordinalRules.bnSelect_ = function(n) {186 if (n == 1 || n == 5 || n == 7 || n == 8 || n == 9 || n == 10) {187 return goog.i18n.ordinalRules.Keyword.ONE;188 }189 if (n == 2 || n == 3) {190 return goog.i18n.ordinalRules.Keyword.TWO;191 }192 if (n == 4) {193 return goog.i18n.ordinalRules.Keyword.FEW;194 }195 if (n == 6) {196 return goog.i18n.ordinalRules.Keyword.MANY;197 }198 return goog.i18n.ordinalRules.Keyword.OTHER;199};200/**201 * Ordinal select rules for zu locale202 *203 * @param {number} n The count of items.204 * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value.205 * @private206 */207goog.i18n.ordinalRules.zuSelect_ = function(n) {208 if (n == 1) {209 return goog.i18n.ordinalRules.Keyword.ONE;210 }211 if (n == (n | 0) && n >= 2 && n <= 9) {212 return goog.i18n.ordinalRules.Keyword.FEW;213 }214 if (n == (n | 0) && (n >= 10 && n <= 19 || n >= 100 && n <= 199 || n >= 1000 && n <= 1999)) {215 return goog.i18n.ordinalRules.Keyword.MANY;216 }217 return goog.i18n.ordinalRules.Keyword.OTHER;218};219/**220 * Selected ordinal rules by locale.221 */222goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;223if (goog.LOCALE == 'am') {224 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;225}226if (goog.LOCALE == 'ar') {227 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;228}229if (goog.LOCALE == 'bg') {230 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;231}232if (goog.LOCALE == 'bn') {233 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.bnSelect_;234}235if (goog.LOCALE == 'br') {236 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;237}238if (goog.LOCALE == 'ca') {239 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.caSelect_;240}241if (goog.LOCALE == 'cs') {242 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;243}244if (goog.LOCALE == 'da') {245 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;246}247if (goog.LOCALE == 'de') {248 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;249}250if (goog.LOCALE == 'de_AT' || goog.LOCALE == 'de-AT') {251 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;252}253if (goog.LOCALE == 'de_CH' || goog.LOCALE == 'de-CH') {254 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;255}256if (goog.LOCALE == 'el') {257 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;258}259if (goog.LOCALE == 'en') {260 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;261}262if (goog.LOCALE == 'en_AU' || goog.LOCALE == 'en-AU') {263 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;264}265if (goog.LOCALE == 'en_GB' || goog.LOCALE == 'en-GB') {266 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;267}268if (goog.LOCALE == 'en_IE' || goog.LOCALE == 'en-IE') {269 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;270}271if (goog.LOCALE == 'en_IN' || goog.LOCALE == 'en-IN') {272 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;273}274if (goog.LOCALE == 'en_SG' || goog.LOCALE == 'en-SG') {275 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;276}277if (goog.LOCALE == 'en_US' || goog.LOCALE == 'en-US') {278 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;279}280if (goog.LOCALE == 'en_ZA' || goog.LOCALE == 'en-ZA') {281 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_;282}283if (goog.LOCALE == 'es') {284 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;285}286if (goog.LOCALE == 'et') {287 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;288}289if (goog.LOCALE == 'eu') {290 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;291}292if (goog.LOCALE == 'fa') {293 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;294}295if (goog.LOCALE == 'fi') {296 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;297}298if (goog.LOCALE == 'fil') {299 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_;300}301if (goog.LOCALE == 'fr') {302 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_;303}304if (goog.LOCALE == 'fr_CA' || goog.LOCALE == 'fr-CA') {305 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_;306}307if (goog.LOCALE == 'gl') {308 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;309}310if (goog.LOCALE == 'gsw') {311 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;312}313if (goog.LOCALE == 'gu') {314 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.guSelect_;315}316if (goog.LOCALE == 'he') {317 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;318}319if (goog.LOCALE == 'hi') {320 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.guSelect_;321}322if (goog.LOCALE == 'hr') {323 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;324}325if (goog.LOCALE == 'hu') {326 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.huSelect_;327}328if (goog.LOCALE == 'id') {329 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;330}331if (goog.LOCALE == 'in') {332 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;333}334if (goog.LOCALE == 'is') {335 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;336}337if (goog.LOCALE == 'it') {338 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.itSelect_;339}340if (goog.LOCALE == 'iw') {341 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;342}343if (goog.LOCALE == 'ja') {344 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;345}346if (goog.LOCALE == 'kn') {347 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;348}349if (goog.LOCALE == 'ko') {350 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;351}352if (goog.LOCALE == 'ln') {353 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;354}355if (goog.LOCALE == 'lt') {356 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;357}358if (goog.LOCALE == 'lv') {359 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;360}361if (goog.LOCALE == 'ml') {362 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;363}364if (goog.LOCALE == 'mr') {365 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.mrSelect_;366}367if (goog.LOCALE == 'ms') {368 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_;369}370if (goog.LOCALE == 'mt') {371 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;372}373if (goog.LOCALE == 'nl') {374 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;375}376if (goog.LOCALE == 'no') {377 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;378}379if (goog.LOCALE == 'or') {380 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;381}382if (goog.LOCALE == 'pl') {383 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;384}385if (goog.LOCALE == 'pt') {386 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;387}388if (goog.LOCALE == 'pt_BR' || goog.LOCALE == 'pt-BR') {389 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;390}391if (goog.LOCALE == 'pt_PT' || goog.LOCALE == 'pt-PT') {392 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;393}394if (goog.LOCALE == 'ro') {395 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_;396}397if (goog.LOCALE == 'ru') {398 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;399}400if (goog.LOCALE == 'sk') {401 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;402}403if (goog.LOCALE == 'sl') {404 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;405}406if (goog.LOCALE == 'sq') {407 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;408}409if (goog.LOCALE == 'sr') {410 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;411}412if (goog.LOCALE == 'sv') {413 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.svSelect_;414}415if (goog.LOCALE == 'sw') {416 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;417}418if (goog.LOCALE == 'ta') {419 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;420}421if (goog.LOCALE == 'te') {422 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;423}424if (goog.LOCALE == 'th') {425 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;426}427if (goog.LOCALE == 'tl') {428 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;429}430if (goog.LOCALE == 'tr') {431 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;432}433if (goog.LOCALE == 'uk') {434 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;435}436if (goog.LOCALE == 'ur') {437 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;438}439if (goog.LOCALE == 'vi') {440 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_;441}442if (goog.LOCALE == 'zh') {443 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;444}445if (goog.LOCALE == 'zh_CN' || goog.LOCALE == 'zh-CN') {446 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;447}448if (goog.LOCALE == 'zh_HK' || goog.LOCALE == 'zh-HK') {449 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;450}451if (goog.LOCALE == 'zh_TW' || goog.LOCALE == 'zh-TW') {452 goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_;...

Full Screen

Full Screen

sync_prometheus_rules.py

Source:sync_prometheus_rules.py Github

copy

Full Screen

1#!/usr/bin/env python32"""Fetch alerting and aggregation rules from provided urls into this chart."""3import textwrap4from os import makedirs5import requests6import yaml7from yaml.representer import SafeRepresenter8import re9# https://stackoverflow.com/a/20863889/96109210class LiteralStr(str):11 pass12def change_style(style, representer):13 def new_representer(dumper, data):14 scalar = representer(dumper, data)15 scalar.style = style16 return scalar17 return new_representer18# Source files list19charts = [20 {21 'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/master/manifests/kubernetes-prometheusRule.yaml',22 'destination': '../templates/prometheus/rules-1.14',23 'min_kubernetes': '1.14.0-0'24 },25 {26 'source': 'https://raw.githubusercontent.com/etcd-io/website/master/content/docs/v3.4.0/op-guide/etcd3_alert.rules.yml',27 'destination': '../templates/prometheus/rules-1.14',28 'min_kubernetes': '1.14.0-0'29 },30 {31 'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/release-0.1/manifests/prometheus-rules.yaml',32 'destination': '../templates/prometheus/rules',33 'min_kubernetes': '1.10.0-0',34 'max_kubernetes': '1.14.0-0'35 },36 {37 'source': 'https://raw.githubusercontent.com/etcd-io/website/master/content/docs/v3.4.0/op-guide/etcd3_alert.rules.yml',38 'destination': '../templates/prometheus/rules',39 'min_kubernetes': '1.10.0-0',40 'max_kubernetes': '1.14.0-0'41 },42]43# Additional conditions map44condition_map = {45 'alertmanager.rules': ' .Values.defaultRules.rules.alertmanager',46 'general.rules': ' .Values.defaultRules.rules.general',47 'k8s.rules': ' .Values.defaultRules.rules.k8s',48 'kube-apiserver.rules': ' .Values.kubeApiServer.enabled .Values.defaultRules.rules.kubeApiserver',49 'kube-apiserver-availability.rules': ' .Values.kubeApiServer.enabled .Values.defaultRules.rules.kubeApiserverAvailability',50 'kube-apiserver-error': ' .Values.kubeApiServer.enabled .Values.defaultRules.rules.kubeApiserverError',51 'kube-apiserver-slos': ' .Values.kubeApiServer.enabled .Values.defaultRules.rules.kubeApiserverSlos',52 'kube-prometheus-general.rules': ' .Values.defaultRules.rules.kubePrometheusGeneral',53 'kube-prometheus-node-alerting.rules': ' .Values.defaultRules.rules.kubePrometheusNodeAlerting',54 'kube-prometheus-node-recording.rules': ' .Values.defaultRules.rules.kubePrometheusNodeRecording',55 'kube-scheduler.rules': ' .Values.kubeScheduler.enabled .Values.defaultRules.rules.kubeScheduler',56 'kube-state-metrics': ' .Values.defaultRules.rules.kubeStateMetrics',57 'kubelet.rules': ' .Values.kubelet.enabled .Values.defaultRules.rules.kubelet',58 'kubernetes-absent': ' .Values.defaultRules.rules.kubernetesAbsent',59 'kubernetes-resources': ' .Values.defaultRules.rules.kubernetesResources',60 'kubernetes-storage': ' .Values.defaultRules.rules.kubernetesStorage',61 'kubernetes-system': ' .Values.defaultRules.rules.kubernetesSystem',62 'kubernetes-system-apiserver': ' .Values.defaultRules.rules.kubernetesSystem', # kubernetes-system was split into more groups in 1.14, one of them is kubernetes-system-apiserver63 'kubernetes-system-kubelet': ' .Values.defaultRules.rules.kubernetesSystem', # kubernetes-system was split into more groups in 1.14, one of them is kubernetes-system-kubelet64 'kubernetes-system-controller-manager': ' .Values.kubeControllerManager.enabled',65 'kubernetes-system-scheduler': ' .Values.kubeScheduler.enabled .Values.defaultRules.rules.kubeScheduler',66 'node-exporter.rules': ' .Values.defaultRules.rules.node',67 'node-exporter': ' .Values.defaultRules.rules.node',68 'node.rules': ' .Values.defaultRules.rules.node',69 'node-network': ' .Values.defaultRules.rules.network',70 'node-time': ' .Values.defaultRules.rules.time',71 'prometheus-operator': ' .Values.defaultRules.rules.prometheusOperator',72 'prometheus.rules': ' .Values.defaultRules.rules.prometheus',73 'prometheus': ' .Values.defaultRules.rules.prometheus', # kube-prometheus >= 1.14 uses prometheus as group instead of prometheus.rules74 'kubernetes-apps': ' .Values.defaultRules.rules.kubernetesApps',75 'etcd': ' .Values.kubeEtcd.enabled .Values.defaultRules.rules.etcd',76}77alert_condition_map = {78 'KubeAPIDown': '.Values.kubeApiServer.enabled', # there are more alerts which are left enabled, because they'll never fire without metrics79 'KubeControllerManagerDown': '.Values.kubeControllerManager.enabled',80 'KubeSchedulerDown': '.Values.kubeScheduler.enabled',81 'KubeStateMetricsDown': '.Values.kubeStateMetrics.enabled', # there are more alerts which are left enabled, because they'll never fire without metrics82 'KubeletDown': '.Values.prometheusOperator.kubeletService.enabled', # there are more alerts which are left enabled, because they'll never fire without metrics83 'PrometheusOperatorDown': '.Values.prometheusOperator.enabled',84 'NodeExporterDown': '.Values.nodeExporter.enabled',85 'CoreDNSDown': '.Values.kubeDns.enabled',86 'AlertmanagerDown': '.Values.alertmanager.enabled',87}88replacement_map = {89 'job="prometheus-operator"': {90 'replacement': 'job="{{ $operatorJob }}"',91 'init': '{{- $operatorJob := printf "%s-%s" (include "kube-prometheus-stack.fullname" .) "operator" }}'},92 'job="prometheus-k8s"': {93 'replacement': 'job="{{ $prometheusJob }}"',94 'init': '{{- $prometheusJob := printf "%s-%s" (include "kube-prometheus-stack.fullname" .) "prometheus" }}'},95 'job="alertmanager-main"': {96 'replacement': 'job="{{ $alertmanagerJob }}"',97 'init': '{{- $alertmanagerJob := printf "%s-%s" (include "kube-prometheus-stack.fullname" .) "alertmanager" }}'},98 'namespace="monitoring"': {99 'replacement': 'namespace="{{ $namespace }}"',100 'init': '{{- $namespace := printf "%s" (include "kube-prometheus-stack.namespace" .) }}'},101 'alertmanager-$1': {102 'replacement': '$1',103 'init': ''},104 'https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md#': {105 'replacement': '{{ .Values.defaultRules.runbookUrl }}',106 'init': ''},107 'https://github.com/prometheus-operator/kube-prometheus/wiki/': {108 'replacement': '{{ .Values.defaultRules.runbookUrl }}alert-name-',109 'init': ''},110 'job="kube-state-metrics"': {111 'replacement': 'job="kube-state-metrics", namespace=~"{{ $targetNamespace }}"',112 'limitGroup': ['kubernetes-apps'],113 'init': '{{- $targetNamespace := .Values.defaultRules.appNamespacesTarget }}'},114 'job="kubelet"': {115 'replacement': 'job="kubelet", namespace=~"{{ $targetNamespace }}"',116 'limitGroup': ['kubernetes-storage'],117 'init': '{{- $targetNamespace := .Values.defaultRules.appNamespacesTarget }}'},118}119# standard header120header = '''{{- /*121Generated from '%(name)s' group from %(url)s122Do not change in-place! In order to change this file first read following link:123https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack124*/ -}}125{{- $kubeTargetVersion := default .Capabilities.KubeVersion.GitVersion .Values.kubeTargetVersionOverride }}126{{- if and (semverCompare ">=%(min_kubernetes)s" $kubeTargetVersion) (semverCompare "<%(max_kubernetes)s" $kubeTargetVersion) .Values.defaultRules.create%(condition)s }}%(init_line)s127apiVersion: monitoring.coreos.com/v1128kind: PrometheusRule129metadata:130 name: {{ printf "%%s-%%s" (include "kube-prometheus-stack.fullname" .) "%(name)s" | trunc 63 | trimSuffix "-" }}131 namespace: {{ template "kube-prometheus-stack.namespace" . }}132 labels:133 app: {{ template "kube-prometheus-stack.name" . }}134{{ include "kube-prometheus-stack.labels" . | indent 4 }}135{{- if .Values.defaultRules.labels }}136{{ toYaml .Values.defaultRules.labels | indent 4 }}137{{- end }}138{{- if .Values.defaultRules.annotations }}139 annotations:140{{ toYaml .Values.defaultRules.annotations | indent 4 }}141{{- end }}142spec:143 groups:144 -'''145def init_yaml_styles():146 represent_literal_str = change_style('|', SafeRepresenter.represent_str)147 yaml.add_representer(LiteralStr, represent_literal_str)148def escape(s):149 return s.replace("{{", "{{`{{").replace("}}", "}}`}}").replace("{{`{{", "{{`{{`}}").replace("}}`}}", "{{`}}`}}")150def fix_expr(rules):151 """Remove trailing whitespaces and line breaks, which happen to creep in152 due to yaml import specifics;153 convert multiline expressions to literal style, |-"""154 for rule in rules:155 rule['expr'] = rule['expr'].rstrip()156 if '\n' in rule['expr']:157 rule['expr'] = LiteralStr(rule['expr'])158def yaml_str_repr(struct, indent=4):159 """represent yaml as a string"""160 text = yaml.dump(161 struct,162 width=1000, # to disable line wrapping163 default_flow_style=False # to disable multiple items on single line164 )165 text = escape(text) # escape {{ and }} for helm166 text = textwrap.indent(text, ' ' * indent)[indent - 1:] # indent everything, and remove very first line extra indentation167 return text168def add_rules_conditions(rules, indent=4):169 """Add if wrapper for rules, listed in alert_condition_map"""170 rule_condition = '{{- if %s }}\n'171 for alert_name in alert_condition_map:172 line_start = ' ' * indent + '- alert: '173 if line_start + alert_name in rules:174 rule_text = rule_condition % alert_condition_map[alert_name]175 # add if condition176 index = rules.index(line_start + alert_name)177 rules = rules[:index] + rule_text + rules[index:]178 # add end of if179 try:180 next_index = rules.index(line_start, index + len(rule_text) + 1)181 except ValueError:182 # we found the last alert in file if there are no alerts after it183 next_index = len(rules)184 # depending on the rule ordering in alert_condition_map it's possible that an if statement from another rule is present at the end of this block.185 found_block_end = False186 last_line_index = next_index187 while not found_block_end:188 last_line_index = rules.rindex('\n', index, last_line_index - 1) # find the starting position of the last line189 last_line = rules[last_line_index + 1:next_index]190 if last_line.startswith('{{- if'):191 next_index = last_line_index + 1 # move next_index back if the current block ends in an if statement192 continue193 found_block_end = True194 rules = rules[:next_index] + '{{- end }}\n' + rules[next_index:]195 return rules196def add_custom_labels(rules, indent=4):197 """Add if wrapper for additional rules labels"""198 rule_condition = '{{- if .Values.defaultRules.additionalRuleLabels }}\n{{ toYaml .Values.defaultRules.additionalRuleLabels | indent 8 }}\n{{- end }}'199 rule_condition_len = len(rule_condition) + 1200 separator = " " * indent + "- alert:.*"201 alerts_positions = re.finditer(separator,rules)202 alert=-1203 for alert_position in alerts_positions:204 # add rule_condition at the end of the alert block205 if alert >= 0 :206 index = alert_position.start() + rule_condition_len * alert - 1207 rules = rules[:index] + "\n" + rule_condition + rules[index:]208 alert += 1209 # add rule_condition at the end of the last alert210 if alert >= 0:211 index = len(rules) - 1212 rules = rules[:index] + "\n" + rule_condition + rules[index:]213 return rules214def write_group_to_file(group, url, destination, min_kubernetes, max_kubernetes):215 fix_expr(group['rules'])216 group_name = group['name']217 # prepare rules string representation218 rules = yaml_str_repr(group)219 # add replacements of custom variables and include their initialisation in case it's needed220 init_line = ''221 for line in replacement_map:222 if group_name in replacement_map[line].get('limitGroup', [group_name]) and line in rules:223 rules = rules.replace(line, replacement_map[line]['replacement'])224 if replacement_map[line]['init']:225 init_line += '\n' + replacement_map[line]['init']226 # append per-alert rules227 rules = add_custom_labels(rules)228 rules = add_rules_conditions(rules)229 # initialize header230 lines = header % {231 'name': group['name'],232 'url': url,233 'condition': condition_map.get(group['name'], ''),234 'init_line': init_line,235 'min_kubernetes': min_kubernetes,236 'max_kubernetes': max_kubernetes237 }238 # rules themselves239 lines += rules240 # footer241 lines += '{{- end }}'242 filename = group['name'] + '.yaml'243 new_filename = "%s/%s" % (destination, filename)244 # make sure directories to store the file exist245 makedirs(destination, exist_ok=True)246 # recreate the file247 with open(new_filename, 'w') as f:248 f.write(lines)249 print("Generated %s" % new_filename)250def main():251 init_yaml_styles()252 # read the rules, create a new template file per group253 for chart in charts:254 print("Generating rules from %s" % chart['source'])255 response = requests.get(chart['source'])256 if response.status_code != 200:257 print('Skipping the file, response code %s not equals 200' % response.status_code)258 continue259 raw_text = response.text260 yaml_text = yaml.full_load(raw_text)261 if ('max_kubernetes' not in chart):262 chart['max_kubernetes']="9.9.9-9"263 # etcd workaround, their file don't have spec level264 groups = yaml_text['spec']['groups'] if yaml_text.get('spec') else yaml_text['groups']265 for group in groups:266 write_group_to_file(group, chart['source'], chart['destination'], chart['min_kubernetes'], chart['max_kubernetes'])267 print("Finished")268if __name__ == '__main__':...

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 hypothesis 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