In [1]:
import asyncio

from waterbutler.core import streams
from waterbutler.providers.s3 import S3Provider
from waterbutler.providers.box import BoxProvider
from waterbutler.providers.github import GitHubProvider
from waterbutler.providers.dropbox import DropboxProvider
from waterbutler.providers.googledrive import GoogleDriveProvider

loop = asyncio.get_event_loop()
In [2]:
creds = {
    's3': {'access_key': '...', 'secret_key': '...'},
    'dropbox': {'token': '...'},
    'box': {'token': '...'},
    'github': {'token': '...'},
    'googledrive': {'token': '...'},
}
settings = {
    's3': {'bucket': 'imatestbucket'},
    'dropbox': {'folder': '/Folder_Name'},
    'box': {'folder': '0'},
    'github': {'repo': 'TestRepo', 'owner': 'chrisseto'},
    'googledrive': {'folder': {'id': 'root', 'name': u'Folder Name', 'path': u'Folder%20Name'}},
}
In [3]:
s3 = S3Provider({}, creds['s3'], settings['s3'])
box = BoxProvider({}, creds['box'], settings['box'])
github = GitHubProvider({}, creds['github'], settings['github'])
dropbox = DropboxProvider({}, creds['dropbox'], settings['dropbox'])
googledrive = GoogleDriveProvider({}, creds['googledrive'], settings['googledrive'])

github.name = 'chrisseto'
github.email = '[email protected]'
In [12]:
# List the root directory of google drive
loop.run_until_complete(box.metadata('/'))
Out[12]:
[{'provider': 'box',
  'name': 'folder',
  'kind': 'folder',
  'path': '/3281410086/',
  'extra': {}},
 {'provider': 'box',
  'name': 'new folder name',
  'kind': 'folder',
  'path': '/3281480428/',
  'extra': {}},
 {'provider': 'box',
  'name': 'new folder name2',
  'kind': 'folder',
  'path': '/3285895474/',
  'extra': {}},
 {'provider': 'box',
  'name': 'test',
  'kind': 'folder',
  'path': '/3281288758/',
  'extra': {}},
 {'provider': 'box',
  'name': 'test folder again1',
  'kind': 'folder',
  'path': '/3286724790/',
  'extra': {}},
 {'provider': 'box',
  'name': 'Test1',
  'kind': 'folder',
  'path': '/3120612255/',
  'extra': {}},
 {'contentType': None,
  'extra': {'etag': '0', 'fullPath': None},
  'size': None,
  'path': '/26848554703/<p>lol.txt',
  'modified': None,
  'provider': 'box',
  'name': '<p>lol.txt',
  'kind': 'file'},
 {'contentType': None,
  'extra': {'etag': '0', 'fullPath': None},
  'size': None,
  'path': '/28128613656/bashrc',
  'modified': None,
  'provider': 'box',
  'name': 'bashrc',
  'kind': 'file'},
 {'contentType': None,
  'extra': {'etag': '0', 'fullPath': None},
  'size': None,
  'path': '/26792383311/bashrc.txt',
  'modified': None,
  'provider': 'box',
  'name': 'bashrc.txt',
  'kind': 'file'},
 {'contentType': None,
  'extra': {'etag': '4', 'fullPath': None},
  'size': None,
  'path': '/28127855422/foo',
  'modified': None,
  'provider': 'box',
  'name': 'foo',
  'kind': 'file'},
 {'contentType': None,
  'extra': {'etag': '1', 'fullPath': None},
  'size': None,
  'path': '/28127908846/kodi-14.0-Helix-x86_64.dmg',
  'modified': None,
  'provider': 'box',
  'name': 'kodi-14.0-Helix-x86_64.dmg',
  'kind': 'file'}]
In [6]:
# Get information about a single file
loop.run_until_complete(s3.metadata('/myfile.txt'))
Out[6]:
{'name': 'myfile.txt',
 'size': '39',
 'contentType': 'binary/octet-stream',
 'provider': 's3',
 'extra': {'md5': 'be6734c825ee2e94df900152f3514f35'},
 'path': '/myfile.txt',
 'modified': 'Mon, 13 Apr 2015 14:00:30 GMT',
 'kind': 'file'}
In [7]:
# Download a file and print it out
loop.run_until_complete(loop.run_until_complete(s3.download('/myfile.txt')).read())
Out[7]:
b'This will be the contents of myfile.txt'
In [10]:
# Upload a file called myfile.txt; returns (metadata, created)
loop.run_until_complete(dropbox.upload(streams.StringStream('This will be the contents of myfile.txt'), '/myfile.txt'))
[2015-04-13 10:08:40,168][WARNING][aiohttp.client]: Attempt to decode JSON with unexpected mimetype: text/javascript
[2015-04-13 10:08:41,186][WARNING][aiohttp.client]: Attempt to decode JSON with unexpected mimetype: text/javascript
Out[10]:
({'name': 'myfile.txt',
  'size': 39,
  'contentType': 'text/plain',
  'provider': 'dropbox',
  'extra': {'revisionId': 'baf6011568c8'},
  'path': '/myfile.txt',
  'modified': 'Mon, 13 Apr 2015 14:07:48 +0000',
  'kind': 'file'},
 False)
In [13]:
# Copy a file called "myfile.txt" from Dropbox to Box and rename it to "myfile.dropbox.txt"; returns (metadata, created)
loop.run_until_complete(dropbox.copy(box, {'path': '/myfile.txt'}, {'path': '/myfile.dropbox.txt'}))
Out[13]:
({'name': 'myfile.dropbox.txt',
  'size': 39,
  'contentType': None,
  'provider': 'box',
  'extra': {'fullPath': '/myfile.dropbox.txt', 'etag': '1'},
  'path': '/28705942404/myfile.dropbox.txt',
  'modified': '2015-04-13T07:09:40-07:00',
  'kind': 'file'},
 False)