|
1 | | -#!/usr/bin/env python2 |
| 1 | +#!/usr/bin/env python |
2 | 2 | """ |
3 | 3 | Simple backup and restore script for Amazon DynamoDB using boto to work similarly to mysqldump. |
4 | 4 |
|
|
15 | 15 | import os |
16 | 16 | import shutil |
17 | 17 | import threading |
18 | | -import Queue |
19 | 18 | import datetime |
20 | 19 | import errno |
21 | 20 | import sys |
22 | 21 | import time |
23 | 22 | import re |
24 | 23 | import zipfile |
25 | 24 | import tarfile |
26 | | -import urllib2 |
| 25 | + |
| 26 | +try: |
| 27 | + from queue import Queue |
| 28 | +except ImportError: |
| 29 | + from Queue import Queue |
| 30 | + |
| 31 | +try: |
| 32 | + from urllib.request import urlopen |
| 33 | + from urllib.error import URLError, HTTPError |
| 34 | +except ImportError: |
| 35 | + from urllib2 import urlopen, URLError, HTTPError |
27 | 36 |
|
28 | 37 | import boto.dynamodb2.layer1 |
29 | 38 | from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException |
@@ -63,13 +72,13 @@ def _get_aws_client(profile, region, service): |
63 | 72 | # Fallback to querying metadata for region |
64 | 73 | if not aws_region: |
65 | 74 | try: |
66 | | - azone = urllib2.urlopen(METADATA_URL + "placement/availability-zone", |
67 | | - data=None, timeout=5).read().decode() |
| 75 | + azone = urlopen(METADATA_URL + "placement/availability-zone", |
| 76 | + data=None, timeout=5).read().decode() |
68 | 77 | aws_region = azone[:-1] |
69 | | - except urllib2.URLError: |
| 78 | + except URLError: |
70 | 79 | logging.exception("Timed out connecting to metadata service.\n\n") |
71 | 80 | sys.exit(1) |
72 | | - except urllib2.HTTPError as e: |
| 81 | + except HTTPError as e: |
73 | 82 | logging.exception("Error determining region used for AWS client. Typo in code?\n\n" + |
74 | 83 | str(e)) |
75 | 84 | sys.exit(1) |
@@ -913,7 +922,7 @@ def main(): |
913 | 922 | except AttributeError: |
914 | 923 | # Didn't specify srcTable if we get here |
915 | 924 |
|
916 | | - q = Queue.Queue() |
| 925 | + q = Queue() |
917 | 926 | threads = [] |
918 | 927 |
|
919 | 928 | for i in range(MAX_NUMBER_BACKUP_WORKERS): |
|
0 commit comments