Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: upload.py

Issue 99235: Silence off the DeprecationWarning in upload.py when running python >=2.5. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2007 Google Inc. 3 # Copyright 2007 Google Inc.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 16 matching lines...) Expand all
27 27
28 It is important for Git/Mercurial users to specify a tree/node/branch to diff 28 It is important for Git/Mercurial users to specify a tree/node/branch to diff
29 against by using the '--rev' option. 29 against by using the '--rev' option.
30 """ 30 """
31 # This code is derived from appcfg.py in the App Engine SDK (open source), 31 # This code is derived from appcfg.py in the App Engine SDK (open source),
32 # and from ASPN recipe #146306. 32 # and from ASPN recipe #146306.
33 33
34 import cookielib 34 import cookielib
35 import getpass 35 import getpass
36 import logging 36 import logging
37 import md5
38 import mimetypes 37 import mimetypes
39 import optparse 38 import optparse
40 import os 39 import os
41 import re 40 import re
42 import socket 41 import socket
43 import subprocess 42 import subprocess
44 import sys 43 import sys
45 import urllib 44 import urllib
46 import urllib2 45 import urllib2
47 import urlparse 46 import urlparse
48 47
48 # Work-around for md5 module deprecation warning in python 2.5+:
49 try:
50 # Try to load hashlib (python 2.5+)
51 from hashlib import md5
52 except ImportError:
53 # If hashlib cannot be imported, load md5.new instead.
54 from md5 import new as md5
55
49 try: 56 try:
50 import readline 57 import readline
51 except ImportError: 58 except ImportError:
52 pass 59 pass
53 60
54 # The logging verbosity: 61 # The logging verbosity:
55 # 0: Errors only. 62 # 0: Errors only.
56 # 1: Status messages. 63 # 1: Status messages.
57 # 2: Info logs. 64 # 2: Info logs.
58 # 3: Debug logs. 65 # 3: Debug logs.
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 file_too_large = False 675 file_too_large = False
669 if is_base: 676 if is_base:
670 type = "base" 677 type = "base"
671 else: 678 else:
672 type = "current" 679 type = "current"
673 if len(content) > MAX_UPLOAD_SIZE: 680 if len(content) > MAX_UPLOAD_SIZE:
674 print ("Not uploading the %s file for %s because it's too large." % 681 print ("Not uploading the %s file for %s because it's too large." %
675 (type, filename)) 682 (type, filename))
676 file_too_large = True 683 file_too_large = True
677 content = "" 684 content = ""
678 checksum = md5.new(content).hexdigest() 685 checksum = md5(content).hexdigest()
679 if options.verbose > 0 and not file_too_large: 686 if options.verbose > 0 and not file_too_large:
680 print "Uploading %s file for %s" % (type, filename) 687 print "Uploading %s file for %s" % (type, filename)
681 url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id) 688 url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
682 form_fields = [("filename", filename), 689 form_fields = [("filename", filename),
683 ("status", status), 690 ("status", status),
684 ("checksum", checksum), 691 ("checksum", checksum),
685 ("is_binary", str(is_binary)), 692 ("is_binary", str(is_binary)),
686 ("is_current", str(not is_base)), 693 ("is_current", str(not is_base)),
687 ] 694 ]
688 if file_too_large: 695 if file_too_large:
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 file = open(options.description_file, 'r') 1313 file = open(options.description_file, 'r')
1307 description = file.read() 1314 description = file.read()
1308 file.close() 1315 file.close()
1309 if description: 1316 if description:
1310 form_fields.append(("description", description)) 1317 form_fields.append(("description", description))
1311 # Send a hash of all the base file so the server can determine if a copy 1318 # Send a hash of all the base file so the server can determine if a copy
1312 # already exists in an earlier patchset. 1319 # already exists in an earlier patchset.
1313 base_hashes = "" 1320 base_hashes = ""
1314 for file, info in files.iteritems(): 1321 for file, info in files.iteritems():
1315 if not info[0] is None: 1322 if not info[0] is None:
1316 checksum = md5.new(info[0]).hexdigest() 1323 checksum = md5(info[0]).hexdigest()
1317 if base_hashes: 1324 if base_hashes:
1318 base_hashes += "|" 1325 base_hashes += "|"
1319 base_hashes += checksum + ":" + file 1326 base_hashes += checksum + ":" + file
1320 form_fields.append(("base_hashes", base_hashes)) 1327 form_fields.append(("base_hashes", base_hashes))
1321 # If we're uploading base files, don't send the email before the uploads, so 1328 # If we're uploading base files, don't send the email before the uploads, so
1322 # that it contains the file status. 1329 # that it contains the file status.
1323 if options.send_mail and options.download_base: 1330 if options.send_mail and options.download_base:
1324 form_fields.append(("send_mail", "1")) 1331 form_fields.append(("send_mail", "1"))
1325 if not options.download_base: 1332 if not options.download_base:
1326 form_fields.append(("content_upload", "1")) 1333 form_fields.append(("content_upload", "1"))
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 try: 1371 try:
1365 RealMain(sys.argv) 1372 RealMain(sys.argv)
1366 except KeyboardInterrupt: 1373 except KeyboardInterrupt:
1367 print 1374 print
1368 StatusUpdate("Interrupted.") 1375 StatusUpdate("Interrupted.")
1369 sys.exit(1) 1376 sys.exit(1)
1370 1377
1371 1378
1372 if __name__ == "__main__": 1379 if __name__ == "__main__":
1373 main() 1380 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698