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
@@ -1,87 +0,0 @@
|
|
1
|
-
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
|
2
|
-
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
|
3
|
-
#
|
4
|
-
# This file is part of logilab-common.
|
5
|
-
#
|
6
|
-
# logilab-common is free software: you can redistribute it and/or modify it under
|
7
|
-
# the terms of the GNU Lesser General Public License as published by the Free
|
8
|
-
# Software Foundation, either version 2.1 of the License, or (at your option) any
|
9
|
-
# later version.
|
10
|
-
#
|
11
|
-
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
-
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
14
|
-
# details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU Lesser General Public License along
|
17
|
-
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
from logilab.common.decorators import monkeypatch
|
19
|
-
|
20
|
-
from sphinx.ext import autodoc
|
21
|
-
|
22
|
-
class DocstringOnlyModuleDocumenter(autodoc.ModuleDocumenter):
|
23
|
-
objtype = 'docstring'
|
24
|
-
def format_signature(self):
|
25
|
-
pass
|
26
|
-
def add_directive_header(self, sig):
|
27
|
-
pass
|
28
|
-
def document_members(self, all_members=False):
|
29
|
-
pass
|
30
|
-
|
31
|
-
def resolve_name(self, modname, parents, path, base):
|
32
|
-
if modname is not None:
|
33
|
-
return modname, parents + [base]
|
34
|
-
return (path or '') + base, []
|
35
|
-
|
36
|
-
|
37
|
-
#autodoc.add_documenter(DocstringOnlyModuleDocumenter)
|
38
|
-
|
39
|
-
def setup(app):
|
40
|
-
app.add_autodocumenter(DocstringOnlyModuleDocumenter)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
from sphinx.ext.autodoc import (ViewList, Options, AutodocReporter, nodes,
|
45
|
-
assemble_option_dict, nested_parse_with_titles)
|
46
|
-
|
47
|
-
@monkeypatch(autodoc.AutoDirective)
|
48
|
-
def run(self):
|
49
|
-
self.filename_set = set() # a set of dependent filenames
|
50
|
-
self.reporter = self.state.document.reporter
|
51
|
-
self.env = self.state.document.settings.env
|
52
|
-
self.warnings = []
|
53
|
-
self.result = ViewList()
|
54
|
-
|
55
|
-
# find out what documenter to call
|
56
|
-
objtype = self.name[4:]
|
57
|
-
doc_class = self._registry[objtype]
|
58
|
-
# process the options with the selected documenter's option_spec
|
59
|
-
self.genopt = Options(assemble_option_dict(
|
60
|
-
self.options.items(), doc_class.option_spec))
|
61
|
-
# generate the output
|
62
|
-
documenter = doc_class(self, self.arguments[0])
|
63
|
-
documenter.generate(more_content=self.content)
|
64
|
-
if not self.result:
|
65
|
-
return self.warnings
|
66
|
-
|
67
|
-
# record all filenames as dependencies -- this will at least
|
68
|
-
# partially make automatic invalidation possible
|
69
|
-
for fn in self.filename_set:
|
70
|
-
self.env.note_dependency(fn)
|
71
|
-
|
72
|
-
# use a custom reporter that correctly assigns lines to source
|
73
|
-
# filename/description and lineno
|
74
|
-
old_reporter = self.state.memo.reporter
|
75
|
-
self.state.memo.reporter = AutodocReporter(self.result,
|
76
|
-
self.state.memo.reporter)
|
77
|
-
if self.name in ('automodule', 'autodocstring'):
|
78
|
-
node = nodes.section()
|
79
|
-
# necessary so that the child nodes get the right source/line set
|
80
|
-
node.document = self.state.document
|
81
|
-
nested_parse_with_titles(self.state, self.result, node)
|
82
|
-
else:
|
83
|
-
node = nodes.paragraph()
|
84
|
-
node.document = self.state.document
|
85
|
-
self.state.nested_parse(self.result, 0, node)
|
86
|
-
self.state.memo.reporter = old_reporter
|
87
|
-
return self.warnings + node.children
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
|
2
|
-
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
|
3
|
-
#
|
4
|
-
# This file is part of logilab-common.
|
5
|
-
#
|
6
|
-
# logilab-common is free software: you can redistribute it and/or modify it under
|
7
|
-
# the terms of the GNU Lesser General Public License as published by the Free
|
8
|
-
# Software Foundation, either version 2.1 of the License, or (at your option) any
|
9
|
-
# later version.
|
10
|
-
#
|
11
|
-
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
-
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
14
|
-
# details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU Lesser General Public License along
|
17
|
-
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
"""Sphinx utils
|
19
|
-
|
20
|
-
ModuleGenerator: Generate a file that lists all the modules of a list of
|
21
|
-
packages in order to pull all the docstring.
|
22
|
-
This should not be used in a makefile to systematically generate sphinx
|
23
|
-
documentation!
|
24
|
-
|
25
|
-
Typical usage:
|
26
|
-
|
27
|
-
>>> from logilab.common.sphinxutils import ModuleGenerator
|
28
|
-
>>> mgen = ModuleGenerator('logilab common', '/home/adim/src/logilab/common')
|
29
|
-
>>> mgen.generate('api_logilab_common.rst', exclude_dirs=('test',))
|
30
|
-
"""
|
31
|
-
|
32
|
-
import os, sys
|
33
|
-
import os.path as osp
|
34
|
-
import inspect
|
35
|
-
|
36
|
-
from logilab.common import STD_BLACKLIST
|
37
|
-
from logilab.common.shellutils import globfind
|
38
|
-
from logilab.common.modutils import load_module_from_file, modpath_from_file
|
39
|
-
|
40
|
-
def module_members(module):
|
41
|
-
members = []
|
42
|
-
for name, value in inspect.getmembers(module):
|
43
|
-
if getattr(value, '__module__', None) == module.__name__:
|
44
|
-
members.append( (name, value) )
|
45
|
-
return sorted(members)
|
46
|
-
|
47
|
-
|
48
|
-
def class_members(klass):
|
49
|
-
return sorted([name for name in vars(klass)
|
50
|
-
if name not in ('__doc__', '__module__',
|
51
|
-
'__dict__', '__weakref__')])
|
52
|
-
|
53
|
-
class ModuleGenerator:
|
54
|
-
file_header = """.. -*- coding: utf-8 -*-\n\n%s\n"""
|
55
|
-
module_def = """
|
56
|
-
:mod:`%s`
|
57
|
-
=======%s
|
58
|
-
|
59
|
-
.. automodule:: %s
|
60
|
-
:members: %s
|
61
|
-
"""
|
62
|
-
class_def = """
|
63
|
-
|
64
|
-
.. autoclass:: %s
|
65
|
-
:members: %s
|
66
|
-
|
67
|
-
"""
|
68
|
-
|
69
|
-
def __init__(self, project_title, code_dir):
|
70
|
-
self.title = project_title
|
71
|
-
self.code_dir = osp.abspath(code_dir)
|
72
|
-
|
73
|
-
def generate(self, dest_file, exclude_dirs=STD_BLACKLIST):
|
74
|
-
"""make the module file"""
|
75
|
-
self.fn = open(dest_file, 'w')
|
76
|
-
num = len(self.title) + 6
|
77
|
-
title = "=" * num + "\n %s API\n" % self.title + "=" * num
|
78
|
-
self.fn.write(self.file_header % title)
|
79
|
-
self.gen_modules(exclude_dirs=exclude_dirs)
|
80
|
-
self.fn.close()
|
81
|
-
|
82
|
-
def gen_modules(self, exclude_dirs):
|
83
|
-
"""generate all modules"""
|
84
|
-
for module in self.find_modules(exclude_dirs):
|
85
|
-
modname = module.__name__
|
86
|
-
classes = []
|
87
|
-
modmembers = []
|
88
|
-
for objname, obj in module_members(module):
|
89
|
-
if inspect.isclass(obj):
|
90
|
-
classmembers = class_members(obj)
|
91
|
-
classes.append( (objname, classmembers) )
|
92
|
-
else:
|
93
|
-
modmembers.append(objname)
|
94
|
-
self.fn.write(self.module_def % (modname, '=' * len(modname),
|
95
|
-
modname,
|
96
|
-
', '.join(modmembers)))
|
97
|
-
for klass, members in classes:
|
98
|
-
self.fn.write(self.class_def % (klass, ', '.join(members)))
|
99
|
-
|
100
|
-
def find_modules(self, exclude_dirs):
|
101
|
-
basepath = osp.dirname(self.code_dir)
|
102
|
-
basedir = osp.basename(basepath) + osp.sep
|
103
|
-
if basedir not in sys.path:
|
104
|
-
sys.path.insert(1, basedir)
|
105
|
-
for filepath in globfind(self.code_dir, '*.py', exclude_dirs):
|
106
|
-
if osp.basename(filepath) in ('setup.py', '__pkginfo__.py'):
|
107
|
-
continue
|
108
|
-
try:
|
109
|
-
module = load_module_from_file(filepath)
|
110
|
-
except: # module might be broken or magic
|
111
|
-
dotted_path = modpath_from_file(filepath)
|
112
|
-
module = type('.'.join(dotted_path), (), {}) # mock it
|
113
|
-
yield module
|
114
|
-
|
115
|
-
|
116
|
-
if __name__ == '__main__':
|
117
|
-
# example :
|
118
|
-
title, code_dir, outfile = sys.argv[1:]
|
119
|
-
generator = ModuleGenerator(title, code_dir)
|
120
|
-
# XXX modnames = ['logilab']
|
121
|
-
generator.generate(outfile, ('test', 'tests', 'examples',
|
122
|
-
'data', 'doc', '.hg', 'migration'))
|
@@ -1,929 +0,0 @@
|
|
1
|
-
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
|
2
|
-
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
|
3
|
-
#
|
4
|
-
# This file is part of logilab-common.
|
5
|
-
#
|
6
|
-
# logilab-common is free software: you can redistribute it and/or modify it under
|
7
|
-
# the terms of the GNU Lesser General Public License as published by the Free
|
8
|
-
# Software Foundation, either version 2.1 of the License, or (at your option) any
|
9
|
-
# later version.
|
10
|
-
#
|
11
|
-
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
-
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
14
|
-
# details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU Lesser General Public License along
|
17
|
-
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
"""Table management module."""
|
19
|
-
|
20
|
-
from __future__ import print_function
|
21
|
-
|
22
|
-
__docformat__ = "restructuredtext en"
|
23
|
-
|
24
|
-
from six.moves import range
|
25
|
-
|
26
|
-
class Table(object):
|
27
|
-
"""Table defines a data table with column and row names.
|
28
|
-
inv:
|
29
|
-
len(self.data) <= len(self.row_names)
|
30
|
-
forall(self.data, lambda x: len(x) <= len(self.col_names))
|
31
|
-
"""
|
32
|
-
|
33
|
-
def __init__(self, default_value=0, col_names=None, row_names=None):
|
34
|
-
self.col_names = []
|
35
|
-
self.row_names = []
|
36
|
-
self.data = []
|
37
|
-
self.default_value = default_value
|
38
|
-
if col_names:
|
39
|
-
self.create_columns(col_names)
|
40
|
-
if row_names:
|
41
|
-
self.create_rows(row_names)
|
42
|
-
|
43
|
-
def _next_row_name(self):
|
44
|
-
return 'row%s' % (len(self.row_names)+1)
|
45
|
-
|
46
|
-
def __iter__(self):
|
47
|
-
return iter(self.data)
|
48
|
-
|
49
|
-
def __eq__(self, other):
|
50
|
-
if other is None:
|
51
|
-
return False
|
52
|
-
else:
|
53
|
-
return list(self) == list(other)
|
54
|
-
|
55
|
-
__hash__ = object.__hash__
|
56
|
-
|
57
|
-
def __ne__(self, other):
|
58
|
-
return not self == other
|
59
|
-
|
60
|
-
def __len__(self):
|
61
|
-
return len(self.row_names)
|
62
|
-
|
63
|
-
## Rows / Columns creation #################################################
|
64
|
-
def create_rows(self, row_names):
|
65
|
-
"""Appends row_names to the list of existing rows
|
66
|
-
"""
|
67
|
-
self.row_names.extend(row_names)
|
68
|
-
for row_name in row_names:
|
69
|
-
self.data.append([self.default_value]*len(self.col_names))
|
70
|
-
|
71
|
-
def create_columns(self, col_names):
|
72
|
-
"""Appends col_names to the list of existing columns
|
73
|
-
"""
|
74
|
-
for col_name in col_names:
|
75
|
-
self.create_column(col_name)
|
76
|
-
|
77
|
-
def create_row(self, row_name=None):
|
78
|
-
"""Creates a rowname to the row_names list
|
79
|
-
"""
|
80
|
-
row_name = row_name or self._next_row_name()
|
81
|
-
self.row_names.append(row_name)
|
82
|
-
self.data.append([self.default_value]*len(self.col_names))
|
83
|
-
|
84
|
-
|
85
|
-
def create_column(self, col_name):
|
86
|
-
"""Creates a colname to the col_names list
|
87
|
-
"""
|
88
|
-
self.col_names.append(col_name)
|
89
|
-
for row in self.data:
|
90
|
-
row.append(self.default_value)
|
91
|
-
|
92
|
-
## Sort by column ##########################################################
|
93
|
-
def sort_by_column_id(self, col_id, method = 'asc'):
|
94
|
-
"""Sorts the table (in-place) according to data stored in col_id
|
95
|
-
"""
|
96
|
-
try:
|
97
|
-
col_index = self.col_names.index(col_id)
|
98
|
-
self.sort_by_column_index(col_index, method)
|
99
|
-
except ValueError:
|
100
|
-
raise KeyError("Col (%s) not found in table" % (col_id))
|
101
|
-
|
102
|
-
|
103
|
-
def sort_by_column_index(self, col_index, method = 'asc'):
|
104
|
-
"""Sorts the table 'in-place' according to data stored in col_index
|
105
|
-
|
106
|
-
method should be in ('asc', 'desc')
|
107
|
-
"""
|
108
|
-
sort_list = sorted([(row[col_index], row, row_name)
|
109
|
-
for row, row_name in zip(self.data, self.row_names)])
|
110
|
-
# Sorting sort_list will sort according to col_index
|
111
|
-
# If we want reverse sort, then reverse list
|
112
|
-
if method.lower() == 'desc':
|
113
|
-
sort_list.reverse()
|
114
|
-
|
115
|
-
# Rebuild data / row names
|
116
|
-
self.data = []
|
117
|
-
self.row_names = []
|
118
|
-
for val, row, row_name in sort_list:
|
119
|
-
self.data.append(row)
|
120
|
-
self.row_names.append(row_name)
|
121
|
-
|
122
|
-
def groupby(self, colname, *others):
|
123
|
-
"""builds indexes of data
|
124
|
-
:returns: nested dictionaries pointing to actual rows
|
125
|
-
"""
|
126
|
-
groups = {}
|
127
|
-
colnames = (colname,) + others
|
128
|
-
col_indexes = [self.col_names.index(col_id) for col_id in colnames]
|
129
|
-
for row in self.data:
|
130
|
-
ptr = groups
|
131
|
-
for col_index in col_indexes[:-1]:
|
132
|
-
ptr = ptr.setdefault(row[col_index], {})
|
133
|
-
ptr = ptr.setdefault(row[col_indexes[-1]],
|
134
|
-
Table(default_value=self.default_value,
|
135
|
-
col_names=self.col_names))
|
136
|
-
ptr.append_row(tuple(row))
|
137
|
-
return groups
|
138
|
-
|
139
|
-
def select(self, colname, value):
|
140
|
-
grouped = self.groupby(colname)
|
141
|
-
try:
|
142
|
-
return grouped[value]
|
143
|
-
except KeyError:
|
144
|
-
return []
|
145
|
-
|
146
|
-
def remove(self, colname, value):
|
147
|
-
col_index = self.col_names.index(colname)
|
148
|
-
for row in self.data[:]:
|
149
|
-
if row[col_index] == value:
|
150
|
-
self.data.remove(row)
|
151
|
-
|
152
|
-
|
153
|
-
## The 'setter' part #######################################################
|
154
|
-
def set_cell(self, row_index, col_index, data):
|
155
|
-
"""sets value of cell 'row_indew', 'col_index' to data
|
156
|
-
"""
|
157
|
-
self.data[row_index][col_index] = data
|
158
|
-
|
159
|
-
|
160
|
-
def set_cell_by_ids(self, row_id, col_id, data):
|
161
|
-
"""sets value of cell mapped by row_id and col_id to data
|
162
|
-
Raises a KeyError if row_id or col_id are not found in the table
|
163
|
-
"""
|
164
|
-
try:
|
165
|
-
row_index = self.row_names.index(row_id)
|
166
|
-
except ValueError:
|
167
|
-
raise KeyError("Row (%s) not found in table" % (row_id))
|
168
|
-
else:
|
169
|
-
try:
|
170
|
-
col_index = self.col_names.index(col_id)
|
171
|
-
self.data[row_index][col_index] = data
|
172
|
-
except ValueError:
|
173
|
-
raise KeyError("Column (%s) not found in table" % (col_id))
|
174
|
-
|
175
|
-
|
176
|
-
def set_row(self, row_index, row_data):
|
177
|
-
"""sets the 'row_index' row
|
178
|
-
pre:
|
179
|
-
type(row_data) == types.ListType
|
180
|
-
len(row_data) == len(self.col_names)
|
181
|
-
"""
|
182
|
-
self.data[row_index] = row_data
|
183
|
-
|
184
|
-
|
185
|
-
def set_row_by_id(self, row_id, row_data):
|
186
|
-
"""sets the 'row_id' column
|
187
|
-
pre:
|
188
|
-
type(row_data) == types.ListType
|
189
|
-
len(row_data) == len(self.row_names)
|
190
|
-
Raises a KeyError if row_id is not found
|
191
|
-
"""
|
192
|
-
try:
|
193
|
-
row_index = self.row_names.index(row_id)
|
194
|
-
self.set_row(row_index, row_data)
|
195
|
-
except ValueError:
|
196
|
-
raise KeyError('Row (%s) not found in table' % (row_id))
|
197
|
-
|
198
|
-
|
199
|
-
def append_row(self, row_data, row_name=None):
|
200
|
-
"""Appends a row to the table
|
201
|
-
pre:
|
202
|
-
type(row_data) == types.ListType
|
203
|
-
len(row_data) == len(self.col_names)
|
204
|
-
"""
|
205
|
-
row_name = row_name or self._next_row_name()
|
206
|
-
self.row_names.append(row_name)
|
207
|
-
self.data.append(row_data)
|
208
|
-
return len(self.data) - 1
|
209
|
-
|
210
|
-
def insert_row(self, index, row_data, row_name=None):
|
211
|
-
"""Appends row_data before 'index' in the table. To make 'insert'
|
212
|
-
behave like 'list.insert', inserting in an out of range index will
|
213
|
-
insert row_data to the end of the list
|
214
|
-
pre:
|
215
|
-
type(row_data) == types.ListType
|
216
|
-
len(row_data) == len(self.col_names)
|
217
|
-
"""
|
218
|
-
row_name = row_name or self._next_row_name()
|
219
|
-
self.row_names.insert(index, row_name)
|
220
|
-
self.data.insert(index, row_data)
|
221
|
-
|
222
|
-
|
223
|
-
def delete_row(self, index):
|
224
|
-
"""Deletes the 'index' row in the table, and returns it.
|
225
|
-
Raises an IndexError if index is out of range
|
226
|
-
"""
|
227
|
-
self.row_names.pop(index)
|
228
|
-
return self.data.pop(index)
|
229
|
-
|
230
|
-
|
231
|
-
def delete_row_by_id(self, row_id):
|
232
|
-
"""Deletes the 'row_id' row in the table.
|
233
|
-
Raises a KeyError if row_id was not found.
|
234
|
-
"""
|
235
|
-
try:
|
236
|
-
row_index = self.row_names.index(row_id)
|
237
|
-
self.delete_row(row_index)
|
238
|
-
except ValueError:
|
239
|
-
raise KeyError('Row (%s) not found in table' % (row_id))
|
240
|
-
|
241
|
-
|
242
|
-
def set_column(self, col_index, col_data):
|
243
|
-
"""sets the 'col_index' column
|
244
|
-
pre:
|
245
|
-
type(col_data) == types.ListType
|
246
|
-
len(col_data) == len(self.row_names)
|
247
|
-
"""
|
248
|
-
|
249
|
-
for row_index, cell_data in enumerate(col_data):
|
250
|
-
self.data[row_index][col_index] = cell_data
|
251
|
-
|
252
|
-
|
253
|
-
def set_column_by_id(self, col_id, col_data):
|
254
|
-
"""sets the 'col_id' column
|
255
|
-
pre:
|
256
|
-
type(col_data) == types.ListType
|
257
|
-
len(col_data) == len(self.col_names)
|
258
|
-
Raises a KeyError if col_id is not found
|
259
|
-
"""
|
260
|
-
try:
|
261
|
-
col_index = self.col_names.index(col_id)
|
262
|
-
self.set_column(col_index, col_data)
|
263
|
-
except ValueError:
|
264
|
-
raise KeyError('Column (%s) not found in table' % (col_id))
|
265
|
-
|
266
|
-
|
267
|
-
def append_column(self, col_data, col_name):
|
268
|
-
"""Appends the 'col_index' column
|
269
|
-
pre:
|
270
|
-
type(col_data) == types.ListType
|
271
|
-
len(col_data) == len(self.row_names)
|
272
|
-
"""
|
273
|
-
self.col_names.append(col_name)
|
274
|
-
for row_index, cell_data in enumerate(col_data):
|
275
|
-
self.data[row_index].append(cell_data)
|
276
|
-
|
277
|
-
|
278
|
-
def insert_column(self, index, col_data, col_name):
|
279
|
-
"""Appends col_data before 'index' in the table. To make 'insert'
|
280
|
-
behave like 'list.insert', inserting in an out of range index will
|
281
|
-
insert col_data to the end of the list
|
282
|
-
pre:
|
283
|
-
type(col_data) == types.ListType
|
284
|
-
len(col_data) == len(self.row_names)
|
285
|
-
"""
|
286
|
-
self.col_names.insert(index, col_name)
|
287
|
-
for row_index, cell_data in enumerate(col_data):
|
288
|
-
self.data[row_index].insert(index, cell_data)
|
289
|
-
|
290
|
-
|
291
|
-
def delete_column(self, index):
|
292
|
-
"""Deletes the 'index' column in the table, and returns it.
|
293
|
-
Raises an IndexError if index is out of range
|
294
|
-
"""
|
295
|
-
self.col_names.pop(index)
|
296
|
-
return [row.pop(index) for row in self.data]
|
297
|
-
|
298
|
-
|
299
|
-
def delete_column_by_id(self, col_id):
|
300
|
-
"""Deletes the 'col_id' col in the table.
|
301
|
-
Raises a KeyError if col_id was not found.
|
302
|
-
"""
|
303
|
-
try:
|
304
|
-
col_index = self.col_names.index(col_id)
|
305
|
-
self.delete_column(col_index)
|
306
|
-
except ValueError:
|
307
|
-
raise KeyError('Column (%s) not found in table' % (col_id))
|
308
|
-
|
309
|
-
|
310
|
-
## The 'getter' part #######################################################
|
311
|
-
|
312
|
-
def get_shape(self):
|
313
|
-
"""Returns a tuple which represents the table's shape
|
314
|
-
"""
|
315
|
-
return len(self.row_names), len(self.col_names)
|
316
|
-
shape = property(get_shape)
|
317
|
-
|
318
|
-
def __getitem__(self, indices):
|
319
|
-
"""provided for convenience"""
|
320
|
-
rows, multirows = None, False
|
321
|
-
cols, multicols = None, False
|
322
|
-
if isinstance(indices, tuple):
|
323
|
-
rows = indices[0]
|
324
|
-
if len(indices) > 1:
|
325
|
-
cols = indices[1]
|
326
|
-
else:
|
327
|
-
rows = indices
|
328
|
-
# define row slice
|
329
|
-
if isinstance(rows, str):
|
330
|
-
try:
|
331
|
-
rows = self.row_names.index(rows)
|
332
|
-
except ValueError:
|
333
|
-
raise KeyError("Row (%s) not found in table" % (rows))
|
334
|
-
if isinstance(rows, int):
|
335
|
-
rows = slice(rows, rows+1)
|
336
|
-
multirows = False
|
337
|
-
else:
|
338
|
-
rows = slice(None)
|
339
|
-
multirows = True
|
340
|
-
# define col slice
|
341
|
-
if isinstance(cols, str):
|
342
|
-
try:
|
343
|
-
cols = self.col_names.index(cols)
|
344
|
-
except ValueError:
|
345
|
-
raise KeyError("Column (%s) not found in table" % (cols))
|
346
|
-
if isinstance(cols, int):
|
347
|
-
cols = slice(cols, cols+1)
|
348
|
-
multicols = False
|
349
|
-
else:
|
350
|
-
cols = slice(None)
|
351
|
-
multicols = True
|
352
|
-
# get sub-table
|
353
|
-
tab = Table()
|
354
|
-
tab.default_value = self.default_value
|
355
|
-
tab.create_rows(self.row_names[rows])
|
356
|
-
tab.create_columns(self.col_names[cols])
|
357
|
-
for idx, row in enumerate(self.data[rows]):
|
358
|
-
tab.set_row(idx, row[cols])
|
359
|
-
if multirows :
|
360
|
-
if multicols:
|
361
|
-
return tab
|
362
|
-
else:
|
363
|
-
return [item[0] for item in tab.data]
|
364
|
-
else:
|
365
|
-
if multicols:
|
366
|
-
return tab.data[0]
|
367
|
-
else:
|
368
|
-
return tab.data[0][0]
|
369
|
-
|
370
|
-
def get_cell_by_ids(self, row_id, col_id):
|
371
|
-
"""Returns the element at [row_id][col_id]
|
372
|
-
"""
|
373
|
-
try:
|
374
|
-
row_index = self.row_names.index(row_id)
|
375
|
-
except ValueError:
|
376
|
-
raise KeyError("Row (%s) not found in table" % (row_id))
|
377
|
-
else:
|
378
|
-
try:
|
379
|
-
col_index = self.col_names.index(col_id)
|
380
|
-
except ValueError:
|
381
|
-
raise KeyError("Column (%s) not found in table" % (col_id))
|
382
|
-
return self.data[row_index][col_index]
|
383
|
-
|
384
|
-
def get_row_by_id(self, row_id):
|
385
|
-
"""Returns the 'row_id' row
|
386
|
-
"""
|
387
|
-
try:
|
388
|
-
row_index = self.row_names.index(row_id)
|
389
|
-
except ValueError:
|
390
|
-
raise KeyError("Row (%s) not found in table" % (row_id))
|
391
|
-
return self.data[row_index]
|
392
|
-
|
393
|
-
def get_column_by_id(self, col_id, distinct=False):
|
394
|
-
"""Returns the 'col_id' col
|
395
|
-
"""
|
396
|
-
try:
|
397
|
-
col_index = self.col_names.index(col_id)
|
398
|
-
except ValueError:
|
399
|
-
raise KeyError("Column (%s) not found in table" % (col_id))
|
400
|
-
return self.get_column(col_index, distinct)
|
401
|
-
|
402
|
-
def get_columns(self):
|
403
|
-
"""Returns all the columns in the table
|
404
|
-
"""
|
405
|
-
return [self[:, index] for index in range(len(self.col_names))]
|
406
|
-
|
407
|
-
def get_column(self, col_index, distinct=False):
|
408
|
-
"""get a column by index"""
|
409
|
-
col = [row[col_index] for row in self.data]
|
410
|
-
if distinct:
|
411
|
-
col = list(set(col))
|
412
|
-
return col
|
413
|
-
|
414
|
-
def apply_stylesheet(self, stylesheet):
|
415
|
-
"""Applies the stylesheet to this table
|
416
|
-
"""
|
417
|
-
for instruction in stylesheet.instructions:
|
418
|
-
eval(instruction)
|
419
|
-
|
420
|
-
|
421
|
-
def transpose(self):
|
422
|
-
"""Keeps the self object intact, and returns the transposed (rotated)
|
423
|
-
table.
|
424
|
-
"""
|
425
|
-
transposed = Table()
|
426
|
-
transposed.create_rows(self.col_names)
|
427
|
-
transposed.create_columns(self.row_names)
|
428
|
-
for col_index, column in enumerate(self.get_columns()):
|
429
|
-
transposed.set_row(col_index, column)
|
430
|
-
return transposed
|
431
|
-
|
432
|
-
|
433
|
-
def pprint(self):
|
434
|
-
"""returns a string representing the table in a pretty
|
435
|
-
printed 'text' format.
|
436
|
-
"""
|
437
|
-
# The maximum row name (to know the start_index of the first col)
|
438
|
-
max_row_name = 0
|
439
|
-
for row_name in self.row_names:
|
440
|
-
if len(row_name) > max_row_name:
|
441
|
-
max_row_name = len(row_name)
|
442
|
-
col_start = max_row_name + 5
|
443
|
-
|
444
|
-
lines = []
|
445
|
-
# Build the 'first' line <=> the col_names one
|
446
|
-
# The first cell <=> an empty one
|
447
|
-
col_names_line = [' '*col_start]
|
448
|
-
for col_name in self.col_names:
|
449
|
-
col_names_line.append(col_name + ' '*5)
|
450
|
-
lines.append('|' + '|'.join(col_names_line) + '|')
|
451
|
-
max_line_length = len(lines[0])
|
452
|
-
|
453
|
-
# Build the table
|
454
|
-
for row_index, row in enumerate(self.data):
|
455
|
-
line = []
|
456
|
-
# First, build the row_name's cell
|
457
|
-
row_name = self.row_names[row_index]
|
458
|
-
line.append(row_name + ' '*(col_start-len(row_name)))
|
459
|
-
|
460
|
-
# Then, build all the table's cell for this line.
|
461
|
-
for col_index, cell in enumerate(row):
|
462
|
-
col_name_length = len(self.col_names[col_index]) + 5
|
463
|
-
data = str(cell)
|
464
|
-
line.append(data + ' '*(col_name_length - len(data)))
|
465
|
-
lines.append('|' + '|'.join(line) + '|')
|
466
|
-
if len(lines[-1]) > max_line_length:
|
467
|
-
max_line_length = len(lines[-1])
|
468
|
-
|
469
|
-
# Wrap the table with '-' to make a frame
|
470
|
-
lines.insert(0, '-'*max_line_length)
|
471
|
-
lines.append('-'*max_line_length)
|
472
|
-
return '\n'.join(lines)
|
473
|
-
|
474
|
-
|
475
|
-
def __repr__(self):
|
476
|
-
return repr(self.data)
|
477
|
-
|
478
|
-
def as_text(self):
|
479
|
-
data = []
|
480
|
-
# We must convert cells into strings before joining them
|
481
|
-
for row in self.data:
|
482
|
-
data.append([str(cell) for cell in row])
|
483
|
-
lines = ['\t'.join(row) for row in data]
|
484
|
-
return '\n'.join(lines)
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
class TableStyle:
|
489
|
-
"""Defines a table's style
|
490
|
-
"""
|
491
|
-
|
492
|
-
def __init__(self, table):
|
493
|
-
|
494
|
-
self._table = table
|
495
|
-
self.size = dict([(col_name, '1*') for col_name in table.col_names])
|
496
|
-
# __row_column__ is a special key to define the first column which
|
497
|
-
# actually has no name (<=> left most column <=> row names column)
|
498
|
-
self.size['__row_column__'] = '1*'
|
499
|
-
self.alignment = dict([(col_name, 'right')
|
500
|
-
for col_name in table.col_names])
|
501
|
-
self.alignment['__row_column__'] = 'right'
|
502
|
-
|
503
|
-
# We shouldn't have to create an entry for
|
504
|
-
# the 1st col (the row_column one)
|
505
|
-
self.units = dict([(col_name, '') for col_name in table.col_names])
|
506
|
-
self.units['__row_column__'] = ''
|
507
|
-
|
508
|
-
# XXX FIXME : params order should be reversed for all set() methods
|
509
|
-
def set_size(self, value, col_id):
|
510
|
-
"""sets the size of the specified col_id to value
|
511
|
-
"""
|
512
|
-
self.size[col_id] = value
|
513
|
-
|
514
|
-
def set_size_by_index(self, value, col_index):
|
515
|
-
"""Allows to set the size according to the column index rather than
|
516
|
-
using the column's id.
|
517
|
-
BE CAREFUL : the '0' column is the '__row_column__' one !
|
518
|
-
"""
|
519
|
-
if col_index == 0:
|
520
|
-
col_id = '__row_column__'
|
521
|
-
else:
|
522
|
-
col_id = self._table.col_names[col_index-1]
|
523
|
-
|
524
|
-
self.size[col_id] = value
|
525
|
-
|
526
|
-
|
527
|
-
def set_alignment(self, value, col_id):
|
528
|
-
"""sets the alignment of the specified col_id to value
|
529
|
-
"""
|
530
|
-
self.alignment[col_id] = value
|
531
|
-
|
532
|
-
|
533
|
-
def set_alignment_by_index(self, value, col_index):
|
534
|
-
"""Allows to set the alignment according to the column index rather than
|
535
|
-
using the column's id.
|
536
|
-
BE CAREFUL : the '0' column is the '__row_column__' one !
|
537
|
-
"""
|
538
|
-
if col_index == 0:
|
539
|
-
col_id = '__row_column__'
|
540
|
-
else:
|
541
|
-
col_id = self._table.col_names[col_index-1]
|
542
|
-
|
543
|
-
self.alignment[col_id] = value
|
544
|
-
|
545
|
-
|
546
|
-
def set_unit(self, value, col_id):
|
547
|
-
"""sets the unit of the specified col_id to value
|
548
|
-
"""
|
549
|
-
self.units[col_id] = value
|
550
|
-
|
551
|
-
|
552
|
-
def set_unit_by_index(self, value, col_index):
|
553
|
-
"""Allows to set the unit according to the column index rather than
|
554
|
-
using the column's id.
|
555
|
-
BE CAREFUL : the '0' column is the '__row_column__' one !
|
556
|
-
(Note that in the 'unit' case, you shouldn't have to set a unit
|
557
|
-
for the 1st column (the __row__column__ one))
|
558
|
-
"""
|
559
|
-
if col_index == 0:
|
560
|
-
col_id = '__row_column__'
|
561
|
-
else:
|
562
|
-
col_id = self._table.col_names[col_index-1]
|
563
|
-
|
564
|
-
self.units[col_id] = value
|
565
|
-
|
566
|
-
|
567
|
-
def get_size(self, col_id):
|
568
|
-
"""Returns the size of the specified col_id
|
569
|
-
"""
|
570
|
-
return self.size[col_id]
|
571
|
-
|
572
|
-
|
573
|
-
def get_size_by_index(self, col_index):
|
574
|
-
"""Allows to get the size according to the column index rather than
|
575
|
-
using the column's id.
|
576
|
-
BE CAREFUL : the '0' column is the '__row_column__' one !
|
577
|
-
"""
|
578
|
-
if col_index == 0:
|
579
|
-
col_id = '__row_column__'
|
580
|
-
else:
|
581
|
-
col_id = self._table.col_names[col_index-1]
|
582
|
-
|
583
|
-
return self.size[col_id]
|
584
|
-
|
585
|
-
|
586
|
-
def get_alignment(self, col_id):
|
587
|
-
"""Returns the alignment of the specified col_id
|
588
|
-
"""
|
589
|
-
return self.alignment[col_id]
|
590
|
-
|
591
|
-
|
592
|
-
def get_alignment_by_index(self, col_index):
|
593
|
-
"""Allors to get the alignment according to the column index rather than
|
594
|
-
using the column's id.
|
595
|
-
BE CAREFUL : the '0' column is the '__row_column__' one !
|
596
|
-
"""
|
597
|
-
if col_index == 0:
|
598
|
-
col_id = '__row_column__'
|
599
|
-
else:
|
600
|
-
col_id = self._table.col_names[col_index-1]
|
601
|
-
|
602
|
-
return self.alignment[col_id]
|
603
|
-
|
604
|
-
|
605
|
-
def get_unit(self, col_id):
|
606
|
-
"""Returns the unit of the specified col_id
|
607
|
-
"""
|
608
|
-
return self.units[col_id]
|
609
|
-
|
610
|
-
|
611
|
-
def get_unit_by_index(self, col_index):
|
612
|
-
"""Allors to get the unit according to the column index rather than
|
613
|
-
using the column's id.
|
614
|
-
BE CAREFUL : the '0' column is the '__row_column__' one !
|
615
|
-
"""
|
616
|
-
if col_index == 0:
|
617
|
-
col_id = '__row_column__'
|
618
|
-
else:
|
619
|
-
col_id = self._table.col_names[col_index-1]
|
620
|
-
|
621
|
-
return self.units[col_id]
|
622
|
-
|
623
|
-
|
624
|
-
import re
|
625
|
-
CELL_PROG = re.compile("([0-9]+)_([0-9]+)")
|
626
|
-
|
627
|
-
class TableStyleSheet:
|
628
|
-
"""A simple Table stylesheet
|
629
|
-
Rules are expressions where cells are defined by the row_index
|
630
|
-
and col_index separated by an underscore ('_').
|
631
|
-
For example, suppose you want to say that the (2,5) cell must be
|
632
|
-
the sum of its two preceding cells in the row, you would create
|
633
|
-
the following rule :
|
634
|
-
2_5 = 2_3 + 2_4
|
635
|
-
You can also use all the math.* operations you want. For example:
|
636
|
-
2_5 = sqrt(2_3**2 + 2_4**2)
|
637
|
-
"""
|
638
|
-
|
639
|
-
def __init__(self, rules = None):
|
640
|
-
rules = rules or []
|
641
|
-
self.rules = []
|
642
|
-
self.instructions = []
|
643
|
-
for rule in rules:
|
644
|
-
self.add_rule(rule)
|
645
|
-
|
646
|
-
|
647
|
-
def add_rule(self, rule):
|
648
|
-
"""Adds a rule to the stylesheet rules
|
649
|
-
"""
|
650
|
-
try:
|
651
|
-
source_code = ['from math import *']
|
652
|
-
source_code.append(CELL_PROG.sub(r'self.data[\1][\2]', rule))
|
653
|
-
self.instructions.append(compile('\n'.join(source_code),
|
654
|
-
'table.py', 'exec'))
|
655
|
-
self.rules.append(rule)
|
656
|
-
except SyntaxError:
|
657
|
-
print("Bad Stylesheet Rule : %s [skipped]" % rule)
|
658
|
-
|
659
|
-
|
660
|
-
def add_rowsum_rule(self, dest_cell, row_index, start_col, end_col):
|
661
|
-
"""Creates and adds a rule to sum over the row at row_index from
|
662
|
-
start_col to end_col.
|
663
|
-
dest_cell is a tuple of two elements (x,y) of the destination cell
|
664
|
-
No check is done for indexes ranges.
|
665
|
-
pre:
|
666
|
-
start_col >= 0
|
667
|
-
end_col > start_col
|
668
|
-
"""
|
669
|
-
cell_list = ['%d_%d'%(row_index, index) for index in range(start_col,
|
670
|
-
end_col + 1)]
|
671
|
-
rule = '%d_%d=' % dest_cell + '+'.join(cell_list)
|
672
|
-
self.add_rule(rule)
|
673
|
-
|
674
|
-
|
675
|
-
def add_rowavg_rule(self, dest_cell, row_index, start_col, end_col):
|
676
|
-
"""Creates and adds a rule to make the row average (from start_col
|
677
|
-
to end_col)
|
678
|
-
dest_cell is a tuple of two elements (x,y) of the destination cell
|
679
|
-
No check is done for indexes ranges.
|
680
|
-
pre:
|
681
|
-
start_col >= 0
|
682
|
-
end_col > start_col
|
683
|
-
"""
|
684
|
-
cell_list = ['%d_%d'%(row_index, index) for index in range(start_col,
|
685
|
-
end_col + 1)]
|
686
|
-
num = (end_col - start_col + 1)
|
687
|
-
rule = '%d_%d=' % dest_cell + '('+'+'.join(cell_list)+')/%f'%num
|
688
|
-
self.add_rule(rule)
|
689
|
-
|
690
|
-
|
691
|
-
def add_colsum_rule(self, dest_cell, col_index, start_row, end_row):
|
692
|
-
"""Creates and adds a rule to sum over the col at col_index from
|
693
|
-
start_row to end_row.
|
694
|
-
dest_cell is a tuple of two elements (x,y) of the destination cell
|
695
|
-
No check is done for indexes ranges.
|
696
|
-
pre:
|
697
|
-
start_row >= 0
|
698
|
-
end_row > start_row
|
699
|
-
"""
|
700
|
-
cell_list = ['%d_%d'%(index, col_index) for index in range(start_row,
|
701
|
-
end_row + 1)]
|
702
|
-
rule = '%d_%d=' % dest_cell + '+'.join(cell_list)
|
703
|
-
self.add_rule(rule)
|
704
|
-
|
705
|
-
|
706
|
-
def add_colavg_rule(self, dest_cell, col_index, start_row, end_row):
|
707
|
-
"""Creates and adds a rule to make the col average (from start_row
|
708
|
-
to end_row)
|
709
|
-
dest_cell is a tuple of two elements (x,y) of the destination cell
|
710
|
-
No check is done for indexes ranges.
|
711
|
-
pre:
|
712
|
-
start_row >= 0
|
713
|
-
end_row > start_row
|
714
|
-
"""
|
715
|
-
cell_list = ['%d_%d'%(index, col_index) for index in range(start_row,
|
716
|
-
end_row + 1)]
|
717
|
-
num = (end_row - start_row + 1)
|
718
|
-
rule = '%d_%d=' % dest_cell + '('+'+'.join(cell_list)+')/%f'%num
|
719
|
-
self.add_rule(rule)
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
class TableCellRenderer:
|
724
|
-
"""Defines a simple text renderer
|
725
|
-
"""
|
726
|
-
|
727
|
-
def __init__(self, **properties):
|
728
|
-
"""keywords should be properties with an associated boolean as value.
|
729
|
-
For example :
|
730
|
-
renderer = TableCellRenderer(units = True, alignment = False)
|
731
|
-
An unspecified property will have a 'False' value by default.
|
732
|
-
Possible properties are :
|
733
|
-
alignment, unit
|
734
|
-
"""
|
735
|
-
self.properties = properties
|
736
|
-
|
737
|
-
|
738
|
-
def render_cell(self, cell_coord, table, table_style):
|
739
|
-
"""Renders the cell at 'cell_coord' in the table, using table_style
|
740
|
-
"""
|
741
|
-
row_index, col_index = cell_coord
|
742
|
-
cell_value = table.data[row_index][col_index]
|
743
|
-
final_content = self._make_cell_content(cell_value,
|
744
|
-
table_style, col_index +1)
|
745
|
-
return self._render_cell_content(final_content,
|
746
|
-
table_style, col_index + 1)
|
747
|
-
|
748
|
-
|
749
|
-
def render_row_cell(self, row_name, table, table_style):
|
750
|
-
"""Renders the cell for 'row_id' row
|
751
|
-
"""
|
752
|
-
cell_value = row_name
|
753
|
-
return self._render_cell_content(cell_value, table_style, 0)
|
754
|
-
|
755
|
-
|
756
|
-
def render_col_cell(self, col_name, table, table_style):
|
757
|
-
"""Renders the cell for 'col_id' row
|
758
|
-
"""
|
759
|
-
cell_value = col_name
|
760
|
-
col_index = table.col_names.index(col_name)
|
761
|
-
return self._render_cell_content(cell_value, table_style, col_index +1)
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
def _render_cell_content(self, content, table_style, col_index):
|
766
|
-
"""Makes the appropriate rendering for this cell content.
|
767
|
-
Rendering properties will be searched using the
|
768
|
-
*table_style.get_xxx_by_index(col_index)' methods
|
769
|
-
|
770
|
-
**This method should be overridden in the derived renderer classes.**
|
771
|
-
"""
|
772
|
-
return content
|
773
|
-
|
774
|
-
|
775
|
-
def _make_cell_content(self, cell_content, table_style, col_index):
|
776
|
-
"""Makes the cell content (adds decoration data, like units for
|
777
|
-
example)
|
778
|
-
"""
|
779
|
-
final_content = cell_content
|
780
|
-
if 'skip_zero' in self.properties:
|
781
|
-
replacement_char = self.properties['skip_zero']
|
782
|
-
else:
|
783
|
-
replacement_char = 0
|
784
|
-
if replacement_char and final_content == 0:
|
785
|
-
return replacement_char
|
786
|
-
|
787
|
-
try:
|
788
|
-
units_on = self.properties['units']
|
789
|
-
if units_on:
|
790
|
-
final_content = self._add_unit(
|
791
|
-
cell_content, table_style, col_index)
|
792
|
-
except KeyError:
|
793
|
-
pass
|
794
|
-
|
795
|
-
return final_content
|
796
|
-
|
797
|
-
|
798
|
-
def _add_unit(self, cell_content, table_style, col_index):
|
799
|
-
"""Adds unit to the cell_content if needed
|
800
|
-
"""
|
801
|
-
unit = table_style.get_unit_by_index(col_index)
|
802
|
-
return str(cell_content) + " " + unit
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
class DocbookRenderer(TableCellRenderer):
|
807
|
-
"""Defines how to render a cell for a docboook table
|
808
|
-
"""
|
809
|
-
|
810
|
-
def define_col_header(self, col_index, table_style):
|
811
|
-
"""Computes the colspec element according to the style
|
812
|
-
"""
|
813
|
-
size = table_style.get_size_by_index(col_index)
|
814
|
-
return '<colspec colname="c%d" colwidth="%s"/>\n' % \
|
815
|
-
(col_index, size)
|
816
|
-
|
817
|
-
|
818
|
-
def _render_cell_content(self, cell_content, table_style, col_index):
|
819
|
-
"""Makes the appropriate rendering for this cell content.
|
820
|
-
Rendering properties will be searched using the
|
821
|
-
table_style.get_xxx_by_index(col_index)' methods.
|
822
|
-
"""
|
823
|
-
try:
|
824
|
-
align_on = self.properties['alignment']
|
825
|
-
alignment = table_style.get_alignment_by_index(col_index)
|
826
|
-
if align_on:
|
827
|
-
return "<entry align='%s'>%s</entry>\n" % \
|
828
|
-
(alignment, cell_content)
|
829
|
-
except KeyError:
|
830
|
-
# KeyError <=> Default alignment
|
831
|
-
return "<entry>%s</entry>\n" % cell_content
|
832
|
-
|
833
|
-
|
834
|
-
class TableWriter:
|
835
|
-
"""A class to write tables
|
836
|
-
"""
|
837
|
-
|
838
|
-
def __init__(self, stream, table, style, **properties):
|
839
|
-
self._stream = stream
|
840
|
-
self.style = style or TableStyle(table)
|
841
|
-
self._table = table
|
842
|
-
self.properties = properties
|
843
|
-
self.renderer = None
|
844
|
-
|
845
|
-
|
846
|
-
def set_style(self, style):
|
847
|
-
"""sets the table's associated style
|
848
|
-
"""
|
849
|
-
self.style = style
|
850
|
-
|
851
|
-
|
852
|
-
def set_renderer(self, renderer):
|
853
|
-
"""sets the way to render cell
|
854
|
-
"""
|
855
|
-
self.renderer = renderer
|
856
|
-
|
857
|
-
|
858
|
-
def update_properties(self, **properties):
|
859
|
-
"""Updates writer's properties (for cell rendering)
|
860
|
-
"""
|
861
|
-
self.properties.update(properties)
|
862
|
-
|
863
|
-
|
864
|
-
def write_table(self, title = ""):
|
865
|
-
"""Writes the table
|
866
|
-
"""
|
867
|
-
raise NotImplementedError("write_table must be implemented !")
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
class DocbookTableWriter(TableWriter):
|
872
|
-
"""Defines an implementation of TableWriter to write a table in Docbook
|
873
|
-
"""
|
874
|
-
|
875
|
-
def _write_headers(self):
|
876
|
-
"""Writes col headers
|
877
|
-
"""
|
878
|
-
# Define col_headers (colstpec elements)
|
879
|
-
for col_index in range(len(self._table.col_names)+1):
|
880
|
-
self._stream.write(self.renderer.define_col_header(col_index,
|
881
|
-
self.style))
|
882
|
-
|
883
|
-
self._stream.write("<thead>\n<row>\n")
|
884
|
-
# XXX FIXME : write an empty entry <=> the first (__row_column) column
|
885
|
-
self._stream.write('<entry></entry>\n')
|
886
|
-
for col_name in self._table.col_names:
|
887
|
-
self._stream.write(self.renderer.render_col_cell(
|
888
|
-
col_name, self._table,
|
889
|
-
self.style))
|
890
|
-
|
891
|
-
self._stream.write("</row>\n</thead>\n")
|
892
|
-
|
893
|
-
|
894
|
-
def _write_body(self):
|
895
|
-
"""Writes the table body
|
896
|
-
"""
|
897
|
-
self._stream.write('<tbody>\n')
|
898
|
-
|
899
|
-
for row_index, row in enumerate(self._table.data):
|
900
|
-
self._stream.write('<row>\n')
|
901
|
-
row_name = self._table.row_names[row_index]
|
902
|
-
# Write the first entry (row_name)
|
903
|
-
self._stream.write(self.renderer.render_row_cell(row_name,
|
904
|
-
self._table,
|
905
|
-
self.style))
|
906
|
-
|
907
|
-
for col_index, cell in enumerate(row):
|
908
|
-
self._stream.write(self.renderer.render_cell(
|
909
|
-
(row_index, col_index),
|
910
|
-
self._table, self.style))
|
911
|
-
|
912
|
-
self._stream.write('</row>\n')
|
913
|
-
|
914
|
-
self._stream.write('</tbody>\n')
|
915
|
-
|
916
|
-
|
917
|
-
def write_table(self, title = ""):
|
918
|
-
"""Writes the table
|
919
|
-
"""
|
920
|
-
self._stream.write('<table>\n<title>%s></title>\n'%(title))
|
921
|
-
self._stream.write(
|
922
|
-
'<tgroup cols="%d" align="left" colsep="1" rowsep="1">\n'%
|
923
|
-
(len(self._table.col_names)+1))
|
924
|
-
self._write_headers()
|
925
|
-
self._write_body()
|
926
|
-
|
927
|
-
self._stream.write('</tgroup>\n</table>\n')
|
928
|
-
|
929
|
-
|