Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace s3cmd with awscli #6

Merged
merged 1 commit into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions scrapy_dotpersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,13 @@ def _load_data(self):
self._bucket, self._projectid, self._spider
)
logger.info('Syncing .scrapy directory from %s' % self._s3path)
# pre-create dest dir as non-existent destination is treated as file
# by s3cmd (1.1.0)
if not os.path.isdir(self._localpath):
os.makedirs(self._localpath)

cmd = ['s3cmd', 'sync', '--no-preserve', self._s3path, self._localpath]
cmd = ['aws', 's3', 'sync', self._s3path, self._localpath]
self._call(cmd)

def _store_data(self):
# check for reason status here?
logger.info('Syncing .scrapy directory to %s' % self._s3path)
cmd = ['s3cmd', 'sync', '--no-preserve',
'--multipart-chunk-size-mb=5120',
'--delete-removed',
cmd = ['aws', 's3', 'sync', '--delete',
self._localpath, self._s3path]
self._call(cmd)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'Programming Language :: Python :: 2.7',
],
install_requires=[
'Scrapy>=1.0.3',
's3cmd>=1.6.0',
'Scrapy>=1.0.3',
'awscli>=1.10.51',
],
)
9 changes: 3 additions & 6 deletions tests/test_dotpersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def test_load_data(self):
self.instance._load_data()
s3_path1 = 's3://test-bucket/test-user/123/dot-scrapy/testspider/'
self.assertEqual(self.instance._s3path, s3_path1)
assert os.path.exists(self.instance._localpath)
mocked_call.assert_called_with(
['s3cmd', 'sync', '--no-preserve', s3_path1, '/tmp/.scrapy'])
['aws', 's3', 'sync', s3_path1, '/tmp/.scrapy'])

# test other s3_path w/o bucket_folder
mocked_call.reset()
Expand All @@ -84,16 +83,14 @@ def test_load_data(self):
s3_path2 = 's3://test-bucket/123/dot-scrapy/testspider/'
self.assertEqual(self.instance._s3path, s3_path2)
mocked_call.assert_called_with(
['s3cmd', 'sync', '--no-preserve', s3_path2, '/tmp/.scrapy'])
['aws', 's3', 'sync', s3_path2, '/tmp/.scrapy'])

def test_store_data(self):
mocked_call = mock.Mock()
self.instance._call = mocked_call
self.instance._store_data()
mocked_call.assert_called_with(
['s3cmd', 'sync', '--no-preserve',
'--multipart-chunk-size-mb=5120',
'--delete-removed', '/tmp/.scrapy',
['aws', 's3', 'sync', '--delete', '/tmp/.scrapy',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't reproduce that issue with multipart uploads for awscli(#3), works fine with awscli.

's3://test-bucket/test-user/123/dot-scrapy/testspider/'])

def test_call(self):
Expand Down