/usr/share/doc/python-lazr.config-doc/html/src/lazr/config/docs/usage.html is in python-lazr.config-doc 2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LAZR config — lazr.config 2.2 documentation</title>
<link rel="stylesheet" href="../../../../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../../',
VERSION: '2.2',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../../_static/underscore.js"></script>
<script type="text/javascript" src="../../../../_static/doctools.js"></script>
<link rel="index" title="Index" href="../../../../genindex.html" />
<link rel="search" title="Search" href="../../../../search.html" />
<link rel="next" title="NEWS for lazr.config" href="NEWS.html" />
<link rel="prev" title="Welcome to lazr.config" href="../../../../README.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="NEWS.html" title="NEWS for lazr.config"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../../../../README.html" title="Welcome to lazr.config"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../README.html">lazr.config 2.2 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="lazr-config">
<h1>LAZR config<a class="headerlink" href="#lazr-config" title="Permalink to this headline">¶</a></h1>
<p>The LAZR config system is typically used to manage process configuration.
Process configuration is for saying how things change when we run systems on
different machines, or under different circumstances.</p>
<p>This system uses ini-like file format of section, keys, and values. The
config file supports inheritance to minimize duplication of information across
files. The format supports schema validation.</p>
<div class="section" id="configschema">
<h2>ConfigSchema<a class="headerlink" href="#configschema" title="Permalink to this headline">¶</a></h2>
<p>A schema is loaded by instantiating the ConfigSchema class with the path to a
configuration file. The schema is explicitly derived from the information in
the configuration file.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pkg_resources</span> <span class="k">import</span> <span class="n">resource_string</span>
<span class="gp">>>> </span><span class="n">raw_schema</span> <span class="o">=</span> <span class="n">resource_string</span><span class="p">(</span><span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'base.conf'</span><span class="p">)</span>
</pre></div>
</div>
<p>The config file contains sections enclosed in square brackets
(e.g. <code class="docutils literal"><span class="pre">[section]</span></code>). The section name may be divided into major and minor
categories using a dot (<code class="docutils literal"><span class="pre">.</span></code>). Beneath each section is a list of key-value
pairs, separated by a colon (<code class="docutils literal"><span class="pre">:</span></code>).</p>
<p>Multiple sections with the same major category may have their keys defined in
another section that appends the <code class="docutils literal"><span class="pre">.template</span></code> suffix to the category name.</p>
<p>A section with <code class="docutils literal"><span class="pre">.optional</span></code> suffix is not required. Lines that start with a
hash (<code class="docutils literal"><span class="pre">#</span></code>) are comments.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pkg_resources</span> <span class="k">import</span> <span class="n">resource_string</span>
<span class="gp">>>> </span><span class="n">raw_schema</span> <span class="o">=</span> <span class="n">resource_string</span><span class="p">(</span><span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'base.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">raw_schema</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'utf-8'</span><span class="p">))</span>
<span class="go"># This section defines required keys and default values.</span>
<span class="go">[section_1]</span>
<span class="go">key1: foo</span>
<span class="go">key2: bar and baz</span>
<span class="go">key3: Launchpad&nbsp;rocks</span>
<span class="go">key4: F&#028c;k yeah!</span>
<span class="go">key5:</span>
<span class="go"># This section is required, and it defines all the keys for its category.</span>
<span class="go">[section-2.app-b]</span>
<span class="go">key1: True</span>
<span class="go"># This section is optional; it uses the keys defined</span>
<span class="go"># by section_3.template.</span>
<span class="go">[section_3.app_a.optional]</span>
<span class="go"># This is a required section whose keys are defined by section_3.template</span>
<span class="go"># and it defines a new key.</span>
<span class="go">[section_3.app_b]</span>
<span class="go">key2: changed</span>
<span class="go">key3: unique</span>
<span class="go"># These sections define a common set of required keys and default values.</span>
<span class="go">[section_3.template]</span>
<span class="go">key1: 17</span>
<span class="go">key2: 3.1415</span>
<span class="go"># This section is optional.</span>
<span class="go">[section-5.optional]</span>
<span class="go">key1: something</span>
<span class="go"># This section has a name similar to a category.</span>
<span class="go">[section_33]</span>
<span class="go">key1: fnord</span>
<span class="go">key2: multiline value 1</span>
<span class="go"> multiline value 2</span>
</pre></div>
</div>
<p>To create the schema, provide a file name.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">ConfigSchema</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config.interfaces</span> <span class="k">import</span> <span class="n">IConfigSchema</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pkg_resources</span> <span class="k">import</span> <span class="n">resource_filename</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">zope.interface.verify</span> <span class="k">import</span> <span class="n">verifyObject</span>
<span class="gp">>>> </span><span class="n">base_conf</span> <span class="o">=</span> <span class="n">resource_filename</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'base.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">schema</span> <span class="o">=</span> <span class="n">ConfigSchema</span><span class="p">(</span><span class="n">base_conf</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigSchema</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The schema has a name and a file name.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">base.conf</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="s1">'file:'</span><span class="p">,</span> <span class="n">schema</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="go">file: ...lazr/config/tests/testdata/base.conf</span>
</pre></div>
</div>
<p>If you provide an optional file-like object as a second argument to the
constructor, that is used instead of opening the named file implicitly.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">base_conf</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span> <span class="k">as</span> <span class="n">file_object</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">other_schema</span> <span class="o">=</span> <span class="n">ConfigSchema</span><span class="p">(</span><span class="s1">'/does/not/exist.conf'</span><span class="p">,</span> <span class="n">file_object</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigSchema</span><span class="p">,</span> <span class="n">other_schema</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>For such schemas, the file name is taken from the first argument.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">other_schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">exist.conf</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">other_schema</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="go">/does/not/exist.conf</span>
</pre></div>
</div>
<p>A schema is made up of multiple SchemaSections. They can be iterated
over in a loop as needed.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">operator</span> <span class="k">import</span> <span class="n">attrgetter</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">section_schema</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section_schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2.app-b</span>
<span class="go">section-5</span>
<span class="go">section_1</span>
<span class="go">section_3.app_a</span>
<span class="go">section_3.app_b</span>
<span class="go">section_33</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">section_schema</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">other_schema</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section_schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2.app-b</span>
<span class="go">section-5</span>
<span class="go">section_1</span>
<span class="go">section_3.app_a</span>
<span class="go">section_3.app_b</span>
<span class="go">section_33</span>
</pre></div>
</div>
<p>You can check if the schema contains a section name, and that can be
used to access the SchemaSection as a subscript.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'section_1'</span> <span class="ow">in</span> <span class="n">schema</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'section-4'</span> <span class="ow">in</span> <span class="n">schema</span>
<span class="go">False</span>
</pre></div>
</div>
<p>A SectionSchema can be retrieved from the schema using the <code class="docutils literal"><span class="pre">[]</span></code> operator.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">section_schema_1</span> <span class="o">=</span> <span class="n">schema</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">section_schema_1</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_1</span>
</pre></div>
</div>
<p>Processes often require resources like databases or virtual hosts that have a
common category of keys. The list of all category names can be retrieved via
the categories attribute.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">category_names</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2</span>
<span class="go">section_3</span>
</pre></div>
</div>
<p>The list of SchemaSections that share common category can be retrieved
using <code class="docutils literal"><span class="pre">getByCategory()</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">all_section_3</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'section_3'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">section_schema</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">all_section_3</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section_schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_3.app_a</span>
<span class="go">section_3.app_b</span>
</pre></div>
</div>
<p>You can pass a default argument to <code class="docutils literal"><span class="pre">getByCategory()</span></code> to avoid the exception.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">missing</span> <span class="o">=</span> <span class="nb">object</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">schema</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'non-section'</span><span class="p">,</span> <span class="n">missing</span><span class="p">)</span> <span class="ow">is</span> <span class="n">missing</span>
<span class="go">True</span>
</pre></div>
</div>
</div>
<div class="section" id="schemasection">
<h2>SchemaSection<a class="headerlink" href="#schemasection" title="Permalink to this headline">¶</a></h2>
<p>A SchemaSection behaves similar to a dictionary. It has keys and values.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config.interfaces</span> <span class="k">import</span> <span class="n">ISectionSchema</span>
<span class="gp">>>> </span><span class="n">section_schema_1</span> <span class="o">=</span> <span class="n">schema</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">ISectionSchema</span><span class="p">,</span> <span class="n">section_schema_1</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Each SchemaSection has a name.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">section_schema_1</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_1</span>
</pre></div>
</div>
<p>A SchemaSection can return a 2-tuple of its category name and specific name
parts.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">schema</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]</span><span class="o">.</span><span class="n">category_and_section_names</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_3</span>
<span class="go">app_b</span>
</pre></div>
</div>
<p>The category name will be <code class="docutils literal"><span class="pre">None</span></code> if the SchemaSection’s name does not
contain a category.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">section_schema_1</span><span class="o">.</span><span class="n">category_and_section_names</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">None</span>
<span class="go">section_1</span>
</pre></div>
</div>
<p>Optional sections have the optional attribute set to <code class="docutils literal"><span class="pre">True</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">section_schema_1</span><span class="o">.</span><span class="n">optional</span>
<span class="go">False</span>
<span class="gp">>>> </span><span class="n">schema</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">]</span><span class="o">.</span><span class="n">optional</span>
<span class="go">True</span>
</pre></div>
</div>
<p>A key can be verified to be in a section.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'key1'</span> <span class="ow">in</span> <span class="n">section_schema_1</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'nonkey'</span> <span class="ow">in</span> <span class="n">section_schema_1</span>
<span class="go">False</span>
</pre></div>
</div>
<p>A key can be accessed directly using as a subscript of the SchemaSection. The
value is always a string.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">section_schema_1</span><span class="p">[</span><span class="s1">'key3'</span><span class="p">])</span>
<span class="go">Launchpad&nbsp;rocks</span>
<span class="gp">>>> </span><span class="n">section_schema_1</span><span class="p">[</span><span class="s1">'key5'</span><span class="p">]</span>
<span class="go">''</span>
</pre></div>
</div>
<p>An error is raised if a non-existent key is accessed.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">section_schema_1</span><span class="p">[</span><span class="s1">'not-exist'</span><span class="p">]</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">KeyError</span>: <span class="n">...</span>
</pre></div>
</div>
<p>In the conf file, <code class="docutils literal"><span class="pre">[section_1]</span></code> is a default section that defines keys and
values. The values specified in the section schema will be used as default
values if not overridden in the configuration. In the case of <em>key5</em>, the key
had no explicit value, so the value is an empty string.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section_schema_1</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">section_schema_1</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : foo</span>
<span class="go">key2 : bar and baz</span>
<span class="go">key3 : Launchpad&nbsp;rocks</span>
<span class="go">key4 : F&#028c;k yeah!</span>
<span class="go">key5 :</span>
</pre></div>
</div>
<p>In the conf file <code class="docutils literal"><span class="pre">[section_3.template]</span></code> defines a common set of keys and
default values for <code class="docutils literal"><span class="pre">[section_3.app_a]</span></code> and <code class="docutils literal"><span class="pre">[section_3.app_b]</span></code>. When a
section defines different keys and default values from the template, the new
data overlays the template data. This is the case for section
<code class="docutils literal"><span class="pre">[section_3.app_b]</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">section_schema</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">all_section_3</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section_schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section_schema</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">section_schema</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
<span class="go">section_3.app_a</span>
<span class="go">key1 : 17</span>
<span class="go">key2 : 3.1415</span>
<span class="go">section_3.app_b</span>
<span class="go">key1 : 17</span>
<span class="go">key2 : changed</span>
<span class="go">key3 : unique</span>
</pre></div>
</div>
</div>
<div class="section" id="configschema-validation">
<h2>ConfigSchema validation<a class="headerlink" href="#configschema-validation" title="Permalink to this headline">¶</a></h2>
<p>The schema parser is self-validating. It checks that the character encoding
is ASCII, and that the data is not ambiguous or self-contradicting. Keys must
exist inside sections and section names may not be defined twice. Sections
may belong to only one category, and only letters, numbers, dots and dashes
may be present in section names.</p>
</div>
<div class="section" id="iconfigloader">
<h2>IConfigLoader<a class="headerlink" href="#iconfigloader" title="Permalink to this headline">¶</a></h2>
<p>ConfigSchema implements the two methods in the IConfigLoader interface. A
Config is created by a schema using either the <code class="docutils literal"><span class="pre">load()</span></code> or <code class="docutils literal"><span class="pre">loadFile()</span></code>
methods to return a Config instance.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config.interfaces</span> <span class="k">import</span> <span class="n">IConfigLoader</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigLoader</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">load()</span></code> method accepts a filename.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">local_conf</span> <span class="o">=</span> <span class="n">resource_filename</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'local.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">config</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">local_conf</span><span class="p">)</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">loadFile()</span></code> method accepts a file-like object and an optional filename
keyword argument. The filename argument must be passed if the file-like
object does not have a <code class="docutils literal"><span class="pre">name</span></code> attribute.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">try</span><span class="p">:</span>
<span class="gp">... </span> <span class="kn">from</span> <span class="nn">io</span> <span class="k">import</span> <span class="n">StringIO</span>
<span class="gp">... </span><span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="gp">... </span> <span class="c1"># Python 2</span>
<span class="gp">... </span> <span class="kn">from</span> <span class="nn">StringIO</span> <span class="k">import</span> <span class="n">StringIO</span>
<span class="gp">>>> </span><span class="n">bad_data</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"""</span>
<span class="gp">... </span><span class="s2"> [meta]</span>
<span class="gp">... </span><span class="s2"> metakey: unsupported</span>
<span class="gp">... </span><span class="s2"> [unknown-section]</span>
<span class="gp">... </span><span class="s2"> key1 = value1</span>
<span class="gp">... </span><span class="s2"> [section_1]</span>
<span class="gp">... </span><span class="s2"> keyn: unknown key</span>
<span class="gp">... </span><span class="s2"> key1: bad character in caf</span><span class="se">\xc3</span><span class="s2">)</span>
<span class="gp">... </span><span class="s2"> [section_3.template]</span>
<span class="gp">... </span><span class="s2"> key1: schema suffixes are not permitted"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">bad_config</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">loadFile</span><span class="p">(</span>
<span class="gp">... </span> <span class="n">StringIO</span><span class="p">(</span><span class="n">bad_data</span><span class="p">),</span> <span class="s1">'bad conf'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="config">
<h2>Config<a class="headerlink" href="#config" title="Permalink to this headline">¶</a></h2>
<p>The config represents the local configuration of the process on a system. It
is validated with a schema. It extends the schema, or other conf files, to
define the specific differences from the extended files that are required to
run the local processes.</p>
<p>The object returned by <code class="docutils literal"><span class="pre">load()</span></code> provides both the <code class="docutils literal"><span class="pre">IConfigData</span></code> and
<code class="docutils literal"><span class="pre">IStackableConfig</span></code> interfaces. <code class="docutils literal"><span class="pre">IConfigData</span></code> is for read-only access to
the configuration data. A process configuration is made up of a stack of
different <code class="docutils literal"><span class="pre">IConfigData</span></code>. The <code class="docutils literal"><span class="pre">IStackableConfig</span></code> interface provides the
methods used to manipulate that stack of configuration overlays.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config.interfaces</span> <span class="k">import</span> <span class="n">IConfigData</span><span class="p">,</span> <span class="n">IStackableConfig</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigData</span><span class="p">,</span> <span class="n">config</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IStackableConfig</span><span class="p">,</span> <span class="n">config</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Like the schema file, the conf file is made up of sections with keys. The
sections may belong to a category. Unlike the schema file, it does not have
template or optional sections. The <code class="docutils literal"><span class="pre">[meta]</span></code> section has the extends key
that declares that this conf extends <code class="docutils literal"><span class="pre">shared.conf</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">local_conf</span><span class="p">,</span> <span class="s1">'rt'</span><span class="p">)</span> <span class="k">as</span> <span class="n">local_file</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">raw_conf</span> <span class="o">=</span> <span class="n">local_file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">raw_conf</span><span class="p">)</span>
<span class="go">[meta]</span>
<span class="go">extends: shared.conf</span>
<span class="go"># Localize a key for section_1.</span>
<span class="go">[section_1]</span>
<span class="go">key5: local value</span>
<span class="go"># Accept the default values for the optional section-5.</span>
<span class="go">[section-5]</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">.master</span></code> section allows admins to define configurations for an
arbitrary number of processes. If the schema defines <code class="docutils literal"><span class="pre">.master</span></code> sections,
then the conf file can contain sections that extend the <code class="docutils literal"><span class="pre">.master</span></code> section.
These are like categories with templates except that the section names
extending <code class="docutils literal"><span class="pre">.master</span></code> need not be named in the schema file.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">master_schema_conf</span> <span class="o">=</span> <span class="n">resource_filename</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'master.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">master_local_conf</span> <span class="o">=</span> <span class="n">resource_filename</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'master-local.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">master_schema</span> <span class="o">=</span> <span class="n">ConfigSchema</span><span class="p">(</span><span class="n">master_schema_conf</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sections</span> <span class="o">=</span> <span class="n">master_schema</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'thing'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">thing.master</span>
<span class="gp">>>> </span><span class="n">master_conf</span> <span class="o">=</span> <span class="n">master_schema</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">master_local_conf</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sections</span> <span class="o">=</span> <span class="n">master_conf</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'thing'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">thing.one</span>
<span class="go">thing.two</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">foo</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">1</span>
<span class="go">2</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">master_conf</span><span class="o">.</span><span class="n">thing</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">thing.one</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">shared.conf</span></code> file derives the keys and default values from the schema.
This config was loaded before <code class="docutils literal"><span class="pre">local.conf</span></code> because its sections and values
are required to be in place before <code class="docutils literal"><span class="pre">local.conf</span></code> applies its changes.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">shared_config</span> <span class="o">=</span> <span class="n">resource_filename</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'shared.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">shared_config</span><span class="p">,</span> <span class="s1">'rt'</span><span class="p">)</span> <span class="k">as</span> <span class="n">shared_file</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">raw_conf</span> <span class="o">=</span> <span class="n">shared_file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">raw_conf</span><span class="p">)</span>
<span class="go"># The schema is defined by base.conf.</span>
<span class="go"># Localize a key for section_1.</span>
<span class="go">[section_1]</span>
<span class="go">key2: sharing is fun</span>
<span class="go">key5: shared value</span>
</pre></div>
</div>
<p>The config that was loaded has <code class="docutils literal"><span class="pre">name</span></code> and <code class="docutils literal"><span class="pre">filename</span></code> attributes to
identify the configuration.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">local.conf</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="s1">'file:'</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="go">file: ...lazr/config/tests/testdata/local.conf</span>
</pre></div>
</div>
<p>The config can access the schema via the schema property.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">base.conf</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">schema</span> <span class="ow">is</span> <span class="n">schema</span>
<span class="go">True</span>
</pre></div>
</div>
<p>A config is made up of multiple Sections like the schema. They can be
iterated over in a loop as needed. This config inherited several sections
defined in schema. Note that the meta section is not present because it
pertains to the config system, not to the processes being configured.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2.app-b</span>
<span class="go">section-5</span>
<span class="go">section_1</span>
<span class="go">section_3.app_b</span>
<span class="go">section_33</span>
</pre></div>
</div>
<p>You can check if a section name is in a config.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'section_1'</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'bad-section'</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">False</span>
</pre></div>
</div>
<p>Optional SchemaSections are not inherited by the config. A config file must
declare all optional sections. Including the section heading is enough to
inherit the section and its keys. The config file may localize the keys by
declaring them too. The <code class="docutils literal"><span class="pre">local.conf</span></code> file includes <code class="docutils literal"><span class="pre">section-5</span></code>, but not
<code class="docutils literal"><span class="pre">section_3.app_a</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'section_3.app_a'</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">False</span>
<span class="gp">>>> </span><span class="s1">'section_3.app_a'</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">schema</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">]</span><span class="o">.</span><span class="n">optional</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'section-5'</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'section-5'</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">schema</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">'section-5'</span><span class="p">]</span><span class="o">.</span><span class="n">optional</span>
<span class="go">True</span>
</pre></div>
</div>
<p>A Section can be accessed using subscript notation. Accessing a section that
does not exist will raise a NoSectionError. NoSectionError is raised for a
undeclared optional sections too.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">section_1</span> <span class="o">=</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">section_1</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Config supports category access like Schema does. The list of categories are
returned by the <code class="docutils literal"><span class="pre">category_names</span></code> property.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">category_names</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2</span>
<span class="go">section_3</span>
</pre></div>
</div>
<p>All the sections that belong to a category can be retrieved using the
<code class="docutils literal"><span class="pre">getByCategory()</span></code> method.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'section_3'</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section_schema</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_3.app_b</span>
</pre></div>
</div>
<p>Passing a non-existent category_name to the method will raise a
NoCategoryError. As with schemas, you can pass a default argument to
<code class="docutils literal"><span class="pre">getByCategory()</span></code> to avoid the exception.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">missing</span> <span class="o">=</span> <span class="nb">object</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'non-section'</span><span class="p">,</span> <span class="n">missing</span><span class="p">)</span> <span class="ow">is</span> <span class="n">missing</span>
<span class="go">True</span>
</pre></div>
</div>
</div>
<div class="section" id="section">
<h2>Section<a class="headerlink" href="#section" title="Permalink to this headline">¶</a></h2>
<p>A Section behaves similar to a dictionary. It has keys and values. It
supports some specialize access methods and properties for working with the
values. Each Section has a name.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config.interfaces</span> <span class="k">import</span> <span class="n">ISection</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">ISection</span><span class="p">,</span> <span class="n">section_1</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">section_1</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_1</span>
</pre></div>
</div>
<p>Like SectionSchemas, sections can return a 2-tuple of their category name and
specific name parts. The category name will be <code class="docutils literal"><span class="pre">None</span></code> if the section’s name
does not contain a category.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]</span><span class="o">.</span><span class="n">category_and_section_names</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">section_3</span>
<span class="go">app_b</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">section_1</span><span class="o">.</span><span class="n">category_and_section_names</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">None</span>
<span class="go">section_1</span>
</pre></div>
</div>
<p>The Section’s type is the same type as the <code class="docutils literal"><span class="pre">ConfigSchema.section_factory</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">section_1</span>
<span class="go"><lazr.config...Section object at ...></span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">section_factory</span>
<span class="go"><class 'lazr.config...Section'></span>
</pre></div>
</div>
<p>A key can be verified to be in a Section.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'key1'</span> <span class="ow">in</span> <span class="n">section_1</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'nonkey'</span> <span class="ow">in</span> <span class="n">section_1</span>
<span class="go">False</span>
</pre></div>
</div>
<p>A key can be accessed directly using as a subscript of the Section.
The value is always a string.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">section_1</span><span class="p">[</span><span class="s1">'key3'</span><span class="p">])</span>
<span class="go">Launchpad&nbsp;rocks</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">section_1</span><span class="p">[</span><span class="s1">'key5'</span><span class="p">])</span>
<span class="go">local value</span>
</pre></div>
</div>
<p>An error is raised if a non-existent key is accessed via a subscript.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">section_1</span><span class="p">[</span><span class="s1">'not-exist'</span><span class="p">]</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">KeyError</span>: <span class="n">...</span>
</pre></div>
</div>
<p>The Section keys can be iterated over. The section has all the keys from the
SectionSchema. The values came form the schema’s default values, then the
values from <code class="docutils literal"><span class="pre">shared.conf</span></code> were applied, and lastly, the values from
<code class="docutils literal"><span class="pre">local.conf</span></code> were applied. The schema provided the values of <code class="docutils literal"><span class="pre">key1</span></code>,
<code class="docutils literal"><span class="pre">key3</span></code>, and <code class="docutils literal"><span class="pre">key4</span></code>. <code class="docutils literal"><span class="pre">shared.conf</span></code> provided the value of <code class="docutils literal"><span class="pre">key2</span></code>
. <code class="docutils literal"><span class="pre">local.conf</span></code> provided <code class="docutils literal"><span class="pre">key5</span></code>. While <code class="docutils literal"><span class="pre">shared.conf</span></code> provided a
<code class="docutils literal"><span class="pre">key5</span></code>, <code class="docutils literal"><span class="pre">local.conf</span></code> takes precedence.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section_1</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">section_1</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : foo</span>
<span class="go">key2 : sharing is fun</span>
<span class="go">key3 : Launchpad&nbsp;rocks</span>
<span class="go">key4 : F&#028c;k yeah!</span>
<span class="go">key5 : local value</span>
<span class="gp">>>> </span><span class="n">section_1</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">'key5'</span><span class="p">]</span>
<span class="go">''</span>
</pre></div>
</div>
<p>The schema provided mandatory sections and default values to the config. So
while the config file did not declare all the sections, they are present. In
the case of <code class="docutils literal"><span class="pre">section_3.app_b</span></code>, its keys were defined in a template section.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : 17</span>
<span class="go">key2 : changed</span>
<span class="go">key3 : unique</span>
</pre></div>
</div>
<p>Sections attributes cannot be directly set to shadow config options. An
<code class="docutils literal"><span class="pre">AttributeError</span></code> is raised when an attempt is made to mutate the config.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]</span><span class="o">.</span><span class="n">key1</span> <span class="o">=</span> <span class="s1">'fail'</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">Config options cannot be set directly.</span>
</pre></div>
</div>
<p>Nor can new attributes be added to a section.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]</span><span class="o">.</span><span class="n">no_such_attribute</span> <span class="o">=</span> <span class="s1">'fail'</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">Config options cannot be set directly.</span>
</pre></div>
</div>
</div>
<div class="section" id="validating-configs">
<h2>Validating configs<a class="headerlink" href="#validating-configs" title="Permalink to this headline">¶</a></h2>
<p>Config provides the <code class="docutils literal"><span class="pre">validate()</span></code> method to verify that the config is valid
according to the schema. The method returns <code class="docutils literal"><span class="pre">True</span></code> if the config is valid.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">validate</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<p>When the config is not valid, a ConfigErrors is raised. The exception has an
<code class="docutils literal"><span class="pre">errors</span></code> property that contains a list of all the errors in the config.</p>
</div>
<div class="section" id="config-overlays">
<h2>Config overlays<a class="headerlink" href="#config-overlays" title="Permalink to this headline">¶</a></h2>
<p>A conf file may contain a meta section that is used by the config system. The
config data can access the config it extended using the <code class="docutils literal"><span class="pre">extends</span></code> property.
The object is just the config data; it does not have any config methods.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">extends</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">shared.conf</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigData</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">extends</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>As Config supports inheritance through the <code class="docutils literal"><span class="pre">extends</span></code> key, each conf file
produces instance of ConfigData, called an <em>overlay</em>. ConfigData represents
the state of a config. The <code class="docutils literal"><span class="pre">overlays</span></code> property is a stack of ConfigData as
it was constructed from the schema’s config to the last config file that was
loaded.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">local.conf</span>
<span class="go">shared.conf</span>
<span class="go">base.conf</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigData</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">overlays</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Conf files can use the <code class="docutils literal"><span class="pre">extends</span></code> key to specify that it extends a schema
without incurring a processing penalty by loading the schema twice in a row.
The schema can never be the second item in the overlays stack.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">single_config</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">schema</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">single_config</span><span class="o">.</span><span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">base.conf</span>
<span class="gp">>>> </span><span class="n">single_config</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">schema</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">raw_schema</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'utf-8'</span><span class="p">))</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">single_config</span><span class="o">.</span><span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">base.conf</span>
</pre></div>
</div>
</div>
<div class="section" id="push">
<h2>push()<a class="headerlink" href="#push" title="Permalink to this headline">¶</a></h2>
<p>Raw config data can be merged with the config to create a new overlay for
testing. The <code class="docutils literal"><span class="pre">push()</span></code> method accepts a string of config data. The data
must conform to the schema. The <code class="docutils literal"><span class="pre">section_1</span></code> sections’s keys are updated
when the unparsed data is pushed onto the config. Note that indented,
unparsed data is passed to <code class="docutils literal"><span class="pre">push()</span></code> in this example; <code class="docutils literal"><span class="pre">push()</span></code> does not
require tests to dedent the test data.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : foo</span>
<span class="go">key2 : sharing is fun</span>
<span class="go">key3 : Launchpad&nbsp;rocks</span>
<span class="go">key4 : F&#028c;k yeah!</span>
<span class="go">key5 : local value</span>
<span class="gp">>>> </span><span class="n">test_data</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"""</span>
<span class="gp">... </span><span class="s2"> [section_1]</span>
<span class="gp">... </span><span class="s2"> key1: test1</span>
<span class="gp">... </span><span class="s2"> key5:"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="s1">'test config'</span><span class="p">,</span> <span class="n">test_data</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : test1</span>
<span class="go">key2 : sharing is fun</span>
<span class="go">key3 : Launchpad&nbsp;rocks</span>
<span class="go">key4 : F&#028c;k yeah!</span>
<span class="go">key5 :</span>
</pre></div>
</div>
<p>Besides updating section keys, optional sections can be enabled too. The
<code class="docutils literal"><span class="pre">section_3.app_a</span></code> section is enabled with the default keys from the schema
in this example.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">]</span><span class="o">.</span><span class="n">optional</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s1">'section_3.app_a'</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">False</span>
<span class="gp">>>> </span><span class="n">app_a_data</span> <span class="o">=</span> <span class="s2">"[section_3.app_a]"</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="s1">'test app_a'</span><span class="p">,</span> <span class="n">app_a_data</span><span class="p">)</span>
<span class="gp">>>> </span><span class="s1">'section_3.app_a'</span> <span class="ow">in</span> <span class="n">config</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : 17</span>
<span class="go">key2 : 3.1415</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="o">.</span><span class="n">schema</span><span class="p">[</span><span class="s1">'section_3.app_a'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : 17</span>
<span class="go">key2 : 3.1415</span>
</pre></div>
</div>
<p>The config’s name and overlays are updated by <code class="docutils literal"><span class="pre">push()</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">test app_a</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="go">test app_a</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">test app_a</span>
<span class="go">test config</span>
<span class="go">local.conf</span>
<span class="go">shared.conf</span>
<span class="go">base.conf</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">test</span> <span class="pre">app_a</span></code> config did not declare an <code class="docutils literal"><span class="pre">extends</span></code> key in a <code class="docutils literal"><span class="pre">meta</span></code>
section. Its <code class="docutils literal"><span class="pre">extends</span></code> property is <code class="docutils literal"><span class="pre">None</span></code>, even though it implicitly
extends <code class="docutils literal"><span class="pre">test</span> <span class="pre">config</span></code>. The <code class="docutils literal"><span class="pre">extends</span></code> property only provides access to
configs that are explicitly extended.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">extends</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">test config</span>
</pre></div>
</div>
<p>The config’s sections are updated with <code class="docutils literal"><span class="pre">section_3.app_a</span></code> too.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2.app-b</span>
<span class="go">section-5</span>
<span class="go">section_1</span>
<span class="go">section_3.app_a</span>
<span class="go">section_3.app_b</span>
<span class="go">section_33</span>
</pre></div>
</div>
<p>A config file may state that it extends its schema (to clearly connect the
config to the schema). The schema can also be pushed to reset the values in
the config to the schema’s default values.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">extender_conf_name</span> <span class="o">=</span> <span class="n">resource_filename</span><span class="p">(</span>
<span class="gp">... </span> <span class="s1">'lazr.config.tests.testdata'</span><span class="p">,</span> <span class="s1">'extender.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">extender_conf_data</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"""</span>
<span class="gp">... </span><span class="s2"> [meta]</span>
<span class="gp">... </span><span class="s2"> extends: base.conf"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">extender_conf_name</span><span class="p">,</span> <span class="n">extender_conf_data</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">extender.conf</span>
<span class="go">base.conf</span>
<span class="go">test app_a</span>
<span class="go">test config</span>
<span class="go">local.conf</span>
<span class="go">shared.conf</span>
<span class="go">base.conf</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">section_1</span></code> section was restored to the schema’s default values.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : foo</span>
<span class="go">key2 : bar and baz</span>
<span class="go">key3 : Launchpad&nbsp;rocks</span>
<span class="go">key4 : F&#028c;k yeah!</span>
<span class="go">key5 :</span>
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">push()</span></code> can also be used to extend master sections.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">sections</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">master_conf</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">))</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">section</span><span class="o">.</span><span class="n">baz</span><span class="p">)</span>
<span class="go">bar.master badger</span>
<span class="go">bar.soup cougar</span>
<span class="gp">>>> </span><span class="n">master_conf</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="s1">'override'</span><span class="p">,</span> <span class="s2">"""</span>
<span class="gp">... </span><span class="s2">[bar.two]</span>
<span class="gp">... </span><span class="s2">baz: dolphin</span>
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sections</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">master_conf</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">))</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">section</span><span class="o">.</span><span class="n">baz</span><span class="p">)</span>
<span class="go">bar.soup cougar</span>
<span class="go">bar.two dolphin</span>
<span class="gp">>>> </span><span class="n">master_conf</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="s1">'overlord'</span><span class="p">,</span> <span class="s2">"""</span>
<span class="gp">... </span><span class="s2">[bar.three]</span>
<span class="gp">... </span><span class="s2">baz: emu</span>
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">sections</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">master_conf</span><span class="o">.</span><span class="n">getByCategory</span><span class="p">(</span><span class="s1">'bar'</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">))</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">sections</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">section</span><span class="o">.</span><span class="n">baz</span><span class="p">)</span>
<span class="go">bar.soup cougar</span>
<span class="go">bar.three emu</span>
<span class="go">bar.two dolphin</span>
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">push()</span></code> works with master sections too.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">schema_file</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">"""</span><span class="se">\</span>
<span class="gp">... </span><span class="s2">[thing.master]</span>
<span class="gp">... </span><span class="s2">foo: 0</span>
<span class="gp">... </span><span class="s2">bar: 0</span>
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">push_schema</span> <span class="o">=</span> <span class="n">ConfigSchema</span><span class="p">(</span><span class="s1">'schema.cfg'</span><span class="p">,</span> <span class="n">schema_file</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">config_file</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">"""</span><span class="se">\</span>
<span class="gp">... </span><span class="s2">[thing.one]</span>
<span class="gp">... </span><span class="s2">foo: 1</span>
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">push_config</span> <span class="o">=</span> <span class="n">push_schema</span><span class="o">.</span><span class="n">loadFile</span><span class="p">(</span><span class="n">config_file</span><span class="p">,</span> <span class="s1">'config.cfg'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">push_config</span><span class="o">.</span><span class="n">thing</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">foo</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">push_config</span><span class="o">.</span><span class="n">thing</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">bar</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">>>> </span><span class="n">push_config</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="s1">'test.cfg'</span><span class="p">,</span> <span class="s2">"""</span><span class="se">\</span>
<span class="gp">... </span><span class="s2">[thing.one]</span>
<span class="gp">... </span><span class="s2">bar: 2</span>
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">push_config</span><span class="o">.</span><span class="n">thing</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">foo</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">push_config</span><span class="o">.</span><span class="n">thing</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">bar</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
</div>
<div class="section" id="pop">
<h2>pop()<a class="headerlink" href="#pop" title="Permalink to this headline">¶</a></h2>
<p>ConfigData can be removed from the stack of overlays using the <code class="docutils literal"><span class="pre">pop()</span></code>
method. The methods returns the list of ConfigData that was removed – a
slice from the specified ConfigData to the top of the stack.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">overlays</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'test config'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">extender.conf</span>
<span class="go">base.conf</span>
<span class="go">test app_a</span>
<span class="go">test config</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">config_data</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">overlays</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">config_data</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">local.conf</span>
<span class="go">shared.conf</span>
<span class="go">base.conf</span>
</pre></div>
</div>
<p>The config’s state was restored to the ConfigData that is on top of the
overlay stack. Section <code class="docutils literal"><span class="pre">section_3.app_a</span></code> was removed completely. The keys
(<code class="docutils literal"><span class="pre">key1</span></code> and <code class="docutils literal"><span class="pre">key5</span></code>) for <code class="docutils literal"><span class="pre">section_1</span></code> were restored.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s1">'name'</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">section-2.app-b</span>
<span class="go">section-5</span>
<span class="go">section_1</span>
<span class="go">section_3.app_b</span>
<span class="go">section_33</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
<span class="go">key1 : foo</span>
<span class="go">key2 : sharing is fun</span>
<span class="go">key3 : Launchpad&nbsp;rocks</span>
<span class="go">key4 : F&#028c;k yeah!</span>
<span class="go">key5 : local value</span>
</pre></div>
</div>
<p>A Config must have at least one ConfigData in the overlays stack so that it
has data. The bottom ConfigData in the overlays was made from the schema’s
required sections. It cannot be removed by the <code class="docutils literal"><span class="pre">pop()</span></code> method.</p>
<p>If all but the bottom ConfigData is popped from overlays, the extends
property returns None.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">overlays</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'shared.conf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">extends</span><span class="p">)</span>
<span class="go">None</span>
</pre></div>
</div>
</div>
<div class="section" id="attribute-access-to-config-data">
<h2>Attribute access to config data<a class="headerlink" href="#attribute-access-to-config-data" title="Permalink to this headline">¶</a></h2>
<p>Config provides attribute-based access to its members. So long as the
section, category, and key names conform to Python identifier naming rules,
they can be accessed as attributes. The Python code will not compile, or will
cause a runtime error if the object being accessed has a bad name.</p>
<p>Sections appear to be attributes of the config.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">local_conf</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">section_1</span> <span class="ow">is</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Accessing an unknown section, or a section whose name is not a valid Python
identifier will raise an AttributeError.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">section</span><span class="o">-</span><span class="mi">5</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">No section or category named section.</span>
</pre></div>
</div>
<p>Categories may be accessed as attributes too. The ICategory interface
provides access to its sections as members.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config.interfaces</span> <span class="k">import</span> <span class="n">ICategory</span>
<span class="gp">>>> </span><span class="n">config_category</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">section_3</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">ICategory</span><span class="p">,</span> <span class="n">config_category</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">config_category</span><span class="o">.</span><span class="n">app_b</span> <span class="ow">is</span> <span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Like a config, a category will raise an AttributeError if it does not have a
section that matches the identifier name.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config_category</span><span class="o">.</span><span class="n">no_such_section</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">No section named no_such_section.</span>
</pre></div>
</div>
<p>Section keys can be accessed directly as members.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">section_1</span><span class="o">.</span><span class="n">key2</span><span class="p">)</span>
<span class="go">sharing is fun</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">section_3</span><span class="o">.</span><span class="n">app_b</span><span class="o">.</span><span class="n">key2</span><span class="p">)</span>
<span class="go">changed</span>
</pre></div>
</div>
<p>Accessing a non-existent section key as an attribute will raise an
AttributeError.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">section_1</span><span class="o">.</span><span class="n">non_key</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">No section key named non_key.</span>
</pre></div>
</div>
</div>
<div class="section" id="implicit-data-typing">
<h2>Implicit data typing<a class="headerlink" href="#implicit-data-typing" title="Permalink to this headline">¶</a></h2>
<p>The ImplicitTypeSchema can create configs that support implicit datatypes.
The value of a Section key is automatically converted from <code class="docutils literal"><span class="pre">str</span></code> to the type
the value appears to be. Implicit typing does not add any validation support;
it adds type casting conveniences for the developer.</p>
<p>An ImplicitTypeSchema can be used to parse the same schema and conf files that
Schema uses.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">ImplicitTypeSchema</span>
<span class="gp">>>> </span><span class="n">implicit_schema</span> <span class="o">=</span> <span class="n">ImplicitTypeSchema</span><span class="p">(</span><span class="n">base_conf</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">IConfigSchema</span><span class="p">,</span> <span class="n">implicit_schema</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The config loaded by ImplicitTypeSchema is the same class with the same
sections as is made by Schema.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">implicit_config</span> <span class="o">=</span> <span class="n">implicit_schema</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">local_conf</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">implicit_config</span>
<span class="go"><lazr.config...Config object at ...></span>
<span class="gp">>>> </span><span class="n">config</span>
<span class="go"><lazr.config...Config object at ...></span>
<span class="gp">>>> </span><span class="n">sections</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">section</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">config</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">implicit_sections</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
<span class="gp">... </span> <span class="n">section</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">implicit_config</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">implicit_sections</span> <span class="o">==</span> <span class="n">sections</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">verifyObject</span><span class="p">(</span><span class="n">ISection</span><span class="p">,</span> <span class="n">implicit_config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">])</span>
<span class="go">True</span>
</pre></div>
</div>
<p>But the type of sections in the config support implicit typing.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">implicit_config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">]</span>
<span class="go"><lazr.config...ImplicitTypeSection object at ...></span>
</pre></div>
</div>
<p>ImplicitTypeSection, in contrast to Section, converts values that appear to be
integer or boolean into ints and bools.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">][</span><span class="s1">'key1'</span><span class="p">]</span>
<span class="go">'17'</span>
<span class="gp">>>> </span><span class="n">implicit_config</span><span class="p">[</span><span class="s1">'section_3.app_b'</span><span class="p">][</span><span class="s1">'key1'</span><span class="p">]</span>
<span class="go">17</span>
<span class="gp">>>> </span><span class="n">config</span><span class="p">[</span><span class="s1">'section-2.app-b'</span><span class="p">][</span><span class="s1">'key1'</span><span class="p">]</span>
<span class="go">'True'</span>
<span class="gp">>>> </span><span class="n">implicit_config</span><span class="p">[</span><span class="s1">'section-2.app-b'</span><span class="p">][</span><span class="s1">'key1'</span><span class="p">]</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The value is also converted when it is accessed as an attribute.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">implicit_config</span><span class="o">.</span><span class="n">section_3</span><span class="o">.</span><span class="n">app_b</span><span class="o">.</span><span class="n">key1</span>
<span class="go">17</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">implicit_config</span><span class="p">[</span><span class="s1">'section-2.app-b'</span><span class="p">]</span><span class="o">.</span><span class="n">key1</span>
<span class="go">True</span>
</pre></div>
</div>
<p>ImplicitTypeSection uses a private method that employs heuristic rules to
convert strings into simple types. It may return a str, bool, or int. When
the argument is the word ‘true’ or ‘false’ (in any case), a bool is returned.
Values like ‘yes’, ‘no’, ‘0’, and ‘1’ are not converted to bool.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">convert</span> <span class="o">=</span> <span class="n">implicit_config</span><span class="p">[</span><span class="s1">'section_1'</span><span class="p">]</span><span class="o">.</span><span class="n">_convert</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'false'</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'TRUE'</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'tRue'</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'yes'</span><span class="p">))</span>
<span class="go">yes</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'1'</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'True or False'</span><span class="p">))</span>
<span class="go">True or False</span>
</pre></div>
</div>
<p>When the argument is the word <code class="docutils literal"><span class="pre">none</span></code>, <code class="docutils literal"><span class="pre">None</span></code> is returned. The token in
the config means the key has no value.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'none'</span><span class="p">))</span>
<span class="go">None</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'None'</span><span class="p">))</span>
<span class="go">None</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'nonE'</span><span class="p">))</span>
<span class="go">None</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'none today'</span><span class="p">))</span>
<span class="go">none today</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'nonevident'</span><span class="p">))</span>
<span class="go">nonevident</span>
</pre></div>
</div>
<p>When the argument is an unbroken sequence of numbers, an int is returned. The
number may have a leading positive or negative. Octal and hex notation is not
supported.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'0'</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'2001'</span><span class="p">)</span>
<span class="go">2001</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'-55'</span><span class="p">)</span>
<span class="go">-55</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'+404'</span><span class="p">)</span>
<span class="go">404</span>
<span class="gp">>>> </span><span class="n">convert</span><span class="p">(</span><span class="s1">'0100'</span><span class="p">)</span>
<span class="go">100</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'2001-01-01'</span><span class="p">))</span>
<span class="go">2001-01-01</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'1000*60*5'</span><span class="p">))</span>
<span class="go">1000*60*5</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'1000 * 60 * 5'</span><span class="p">))</span>
<span class="go">1000 * 60 * 5</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'1,024'</span><span class="p">))</span>
<span class="go">1,024</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'0.5'</span><span class="p">))</span>
<span class="go">0.5</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s1">'0x100'</span><span class="p">))</span>
<span class="go">0x100</span>
</pre></div>
</div>
<p>Multiline values are always strings, with white space (and line breaks)
removed from the beginning and end.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="s2">"""multiline value 1</span>
<span class="gp">... </span><span class="s2"> multiline value 2"""</span><span class="p">))</span>
<span class="go">multiline value 1</span>
<span class="go">multiline value 2</span>
</pre></div>
</div>
</div>
<div class="section" id="type-conversion-helpers">
<h2>Type conversion helpers<a class="headerlink" href="#type-conversion-helpers" title="Permalink to this headline">¶</a></h2>
<p>lazr.config provides a few helpers for doing explicit type conversion. These
functions have to be imported and called explicitly on the configuration
variable values.</p>
<div class="section" id="booleans">
<h3>Booleans<a class="headerlink" href="#booleans" title="Permalink to this headline">¶</a></h3>
<p>There is a helper for turning various strings into the boolean values <code class="docutils literal"><span class="pre">True</span></code>
and <code class="docutils literal"><span class="pre">False</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">as_boolean</span>
</pre></div>
</div>
<p>True values include (case-insensitively): true, yes, 1, on, enabled, and
enable.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">'true'</span><span class="p">,</span> <span class="s1">'yes'</span><span class="p">,</span> <span class="s1">'on'</span><span class="p">,</span> <span class="s1">'enable'</span><span class="p">,</span> <span class="s1">'enabled'</span><span class="p">,</span> <span class="s1">'1'</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">as_boolean</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">as_boolean</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">()))</span>
<span class="go">true -> True</span>
<span class="go">TRUE -> True</span>
<span class="go">yes -> True</span>
<span class="go">YES -> True</span>
<span class="go">on -> True</span>
<span class="go">ON -> True</span>
<span class="go">enable -> True</span>
<span class="go">ENABLE -> True</span>
<span class="go">enabled -> True</span>
<span class="go">ENABLED -> True</span>
<span class="go">1 -> True</span>
<span class="go">1 -> True</span>
</pre></div>
</div>
<p>False values include (case-insensitively): false, no, 0, off, disabled, and
disable.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">'false'</span><span class="p">,</span> <span class="s1">'no'</span><span class="p">,</span> <span class="s1">'off'</span><span class="p">,</span> <span class="s1">'disable'</span><span class="p">,</span> <span class="s1">'disabled'</span><span class="p">,</span> <span class="s1">'0'</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">as_boolean</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">as_boolean</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">()))</span>
<span class="go">false -> False</span>
<span class="go">FALSE -> False</span>
<span class="go">no -> False</span>
<span class="go">NO -> False</span>
<span class="go">off -> False</span>
<span class="go">OFF -> False</span>
<span class="go">disable -> False</span>
<span class="go">DISABLE -> False</span>
<span class="go">disabled -> False</span>
<span class="go">DISABLED -> False</span>
<span class="go">0 -> False</span>
<span class="go">0 -> False</span>
</pre></div>
</div>
<p>Anything else is a error.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_boolean</span><span class="p">(</span><span class="s1">'cheese'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">Invalid boolean value: cheese</span>
</pre></div>
</div>
</div>
<div class="section" id="host-and-port">
<h3>Host and port<a class="headerlink" href="#host-and-port" title="Permalink to this headline">¶</a></h3>
<p>There is a helper for converting from a <code class="docutils literal"><span class="pre">host:port</span></code> string to a 2-tuple of
<code class="docutils literal"><span class="pre">(host,</span> <span class="pre">port)</span></code>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">as_host_port</span>
<span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">'host:25'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">host 25</span>
</pre></div>
</div>
<p>The port string is optional, in which case, port 25 is the default (for
historical reasons).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">'host'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">host 25</span>
</pre></div>
</div>
<p>The default port can be overridden.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">'host'</span><span class="p">,</span> <span class="n">default_port</span><span class="o">=</span><span class="mi">22</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">host 22</span>
</pre></div>
</div>
<p>The default port is ignored if it is given in the value.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">'host:80'</span><span class="p">,</span> <span class="n">default_port</span><span class="o">=</span><span class="mi">22</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">host 80</span>
</pre></div>
</div>
<p>The host name is also optional, as denoted by a leading colon. When omitted,
localhost is used.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">':80'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">localhost 80</span>
</pre></div>
</div>
<p>The default host name can be overridden though.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">':80'</span><span class="p">,</span> <span class="n">default_host</span><span class="o">=</span><span class="s1">'myhost'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">myhost 80</span>
</pre></div>
</div>
<p>The default host name is ignored if the value string contains it.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">as_host_port</span><span class="p">(</span><span class="s1">'yourhost:80'</span><span class="p">,</span> <span class="n">default_host</span><span class="o">=</span><span class="s1">'myhost'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
<span class="go">yourhost 80</span>
</pre></div>
</div>
<p>A ValueError occurs if the port number in the configuration value string is
not an integer.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_host_port</span><span class="p">(</span><span class="s1">':foo'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">invalid literal for int...foo...</span>
</pre></div>
</div>
</div>
<div class="section" id="user-and-group">
<h3>User and group<a class="headerlink" href="#user-and-group" title="Permalink to this headline">¶</a></h3>
<p>A helper is provided for turning a <code class="docutils literal"><span class="pre">chown(1)</span></code>-style <code class="docutils literal"><span class="pre">user:group</span></code>
specification into a 2-tuple of the user name and group name.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">as_username_groupname</span>
</pre></div>
</div>
<p>The value string must contain both a user name and group name, separated by a
colon, otherwise an exception is raised.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_username_groupname</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">...</span>
</pre></div>
</div>
<p>When both are given, the strings are returned unchanged or validated.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">user</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="n">as_username_groupname</span><span class="p">(</span><span class="s1">'person:group'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">group</span><span class="p">)</span>
<span class="go">person group</span>
</pre></div>
</div>
<p>Numeric values can be given, but they are not converted into their symbolic
names.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">uid</span><span class="p">,</span> <span class="n">gid</span> <span class="o">=</span> <span class="n">as_username_groupname</span><span class="p">(</span><span class="s1">'25:26'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">uid</span><span class="p">,</span> <span class="n">gid</span><span class="p">)</span>
<span class="go">25 26</span>
</pre></div>
</div>
<p>By default the current user and group names are returned.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">grp</span><span class="o">,</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">pwd</span>
<span class="gp">>>> </span><span class="n">user</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="n">as_username_groupname</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">user</span> <span class="o">==</span> <span class="n">pwd</span><span class="o">.</span><span class="n">getpwuid</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getuid</span><span class="p">())</span><span class="o">.</span><span class="n">pw_name</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">group</span> <span class="o">==</span> <span class="n">grp</span><span class="o">.</span><span class="n">getgrgid</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getgid</span><span class="p">())</span><span class="o">.</span><span class="n">gr_name</span>
<span class="go">True</span>
</pre></div>
</div>
</div>
<div class="section" id="time-intervals">
<h3>Time intervals<a class="headerlink" href="#time-intervals" title="Permalink to this headline">¶</a></h3>
<p>This converter accepts a range of <em>time interval specifications</em>, and returns
a Python <a class="reference external" href="http://docs.python.org/3/library/datetime.html#timedelta-objects">timedelta</a>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">as_timedelta</span>
</pre></div>
</div>
<p>The function converts from an integer to the equivalent number of seconds.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'45s'</span><span class="p">)</span>
<span class="go">datetime.timedelta(0, 45)</span>
</pre></div>
</div>
<p>The function also accepts suffixes <code class="docutils literal"><span class="pre">m</span></code> for minutes...</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'3m'</span><span class="p">)</span>
<span class="go">datetime.timedelta(0, 180)</span>
</pre></div>
</div>
<p>...``h`` for hours...</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'2h'</span><span class="p">)</span>
<span class="go">datetime.timedelta(0, 7200)</span>
</pre></div>
</div>
<p>...and <code class="docutils literal"><span class="pre">d</span></code> for days...</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'4d'</span><span class="p">)</span>
<span class="go">datetime.timedelta(4)</span>
</pre></div>
</div>
<p>...and <code class="docutils literal"><span class="pre">w</span></code> for weeks.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'4w'</span><span class="p">)</span>
<span class="go">datetime.timedelta(28)</span>
</pre></div>
</div>
<p>The function accepts a fractional number of seconds, indicating microseconds.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'3.2s'</span><span class="p">)</span>
<span class="go">datetime.timedelta(0, 3, 200000)</span>
</pre></div>
</div>
<p>It also accepts any combination thereof.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'3m22.5s'</span><span class="p">)</span>
<span class="go">datetime.timedelta(0, 202, 500000)</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'4w2d9h3s'</span><span class="p">)</span>
<span class="go">datetime.timedelta(30, 32403)</span>
</pre></div>
</div>
<p>But doesn’t accept “weird” or duplicate combinations.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'3s2s'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'2.9s4w'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'m'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'3m2'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'45'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'45wm'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
<span class="gp">>>> </span><span class="n">as_timedelta</span><span class="p">(</span><span class="s1">'45z'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>
</pre></div>
</div>
</div>
<div class="section" id="log-levels">
<h3>Log levels<a class="headerlink" href="#log-levels" title="Permalink to this headline">¶</a></h3>
<p>It’s convenient to be able to use symbolic log level names when using
<code class="docutils literal"><span class="pre">lazr.config</span></code> to configure the Python logger.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">lazr.config</span> <span class="k">import</span> <span class="n">as_log_level</span>
</pre></div>
</div>
<p>Any symbolic log level value is valid to use, case insensitively.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">'critical'</span><span class="p">,</span> <span class="s1">'error'</span><span class="p">,</span> <span class="s1">'warning'</span><span class="p">,</span> <span class="s1">'info'</span><span class="p">,</span>
<span class="gp">... </span> <span class="s1">'debug'</span><span class="p">,</span> <span class="s1">'notset'</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">as_log_level</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">as_log_level</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">()))</span>
<span class="go">critical -> 50</span>
<span class="go">CRITICAL -> 50</span>
<span class="go">error -> 40</span>
<span class="go">ERROR -> 40</span>
<span class="go">warning -> 30</span>
<span class="go">WARNING -> 30</span>
<span class="go">info -> 20</span>
<span class="go">INFO -> 20</span>
<span class="go">debug -> 10</span>
<span class="go">DEBUG -> 10</span>
<span class="go">notset -> 0</span>
<span class="go">NOTSET -> 0</span>
</pre></div>
</div>
<p>Non-log levels cannot be used here.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">as_log_level</span><span class="p">(</span><span class="s1">'cheese'</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AttributeError</span>: <span class="n">...</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="other-documents">
<h2>Other Documents<a class="headerlink" href="#other-documents" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="NEWS.html">NEWS for lazr.config</a><ul>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id1">2.2 (2017-02-07)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id2">2.1 (2015-01-05)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id3">2.0.1 (2014-08-22)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id4">2.0 (2013-01-10)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id5">1.1.3 (2009-08-25)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id6">1.1.2 (2009-08-25)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id7">1.1.1 (2009-03-24)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id8">1.1 (2009-01-05)</a></li>
<li class="toctree-l2"><a class="reference internal" href="NEWS.html#id9">1.0 (2008-12-19)</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../../README.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">LAZR config</a><ul>
<li><a class="reference internal" href="#configschema">ConfigSchema</a></li>
<li><a class="reference internal" href="#schemasection">SchemaSection</a></li>
<li><a class="reference internal" href="#configschema-validation">ConfigSchema validation</a></li>
<li><a class="reference internal" href="#iconfigloader">IConfigLoader</a></li>
<li><a class="reference internal" href="#config">Config</a></li>
<li><a class="reference internal" href="#section">Section</a></li>
<li><a class="reference internal" href="#validating-configs">Validating configs</a></li>
<li><a class="reference internal" href="#config-overlays">Config overlays</a></li>
<li><a class="reference internal" href="#push">push()</a></li>
<li><a class="reference internal" href="#pop">pop()</a></li>
<li><a class="reference internal" href="#attribute-access-to-config-data">Attribute access to config data</a></li>
<li><a class="reference internal" href="#implicit-data-typing">Implicit data typing</a></li>
<li><a class="reference internal" href="#type-conversion-helpers">Type conversion helpers</a><ul>
<li><a class="reference internal" href="#booleans">Booleans</a></li>
<li><a class="reference internal" href="#host-and-port">Host and port</a></li>
<li><a class="reference internal" href="#user-and-group">User and group</a></li>
<li><a class="reference internal" href="#time-intervals">Time intervals</a></li>
<li><a class="reference internal" href="#log-levels">Log levels</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-documents">Other Documents</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="../../../../README.html"
title="previous chapter">Welcome to lazr.config</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="NEWS.html"
title="next chapter">NEWS for lazr.config</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../../../_sources/src/lazr/config/docs/usage.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../../../../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="NEWS.html" title="NEWS for lazr.config"
>next</a> |</li>
<li class="right" >
<a href="../../../../README.html" title="Welcome to lazr.config"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../../README.html">lazr.config 2.2 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2013-2017, LAZR developers.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.6.
</div>
</body>
</html>
|