OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 Subversion | 26 Subversion |
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 # Work-around for md5 module deprecation warning in python 2.5+: |
| 37 try: |
| 38 import hashlib # Try to load hashlib (python 2.5+) |
| 39 except ImportError: # If it cannot be imported, set it to None |
| 40 hashlib = None |
36 import logging | 41 import logging |
37 import md5 | 42 if not hashlib: # If hashlib was not imported, then this is python 2.4: use md5 |
| 43 import md5 |
38 import mimetypes | 44 import mimetypes |
39 import optparse | 45 import optparse |
40 import os | 46 import os |
41 import re | 47 import re |
42 import socket | 48 import socket |
43 import subprocess | 49 import subprocess |
44 import sys | 50 import sys |
45 import urllib | 51 import urllib |
46 import urllib2 | 52 import urllib2 |
47 import urlparse | 53 import urlparse |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 file_too_large = False | 673 file_too_large = False |
668 if is_base: | 674 if is_base: |
669 type = "base" | 675 type = "base" |
670 else: | 676 else: |
671 type = "current" | 677 type = "current" |
672 if len(content) > MAX_UPLOAD_SIZE: | 678 if len(content) > MAX_UPLOAD_SIZE: |
673 print ("Not uploading the %s file for %s because it's too large." % | 679 print ("Not uploading the %s file for %s because it's too large." % |
674 (type, filename)) | 680 (type, filename)) |
675 file_too_large = True | 681 file_too_large = True |
676 content = "" | 682 content = "" |
677 checksum = md5.new(content).hexdigest() | 683 if hashlib: # python 2.5+ uses hashlib |
| 684 checksum = hashlib.md5(content).hexdigest() |
| 685 else: # python 2.4- uses md5 |
| 686 checksum = md5.new(content).hexdigest() |
678 if options.verbose > 0 and not file_too_large: | 687 if options.verbose > 0 and not file_too_large: |
679 print "Uploading %s file for %s" % (type, filename) | 688 print "Uploading %s file for %s" % (type, filename) |
680 url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id) | 689 url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id) |
681 form_fields = [("filename", filename), | 690 form_fields = [("filename", filename), |
682 ("status", status), | 691 ("status", status), |
683 ("checksum", checksum), | 692 ("checksum", checksum), |
684 ("is_binary", str(is_binary)), | 693 ("is_binary", str(is_binary)), |
685 ("is_current", str(not is_base)), | 694 ("is_current", str(not is_base)), |
686 ] | 695 ] |
687 if file_too_large: | 696 if file_too_large: |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 file = open(options.description_file, 'r') | 1328 file = open(options.description_file, 'r') |
1320 description = file.read() | 1329 description = file.read() |
1321 file.close() | 1330 file.close() |
1322 if description: | 1331 if description: |
1323 form_fields.append(("description", description)) | 1332 form_fields.append(("description", description)) |
1324 # Send a hash of all the base file so the server can determine if a copy | 1333 # Send a hash of all the base file so the server can determine if a copy |
1325 # already exists in an earlier patchset. | 1334 # already exists in an earlier patchset. |
1326 base_hashes = "" | 1335 base_hashes = "" |
1327 for file, info in files.iteritems(): | 1336 for file, info in files.iteritems(): |
1328 if not info[0] is None: | 1337 if not info[0] is None: |
1329 checksum = md5.new(info[0]).hexdigest() | 1338 if hashlib: # python 2.5+ uses hashlib |
| 1339 checksum = hashlib.md5(info[0]).hexdigest() |
| 1340 else: # python 2.4- uses md5 |
| 1341 checksum = md5.new(info[0]).hexdigest() |
1330 if base_hashes: | 1342 if base_hashes: |
1331 base_hashes += "|" | 1343 base_hashes += "|" |
1332 base_hashes += checksum + ":" + file | 1344 base_hashes += checksum + ":" + file |
1333 form_fields.append(("base_hashes", base_hashes)) | 1345 form_fields.append(("base_hashes", base_hashes)) |
1334 # If we're uploading base files, don't send the email before the uploads, so | 1346 # If we're uploading base files, don't send the email before the uploads, so |
1335 # that it contains the file status. | 1347 # that it contains the file status. |
1336 if options.send_mail and options.download_base: | 1348 if options.send_mail and options.download_base: |
1337 form_fields.append(("send_mail", "1")) | 1349 form_fields.append(("send_mail", "1")) |
1338 if not options.download_base: | 1350 if not options.download_base: |
1339 form_fields.append(("content_upload", "1")) | 1351 form_fields.append(("content_upload", "1")) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 try: | 1390 try: |
1379 RealMain(sys.argv) | 1391 RealMain(sys.argv) |
1380 except KeyboardInterrupt: | 1392 except KeyboardInterrupt: |
1381 print | 1393 print |
1382 StatusUpdate("Interrupted.") | 1394 StatusUpdate("Interrupted.") |
1383 sys.exit(1) | 1395 sys.exit(1) |
1384 | 1396 |
1385 | 1397 |
1386 if __name__ == "__main__": | 1398 if __name__ == "__main__": |
1387 main() | 1399 main() |
OLD | NEW |