Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 import getpass | 3 import getpass |
| 4 import optparse | 4 import optparse |
| 5 import os | 5 import os |
| 6 import subprocess | 6 import subprocess |
| 7 import tempfile | 7 import tempfile |
| 8 import traceback | 8 import traceback |
| 9 import urllib | 9 import urllib |
| 10 import sys | 10 import sys |
| 11 import re | |
| 12 import trychange | |
| 11 | 13 |
| 12 | 14 |
| 13 def Backquote(cmd): | 15 def Backquote(cmd): |
| 14 """Like running `cmd` in a shell script.""" | 16 """Like running `cmd` in a shell script.""" |
| 15 return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].strip() | 17 return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].strip() |
| 16 | 18 |
| 17 | 19 |
| 18 def GetTryServerConfig(): | 20 def GetTryServerConfig(): |
| 19 """Returns the dictionary of try server options or None if they | 21 """Returns the dictionary of try server options or None if they |
| 20 cannot be found.""" | 22 cannot be found.""" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 line = line[0:4] + 'src/' + line[4:] | 88 line = line[0:4] + 'src/' + line[4:] |
| 87 output.append(line) | 89 output.append(line) |
| 88 | 90 |
| 89 munged_diff = ''.join(output) | 91 munged_diff = ''.join(output) |
| 90 if len(munged_diff.strip()) == 0: | 92 if len(munged_diff.strip()) == 0: |
| 91 raise Exception("Patch was empty, did you give the right remote branch?") | 93 raise Exception("Patch was empty, did you give the right remote branch?") |
| 92 | 94 |
| 93 return munged_diff | 95 return munged_diff |
| 94 | 96 |
| 95 | 97 |
| 98 def ValidEmail(email): | |
| 99 return re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email) | |
| 100 | |
| 101 | |
| 96 def GetEmail(): | 102 def GetEmail(): |
| 97 # TODO: check for errors here? | 103 email = Backquote(['git', 'config', 'user.email']) |
| 98 return Backquote(['git', 'config', 'user.email']) | 104 runmsg = "Try: git config user.email <EMAIL>" |
| 105 assert ValidEmail(email), "Email '%s' is not valid. %s" % (email, runmsg) | |
| 106 return email | |
| 99 | 107 |
| 100 | 108 |
| 101 def TryChange(args): | 109 def TryChange(args): |
| 102 """Put a patch on the try server using SVN.""" | 110 """Put a patch on the try server.""" |
| 103 root_dir = Backquote(['git', 'rev-parse', '--show-cdup']) | 111 root_dir = Backquote(['git', 'rev-parse', '--show-cdup']) |
| 104 script_path = os.path.dirname(sys.argv[0]) | |
| 105 sys.path.append(script_path) | |
| 106 try: | |
| 107 import trychange | |
| 108 except ImportError, e: | |
| 109 print "Error trying to import trychange from", script_path | |
| 110 print "git-try expects to live at depot_tools/git-try" | |
| 111 raise e | |
| 112 trychange.checkout_root = os.path.abspath(root_dir) | 112 trychange.checkout_root = os.path.abspath(root_dir) |
| 113 trychange.TryChange(args, None, False) | 113 trychange.TryChange(args, None, False) |
| 114 | 114 |
| 115 | 115 |
| 116 def WriteTryDiffHTTP(config, patch_name, diff, options): | |
| 117 """Put a patch on the try server.""" | |
| 118 params = { | |
| 119 'user': getpass.getuser(), | |
| 120 'name': patch_name, | |
| 121 'patch': diff | |
| 122 } | |
| 123 | |
| 124 if GetRietveldPatchsetNumber(): | |
| 125 params['issue'] = GetRietveldIssueNumber() | |
| 126 params['patchset'] = GetRietveldPatchsetNumber() | |
| 127 | |
| 128 if options.bot: | |
| 129 params['bot'] = options.bot | |
| 130 | |
| 131 if options.clobber: | |
| 132 params['clobber'] = 'true' | |
| 133 | |
| 134 url = 'http://%s:%s/send_try_patch' % (config['try_server_http_host'], | |
| 135 config['try_server_http_port']) | |
| 136 connection = urllib.urlopen(url, urllib.urlencode(params)) | |
| 137 response = connection.read() | |
| 138 if (response != 'OK'): | |
| 139 print "Error posting to", url | |
| 140 print response | |
| 141 assert False | |
| 142 | |
| 143 | |
| 144 if __name__ == '__main__': | 116 if __name__ == '__main__': |
| 145 parser = optparse.OptionParser( | 117 parser = optparse.OptionParser( |
| 146 usage='git try [options] [branch]', | 118 usage='git try [options] [branch]', |
| 147 description='Upload the current diff of branch...HEAD to the try server.') | 119 description='Upload the current diff of branch...HEAD to the try server.') |
| 148 parser.add_option("-b", "--bot", | 120 parser.add_option("-b", "--bot", |
| 149 help="Force the use of a specific build slave (eg mac, " | 121 help="Force the use of a specific build slave (eg mac, " |
| 150 "win, or linux)") | 122 "win, or linux)") |
| 151 parser.add_option("-c", "--clobber", action="store_true", | 123 parser.add_option("-c", "--clobber", action="store_true", |
| 152 help="Make the try run use be a clobber build") | 124 help="Make the try run use be a clobber build") |
| 153 parser.add_option("-r", "--revision", | 125 parser.add_option("-r", "--revision", |
| 154 help="Specify the SVN base revision to use") | 126 help="Specify the SVN base revision to use") |
| 155 (options, args) = parser.parse_args(sys.argv) | 127 (options, args) = parser.parse_args(sys.argv) |
| 156 | 128 |
| 157 branch = None | 129 branch = None |
| 158 if len(args) > 1: | 130 if len(args) > 1: |
| 159 branch = args[1] | 131 branch = args[1] |
| 160 | 132 |
| 161 patch_name = GetPatchName() | 133 patch_name = GetPatchName() |
| 162 diff = GetMungedDiff(branch) | 134 diff = GetMungedDiff(branch) |
| 163 | 135 |
| 164 # Send directly to try server if we can parse the config, otherwise | 136 # Write the diff out to a temporary file |
| 137 diff_file = tempfile.NamedTemporaryFile() | |
| 138 diff_file.write(diff) | |
| 139 diff_file.flush() | |
| 140 | |
| 141 email = GetEmail() | |
| 142 user = email.partition('@')[0] | |
| 143 args = [ | |
| 144 '-u', user, | |
| 145 '-e', email, | |
| 146 '-n', patch_name, | |
| 147 '--diff', diff_file.name, | |
| 148 ] | |
| 149 | |
| 150 # Send to try server via HTTP if we can parse the config, otherwise | |
| 165 # upload via SVN. | 151 # upload via SVN. |
| 166 config = GetTryServerConfig() | 152 config = GetTryServerConfig() |
| 167 if config is not None: | 153 if config is not None: |
| 168 print "Sending %s using HTTP..." % patch_name | 154 sendmsg = "Sending %s using HTTP..." % patch_name |
| 169 WriteTryDiffHTTP(config=config, patch_name=patch_name, diff=diff, | 155 args.extend(['--use_http']) |
| 170 options=options) | 156 if config['try_server_http_host'] is not None: |
| 157 args.extend(['--host', config['try_server_http_host']]) | |
| 158 if config['try_server_http_port'] is not None: | |
| 159 args.extend(['--port', config['try_server_http_port']]) | |
| 160 | |
| 171 else: | 161 else: |
| 172 print "Could not get server config -- if you're within Google, " | 162 print "Could not get server config -- if you're within Google, " |
| 173 print "do you have have src-internal checked out?" | 163 print "do you have have src-internal checked out?" |
| 174 print "Sending %s using SVN..." % patch_name | 164 sendmsg = "Sending %s using SVN..." % patch_name |
| 165 args.extend([ | |
| 166 '--use_svn', '--svn_repo', | |
| 167 'svn://svn.chromium.org/chrome-try/try', | |
|
M-A Ruel
2009/08/25 20:56:50
Err, you may break folks with that but I guess it'
| |
| 168 ]) | |
| 175 | 169 |
| 176 # Write the diff out to a temporary file | 170 if options.bot: |
| 177 diff_file = tempfile.NamedTemporaryFile() | 171 args.extend(['--bot', options.bot]) |
| 178 diff_file.write(diff) | 172 if options.clobber: |
| 179 diff_file.flush() | 173 args.append('--clobber') |
| 174 if options.revision: | |
| 175 args.extend(['-r', options.revision]) | |
| 176 else: | |
| 177 args.extend(['-r', GetRevision()]) | |
| 178 if GetRietveldPatchsetNumber(): | |
| 179 args.extend([ | |
| 180 '--issue', GetRietveldIssueNumber(), | |
| 181 '--patchset', GetRietveldPatchsetNumber(), | |
| 182 ]) | |
| 180 | 183 |
| 181 email = GetEmail() | 184 print sendmsg |
| 182 user = email.partition('@')[0] | 185 TryChange(args=args) |
| 183 args = [ | |
| 184 '--use_svn', | |
| 185 '--svn_repo', 'svn://svn.chromium.org/chrome-try/try', | |
| 186 '-u', user, | |
| 187 '-e', email, | |
| 188 '-n', patch_name, | |
| 189 '--diff', diff_file.name, | |
| 190 ] | |
| 191 if options.bot: | |
| 192 args.extend(['--bot', options.bot]) | |
| 193 if options.clobber: | |
| 194 args.append('--clobber') | |
| 195 if options.revision: | |
| 196 args.extend(['-r', options.revision]) | |
| 197 else: | |
| 198 args.extend(['-r', GetRevision()]) | |
| 199 if GetRietveldPatchsetNumber(): | |
| 200 args.extend([ | |
| 201 '--issue', GetRietveldIssueNumber(), | |
| 202 '--patchset', GetRietveldPatchsetNumber(), | |
| 203 ]) | |
| 204 TryChange(args=args) | |
| OLD | NEW |