| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A wrapper script to manage a set of client modules in different SCM. | 6 """A wrapper script to manage a set of client modules in different SCM. |
| 7 | 7 |
| 8 This script is intended to be used to help basic management of client | 8 This script is intended to be used to help basic management of client |
| 9 program sources residing in one or more Subversion modules and Git | 9 program sources residing in one or more Subversion modules and Git |
| 10 repositories, along with other modules it depends on, also in Subversion or Git, | 10 repositories, along with other modules it depends on, also in Subversion or Git, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 it will be removed from the list and the list will be extended | 48 it will be removed from the list and the list will be extended |
| 49 by the list of matching files. | 49 by the list of matching files. |
| 50 | 50 |
| 51 Example: | 51 Example: |
| 52 hooks = [ | 52 hooks = [ |
| 53 { "pattern": "\\.(gif|jpe?g|pr0n|png)$", | 53 { "pattern": "\\.(gif|jpe?g|pr0n|png)$", |
| 54 "action": ["python", "image_indexer.py", "--all"]}, | 54 "action": ["python", "image_indexer.py", "--all"]}, |
| 55 ] | 55 ] |
| 56 """ | 56 """ |
| 57 | 57 |
| 58 __version__ = "0.3.6" | 58 __version__ = "0.3.7" |
| 59 | 59 |
| 60 import errno | 60 import errno |
| 61 import logging | 61 import logging |
| 62 import optparse | 62 import optparse |
| 63 import os | 63 import os |
| 64 import pprint | 64 import pprint |
| 65 import re | 65 import re |
| 66 import sys | 66 import sys |
| 67 import urlparse | 67 import urlparse |
| 68 import urllib | 68 import urllib |
| 69 | 69 |
| 70 import breakpad | 70 import breakpad |
| 71 | 71 |
| 72 import gclient_scm | 72 import gclient_scm |
| 73 import gclient_utils | 73 import gclient_utils |
| 74 from third_party.repo.progress import Progress | 74 from third_party.repo.progress import Progress |
| 75 | 75 |
| 76 # default help text | 76 # default help text |
| 77 DEFAULT_USAGE_TEXT = ( | 77 DEFAULT_USAGE_TEXT = ( |
| 78 """usage: %prog <subcommand> [options] [--] [SCM options/args...] | 78 """%prog <subcommand> [options] [--] [SCM options/args...] |
| 79 a wrapper for managing a set of svn client modules and/or git repositories. | 79 a wrapper for managing a set of svn client modules and/or git repositories. |
| 80 Version """ + __version__ + """ | 80 Version """ + __version__ + """ |
| 81 | 81 |
| 82 subcommands: | |
| 83 cleanup | |
| 84 config | |
| 85 diff | |
| 86 export | |
| 87 pack | |
| 88 revert | |
| 89 status | |
| 90 sync | |
| 91 update | |
| 92 runhooks | |
| 93 revinfo | |
| 94 | |
| 95 Options and extra arguments can be passed to invoked SCM commands by | 82 Options and extra arguments can be passed to invoked SCM commands by |
| 96 appending them to the command line. Note that if the first such | 83 appending them to the command line. Note that if the first such |
| 97 appended option starts with a dash (-) then the options must be | 84 appended option starts with a dash (-) then the options must be |
| 98 preceded by -- to distinguish them from gclient options. | 85 preceded by -- to distinguish them from gclient options. |
| 99 | 86 |
| 100 For additional help on a subcommand or examples of usage, try | 87 For additional help on a subcommand or examples of usage, try |
| 101 %prog help <subcommand> | 88 %prog help <subcommand> |
| 102 %prog help files | 89 %prog help files |
| 103 """) | 90 """) |
| 104 | 91 |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 if self._options.snapshot: | 809 if self._options.snapshot: |
| 823 config = self.DEFAULT_SNAPSHOT_FILE_TEXT % {'solution_list': new_gclient} | 810 config = self.DEFAULT_SNAPSHOT_FILE_TEXT % {'solution_list': new_gclient} |
| 824 snapclient = GClient(self._root_dir, self._options) | 811 snapclient = GClient(self._root_dir, self._options) |
| 825 snapclient.SetConfig(config) | 812 snapclient.SetConfig(config) |
| 826 print(snapclient._config_content) | 813 print(snapclient._config_content) |
| 827 | 814 |
| 828 | 815 |
| 829 ## gclient commands. | 816 ## gclient commands. |
| 830 | 817 |
| 831 | 818 |
| 832 def CMDcleanup(options, args): | 819 def CMDcleanup(parser, options, args): |
| 833 """Clean up all working copies, using 'svn cleanup' for each module. | 820 """Clean up all working copies, using 'svn cleanup' for each module. |
| 821 |
| 834 Additional options and args may be passed to 'svn cleanup'. | 822 Additional options and args may be passed to 'svn cleanup'. |
| 835 | 823 |
| 836 usage: cleanup [options] [--] [svn cleanup args/options] | 824 usage: cleanup [options] [--] [svn cleanup args/options] |
| 837 | 825 |
| 838 Valid options: | 826 Valid options: |
| 839 --verbose : output additional diagnostics | 827 --verbose : output additional diagnostics |
| 840 """ | 828 """ |
| 841 client = GClient.LoadCurrentConfig(options) | 829 client = GClient.LoadCurrentConfig(options) |
| 842 if not client: | 830 if not client: |
| 843 raise gclient_utils.Error("client not configured; see 'gclient config'") | 831 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 844 if options.verbose: | 832 if options.verbose: |
| 845 # Print out the .gclient file. This is longer than if we just printed the | 833 # Print out the .gclient file. This is longer than if we just printed the |
| 846 # client dict, but more legible, and it might contain helpful comments. | 834 # client dict, but more legible, and it might contain helpful comments. |
| 847 print(client.ConfigContent()) | 835 print(client.ConfigContent()) |
| 848 return client.RunOnDeps('cleanup', args) | 836 return client.RunOnDeps('cleanup', args) |
| 849 | 837 |
| 850 | 838 |
| 851 def CMDconfig(options, args): | 839 def CMDconfig(parser, options, args): |
| 852 """Create a .gclient file in the current directory; this | 840 """Create a .gclient file in the current directory. |
| 853 specifies the configuration for further commands. After update/sync, | 841 |
| 842 This specifies the configuration for further commands. After update/sync, |
| 854 top-level DEPS files in each module are read to determine dependent | 843 top-level DEPS files in each module are read to determine dependent |
| 855 modules to operate on as well. If optional [url] parameter is | 844 modules to operate on as well. If optional [url] parameter is |
| 856 provided, then configuration is read from a specified Subversion server | 845 provided, then configuration is read from a specified Subversion server |
| 857 URL. Otherwise, a --spec option must be provided. A --name option overrides | 846 URL. Otherwise, a --spec option must be provided. A --name option overrides |
| 858 the default name for the solutions. | 847 the default name for the solutions. |
| 859 | 848 |
| 860 usage: config [option | url] [safesync url] | 849 usage: config [option | url] [safesync url] |
| 861 | 850 |
| 862 Valid options: | 851 Valid options: |
| 863 --name path : alternate relative path for the solution | 852 --name path : alternate relative path for the solution |
| (...skipping 26 matching lines...) Expand all Loading... |
| 890 # specify an alternate relpath for the given URL. | 879 # specify an alternate relpath for the given URL. |
| 891 name = options.name | 880 name = options.name |
| 892 safesync_url = "" | 881 safesync_url = "" |
| 893 if len(args) > 1: | 882 if len(args) > 1: |
| 894 safesync_url = args[1] | 883 safesync_url = args[1] |
| 895 client.SetDefaultConfig(name, base_url, safesync_url) | 884 client.SetDefaultConfig(name, base_url, safesync_url) |
| 896 client.SaveConfig() | 885 client.SaveConfig() |
| 897 return 0 | 886 return 0 |
| 898 | 887 |
| 899 | 888 |
| 900 def CMDexport(options, args): | 889 def CMDexport(parser, options, args): |
| 901 """Wrapper for svn export for all managed directories | 890 """Wrapper for svn export for all managed directories.""" |
| 902 """ | |
| 903 if len(args) != 1: | 891 if len(args) != 1: |
| 904 raise gclient_utils.Error("Need directory name") | 892 raise gclient_utils.Error("Need directory name") |
| 905 client = GClient.LoadCurrentConfig(options) | 893 client = GClient.LoadCurrentConfig(options) |
| 906 | 894 |
| 907 if not client: | 895 if not client: |
| 908 raise gclient_utils.Error("client not configured; see 'gclient config'") | 896 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 909 | 897 |
| 910 if options.verbose: | 898 if options.verbose: |
| 911 # Print out the .gclient file. This is longer than if we just printed the | 899 # Print out the .gclient file. This is longer than if we just printed the |
| 912 # client dict, but more legible, and it might contain helpful comments. | 900 # client dict, but more legible, and it might contain helpful comments. |
| 913 print(client.ConfigContent()) | 901 print(client.ConfigContent()) |
| 914 return client.RunOnDeps('export', args) | 902 return client.RunOnDeps('export', args) |
| 915 | 903 |
| 916 | 904 |
| 917 def CMDhelp(options, args): | 905 def CMDpack(parser, options, args): |
| 918 """Describe the usage of this program or its subcommands. | 906 """Generate a patch which can be applied at the root of the tree. |
| 919 | 907 |
| 920 usage: help [options] [subcommand] | |
| 921 | |
| 922 Valid options: | |
| 923 --verbose : output additional diagnostics | |
| 924 """ | |
| 925 __pychecker__ = 'unusednames=options' | |
| 926 module = sys.modules[__name__] | |
| 927 commands = [x[3:] for x in dir(module) if x.startswith('CMD')] | |
| 928 if len(args) == 1 and args[0] in commands: | |
| 929 print getattr(module, 'CMD' + args[0]).__doc__ | |
| 930 else: | |
| 931 raise gclient_utils.Error("unknown subcommand '%s'; see 'gclient help'" % | |
| 932 args[0]) | |
| 933 return 0 | |
| 934 | |
| 935 | |
| 936 def CMDpack(options, args): | |
| 937 """Generate a patch which can be applied at the root of the tree. | |
| 938 Internally, runs 'svn diff' on each checked out module and | 908 Internally, runs 'svn diff' on each checked out module and |
| 939 dependencies, and performs minimal postprocessing of the output. The | 909 dependencies, and performs minimal postprocessing of the output. The |
| 940 resulting patch is printed to stdout and can be applied to a freshly | 910 resulting patch is printed to stdout and can be applied to a freshly |
| 941 checked out tree via 'patch -p0 < patchfile'. Additional args and | 911 checked out tree via 'patch -p0 < patchfile'. Additional args and |
| 942 options to 'svn diff' can be passed after gclient options. | 912 options to 'svn diff' can be passed after gclient options. |
| 943 | 913 |
| 944 usage: pack [options] [--] [svn args/options] | 914 usage: pack [options] [--] [svn args/options] |
| 945 | 915 |
| 946 Valid options: | 916 Valid options: |
| 947 --verbose : output additional diagnostics | 917 --verbose : output additional diagnostics |
| (...skipping 11 matching lines...) Expand all Loading... |
| 959 client = GClient.LoadCurrentConfig(options) | 929 client = GClient.LoadCurrentConfig(options) |
| 960 if not client: | 930 if not client: |
| 961 raise gclient_utils.Error("client not configured; see 'gclient config'") | 931 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 962 if options.verbose: | 932 if options.verbose: |
| 963 # Print out the .gclient file. This is longer than if we just printed the | 933 # Print out the .gclient file. This is longer than if we just printed the |
| 964 # client dict, but more legible, and it might contain helpful comments. | 934 # client dict, but more legible, and it might contain helpful comments. |
| 965 print(client.ConfigContent()) | 935 print(client.ConfigContent()) |
| 966 return client.RunOnDeps('pack', args) | 936 return client.RunOnDeps('pack', args) |
| 967 | 937 |
| 968 | 938 |
| 969 def CMDstatus(options, args): | 939 def CMDstatus(parser, options, args): |
| 970 """Show the status of client and dependent modules, using 'svn diff' | 940 """Show the modification status of for every dependencies. |
| 971 for each module. Additional options and args may be passed to 'svn diff'. | 941 |
| 942 Additional options and args may be passed to 'svn status'. |
| 972 | 943 |
| 973 usage: status [options] [--] [svn diff args/options] | 944 usage: status [options] [--] [svn diff args/options] |
| 974 | 945 |
| 975 Valid options: | 946 Valid options: |
| 976 --verbose : output additional diagnostics | 947 --verbose : output additional diagnostics |
| 977 --nohooks : don't run the hooks after the update is complete | 948 --nohooks : don't run the hooks after the update is complete |
| 978 """ | 949 """ |
| 979 client = GClient.LoadCurrentConfig(options) | 950 client = GClient.LoadCurrentConfig(options) |
| 980 if not client: | 951 if not client: |
| 981 raise gclient_utils.Error("client not configured; see 'gclient config'") | 952 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 982 if options.verbose: | 953 if options.verbose: |
| 983 # Print out the .gclient file. This is longer than if we just printed the | 954 # Print out the .gclient file. This is longer than if we just printed the |
| 984 # client dict, but more legible, and it might contain helpful comments. | 955 # client dict, but more legible, and it might contain helpful comments. |
| 985 print(client.ConfigContent()) | 956 print(client.ConfigContent()) |
| 986 return client.RunOnDeps('status', args) | 957 return client.RunOnDeps('status', args) |
| 987 | 958 |
| 988 | 959 |
| 989 def CMDsync(options, args): | 960 def CMDsync(parser, options, args): |
| 990 """Perform a checkout/update of the modules specified by the gclient | 961 """Checkout/update the modules specified by the gclient configuration. |
| 991 configuration; see 'help config'. Unless --revision is specified, | 962 |
| 992 then the latest revision of the root solutions is checked out, with | 963 Unless --revision is specified, then the latest revision of the root solutions |
| 993 dependent submodule versions updated according to DEPS files. | 964 is checked out, with dependent submodule versions updated according to DEPS |
| 994 If --revision is specified, then the given revision is used in place | 965 files. If --revision is specified, then the given revision is used in place |
| 995 of the latest, either for a single solution or for all solutions. | 966 of the latest, either for a single solution or for all solutions. |
| 996 Unless the --force option is provided, solutions and modules whose | 967 Unless the --force option is provided, solutions and modules whose |
| 997 local revision matches the one to update (i.e., they have not changed | 968 local revision matches the one to update (i.e., they have not changed |
| 998 in the repository) are *not* modified. Unless --nohooks is provided, | 969 in the repository) are *not* modified. Unless --nohooks is provided, |
| 999 the hooks are run. | 970 the hooks are run. See 'help config' for more information. |
| 1000 | 971 |
| 1001 usage: gclient sync [options] [--] [SCM update options/args] | 972 usage: gclient sync [options] [--] [SCM update options/args] |
| 1002 | 973 |
| 1003 Valid options: | 974 Valid options: |
| 1004 --force : force update even for unchanged modules | 975 --force : force update even for unchanged modules |
| 1005 --nohooks : don't run the hooks after the update is complete | 976 --nohooks : don't run the hooks after the update is complete |
| 1006 --revision SOLUTION@REV : update given solution to specified revision | 977 --revision SOLUTION@REV : update given solution to specified revision |
| 1007 --deps PLATFORM(S) : sync deps for the given platform(s), or 'all' | 978 --deps PLATFORM(S) : sync deps for the given platform(s), or 'all' |
| 1008 --verbose : output additional diagnostics | 979 --verbose : output additional diagnostics |
| 1009 --head : update to latest revision, instead of last good | 980 --head : update to latest revision, instead of last good |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 if len(rev): | 1016 if len(rev): |
| 1046 options.revisions.append(s['name']+'@'+rev) | 1017 options.revisions.append(s['name']+'@'+rev) |
| 1047 | 1018 |
| 1048 if options.verbose: | 1019 if options.verbose: |
| 1049 # Print out the .gclient file. This is longer than if we just printed the | 1020 # Print out the .gclient file. This is longer than if we just printed the |
| 1050 # client dict, but more legible, and it might contain helpful comments. | 1021 # client dict, but more legible, and it might contain helpful comments. |
| 1051 print(client.ConfigContent()) | 1022 print(client.ConfigContent()) |
| 1052 return client.RunOnDeps('update', args) | 1023 return client.RunOnDeps('update', args) |
| 1053 | 1024 |
| 1054 | 1025 |
| 1055 def CMDupdate(options, args): | 1026 def CMDupdate(parser, options, args): |
| 1056 """Alias for the sync command. Deprecated. | 1027 """Alias for the sync command. Deprecated.""" |
| 1057 """ | 1028 return CMDsync(parser, options, args) |
| 1058 return CMDsync(options, args) | |
| 1059 | 1029 |
| 1060 | 1030 |
| 1061 def CMDdiff(options, args): | 1031 def CMDdiff(parser, options, args): |
| 1062 """Display the differences between two revisions of modules. | 1032 """Display the differences between two revisions of modules. |
| 1033 |
| 1063 (Does 'svn diff' for each checked out module and dependences.) | 1034 (Does 'svn diff' for each checked out module and dependences.) |
| 1064 Additional args and options to 'svn diff' can be passed after | 1035 Additional args and options to 'svn diff' can be passed after |
| 1065 gclient options. | 1036 gclient options. |
| 1066 | 1037 |
| 1067 usage: diff [options] [--] [svn args/options] | 1038 usage: diff [options] [--] [svn args/options] |
| 1068 | 1039 |
| 1069 Valid options: | 1040 Valid options: |
| 1070 --verbose : output additional diagnostics | 1041 --verbose : output additional diagnostics |
| 1071 | 1042 |
| 1072 Examples: | 1043 Examples: |
| 1073 gclient diff | 1044 gclient diff |
| 1074 simple 'svn diff' for configured client and dependences | 1045 simple 'svn diff' for configured client and dependences |
| 1075 gclient diff -- -x -b | 1046 gclient diff -- -x -b |
| 1076 use 'svn diff -x -b' to suppress whitespace-only differences | 1047 use 'svn diff -x -b' to suppress whitespace-only differences |
| 1077 gclient diff -- -r HEAD -x -b | 1048 gclient diff -- -r HEAD -x -b |
| 1078 diff versus the latest version of each module | 1049 diff versus the latest version of each module |
| 1079 """ | 1050 """ |
| 1080 client = GClient.LoadCurrentConfig(options) | 1051 client = GClient.LoadCurrentConfig(options) |
| 1081 if not client: | 1052 if not client: |
| 1082 raise gclient_utils.Error("client not configured; see 'gclient config'") | 1053 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 1083 if options.verbose: | 1054 if options.verbose: |
| 1084 # Print out the .gclient file. This is longer than if we just printed the | 1055 # Print out the .gclient file. This is longer than if we just printed the |
| 1085 # client dict, but more legible, and it might contain helpful comments. | 1056 # client dict, but more legible, and it might contain helpful comments. |
| 1086 print(client.ConfigContent()) | 1057 print(client.ConfigContent()) |
| 1087 return client.RunOnDeps('diff', args) | 1058 return client.RunOnDeps('diff', args) |
| 1088 | 1059 |
| 1089 | 1060 |
| 1090 def CMDrevert(options, args): | 1061 def CMDrevert(parser, options, args): |
| 1091 """Revert every file in every managed directory in the client view. | 1062 """Revert every file in every managed directory in the client view.""" |
| 1092 """ | |
| 1093 client = GClient.LoadCurrentConfig(options) | 1063 client = GClient.LoadCurrentConfig(options) |
| 1094 if not client: | 1064 if not client: |
| 1095 raise gclient_utils.Error("client not configured; see 'gclient config'") | 1065 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 1096 return client.RunOnDeps('revert', args) | 1066 return client.RunOnDeps('revert', args) |
| 1097 | 1067 |
| 1098 | 1068 |
| 1099 def CMDrunhooks(options, args): | 1069 def CMDrunhooks(parser, options, args): |
| 1100 """Runs hooks for files that have been modified in the local working copy, | 1070 """Runs hooks for files that have been modified in the local working copy. |
| 1101 according to 'svn status'. Implies --force. | 1071 |
| 1072 Implies --force. |
| 1102 | 1073 |
| 1103 usage: runhooks [options] | 1074 usage: runhooks [options] |
| 1104 | 1075 |
| 1105 Valid options: | 1076 Valid options: |
| 1106 --verbose : output additional diagnostics | 1077 --verbose : output additional diagnostics |
| 1107 """ | 1078 """ |
| 1108 client = GClient.LoadCurrentConfig(options) | 1079 client = GClient.LoadCurrentConfig(options) |
| 1109 if not client: | 1080 if not client: |
| 1110 raise gclient_utils.Error("client not configured; see 'gclient config'") | 1081 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 1111 if options.verbose: | 1082 if options.verbose: |
| 1112 # Print out the .gclient file. This is longer than if we just printed the | 1083 # Print out the .gclient file. This is longer than if we just printed the |
| 1113 # client dict, but more legible, and it might contain helpful comments. | 1084 # client dict, but more legible, and it might contain helpful comments. |
| 1114 print(client.ConfigContent()) | 1085 print(client.ConfigContent()) |
| 1115 options.force = True | 1086 options.force = True |
| 1116 return client.RunOnDeps('runhooks', args) | 1087 return client.RunOnDeps('runhooks', args) |
| 1117 | 1088 |
| 1118 | 1089 |
| 1119 def CMDrevinfo(options, args): | 1090 def CMDrevinfo(parser, options, args): |
| 1120 """Outputs source path, server URL and revision information for every | 1091 """Outputs defails for every dependencies. |
| 1092 |
| 1093 This includes source path, server URL and revision information for every |
| 1121 dependency in all solutions. | 1094 dependency in all solutions. |
| 1122 | 1095 |
| 1123 usage: revinfo [options] | 1096 usage: revinfo [options] |
| 1124 """ | 1097 """ |
| 1125 __pychecker__ = 'unusednames=args' | 1098 __pychecker__ = 'unusednames=args' |
| 1126 client = GClient.LoadCurrentConfig(options) | 1099 client = GClient.LoadCurrentConfig(options) |
| 1127 if not client: | 1100 if not client: |
| 1128 raise gclient_utils.Error("client not configured; see 'gclient config'") | 1101 raise gclient_utils.Error("client not configured; see 'gclient config'") |
| 1129 client.PrintRevInfo() | 1102 client.PrintRevInfo() |
| 1130 return 0 | 1103 return 0 |
| 1131 | 1104 |
| 1132 | 1105 |
| 1133 def DispatchCommand(command, options, args): | 1106 def CMDhelp(parser, options, args): |
| 1134 """Dispatches the appropriate subcommand based on command line arguments. | 1107 """Prints general help or command-specific documentation.""" |
| 1135 """ | 1108 if len(args) == 1: |
| 1136 module = sys.modules[__name__] | 1109 command = Command(args[0]) |
| 1137 command = getattr(module, 'CMD' + command, None) | 1110 if command: |
| 1138 if command: | 1111 print getattr(sys.modules[__name__], 'CMD' + args[0]).__doc__ |
| 1139 return command(options, args) | 1112 return 0 |
| 1140 else: | 1113 parser.usage = (DEFAULT_USAGE_TEXT + '\nCommands are:\n' + '\n'.join([ |
| 1141 raise gclient_utils.Error("unknown subcommand '%s'; see 'gclient help'" % | 1114 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) |
| 1142 command) | 1115 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) |
| 1116 parser.print_help() |
| 1117 return 0 |
| 1118 |
| 1119 |
| 1120 def Command(command): |
| 1121 return getattr(sys.modules[__name__], 'CMD' + command, CMDhelp) |
| 1143 | 1122 |
| 1144 | 1123 |
| 1145 def Main(argv): | 1124 def Main(argv): |
| 1146 option_parser = optparse.OptionParser(usage=DEFAULT_USAGE_TEXT, | 1125 parser = optparse.OptionParser(usage=DEFAULT_USAGE_TEXT, |
| 1147 version=__version__) | 1126 version='%prog ' + __version__) |
| 1148 option_parser.add_option("--force", action="store_true", | 1127 parser.add_option("-v", "--verbose", action="count", default=0, |
| 1149 help="(update/sync only) force update even " | 1128 help="Produces additional output for diagnostics. Can be " |
| 1150 "for modules which haven't changed") | 1129 "used up to three times for more logging info.") |
| 1151 option_parser.add_option("--nohooks", action="store_true", | 1130 parser.add_option("--gclientfile", metavar="FILENAME", dest="config_filename", |
| 1152 help="(update/sync/revert only) prevent the hooks " | 1131 default=os.environ.get("GCLIENT_FILE", ".gclient"), |
| 1153 "from running") | 1132 help="Specify an alternate .gclient file") |
| 1154 option_parser.add_option("--revision", action="append", dest="revisions", | 1133 # The other options will be moved eventually. |
| 1155 metavar="REV", default=[], | 1134 parser.add_option("--force", action="store_true", |
| 1156 help="(update/sync only) sync to a specific " | 1135 help="(update/sync only) force update even " |
| 1157 "revision, can be used multiple times for " | 1136 "for modules which haven't changed") |
| 1158 "each solution, e.g. --revision=src@123, " | 1137 parser.add_option("--nohooks", action="store_true", |
| 1159 "--revision=internal@32") | 1138 help="(update/sync/revert only) prevent the hooks " |
| 1160 option_parser.add_option("--deps", dest="deps_os", metavar="OS_LIST", | 1139 "from running") |
| 1161 help="(update/sync only) sync deps for the " | 1140 parser.add_option("--revision", action="append", dest="revisions", |
| 1162 "specified (comma-separated) platform(s); " | 1141 metavar="REV", default=[], |
| 1163 "'all' will sync all platforms") | 1142 help="(update/sync only) sync to a specific " |
| 1164 option_parser.add_option("--reset", action="store_true", | 1143 "revision, can be used multiple times for " |
| 1165 help="(update/sync only) resets any local changes " | 1144 "each solution, e.g. --revision=src@123, " |
| 1166 "before updating (git only)") | 1145 "--revision=internal@32") |
| 1167 option_parser.add_option("--spec", | 1146 parser.add_option("--deps", dest="deps_os", metavar="OS_LIST", |
| 1168 help="(config only) create a gclient file " | 1147 help="(update/sync only) sync deps for the " |
| 1169 "containing the provided string") | 1148 "specified (comma-separated) platform(s); " |
| 1170 option_parser.add_option("-v", "--verbose", action="count", default=0, | 1149 "'all' will sync all platforms") |
| 1171 help="produce additional output for diagnostics") | 1150 parser.add_option("--reset", action="store_true", |
| 1172 option_parser.add_option("--manually_grab_svn_rev", action="store_true", | 1151 help="(update/sync only) resets any local changes " |
| 1173 help="Skip svn up whenever possible by requesting " | 1152 "before updating (git only)") |
| 1174 "actual HEAD revision from the repository") | 1153 parser.add_option("--spec", |
| 1175 option_parser.add_option("--head", action="store_true", | 1154 help="(config only) create a gclient file " |
| 1176 help="skips any safesync_urls specified in " | 1155 "containing the provided string") |
| 1177 "configured solutions") | 1156 parser.add_option("--manually_grab_svn_rev", action="store_true", |
| 1178 option_parser.add_option("--delete_unversioned_trees", action="store_true", | 1157 help="Skip svn up whenever possible by requesting " |
| 1179 help="on update, delete any unexpected " | 1158 "actual HEAD revision from the repository") |
| 1180 "unversioned trees that are in the checkout") | 1159 parser.add_option("--head", action="store_true", |
| 1181 option_parser.add_option("--snapshot", action="store_true", | 1160 help="skips any safesync_urls specified in " |
| 1182 help="(revinfo only), create a snapshot file " | 1161 "configured solutions") |
| 1183 "of the current version of all repositories") | 1162 parser.add_option("--delete_unversioned_trees", action="store_true", |
| 1184 option_parser.add_option("--name", | 1163 help="on update, delete any unexpected " |
| 1185 help="specify alternate relative solution path") | 1164 "unversioned trees that are in the checkout") |
| 1186 option_parser.add_option("--gclientfile", metavar="FILENAME", | 1165 parser.add_option("--snapshot", action="store_true", |
| 1187 help="specify an alternate .gclient file") | 1166 help="(revinfo only), create a snapshot file " |
| 1167 "of the current version of all repositories") |
| 1168 parser.add_option("--name", |
| 1169 help="specify alternate relative solution path") |
| 1170 # Integrate standard options processing. |
| 1171 old_parser = parser.parse_args |
| 1172 def Parse(args): |
| 1173 (options, args) = old_parser(args) |
| 1174 if options.verbose == 2: |
| 1175 logging.basicConfig(level=logging.INFO) |
| 1176 elif options.verbose > 2: |
| 1177 logging.basicConfig(level=logging.DEBUG) |
| 1178 options.entries_filename = options.config_filename + "_entries" |
| 1179 return (options, args) |
| 1180 parser.parse_args = Parse |
| 1181 # We don't want wordwrapping in epilog (usually examples) |
| 1182 parser.format_epilog = lambda _: parser.epilog or '' |
| 1188 | 1183 |
| 1189 if len(argv) < 2: | 1184 if not len(argv): |
| 1190 # Users don't need to be told to use the 'help' command. | 1185 argv = ['help'] |
| 1191 option_parser.print_help() | |
| 1192 return 1 | |
| 1193 # Add manual support for --version as first argument. | 1186 # Add manual support for --version as first argument. |
| 1194 if argv[1] == '--version': | 1187 if argv[0] == '--version': |
| 1195 option_parser.print_version() | 1188 parser.print_version() |
| 1196 return 0 | 1189 return 0 |
| 1197 | |
| 1198 # Add manual support for --help as first argument. | 1190 # Add manual support for --help as first argument. |
| 1199 if argv[1] == '--help': | 1191 if argv[0] == '--help': |
| 1200 argv[1] = 'help' | 1192 argv[0] = 'help' |
| 1201 | 1193 options, args = parser.parse_args(argv[1:]) |
| 1202 command = argv[1] | 1194 return Command(argv[0])(parser, options, args) |
| 1203 options, args = option_parser.parse_args(argv[2:]) | |
| 1204 | |
| 1205 if len(argv) < 3 and command == "help": | |
| 1206 option_parser.print_help() | |
| 1207 return 0 | |
| 1208 | |
| 1209 if options.verbose > 1: | |
| 1210 logging.basicConfig(level=logging.DEBUG) | |
| 1211 | |
| 1212 # Files used for configuration and state saving. | |
| 1213 options.config_filename = os.environ.get("GCLIENT_FILE", ".gclient") | |
| 1214 if options.gclientfile: | |
| 1215 options.config_filename = options.gclientfile | |
| 1216 options.entries_filename = options.config_filename + "_entries" | |
| 1217 options.deps_file = "DEPS" | |
| 1218 | |
| 1219 options.platform = sys.platform | |
| 1220 return DispatchCommand(command, options, args) | |
| 1221 | 1195 |
| 1222 | 1196 |
| 1223 if "__main__" == __name__: | 1197 if "__main__" == __name__: |
| 1224 try: | 1198 try: |
| 1225 result = Main(sys.argv) | 1199 sys.exit(Main(sys.argv[1:])) |
| 1226 except gclient_utils.Error, e: | 1200 except gclient_utils.Error, e: |
| 1227 print >> sys.stderr, "Error: %s" % str(e) | 1201 print >> sys.stderr, "Error: %s" % str(e) |
| 1228 result = 1 | 1202 sys.exit(1) |
| 1229 sys.exit(result) | |
| 1230 | 1203 |
| 1231 # vim: ts=2:sw=2:tw=80:et: | 1204 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |