libv8 6.7.288.46.1 → 7.3.492.27.0beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/ext/libv8/builder.rb +6 -2
- data/lib/libv8/version.rb +1 -1
- data/vendor/depot_tools/.gitattributes +1 -0
- data/vendor/depot_tools/.gitignore +7 -0
- data/vendor/depot_tools/CROS_OWNERS +5 -0
- data/vendor/depot_tools/OWNERS +12 -1
- data/vendor/depot_tools/PRESUBMIT.py +16 -9
- data/vendor/depot_tools/README.md +9 -2
- data/vendor/depot_tools/autoninja +14 -6
- data/vendor/depot_tools/autoninja.bat +11 -1
- data/vendor/depot_tools/autoninja.py +40 -18
- data/vendor/depot_tools/bb +12 -0
- data/vendor/depot_tools/bb.bat +7 -0
- data/vendor/depot_tools/bootstrap/win/manifest.txt +1 -1
- data/vendor/depot_tools/bootstrap/win/manifest_bleeding_edge.txt +1 -1
- data/vendor/depot_tools/bootstrap/win/win_tools.py +2 -1
- data/vendor/depot_tools/buildbucket.py +57 -4
- data/vendor/depot_tools/cipd +157 -44
- data/vendor/depot_tools/cipd.bat +51 -14
- data/vendor/depot_tools/cipd.ps1 +104 -42
- data/vendor/depot_tools/cipd_client_version +1 -1
- data/vendor/depot_tools/cipd_client_version.digests +21 -0
- data/vendor/depot_tools/cipd_manifest.txt +19 -6
- data/vendor/depot_tools/cipd_manifest.versions +318 -0
- data/vendor/depot_tools/clang_format.py +4 -4
- data/vendor/depot_tools/cpplint.py +44 -199
- data/vendor/depot_tools/dart_format.py +2 -2
- data/vendor/depot_tools/detect_host_arch.py +8 -3
- data/vendor/depot_tools/download_from_google_storage.py +47 -39
- data/vendor/depot_tools/fetch.py +30 -18
- data/vendor/depot_tools/fetch_configs/android_internal.py +34 -0
- data/vendor/depot_tools/fetch_configs/chromium.py +18 -1
- data/vendor/depot_tools/fetch_configs/config_util.py +4 -2
- data/vendor/depot_tools/fetch_configs/inspector_protocol.py +40 -0
- data/vendor/depot_tools/fetch_configs/node-ci.py +41 -0
- data/vendor/depot_tools/fix_encoding.py +3 -3
- data/vendor/depot_tools/gclient +1 -1
- data/vendor/depot_tools/gclient.py +415 -198
- data/vendor/depot_tools/gclient_eval.py +220 -171
- data/vendor/depot_tools/gclient_paths.py +142 -0
- data/vendor/depot_tools/gclient_scm.py +200 -51
- data/vendor/depot_tools/gclient_utils.py +88 -191
- data/vendor/depot_tools/gerrit_client.py +13 -0
- data/vendor/depot_tools/gerrit_util.py +158 -23
- data/vendor/depot_tools/git-nav-upstream +1 -1
- data/vendor/depot_tools/git_cache.py +77 -24
- data/vendor/depot_tools/git_cl.py +705 -1099
- data/vendor/depot_tools/git_common.py +9 -6
- data/vendor/depot_tools/git_map_branches.py +19 -2
- data/vendor/depot_tools/git_nav_downstream.py +3 -4
- data/vendor/depot_tools/git_rebase_update.py +14 -0
- data/vendor/depot_tools/git_reparent_branch.py +8 -2
- data/vendor/depot_tools/gn.py +38 -3
- data/vendor/depot_tools/gsutil.py +8 -3
- data/vendor/depot_tools/gsutil.py.bat +15 -0
- data/vendor/depot_tools/gsutil.vpython +16 -0
- data/vendor/depot_tools/infra/config/OWNERS +0 -1
- data/vendor/depot_tools/infra/config/recipes.cfg +3 -2
- data/vendor/depot_tools/lucicfg +12 -0
- data/vendor/depot_tools/lucicfg.bat +7 -0
- data/vendor/depot_tools/man/html/git-map-branches.html +34 -2
- data/vendor/depot_tools/man/html/git-new-branch.html +40 -32
- data/vendor/depot_tools/man/man1/git-map-branches.1 +24 -5
- data/vendor/depot_tools/man/man1/git-new-branch.1 +35 -27
- data/vendor/depot_tools/man/src/git-map-branches.demo.1.sh +1 -0
- data/vendor/depot_tools/man/src/git-map-branches.txt +10 -0
- data/vendor/depot_tools/man/src/git-new-branch.demo.1.sh +9 -4
- data/vendor/depot_tools/man/src/git-new-branch.txt +1 -1
- data/vendor/depot_tools/metrics.README.md +98 -0
- data/vendor/depot_tools/metrics.py +296 -0
- data/vendor/depot_tools/metrics_utils.py +303 -0
- data/vendor/depot_tools/my_activity.py +91 -29
- data/vendor/depot_tools/ninja +1 -1
- data/vendor/depot_tools/ninjalog.README.md +64 -0
- data/vendor/depot_tools/ninjalog_uploader.py +232 -0
- data/vendor/depot_tools/ninjalog_uploader_wrapper.py +116 -0
- data/vendor/depot_tools/owners.py +30 -13
- data/vendor/depot_tools/owners_finder.py +5 -2
- data/vendor/depot_tools/presubmit_canned_checks.py +188 -29
- data/vendor/depot_tools/presubmit_support.py +18 -41
- data/vendor/depot_tools/pylintrc +23 -19
- data/vendor/depot_tools/recipes/OWNERS +2 -0
- data/vendor/depot_tools/recipes/README.recipes.md +344 -151
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/OWNERS +2 -0
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/__init__.py +2 -16
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/api.py +141 -99
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/basic.json +5 -8
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/basic_luci.json +5 -8
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/basic_with_branch_heads.json +6 -98
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/clobber.json +4 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/deprecated_got_revision_mapping.json +45 -5
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/gerrit_no_rebase_patch_ref.json +4 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/gerrit_no_reset.json +4 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/{tryjob.json → input_commit_with_id_without_repo.json} +6 -11
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/{tryjob_empty_revision.json → multiple_patch_refs.json} +8 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/no_apply_patch_on_gclient.json +19 -29
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/{trychange.json → refs.json} +4 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/reset_root_solution_revision.json +4 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_fail.json +51 -6
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_fail_patch.json +50 -6
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_fail_patch_download.json +51 -6
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_angle.json +17 -25
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_branch_heads.json +17 -25
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_feature_branch.json +18 -26
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_v8_feature_branch.json +18 -26
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_webrtc.json +26 -28
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_v8.json +45 -5
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_v8_head_by_default.json +17 -25
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/unrecognized_commit_repo.json +13 -0
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/with_manifest_name.json +13 -152
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/with_tags.json +4 -9
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.py +185 -202
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/resources/bot_update.py +52 -157
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/test_api.py +5 -14
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/tests/ensure_checkout.py +34 -0
- data/vendor/depot_tools/recipes/recipe_modules/cipd/api.py +14 -2
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/basic.json +4 -5
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/basic_pkg.json +4 -5
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/describe-failed.json +7 -5
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/describe-many-instances.json +4 -5
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/mac64.json +4 -5
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/pkg_bad_file.json +9 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/pkg_bad_mode.json +9 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/pkg_bad_verfile.json +9 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/full.expected/win64.json +4 -5
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/junk arch.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/junk bits.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/linux_arm_32.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/linux_arm_64.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/linux_intel_32.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/linux_intel_64.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/linux_mips_64.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/mac_intel_64.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/win_intel_32.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/cipd/examples/platform_suffix.expected/win_intel_64.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/depot_tools/api.py +13 -8
- data/vendor/depot_tools/recipes/recipe_modules/depot_tools/examples/full.expected/basic.json +18 -12
- data/vendor/depot_tools/recipes/recipe_modules/depot_tools/examples/full.expected/basic_luci.json +18 -12
- data/vendor/depot_tools/recipes/recipe_modules/depot_tools/examples/full.expected/win.json +18 -12
- data/vendor/depot_tools/recipes/recipe_modules/depot_tools/examples/full.py +3 -0
- data/vendor/depot_tools/recipes/recipe_modules/gclient/__init__.py +1 -0
- data/vendor/depot_tools/recipes/recipe_modules/gclient/api.py +58 -46
- data/vendor/depot_tools/recipes/recipe_modules/gclient/config.py +65 -22
- data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/basic.json +20 -21
- data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/buildbot.json +20 -21
- data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/revision.json +20 -21
- data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/tryserver.json +20 -21
- data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.py +5 -2
- data/vendor/depot_tools/recipes/recipe_modules/gclient/tests/patch_project.py +62 -14
- data/vendor/depot_tools/recipes/recipe_modules/gerrit/api.py +24 -38
- data/vendor/depot_tools/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +56 -50
- data/vendor/depot_tools/recipes/recipe_modules/gerrit/examples/full.py +15 -9
- data/vendor/depot_tools/recipes/recipe_modules/git/__init__.py +4 -1
- data/vendor/depot_tools/recipes/recipe_modules/git/api.py +34 -22
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_branch.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_file_name.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_hash.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_luci.json +222 -0
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_ref.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_submodule_update_force.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/basic_tags.json +224 -0
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/can_fail_build.json +10 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/cannot_fail_build.json +5 -7
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/cat-file_test.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/count-objects_delta.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/count-objects_failed.json +5 -7
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output_fails_build.json +10 -5
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/curl_trace_file.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/git-cache-checkout.json +8 -9
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/platform_win.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/rebase_failed.json +12 -8
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/remote_not_origin.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.expected/set_got_revision.json +5 -6
- data/vendor/depot_tools/recipes/recipe_modules/git/examples/full.py +27 -11
- data/vendor/depot_tools/recipes/recipe_modules/git_cl/api.py +1 -1
- data/vendor/depot_tools/recipes/recipe_modules/git_cl/examples/full.expected/basic.json +12 -13
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/__init__.py +5 -0
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/api.py +120 -5
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/examples/full.expected/basic.json +45 -3
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/examples/full.py +25 -0
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/resources/gerrit_client.py +56 -4
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/tests/parse_repo_url.expected/basic.json +6 -0
- data/vendor/depot_tools/recipes/recipe_modules/gitiles/tests/parse_repo_url.py +49 -0
- data/vendor/depot_tools/recipes/recipe_modules/gsutil/api.py +24 -13
- data/vendor/depot_tools/recipes/recipe_modules/gsutil/examples/full.expected/basic.json +13 -14
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/basic.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_buildbot_linux.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_buildbot_mac.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_buildbot_win.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_generic_linux.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_generic_mac.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_generic_win.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_kitchen_linux.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_kitchen_mac.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/examples/full.expected/paths_kitchen_win.json +2 -3
- data/vendor/depot_tools/recipes/recipe_modules/infra_paths/path_config.py +1 -2
- data/vendor/depot_tools/recipes/recipe_modules/osx_sdk/__init__.py +35 -0
- data/vendor/depot_tools/recipes/recipe_modules/osx_sdk/api.py +116 -0
- data/vendor/depot_tools/recipes/recipe_modules/osx_sdk/examples/full.expected/linux.json +22 -0
- data/vendor/depot_tools/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json +82 -0
- data/vendor/depot_tools/recipes/recipe_modules/osx_sdk/examples/full.expected/win.json +22 -0
- data/vendor/depot_tools/recipes/recipe_modules/osx_sdk/examples/full.py +23 -0
- data/vendor/depot_tools/recipes/recipe_modules/presubmit/__init__.py +1 -0
- data/vendor/depot_tools/recipes/recipe_modules/presubmit/api.py +2 -7
- data/vendor/depot_tools/recipes/recipe_modules/presubmit/examples/full.expected/basic.json +7 -6
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/__init__.py +1 -0
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/api.py +117 -8
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/basic_tags.json +4 -5
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/set_failure_hash_with_no_steps.json +7 -4
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch.json +98 -7
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_gerrit_patch_and_target_ref.json +147 -0
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_git_patch.json +8 -5
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_git_patch_luci.json +8 -5
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_wrong_patch.json +9 -6
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_wrong_patch_new.json +9 -6
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.py +27 -2
- data/vendor/depot_tools/recipes/recipe_modules/tryserver/test_api.py +14 -0
- data/vendor/depot_tools/recipes/recipe_modules/windows_sdk/__init__.py +25 -0
- data/vendor/depot_tools/recipes/recipe_modules/windows_sdk/api.py +137 -0
- data/vendor/depot_tools/recipes/recipe_modules/windows_sdk/examples/full.expected/linux.json +22 -0
- data/vendor/depot_tools/recipes/recipe_modules/windows_sdk/examples/full.expected/mac.json +22 -0
- data/vendor/depot_tools/recipes/recipe_modules/windows_sdk/examples/full.expected/win.json +107 -0
- data/vendor/depot_tools/recipes/recipe_modules/windows_sdk/examples/full.py +26 -0
- data/vendor/depot_tools/recipes/recipes.py +37 -27
- data/vendor/depot_tools/recipes/recipes/fetch_end_to_end_test.expected/basic.json +7 -10
- data/vendor/depot_tools/repo +34 -8
- data/vendor/depot_tools/roll_dep.py +52 -49
- data/vendor/depot_tools/scm.py +38 -23
- data/vendor/depot_tools/setup_color.py +4 -2
- data/vendor/depot_tools/split_cl.py +32 -4
- data/vendor/depot_tools/subprocess2.py +22 -4
- data/vendor/depot_tools/third_party/httplib2/README.chromium +2 -2
- data/vendor/depot_tools/third_party/httplib2/__init__.py +242 -158
- data/vendor/depot_tools/third_party/httplib2/cacerts.txt +57 -44
- data/vendor/depot_tools/third_party/httplib2/socks.py +15 -5
- data/vendor/depot_tools/third_party/logilab/README.chromium +2 -4
- data/vendor/depot_tools/third_party/logilab/astroid/README.chromium +2 -1
- data/vendor/depot_tools/third_party/logilab/astroid/__init__.py +10 -5
- data/vendor/depot_tools/third_party/logilab/astroid/__pkginfo__.py +5 -5
- data/vendor/depot_tools/third_party/logilab/astroid/arguments.py +233 -0
- data/vendor/depot_tools/third_party/logilab/astroid/as_string.py +82 -33
- data/vendor/depot_tools/third_party/logilab/astroid/bases.py +137 -153
- data/vendor/depot_tools/third_party/logilab/astroid/brain/{builtin_inference.py → brain_builtin_inference.py} +117 -26
- data/vendor/depot_tools/third_party/logilab/astroid/brain/brain_dateutil.py +15 -0
- data/vendor/depot_tools/third_party/logilab/astroid/brain/{py2gi.py → brain_gi.py} +48 -8
- data/vendor/depot_tools/third_party/logilab/astroid/brain/{py2mechanize.py → brain_mechanize.py} +0 -0
- data/vendor/depot_tools/third_party/logilab/astroid/brain/{pynose.py → brain_nose.py} +4 -1
- data/vendor/depot_tools/third_party/logilab/astroid/brain/brain_numpy.py +62 -0
- data/vendor/depot_tools/third_party/logilab/astroid/brain/brain_pytest.py +76 -0
- data/vendor/depot_tools/third_party/logilab/astroid/brain/brain_qt.py +44 -0
- data/vendor/depot_tools/third_party/logilab/astroid/brain/{pysix_moves.py → brain_six.py} +28 -1
- data/vendor/depot_tools/third_party/logilab/astroid/brain/brain_ssl.py +65 -0
- data/vendor/depot_tools/third_party/logilab/astroid/brain/brain_stdlib.py +473 -0
- data/vendor/depot_tools/third_party/logilab/astroid/builder.py +104 -81
- data/vendor/depot_tools/third_party/logilab/astroid/context.py +81 -0
- data/vendor/depot_tools/third_party/logilab/astroid/decorators.py +75 -0
- data/vendor/depot_tools/third_party/logilab/astroid/exceptions.py +20 -0
- data/vendor/depot_tools/third_party/logilab/astroid/inference.py +137 -183
- data/vendor/depot_tools/third_party/logilab/astroid/manager.py +45 -169
- data/vendor/depot_tools/third_party/logilab/astroid/mixins.py +37 -14
- data/vendor/depot_tools/third_party/logilab/astroid/modutils.py +112 -41
- data/vendor/depot_tools/third_party/logilab/astroid/node_classes.py +243 -156
- data/vendor/depot_tools/third_party/logilab/astroid/nodes.py +35 -22
- data/vendor/depot_tools/third_party/logilab/astroid/objects.py +186 -0
- data/vendor/depot_tools/third_party/logilab/astroid/protocols.py +157 -102
- data/vendor/depot_tools/third_party/logilab/astroid/raw_building.py +32 -8
- data/vendor/depot_tools/third_party/logilab/astroid/rebuilder.py +372 -309
- data/vendor/depot_tools/third_party/logilab/astroid/scoped_nodes.py +652 -420
- data/vendor/depot_tools/third_party/logilab/astroid/test_utils.py +4 -21
- data/vendor/depot_tools/third_party/logilab/astroid/transforms.py +96 -0
- data/vendor/depot_tools/third_party/logilab/astroid/util.py +89 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/LICENSE +19 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/README.chromium +11 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/__init__.py +20 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/cext.c +1421 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/compat.py +9 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/simple.py +246 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/slots.py +414 -0
- data/vendor/depot_tools/third_party/logilab/lazy_object_proxy/utils.py +13 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/LICENSE +24 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/README.chromium +11 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/__init__.py +19 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/_wrappers.c +2729 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/arguments.py +96 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/decorators.py +512 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/importer.py +228 -0
- data/vendor/depot_tools/third_party/logilab/wrapt/wrappers.py +901 -0
- data/vendor/depot_tools/third_party/pylint/README.chromium +2 -25
- data/vendor/depot_tools/third_party/pylint/__pkginfo__.py +13 -3
- data/vendor/depot_tools/third_party/pylint/checkers/__init__.py +1 -2
- data/vendor/depot_tools/third_party/pylint/checkers/async.py +82 -0
- data/vendor/depot_tools/third_party/pylint/checkers/base.py +893 -119
- data/vendor/depot_tools/third_party/pylint/checkers/classes.py +342 -204
- data/vendor/depot_tools/third_party/pylint/checkers/design_analysis.py +51 -34
- data/vendor/depot_tools/third_party/pylint/checkers/exceptions.py +84 -47
- data/vendor/depot_tools/third_party/pylint/checkers/format.py +55 -30
- data/vendor/depot_tools/third_party/pylint/checkers/imports.py +314 -73
- data/vendor/depot_tools/third_party/pylint/checkers/logging.py +10 -8
- data/vendor/depot_tools/third_party/pylint/checkers/misc.py +2 -1
- data/vendor/depot_tools/third_party/pylint/checkers/newstyle.py +45 -48
- data/vendor/depot_tools/third_party/pylint/checkers/python3.py +31 -21
- data/vendor/depot_tools/third_party/pylint/checkers/raw_metrics.py +3 -3
- data/vendor/depot_tools/third_party/pylint/checkers/similar.py +4 -5
- data/vendor/depot_tools/third_party/pylint/checkers/spelling.py +24 -10
- data/vendor/depot_tools/third_party/pylint/checkers/stdlib.py +120 -56
- data/vendor/depot_tools/third_party/pylint/checkers/strings.py +38 -35
- data/vendor/depot_tools/third_party/pylint/checkers/typecheck.py +485 -138
- data/vendor/depot_tools/third_party/pylint/checkers/utils.py +319 -142
- data/vendor/depot_tools/third_party/pylint/checkers/variables.py +329 -207
- data/vendor/depot_tools/third_party/pylint/config.py +739 -76
- data/vendor/depot_tools/third_party/pylint/epylint.py +9 -5
- data/vendor/depot_tools/third_party/pylint/extensions/__init__.py +0 -0
- data/vendor/depot_tools/third_party/pylint/extensions/check_docs.py +311 -0
- data/vendor/depot_tools/third_party/pylint/extensions/check_elif.py +62 -0
- data/vendor/depot_tools/third_party/{logilab/common → pylint}/graph.py +30 -133
- data/vendor/depot_tools/third_party/pylint/gui.py +2 -2
- data/vendor/depot_tools/third_party/pylint/interfaces.py +21 -3
- data/vendor/depot_tools/third_party/pylint/lint.py +123 -140
- data/vendor/depot_tools/third_party/pylint/pyreverse/diadefslib.py +10 -13
- data/vendor/depot_tools/third_party/pylint/pyreverse/diagrams.py +15 -4
- data/vendor/depot_tools/third_party/pylint/pyreverse/inspector.py +372 -0
- data/vendor/depot_tools/third_party/pylint/pyreverse/main.py +30 -7
- data/vendor/depot_tools/third_party/pylint/pyreverse/utils.py +80 -2
- data/vendor/depot_tools/third_party/{logilab/common → pylint/pyreverse}/vcgutils.py +19 -37
- data/vendor/depot_tools/third_party/pylint/pyreverse/writer.py +3 -4
- data/vendor/depot_tools/third_party/pylint/reporters/__init__.py +34 -18
- data/vendor/depot_tools/third_party/pylint/reporters/guireporter.py +1 -1
- data/vendor/depot_tools/third_party/pylint/reporters/html.py +10 -3
- data/vendor/depot_tools/third_party/pylint/reporters/json.py +10 -4
- data/vendor/depot_tools/third_party/pylint/reporters/text.py +94 -3
- data/vendor/depot_tools/third_party/pylint/reporters/ureports/__init__.py +106 -0
- data/vendor/depot_tools/third_party/{logilab/common → pylint/reporters}/ureports/html_writer.py +17 -57
- data/vendor/depot_tools/third_party/{logilab/common → pylint/reporters}/ureports/nodes.py +52 -74
- data/vendor/depot_tools/third_party/{logilab/common → pylint/reporters}/ureports/text_writer.py +14 -60
- data/vendor/depot_tools/third_party/pylint/testutils.py +22 -20
- data/vendor/depot_tools/third_party/pylint/utils.py +268 -44
- data/vendor/depot_tools/third_party/repo/progress.py +42 -0
- data/vendor/depot_tools/update_depot_tools +1 -1
- data/vendor/depot_tools/upload_metrics.py +25 -0
- data/vendor/depot_tools/win_toolchain/get_toolchain_if_necessary.py +45 -15
- data/vendor/depot_tools/win_toolchain/package_from_installed.py +71 -24
- data/vendor/depot_tools/yapf +1 -1
- data/vendor/depot_tools/yapf.bat +1 -1
- metadata +92 -77
- data/vendor/depot_tools/git-crsync +0 -3
- data/vendor/depot_tools/infra/config/cq.cfg +0 -32
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/apply_gerrit_ref.json +0 -29
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/apply_gerrit_ref_custom.json +0 -29
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/buildbot.json +0 -105
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/shallow.json +0 -195
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_angle_deprecated.json +0 -248
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_v8.json +0 -248
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/with_manifest_name_no_patch.json +0 -105
- data/vendor/depot_tools/recipes/recipe_modules/bot_update/resources/apply_gerrit.py +0 -33
- data/vendor/depot_tools/third_party/logilab/astroid/brain/py2pytest.py +0 -31
- data/vendor/depot_tools/third_party/logilab/astroid/brain/py2qt4.py +0 -22
- data/vendor/depot_tools/third_party/logilab/astroid/brain/py2stdlib.py +0 -334
- data/vendor/depot_tools/third_party/logilab/astroid/inspector.py +0 -273
- data/vendor/depot_tools/third_party/logilab/astroid/utils.py +0 -239
- data/vendor/depot_tools/third_party/logilab/common/LICENSE.txt +0 -339
- data/vendor/depot_tools/third_party/logilab/common/README.chromium +0 -11
- data/vendor/depot_tools/third_party/logilab/common/__init__.py +0 -175
- data/vendor/depot_tools/third_party/logilab/common/__pkginfo__.py +0 -57
- data/vendor/depot_tools/third_party/logilab/common/cache.py +0 -114
- data/vendor/depot_tools/third_party/logilab/common/changelog.py +0 -238
- data/vendor/depot_tools/third_party/logilab/common/clcommands.py +0 -334
- data/vendor/depot_tools/third_party/logilab/common/cli.py +0 -211
- data/vendor/depot_tools/third_party/logilab/common/compat.py +0 -78
- data/vendor/depot_tools/third_party/logilab/common/configuration.py +0 -1105
- data/vendor/depot_tools/third_party/logilab/common/contexts.py +0 -5
- data/vendor/depot_tools/third_party/logilab/common/corbautils.py +0 -117
- data/vendor/depot_tools/third_party/logilab/common/daemon.py +0 -101
- data/vendor/depot_tools/third_party/logilab/common/date.py +0 -335
- data/vendor/depot_tools/third_party/logilab/common/dbf.py +0 -231
- data/vendor/depot_tools/third_party/logilab/common/debugger.py +0 -214
- data/vendor/depot_tools/third_party/logilab/common/decorators.py +0 -281
- data/vendor/depot_tools/third_party/logilab/common/deprecation.py +0 -189
- data/vendor/depot_tools/third_party/logilab/common/fileutils.py +0 -404
- data/vendor/depot_tools/third_party/logilab/common/interface.py +0 -71
- data/vendor/depot_tools/third_party/logilab/common/logging_ext.py +0 -195
- data/vendor/depot_tools/third_party/logilab/common/modutils.py +0 -702
- data/vendor/depot_tools/third_party/logilab/common/optik_ext.py +0 -392
- data/vendor/depot_tools/third_party/logilab/common/optparser.py +0 -92
- data/vendor/depot_tools/third_party/logilab/common/proc.py +0 -277
- data/vendor/depot_tools/third_party/logilab/common/pyro_ext.py +0 -180
- data/vendor/depot_tools/third_party/logilab/common/pytest.py +0 -1199
- data/vendor/depot_tools/third_party/logilab/common/registry.py +0 -1119
- data/vendor/depot_tools/third_party/logilab/common/shellutils.py +0 -462
- data/vendor/depot_tools/third_party/logilab/common/sphinx_ext.py +0 -87
- data/vendor/depot_tools/third_party/logilab/common/sphinxutils.py +0 -122
- data/vendor/depot_tools/third_party/logilab/common/table.py +0 -929
- data/vendor/depot_tools/third_party/logilab/common/tasksqueue.py +0 -101
- data/vendor/depot_tools/third_party/logilab/common/testlib.py +0 -1392
- data/vendor/depot_tools/third_party/logilab/common/textutils.py +0 -537
- data/vendor/depot_tools/third_party/logilab/common/tree.py +0 -369
- data/vendor/depot_tools/third_party/logilab/common/umessage.py +0 -194
- data/vendor/depot_tools/third_party/logilab/common/ureports/__init__.py +0 -172
- data/vendor/depot_tools/third_party/logilab/common/ureports/docbook_writer.py +0 -140
- data/vendor/depot_tools/third_party/logilab/common/urllib2ext.py +0 -89
- data/vendor/depot_tools/third_party/logilab/common/visitor.py +0 -109
- data/vendor/depot_tools/third_party/logilab/common/xmlrpcutils.py +0 -131
- data/vendor/depot_tools/third_party/logilab/common/xmlutils.py +0 -61
@@ -16,40 +16,50 @@
|
|
16
16
|
* pylintrc
|
17
17
|
* pylint.d (PYLINTHOME)
|
18
18
|
"""
|
19
|
-
from __future__ import with_statement
|
20
19
|
from __future__ import print_function
|
21
20
|
|
22
|
-
|
21
|
+
# TODO(cpopa): this module contains the logic for the
|
22
|
+
# configuration parser and for the command line parser,
|
23
|
+
# but it's really coupled to optparse's internals.
|
24
|
+
# The code was copied almost verbatim from logilab.common,
|
25
|
+
# in order to not depend on it anymore and it will definitely
|
26
|
+
# need a cleanup. It could be completely reengineered as well.
|
27
|
+
|
28
|
+
import contextlib
|
29
|
+
import collections
|
30
|
+
import copy
|
31
|
+
import io
|
32
|
+
import optparse
|
23
33
|
import os
|
34
|
+
import pickle
|
35
|
+
import re
|
24
36
|
import sys
|
25
|
-
|
37
|
+
import time
|
38
|
+
|
39
|
+
from six.moves import configparser
|
40
|
+
from six.moves import range
|
26
41
|
|
27
|
-
|
42
|
+
from pylint import utils
|
28
43
|
|
29
|
-
|
44
|
+
|
45
|
+
USER_HOME = os.path.expanduser('~')
|
30
46
|
if 'PYLINTHOME' in os.environ:
|
31
47
|
PYLINT_HOME = os.environ['PYLINTHOME']
|
32
48
|
if USER_HOME == '~':
|
33
|
-
USER_HOME = dirname(PYLINT_HOME)
|
49
|
+
USER_HOME = os.path.dirname(PYLINT_HOME)
|
34
50
|
elif USER_HOME == '~':
|
35
51
|
PYLINT_HOME = ".pylint.d"
|
36
52
|
else:
|
37
|
-
PYLINT_HOME = join(USER_HOME, '.pylint.d')
|
53
|
+
PYLINT_HOME = os.path.join(USER_HOME, '.pylint.d')
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
given base_name with the given options values
|
42
|
-
"""
|
55
|
+
|
56
|
+
def _get_pdata_path(base_name, recurs):
|
43
57
|
base_name = base_name.replace(os.sep, '_')
|
44
|
-
return join(PYLINT_HOME, "%s%s%s"%(base_name, recurs, '.stats'))
|
58
|
+
return os.path.join(PYLINT_HOME, "%s%s%s"%(base_name, recurs, '.stats'))
|
45
59
|
|
46
|
-
def load_results(base):
|
47
|
-
"""try to unpickle and return data from file if it exists and is not
|
48
|
-
corrupted
|
49
60
|
|
50
|
-
|
51
|
-
|
52
|
-
data_file = get_pdata_path(base, 1)
|
61
|
+
def load_results(base):
|
62
|
+
data_file = _get_pdata_path(base, 1)
|
53
63
|
try:
|
54
64
|
with open(data_file, _PICK_LOAD) as stream:
|
55
65
|
return pickle.load(stream)
|
@@ -62,46 +72,47 @@ else:
|
|
62
72
|
_PICK_DUMP, _PICK_LOAD = 'wb', 'rb'
|
63
73
|
|
64
74
|
def save_results(results, base):
|
65
|
-
|
66
|
-
if not exists(PYLINT_HOME):
|
75
|
+
if not os.path.exists(PYLINT_HOME):
|
67
76
|
try:
|
68
77
|
os.mkdir(PYLINT_HOME)
|
69
78
|
except OSError:
|
70
79
|
print('Unable to create directory %s' % PYLINT_HOME, file=sys.stderr)
|
71
|
-
data_file =
|
80
|
+
data_file = _get_pdata_path(base, 1)
|
72
81
|
try:
|
73
82
|
with open(data_file, _PICK_DUMP) as stream:
|
74
83
|
pickle.dump(results, stream)
|
75
84
|
except (IOError, OSError) as ex:
|
76
85
|
print('Unable to create file %s: %s' % (data_file, ex), file=sys.stderr)
|
77
86
|
|
78
|
-
# location of the configuration file ##########################################
|
79
|
-
|
80
87
|
|
81
88
|
def find_pylintrc():
|
82
89
|
"""search the pylint rc file and return its path if it find it, else None
|
83
90
|
"""
|
84
91
|
# is there a pylint rc file in the current directory ?
|
85
|
-
if exists('pylintrc'):
|
86
|
-
return abspath('pylintrc')
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
92
|
+
if os.path.exists('pylintrc'):
|
93
|
+
return os.path.abspath('pylintrc')
|
94
|
+
if os.path.exists('.pylintrc'):
|
95
|
+
return os.path.abspath('.pylintrc')
|
96
|
+
if os.path.isfile('__init__.py'):
|
97
|
+
curdir = os.path.abspath(os.getcwd())
|
98
|
+
while os.path.isfile(os.path.join(curdir, '__init__.py')):
|
99
|
+
curdir = os.path.abspath(os.path.join(curdir, '..'))
|
100
|
+
if os.path.isfile(os.path.join(curdir, 'pylintrc')):
|
101
|
+
return os.path.join(curdir, 'pylintrc')
|
102
|
+
if os.path.isfile(os.path.join(curdir, '.pylintrc')):
|
103
|
+
return os.path.join(curdir, '.pylintrc')
|
104
|
+
if 'PYLINTRC' in os.environ and os.path.exists(os.environ['PYLINTRC']):
|
94
105
|
pylintrc = os.environ['PYLINTRC']
|
95
106
|
else:
|
96
|
-
user_home = expanduser('~')
|
107
|
+
user_home = os.path.expanduser('~')
|
97
108
|
if user_home == '~' or user_home == '/root':
|
98
109
|
pylintrc = ".pylintrc"
|
99
110
|
else:
|
100
|
-
pylintrc = join(user_home, '.pylintrc')
|
101
|
-
if not isfile(pylintrc):
|
102
|
-
pylintrc = join(user_home, '.config', 'pylintrc')
|
103
|
-
if not isfile(pylintrc):
|
104
|
-
if isfile('/etc/pylintrc'):
|
111
|
+
pylintrc = os.path.join(user_home, '.pylintrc')
|
112
|
+
if not os.path.isfile(pylintrc):
|
113
|
+
pylintrc = os.path.join(user_home, '.config', 'pylintrc')
|
114
|
+
if not os.path.isfile(pylintrc):
|
115
|
+
if os.path.isfile('/etc/pylintrc'):
|
105
116
|
pylintrc = '/etc/pylintrc'
|
106
117
|
else:
|
107
118
|
pylintrc = None
|
@@ -110,48 +121,700 @@ def find_pylintrc():
|
|
110
121
|
PYLINTRC = find_pylintrc()
|
111
122
|
|
112
123
|
ENV_HELP = '''
|
113
|
-
The following environment variables are used:
|
114
|
-
* PYLINTHOME
|
115
|
-
Path to the directory where the persistent for the run will be stored. If
|
116
|
-
not found, it defaults to ~/.pylint.d/ or .pylint.d (in the current working
|
117
|
-
directory).
|
118
|
-
* PYLINTRC
|
124
|
+
The following environment variables are used:
|
125
|
+
* PYLINTHOME
|
126
|
+
Path to the directory where the persistent for the run will be stored. If
|
127
|
+
not found, it defaults to ~/.pylint.d/ or .pylint.d (in the current working
|
128
|
+
directory).
|
129
|
+
* PYLINTRC
|
119
130
|
Path to the configuration file. See the documentation for the method used
|
120
131
|
to search for configuration file.
|
121
132
|
''' % globals()
|
122
133
|
|
123
|
-
# evaluation messages #########################################################
|
124
134
|
|
125
|
-
|
126
|
-
"""
|
127
|
-
|
135
|
+
class UnsupportedAction(Exception):
|
136
|
+
"""raised by set_option when it doesn't know what to do for an action"""
|
137
|
+
|
138
|
+
|
139
|
+
def _multiple_choice_validator(choices, name, value):
|
140
|
+
values = utils._check_csv(value)
|
141
|
+
for value in values:
|
142
|
+
if value not in choices:
|
143
|
+
msg = "option %s: invalid value: %r, should be in %s"
|
144
|
+
raise optparse.OptionValueError(msg % (name, value, choices))
|
145
|
+
return values
|
146
|
+
|
147
|
+
|
148
|
+
def _choice_validator(choices, name, value):
|
149
|
+
if value not in choices:
|
150
|
+
msg = "option %s: invalid value: %r, should be in %s"
|
151
|
+
raise optparse.OptionValueError(msg % (name, value, choices))
|
152
|
+
return value
|
153
|
+
|
154
|
+
# pylint: disable=unused-argument
|
155
|
+
def _csv_validator(_, name, value):
|
156
|
+
return utils._check_csv(value)
|
157
|
+
|
158
|
+
|
159
|
+
# pylint: disable=unused-argument
|
160
|
+
def _regexp_validator(_, name, value):
|
161
|
+
if hasattr(value, 'pattern'):
|
162
|
+
return value
|
163
|
+
return re.compile(value)
|
164
|
+
|
165
|
+
|
166
|
+
def _yn_validator(opt, _, value):
|
167
|
+
if isinstance(value, int):
|
168
|
+
return bool(value)
|
169
|
+
if value in ('y', 'yes'):
|
170
|
+
return True
|
171
|
+
if value in ('n', 'no'):
|
172
|
+
return False
|
173
|
+
msg = "option %s: invalid yn value %r, should be in (y, yes, n, no)"
|
174
|
+
raise optparse.OptionValueError(msg % (opt, value))
|
175
|
+
|
176
|
+
|
177
|
+
VALIDATORS = {
|
178
|
+
'string': utils._unquote,
|
179
|
+
'int': int,
|
180
|
+
'regexp': re.compile,
|
181
|
+
'csv': _csv_validator,
|
182
|
+
'yn': _yn_validator,
|
183
|
+
'choice': lambda opt, name, value: _choice_validator(opt['choices'], name, value),
|
184
|
+
'multiple_choice': lambda opt, name, value: _multiple_choice_validator(opt['choices'],
|
185
|
+
name, value),
|
186
|
+
}
|
187
|
+
|
188
|
+
def _call_validator(opttype, optdict, option, value):
|
189
|
+
if opttype not in VALIDATORS:
|
190
|
+
raise Exception('Unsupported type "%s"' % opttype)
|
191
|
+
try:
|
192
|
+
return VALIDATORS[opttype](optdict, option, value)
|
193
|
+
except TypeError:
|
194
|
+
try:
|
195
|
+
return VALIDATORS[opttype](value)
|
196
|
+
except Exception:
|
197
|
+
raise optparse.OptionValueError('%s value (%r) should be of type %s' %
|
198
|
+
(option, value, opttype))
|
199
|
+
|
200
|
+
|
201
|
+
def _validate(value, optdict, name=''):
|
202
|
+
"""return a validated value for an option according to its type
|
203
|
+
|
204
|
+
optional argument name is only used for error message formatting
|
205
|
+
"""
|
206
|
+
try:
|
207
|
+
_type = optdict['type']
|
208
|
+
except KeyError:
|
209
|
+
# FIXME
|
210
|
+
return value
|
211
|
+
return _call_validator(_type, optdict, name, value)
|
212
|
+
|
213
|
+
|
214
|
+
def _level_options(group, outputlevel):
|
215
|
+
return [option for option in group.option_list
|
216
|
+
if (getattr(option, 'level', 0) or 0) <= outputlevel
|
217
|
+
and option.help is not optparse.SUPPRESS_HELP]
|
218
|
+
|
219
|
+
|
220
|
+
def _expand_default(self, option):
|
221
|
+
"""Patch OptionParser.expand_default with custom behaviour
|
222
|
+
|
223
|
+
This will handle defaults to avoid overriding values in the
|
224
|
+
configuration file.
|
128
225
|
"""
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
msg = "Come on! You can't be proud of this code"
|
137
|
-
elif note < 3:
|
138
|
-
msg = 'Hum... Needs work.'
|
139
|
-
elif note < 4:
|
140
|
-
msg = 'Wouldn\'t you be a bit lazy?'
|
141
|
-
elif note < 5:
|
142
|
-
msg = 'A little more work would make it acceptable.'
|
143
|
-
elif note < 6:
|
144
|
-
msg = 'Just the bare minimum. Give it a bit more polish. '
|
145
|
-
elif note < 7:
|
146
|
-
msg = 'This is okay-ish, but I\'m sure you can do better.'
|
147
|
-
elif note < 8:
|
148
|
-
msg = 'If you commit now, people should not be making nasty \
|
149
|
-
comments about you on c.l.py'
|
150
|
-
elif note < 9:
|
151
|
-
msg = 'That\'s pretty good. Good work mate.'
|
152
|
-
elif note < 10:
|
153
|
-
msg = 'So close to being perfect...'
|
226
|
+
if self.parser is None or not self.default_tag:
|
227
|
+
return option.help
|
228
|
+
optname = option._long_opts[0][2:]
|
229
|
+
try:
|
230
|
+
provider = self.parser.options_manager._all_options[optname]
|
231
|
+
except KeyError:
|
232
|
+
value = None
|
154
233
|
else:
|
155
|
-
|
156
|
-
|
157
|
-
|
234
|
+
optdict = provider.get_option_def(optname)
|
235
|
+
optname = provider.option_attrname(optname, optdict)
|
236
|
+
value = getattr(provider.config, optname, optdict)
|
237
|
+
value = utils._format_option_value(optdict, value)
|
238
|
+
if value is optparse.NO_DEFAULT or not value:
|
239
|
+
value = self.NO_DEFAULT_VALUE
|
240
|
+
return option.help.replace(self.default_tag, str(value))
|
241
|
+
|
242
|
+
|
243
|
+
@contextlib.contextmanager
|
244
|
+
def _patch_optparse():
|
245
|
+
orig_default = optparse.HelpFormatter
|
246
|
+
try:
|
247
|
+
optparse.HelpFormatter.expand_default = _expand_default
|
248
|
+
yield
|
249
|
+
finally:
|
250
|
+
optparse.HelpFormatter.expand_default = orig_default
|
251
|
+
|
252
|
+
|
253
|
+
def _multiple_choices_validating_option(opt, name, value):
|
254
|
+
return _multiple_choice_validator(opt.choices, name, value)
|
255
|
+
|
256
|
+
|
257
|
+
class Option(optparse.Option):
|
258
|
+
TYPES = optparse.Option.TYPES + ('regexp', 'csv', 'yn', 'multiple_choice')
|
259
|
+
ATTRS = optparse.Option.ATTRS + ['hide', 'level']
|
260
|
+
TYPE_CHECKER = copy.copy(optparse.Option.TYPE_CHECKER)
|
261
|
+
TYPE_CHECKER['regexp'] = _regexp_validator
|
262
|
+
TYPE_CHECKER['csv'] = _csv_validator
|
263
|
+
TYPE_CHECKER['yn'] = _yn_validator
|
264
|
+
TYPE_CHECKER['multiple_choice'] = _multiple_choices_validating_option
|
265
|
+
|
266
|
+
def __init__(self, *opts, **attrs):
|
267
|
+
optparse.Option.__init__(self, *opts, **attrs)
|
268
|
+
if hasattr(self, "hide") and self.hide:
|
269
|
+
self.help = optparse.SUPPRESS_HELP
|
270
|
+
|
271
|
+
def _check_choice(self):
|
272
|
+
if self.type in ("choice", "multiple_choice"):
|
273
|
+
if self.choices is None:
|
274
|
+
raise optparse.OptionError(
|
275
|
+
"must supply a list of choices for type 'choice'", self)
|
276
|
+
elif not isinstance(self.choices, (tuple, list)):
|
277
|
+
raise optparse.OptionError(
|
278
|
+
"choices must be a list of strings ('%s' supplied)"
|
279
|
+
% str(type(self.choices)).split("'")[1], self)
|
280
|
+
elif self.choices is not None:
|
281
|
+
raise optparse.OptionError(
|
282
|
+
"must not supply choices for type %r" % self.type, self)
|
283
|
+
optparse.Option.CHECK_METHODS[2] = _check_choice
|
284
|
+
|
285
|
+
def process(self, opt, value, values, parser):
|
286
|
+
# First, convert the value(s) to the right type. Howl if any
|
287
|
+
# value(s) are bogus.
|
288
|
+
value = self.convert_value(opt, value)
|
289
|
+
if self.type == 'named':
|
290
|
+
existant = getattr(values, self.dest)
|
291
|
+
if existant:
|
292
|
+
existant.update(value)
|
293
|
+
value = existant
|
294
|
+
# And then take whatever action is expected of us.
|
295
|
+
# This is a separate method to make life easier for
|
296
|
+
# subclasses to add new actions.
|
297
|
+
return self.take_action(
|
298
|
+
self.action, self.dest, opt, value, values, parser)
|
299
|
+
|
300
|
+
|
301
|
+
class OptionParser(optparse.OptionParser):
|
302
|
+
|
303
|
+
def __init__(self, option_class=Option, *args, **kwargs):
|
304
|
+
optparse.OptionParser.__init__(self, option_class=Option, *args, **kwargs)
|
305
|
+
|
306
|
+
def format_option_help(self, formatter=None):
|
307
|
+
if formatter is None:
|
308
|
+
formatter = self.formatter
|
309
|
+
outputlevel = getattr(formatter, 'output_level', 0)
|
310
|
+
formatter.store_option_strings(self)
|
311
|
+
result = []
|
312
|
+
result.append(formatter.format_heading("Options"))
|
313
|
+
formatter.indent()
|
314
|
+
if self.option_list:
|
315
|
+
result.append(optparse.OptionContainer.format_option_help(self, formatter))
|
316
|
+
result.append("\n")
|
317
|
+
for group in self.option_groups:
|
318
|
+
if group.level <= outputlevel and (
|
319
|
+
group.description or _level_options(group, outputlevel)):
|
320
|
+
result.append(group.format_help(formatter))
|
321
|
+
result.append("\n")
|
322
|
+
formatter.dedent()
|
323
|
+
# Drop the last "\n", or the header if no options or option groups:
|
324
|
+
return "".join(result[:-1])
|
325
|
+
|
326
|
+
def _match_long_opt(self, opt):
|
327
|
+
"""Disable abbreviations."""
|
328
|
+
if opt not in self._long_opt:
|
329
|
+
raise optparse.BadOptionError(opt)
|
330
|
+
return opt
|
331
|
+
|
332
|
+
|
333
|
+
# pylint: disable=abstract-method; by design?
|
334
|
+
class _ManHelpFormatter(optparse.HelpFormatter):
|
335
|
+
|
336
|
+
def __init__(self, indent_increment=0, max_help_position=24,
|
337
|
+
width=79, short_first=0):
|
338
|
+
optparse.HelpFormatter.__init__(
|
339
|
+
self, indent_increment, max_help_position, width, short_first)
|
340
|
+
|
341
|
+
def format_heading(self, heading):
|
342
|
+
return '.SH %s\n' % heading.upper()
|
343
|
+
|
344
|
+
def format_description(self, description):
|
345
|
+
return description
|
346
|
+
|
347
|
+
def format_option(self, option):
|
348
|
+
try:
|
349
|
+
optstring = option.option_strings
|
350
|
+
except AttributeError:
|
351
|
+
optstring = self.format_option_strings(option)
|
352
|
+
if option.help:
|
353
|
+
help_text = self.expand_default(option)
|
354
|
+
help = ' '.join([l.strip() for l in help_text.splitlines()])
|
355
|
+
else:
|
356
|
+
help = ''
|
357
|
+
return '''.IP "%s"
|
358
|
+
%s
|
359
|
+
''' % (optstring, help)
|
360
|
+
|
361
|
+
def format_head(self, optparser, pkginfo, section=1):
|
362
|
+
long_desc = ""
|
363
|
+
try:
|
364
|
+
pgm = optparser._get_prog_name()
|
365
|
+
except AttributeError:
|
366
|
+
# py >= 2.4.X (dunno which X exactly, at least 2)
|
367
|
+
pgm = optparser.get_prog_name()
|
368
|
+
short_desc = self.format_short_description(pgm, pkginfo.description)
|
369
|
+
if hasattr(pkginfo, "long_desc"):
|
370
|
+
long_desc = self.format_long_description(pgm, pkginfo.long_desc)
|
371
|
+
return '%s\n%s\n%s\n%s' % (self.format_title(pgm, section),
|
372
|
+
short_desc, self.format_synopsis(pgm),
|
373
|
+
long_desc)
|
374
|
+
|
375
|
+
@staticmethod
|
376
|
+
def format_title(pgm, section):
|
377
|
+
date = '-'.join(str(num) for num in time.localtime()[:3])
|
378
|
+
return '.TH %s %s "%s" %s' % (pgm, section, date, pgm)
|
379
|
+
|
380
|
+
@staticmethod
|
381
|
+
def format_short_description(pgm, short_desc):
|
382
|
+
return '''.SH NAME
|
383
|
+
.B %s
|
384
|
+
\- %s
|
385
|
+
''' % (pgm, short_desc.strip())
|
386
|
+
|
387
|
+
@staticmethod
|
388
|
+
def format_synopsis(pgm):
|
389
|
+
return '''.SH SYNOPSIS
|
390
|
+
.B %s
|
391
|
+
[
|
392
|
+
.I OPTIONS
|
393
|
+
] [
|
394
|
+
.I <arguments>
|
395
|
+
]
|
396
|
+
''' % pgm
|
397
|
+
|
398
|
+
@staticmethod
|
399
|
+
def format_long_description(pgm, long_desc):
|
400
|
+
long_desc = '\n'.join(line.lstrip()
|
401
|
+
for line in long_desc.splitlines())
|
402
|
+
long_desc = long_desc.replace('\n.\n', '\n\n')
|
403
|
+
if long_desc.lower().startswith(pgm):
|
404
|
+
long_desc = long_desc[len(pgm):]
|
405
|
+
return '''.SH DESCRIPTION
|
406
|
+
.B %s
|
407
|
+
%s
|
408
|
+
''' % (pgm, long_desc.strip())
|
409
|
+
|
410
|
+
@staticmethod
|
411
|
+
def format_tail(pkginfo):
|
412
|
+
tail = '''.SH SEE ALSO
|
413
|
+
/usr/share/doc/pythonX.Y-%s/
|
414
|
+
|
415
|
+
.SH BUGS
|
416
|
+
Please report bugs on the project\'s mailing list:
|
417
|
+
%s
|
418
|
+
|
419
|
+
.SH AUTHOR
|
420
|
+
%s <%s>
|
421
|
+
''' % (getattr(pkginfo, 'debian_name', pkginfo.modname),
|
422
|
+
pkginfo.mailinglist, pkginfo.author, pkginfo.author_email)
|
423
|
+
|
424
|
+
if hasattr(pkginfo, "copyright"):
|
425
|
+
tail += '''
|
426
|
+
.SH COPYRIGHT
|
427
|
+
%s
|
428
|
+
''' % pkginfo.copyright
|
429
|
+
|
430
|
+
return tail
|
431
|
+
|
432
|
+
|
433
|
+
class OptionsManagerMixIn(object):
|
434
|
+
"""Handle configuration from both a configuration file and command line options"""
|
435
|
+
|
436
|
+
def __init__(self, usage, config_file=None, version=None, quiet=0):
|
437
|
+
self.config_file = config_file
|
438
|
+
self.reset_parsers(usage, version=version)
|
439
|
+
# list of registered options providers
|
440
|
+
self.options_providers = []
|
441
|
+
# dictionary associating option name to checker
|
442
|
+
self._all_options = collections.OrderedDict()
|
443
|
+
self._short_options = {}
|
444
|
+
self._nocallback_options = {}
|
445
|
+
self._mygroups = {}
|
446
|
+
# verbosity
|
447
|
+
self.quiet = quiet
|
448
|
+
self._maxlevel = 0
|
449
|
+
|
450
|
+
def reset_parsers(self, usage='', version=None):
|
451
|
+
# configuration file parser
|
452
|
+
self.cfgfile_parser = configparser.ConfigParser()
|
453
|
+
# command line parser
|
454
|
+
self.cmdline_parser = OptionParser(usage=usage, version=version)
|
455
|
+
self.cmdline_parser.options_manager = self
|
456
|
+
self._optik_option_attrs = set(self.cmdline_parser.option_class.ATTRS)
|
457
|
+
|
458
|
+
def register_options_provider(self, provider, own_group=True):
|
459
|
+
"""register an options provider"""
|
460
|
+
assert provider.priority <= 0, "provider's priority can't be >= 0"
|
461
|
+
for i in range(len(self.options_providers)):
|
462
|
+
if provider.priority > self.options_providers[i].priority:
|
463
|
+
self.options_providers.insert(i, provider)
|
464
|
+
break
|
465
|
+
else:
|
466
|
+
self.options_providers.append(provider)
|
467
|
+
non_group_spec_options = [option for option in provider.options
|
468
|
+
if 'group' not in option[1]]
|
469
|
+
groups = getattr(provider, 'option_groups', ())
|
470
|
+
if own_group and non_group_spec_options:
|
471
|
+
self.add_option_group(provider.name.upper(), provider.__doc__,
|
472
|
+
non_group_spec_options, provider)
|
473
|
+
else:
|
474
|
+
for opt, optdict in non_group_spec_options:
|
475
|
+
self.add_optik_option(provider, self.cmdline_parser, opt, optdict)
|
476
|
+
for gname, gdoc in groups:
|
477
|
+
gname = gname.upper()
|
478
|
+
goptions = [option for option in provider.options
|
479
|
+
if option[1].get('group', '').upper() == gname]
|
480
|
+
self.add_option_group(gname, gdoc, goptions, provider)
|
481
|
+
|
482
|
+
def add_option_group(self, group_name, _, options, provider):
|
483
|
+
# add option group to the command line parser
|
484
|
+
if group_name in self._mygroups:
|
485
|
+
group = self._mygroups[group_name]
|
486
|
+
else:
|
487
|
+
group = optparse.OptionGroup(self.cmdline_parser,
|
488
|
+
title=group_name.capitalize())
|
489
|
+
self.cmdline_parser.add_option_group(group)
|
490
|
+
group.level = provider.level
|
491
|
+
self._mygroups[group_name] = group
|
492
|
+
# add section to the config file
|
493
|
+
if group_name != "DEFAULT":
|
494
|
+
self.cfgfile_parser.add_section(group_name)
|
495
|
+
# add provider's specific options
|
496
|
+
for opt, optdict in options:
|
497
|
+
self.add_optik_option(provider, group, opt, optdict)
|
498
|
+
|
499
|
+
def add_optik_option(self, provider, optikcontainer, opt, optdict):
|
500
|
+
args, optdict = self.optik_option(provider, opt, optdict)
|
501
|
+
option = optikcontainer.add_option(*args, **optdict)
|
502
|
+
self._all_options[opt] = provider
|
503
|
+
self._maxlevel = max(self._maxlevel, option.level or 0)
|
504
|
+
|
505
|
+
def optik_option(self, provider, opt, optdict):
|
506
|
+
"""get our personal option definition and return a suitable form for
|
507
|
+
use with optik/optparse
|
508
|
+
"""
|
509
|
+
optdict = copy.copy(optdict)
|
510
|
+
if 'action' in optdict:
|
511
|
+
self._nocallback_options[provider] = opt
|
512
|
+
else:
|
513
|
+
optdict['action'] = 'callback'
|
514
|
+
optdict['callback'] = self.cb_set_provider_option
|
515
|
+
# default is handled here and *must not* be given to optik if you
|
516
|
+
# want the whole machinery to work
|
517
|
+
if 'default' in optdict:
|
518
|
+
if ('help' in optdict
|
519
|
+
and optdict.get('default') is not None
|
520
|
+
and optdict['action'] not in ('store_true', 'store_false')):
|
521
|
+
optdict['help'] += ' [current: %default]'
|
522
|
+
del optdict['default']
|
523
|
+
args = ['--' + str(opt)]
|
524
|
+
if 'short' in optdict:
|
525
|
+
self._short_options[optdict['short']] = opt
|
526
|
+
args.append('-' + optdict['short'])
|
527
|
+
del optdict['short']
|
528
|
+
# cleanup option definition dict before giving it to optik
|
529
|
+
for key in list(optdict.keys()):
|
530
|
+
if key not in self._optik_option_attrs:
|
531
|
+
optdict.pop(key)
|
532
|
+
return args, optdict
|
533
|
+
|
534
|
+
def cb_set_provider_option(self, option, opt, value, parser):
|
535
|
+
"""optik callback for option setting"""
|
536
|
+
if opt.startswith('--'):
|
537
|
+
# remove -- on long option
|
538
|
+
opt = opt[2:]
|
539
|
+
else:
|
540
|
+
# short option, get its long equivalent
|
541
|
+
opt = self._short_options[opt[1:]]
|
542
|
+
# trick since we can't set action='store_true' on options
|
543
|
+
if value is None:
|
544
|
+
value = 1
|
545
|
+
self.global_set_option(opt, value)
|
546
|
+
|
547
|
+
def global_set_option(self, opt, value):
|
548
|
+
"""set option on the correct option provider"""
|
549
|
+
self._all_options[opt].set_option(opt, value)
|
550
|
+
|
551
|
+
def generate_config(self, stream=None, skipsections=(), encoding=None):
|
552
|
+
"""write a configuration file according to the current configuration
|
553
|
+
into the given stream or stdout
|
554
|
+
"""
|
555
|
+
options_by_section = {}
|
556
|
+
sections = []
|
557
|
+
for provider in self.options_providers:
|
558
|
+
for section, options in provider.options_by_section():
|
559
|
+
if section is None:
|
560
|
+
section = provider.name
|
561
|
+
if section in skipsections:
|
562
|
+
continue
|
563
|
+
options = [(n, d, v) for (n, d, v) in options
|
564
|
+
if d.get('type') is not None
|
565
|
+
and not d.get('deprecated')]
|
566
|
+
if not options:
|
567
|
+
continue
|
568
|
+
if section not in sections:
|
569
|
+
sections.append(section)
|
570
|
+
alloptions = options_by_section.setdefault(section, [])
|
571
|
+
alloptions += options
|
572
|
+
stream = stream or sys.stdout
|
573
|
+
encoding = utils._get_encoding(encoding, stream)
|
574
|
+
printed = False
|
575
|
+
for section in sections:
|
576
|
+
if printed:
|
577
|
+
print('\n', file=stream)
|
578
|
+
utils.format_section(stream, section.upper(),
|
579
|
+
options_by_section[section],
|
580
|
+
encoding)
|
581
|
+
printed = True
|
582
|
+
|
583
|
+
def generate_manpage(self, pkginfo, section=1, stream=None):
|
584
|
+
with _patch_optparse():
|
585
|
+
_generate_manpage(self.cmdline_parser, pkginfo,
|
586
|
+
section, stream=stream or sys.stdout,
|
587
|
+
level=self._maxlevel)
|
588
|
+
|
589
|
+
def load_provider_defaults(self):
|
590
|
+
"""initialize configuration using default values"""
|
591
|
+
for provider in self.options_providers:
|
592
|
+
provider.load_defaults()
|
593
|
+
|
594
|
+
def read_config_file(self, config_file=None):
|
595
|
+
"""read the configuration file but do not load it (i.e. dispatching
|
596
|
+
values to each options provider)
|
597
|
+
"""
|
598
|
+
helplevel = 1
|
599
|
+
while helplevel <= self._maxlevel:
|
600
|
+
opt = '-'.join(['long'] * helplevel) + '-help'
|
601
|
+
if opt in self._all_options:
|
602
|
+
break # already processed
|
603
|
+
# pylint: disable=unused-argument
|
604
|
+
def helpfunc(option, opt, val, p, level=helplevel):
|
605
|
+
print(self.help(level))
|
606
|
+
sys.exit(0)
|
607
|
+
helpmsg = '%s verbose help.' % ' '.join(['more'] * helplevel)
|
608
|
+
optdict = {'action': 'callback', 'callback': helpfunc,
|
609
|
+
'help': helpmsg}
|
610
|
+
provider = self.options_providers[0]
|
611
|
+
self.add_optik_option(provider, self.cmdline_parser, opt, optdict)
|
612
|
+
provider.options += ((opt, optdict),)
|
613
|
+
helplevel += 1
|
614
|
+
if config_file is None:
|
615
|
+
config_file = self.config_file
|
616
|
+
if config_file is not None:
|
617
|
+
config_file = os.path.expanduser(config_file)
|
618
|
+
if config_file and os.path.exists(config_file):
|
619
|
+
parser = self.cfgfile_parser
|
620
|
+
|
621
|
+
# Use this encoding in order to strip the BOM marker, if any.
|
622
|
+
with io.open(config_file, 'r', encoding='utf_8_sig') as fp:
|
623
|
+
# pylint: disable=deprecated-method
|
624
|
+
parser.readfp(fp)
|
625
|
+
|
626
|
+
# normalize sections'title
|
627
|
+
for sect, values in list(parser._sections.items()):
|
628
|
+
if not sect.isupper() and values:
|
629
|
+
parser._sections[sect.upper()] = values
|
630
|
+
elif not self.quiet:
|
631
|
+
msg = 'No config file found, using default configuration'
|
632
|
+
print(msg, file=sys.stderr)
|
633
|
+
return
|
634
|
+
|
635
|
+
def load_config_file(self):
|
636
|
+
"""dispatch values previously read from a configuration file to each
|
637
|
+
options provider)
|
638
|
+
"""
|
639
|
+
parser = self.cfgfile_parser
|
640
|
+
for section in parser.sections():
|
641
|
+
for option, value in parser.items(section):
|
642
|
+
try:
|
643
|
+
self.global_set_option(option, value)
|
644
|
+
except (KeyError, optparse.OptionError):
|
645
|
+
# TODO handle here undeclared options appearing in the config file
|
646
|
+
continue
|
647
|
+
|
648
|
+
def load_configuration(self, **kwargs):
|
649
|
+
"""override configuration according to given parameters"""
|
650
|
+
return self.load_configuration_from_config(kwargs)
|
651
|
+
|
652
|
+
def load_configuration_from_config(self, config):
|
653
|
+
for opt, opt_value in config.items():
|
654
|
+
opt = opt.replace('_', '-')
|
655
|
+
provider = self._all_options[opt]
|
656
|
+
provider.set_option(opt, opt_value)
|
657
|
+
|
658
|
+
def load_command_line_configuration(self, args=None):
|
659
|
+
"""Override configuration according to command line parameters
|
660
|
+
|
661
|
+
return additional arguments
|
662
|
+
"""
|
663
|
+
with _patch_optparse():
|
664
|
+
if args is None:
|
665
|
+
args = sys.argv[1:]
|
666
|
+
else:
|
667
|
+
args = list(args)
|
668
|
+
(options, args) = self.cmdline_parser.parse_args(args=args)
|
669
|
+
for provider in self._nocallback_options.keys():
|
670
|
+
config = provider.config
|
671
|
+
for attr in config.__dict__.keys():
|
672
|
+
value = getattr(options, attr, None)
|
673
|
+
if value is None:
|
674
|
+
continue
|
675
|
+
setattr(config, attr, value)
|
676
|
+
return args
|
677
|
+
|
678
|
+
def add_help_section(self, title, description, level=0):
|
679
|
+
"""add a dummy option section for help purpose """
|
680
|
+
group = optparse.OptionGroup(self.cmdline_parser,
|
681
|
+
title=title.capitalize(),
|
682
|
+
description=description)
|
683
|
+
group.level = level
|
684
|
+
self._maxlevel = max(self._maxlevel, level)
|
685
|
+
self.cmdline_parser.add_option_group(group)
|
686
|
+
|
687
|
+
def help(self, level=0):
|
688
|
+
"""return the usage string for available options """
|
689
|
+
self.cmdline_parser.formatter.output_level = level
|
690
|
+
with _patch_optparse():
|
691
|
+
return self.cmdline_parser.format_help()
|
692
|
+
|
693
|
+
|
694
|
+
class OptionsProviderMixIn(object):
|
695
|
+
"""Mixin to provide options to an OptionsManager"""
|
696
|
+
|
697
|
+
# those attributes should be overridden
|
698
|
+
priority = -1
|
699
|
+
name = 'default'
|
700
|
+
options = ()
|
701
|
+
level = 0
|
702
|
+
|
703
|
+
def __init__(self):
|
704
|
+
self.config = optparse.Values()
|
705
|
+
self.load_defaults()
|
706
|
+
|
707
|
+
def load_defaults(self):
|
708
|
+
"""initialize the provider using default values"""
|
709
|
+
for opt, optdict in self.options:
|
710
|
+
action = optdict.get('action')
|
711
|
+
if action != 'callback':
|
712
|
+
# callback action have no default
|
713
|
+
if optdict is None:
|
714
|
+
optdict = self.get_option_def(opt)
|
715
|
+
default = optdict.get('default')
|
716
|
+
self.set_option(opt, default, action, optdict)
|
717
|
+
|
718
|
+
def option_attrname(self, opt, optdict=None):
|
719
|
+
"""get the config attribute corresponding to opt"""
|
720
|
+
if optdict is None:
|
721
|
+
optdict = self.get_option_def(opt)
|
722
|
+
return optdict.get('dest', opt.replace('-', '_'))
|
723
|
+
|
724
|
+
def option_value(self, opt):
|
725
|
+
"""get the current value for the given option"""
|
726
|
+
return getattr(self.config, self.option_attrname(opt), None)
|
727
|
+
|
728
|
+
def set_option(self, opt, value, action=None, optdict=None):
|
729
|
+
"""method called to set an option (registered in the options list)"""
|
730
|
+
if optdict is None:
|
731
|
+
optdict = self.get_option_def(opt)
|
732
|
+
if value is not None:
|
733
|
+
value = _validate(value, optdict, opt)
|
734
|
+
if action is None:
|
735
|
+
action = optdict.get('action', 'store')
|
736
|
+
if action == 'store':
|
737
|
+
setattr(self.config, self.option_attrname(opt, optdict), value)
|
738
|
+
elif action in ('store_true', 'count'):
|
739
|
+
setattr(self.config, self.option_attrname(opt, optdict), 0)
|
740
|
+
elif action == 'store_false':
|
741
|
+
setattr(self.config, self.option_attrname(opt, optdict), 1)
|
742
|
+
elif action == 'append':
|
743
|
+
opt = self.option_attrname(opt, optdict)
|
744
|
+
_list = getattr(self.config, opt, None)
|
745
|
+
if _list is None:
|
746
|
+
if isinstance(value, (list, tuple)):
|
747
|
+
_list = value
|
748
|
+
elif value is not None:
|
749
|
+
_list = []
|
750
|
+
_list.append(value)
|
751
|
+
setattr(self.config, opt, _list)
|
752
|
+
elif isinstance(_list, tuple):
|
753
|
+
setattr(self.config, opt, _list + (value,))
|
754
|
+
else:
|
755
|
+
_list.append(value)
|
756
|
+
elif action == 'callback':
|
757
|
+
optdict['callback'](None, opt, value, None)
|
758
|
+
else:
|
759
|
+
raise UnsupportedAction(action)
|
760
|
+
|
761
|
+
def get_option_def(self, opt):
|
762
|
+
"""return the dictionary defining an option given its name"""
|
763
|
+
assert self.options
|
764
|
+
for option in self.options:
|
765
|
+
if option[0] == opt:
|
766
|
+
return option[1]
|
767
|
+
raise optparse.OptionError('no such option %s in section %r'
|
768
|
+
% (opt, self.name), opt)
|
769
|
+
|
770
|
+
def options_by_section(self):
|
771
|
+
"""return an iterator on options grouped by section
|
772
|
+
|
773
|
+
(section, [list of (optname, optdict, optvalue)])
|
774
|
+
"""
|
775
|
+
sections = {}
|
776
|
+
for optname, optdict in self.options:
|
777
|
+
sections.setdefault(optdict.get('group'), []).append(
|
778
|
+
(optname, optdict, self.option_value(optname)))
|
779
|
+
if None in sections:
|
780
|
+
yield None, sections.pop(None)
|
781
|
+
for section, options in sorted(sections.items()):
|
782
|
+
yield section.upper(), options
|
783
|
+
|
784
|
+
def options_and_values(self, options=None):
|
785
|
+
if options is None:
|
786
|
+
options = self.options
|
787
|
+
for optname, optdict in options:
|
788
|
+
yield (optname, optdict, self.option_value(optname))
|
789
|
+
|
790
|
+
|
791
|
+
class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn):
|
792
|
+
"""basic mixin for simple configurations which don't need the
|
793
|
+
manager / providers model
|
794
|
+
"""
|
795
|
+
def __init__(self, *args, **kwargs):
|
796
|
+
if not args:
|
797
|
+
kwargs.setdefault('usage', '')
|
798
|
+
kwargs.setdefault('quiet', 1)
|
799
|
+
OptionsManagerMixIn.__init__(self, *args, **kwargs)
|
800
|
+
OptionsProviderMixIn.__init__(self)
|
801
|
+
if not getattr(self, 'option_groups', None):
|
802
|
+
self.option_groups = []
|
803
|
+
for _, optdict in self.options:
|
804
|
+
try:
|
805
|
+
gdef = (optdict['group'].upper(), '')
|
806
|
+
except KeyError:
|
807
|
+
continue
|
808
|
+
if gdef not in self.option_groups:
|
809
|
+
self.option_groups.append(gdef)
|
810
|
+
self.register_options_provider(self, own_group=False)
|
811
|
+
|
812
|
+
|
813
|
+
def _generate_manpage(optparser, pkginfo, section=1,
|
814
|
+
stream=sys.stdout, level=0):
|
815
|
+
formatter = _ManHelpFormatter()
|
816
|
+
formatter.output_level = level
|
817
|
+
formatter.parser = optparser
|
818
|
+
print(formatter.format_head(optparser, pkginfo, section), file=stream)
|
819
|
+
print(optparser.format_option_help(formatter), file=stream)
|
820
|
+
print(formatter.format_tail(pkginfo), file=stream)
|