Merge lp:~noizyland/duplicity/azurebackend-fixes into lp:~duplicity-team/duplicity/0.7-series

Proposed by Scott McKenzie
Status: Merged
Merged at revision: 1156
Proposed branch: lp:~noizyland/duplicity/azurebackend-fixes
Merge into: lp:~duplicity-team/duplicity/0.7-series
Diff against target: 104 lines (+32/-18)
2 files modified
bin/duplicity.1 (+4/-4)
duplicity/backends/azurebackend.py (+28/-14)
To merge this branch: bzr merge lp:~noizyland/duplicity/azurebackend-fixes
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+279347@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/duplicity.1'
2--- bin/duplicity.1 2015-10-10 00:02:35 +0000
3+++ bin/duplicity.1 2015-12-02 20:23:07 +0000
4@@ -1465,8 +1465,8 @@
5 if /home/ben/1234567 existed.
6
7 .SH A NOTE ON AZURE ACCESS
8-The Azure backend requires the Microsoft Azure SDK for Python to be installed
9-on the system.
10+The Azure backend requires the Microsoft Azure Storage SDK for Python to be
11+installed on the system.
12 See
13 .B REQUIREMENTS
14 above.
15@@ -1960,8 +1960,8 @@
16 Some backends also require additional components (probably available as packages for your specific platform):
17 .TP
18 .BR "azure backend" " (Azure Blob Storage Service)"
19-.B Microsoft Azure SDK for Python
20-- https://github.com/Azure/azure-sdk-for-python
21+.B Microsoft Azure Storage SDK for Python
22+- https://pypi.python.org/pypi/azure-storage/
23 .TP
24 .BR "boto backend" " (S3 Amazon Web Services, Google Cloud Storage)"
25 .B boto version 2.0+
26
27=== modified file 'duplicity/backends/azurebackend.py'
28--- duplicity/backends/azurebackend.py 2015-11-24 14:25:01 +0000
29+++ duplicity/backends/azurebackend.py 2015-12-02 20:23:07 +0000
30@@ -33,29 +33,36 @@
31 def __init__(self, parsed_url):
32 duplicity.backend.Backend.__init__(self, parsed_url)
33
34- # Import Microsoft Azure SDK for Python library.
35+ # Import Microsoft Azure Storage SDK for Python library.
36 try:
37 import azure
38- from azure.storage.blob import BlobService
39+ import azure.storage
40+ if hasattr(azure.storage, 'BlobService'):
41+ # v0.11.1 and below
42+ from azure.storage import BlobService
43+ self.AzureMissingResourceError = azure.WindowsAzureMissingResourceError
44+ self.AzureConflictError = azure.WindowsAzureConflictError
45+ else:
46+ # v1.0.0 and above
47+ from azure.storage.blob import BlobService
48+ self.AzureMissingResourceError = azure.common.AzureMissingResourceHttpError
49+ self.AzureConflictError = azure.common.AzureConflictHttpError
50 except ImportError:
51- raise BackendException('Azure backend requires Microsoft Azure SDK for Python '
52- '(https://github.com/Azure/azure-sdk-for-python).')
53+ raise BackendException('Azure backend requires Microsoft Azure Storage SDK for Python '
54+ '(https://pypi.python.org/pypi/azure-storage/).')
55
56 if 'AZURE_ACCOUNT_NAME' not in os.environ:
57 raise BackendException('AZURE_ACCOUNT_NAME environment variable not set.')
58-
59 if 'AZURE_ACCOUNT_KEY' not in os.environ:
60 raise BackendException('AZURE_ACCOUNT_KEY environment variable not set.')
61+ self.blob_service = BlobService(account_name=os.environ['AZURE_ACCOUNT_NAME'],
62+ account_key=os.environ['AZURE_ACCOUNT_KEY'])
63
64- account_name = os.environ['AZURE_ACCOUNT_NAME']
65- account_key = os.environ['AZURE_ACCOUNT_KEY']
66- self.WindowsAzureMissingResourceError = azure.common.AzureMissingResourceHttpError
67- self.blob_service = BlobService(account_name=account_name, account_key=account_key)
68 # TODO: validate container name
69 self.container = parsed_url.path.lstrip('/')
70 try:
71 self.blob_service.create_container(self.container, fail_on_exist=True)
72- except azure.common.AzureConflictHttpError:
73+ except self.AzureConflictError:
74 # Indicates that the resource could not be created because it already exists.
75 pass
76 except Exception as e:
77@@ -64,16 +71,23 @@
78 log.ErrorCode.connection_failed)
79
80 def _put(self, source_path, remote_filename):
81- # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#upload-blob
82+ # https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#upload-a-blob-into-a-container
83 self.blob_service.put_block_blob_from_path(self.container, remote_filename, source_path.name)
84
85 def _get(self, remote_filename, local_path):
86- # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#download-blobs
87+ # https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#download-blobs
88 self.blob_service.get_blob_to_path(self.container, remote_filename, local_path.name)
89
90 def _list(self):
91- # http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#list-blob
92- blobs = self.blob_service.list_blobs(self.container)
93+ # https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#list-the-blobs-in-a-container
94+ blobs = []
95+ marker = None
96+ while True:
97+ batch = self.blob_service.list_blobs(self.container, marker=marker)
98+ blobs.extend(batch)
99+ if not batch.next_marker:
100+ break
101+ marker = batch.next_marker
102 return [blob.name for blob in blobs]
103
104 def _delete(self, filename):

Subscribers

People subscribed via source and target branches