Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit e9a9db3

Browse files
rgreggD4N14L
authored andcommitted
Initial commit
0 parents  commit e9a9db3

File tree

156 files changed

+17606
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+17606
-0
lines changed

.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.coverage.*
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
*,cover
45+
46+
# Translations
47+
*.mo
48+
*.pot
49+
50+
# Django stuff:
51+
*.log
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# PyBuilder
57+
target/

DESCRIPTION.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OneDrive Python SDK
2+
===================
3+
4+
Lorem ipsum

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 OneDrive
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE
2+
include DESCRIPTION.rst

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
**Getting Started with the OneDrive Python SDK**
2+
3+
------------------------------------------------------------------------
4+
[![Build status](https://ci.appveyor.com/api/projects/status/x1cjahp817w6r455?svg=true)](https://ci.appveyor.com/project/OneDrive/vroom-client-python)
5+
6+
Installation
7+
============
8+
9+
To install the OneDrive Python SDK, open a command prompt and type:
10+
11+
<pre><code>pip install onedrivesdk
12+
</code></pre>
13+
Next, include the SDK in your python project by adding
14+
15+
<pre><code>import onedrivesdk</code></pre>
16+
17+
Authentication
18+
==============
19+
20+
To interact with the OneDrive API, you must authenticate. You can use the following code sample to do so.
21+
22+
<pre><code>import onedrivesdk
23+
from onedrivesdk.helpers import GetAuthCodeServer
24+
25+
redirect_uri = "http://localhost:8080/"
26+
client_secret = "your_app_secret"
27+
28+
client = onedrivesdk.get_default_client(client_id='your_client_id',
29+
scopes=['wl.signin',
30+
'wl.offline_access',
31+
'onedrive.readwrite'])
32+
33+
auth_url = client.auth_provider.get_auth_url(redirect_uri)
34+
35+
#this will block until we have the code
36+
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
37+
38+
client.auth_provider.authenticate(code, redirect_uri, client_secret)
39+
</code></pre>
40+
41+
Once you are authenticated, you should have access to the OneDrive API, and
42+
can begin making calls using the SDK!
43+
44+
Examples
45+
========
46+
47+
NOTE: All examples assume that the
48+
[Authentication](#authentication) has already occured.
49+
50+
Upload an Item
51+
--------------
52+
53+
<pre><code>returned_item = client.item(drive="me", id="root").children["newfile.txt"].upload("./path_to_file.txt")</code></pre>
54+
55+
Download an Item
56+
----------------
57+
58+
<pre><code>root_folder = client.item(drive="me", id="root").children.get()
59+
id_of_file = root_folder[0].id
60+
61+
client.item(drive="me", id=id_of_file).download("./path_to_download_to.txt")
62+
</code></pre>
63+
64+
Add a Folder
65+
------------
66+
67+
<pre><code>f = onedrivesdk.Folder()
68+
i = onedrivesdk.Item()
69+
i.name = "New Folder"
70+
i.folder = f
71+
72+
returned_item = client.item(drive="me", id="root").children.add(i)
73+
</code></pre>
74+
75+
Copying an Item
76+
---------------
77+
78+
<pre><code>from onedrivesdk.item_reference import ItemReference
79+
80+
ref = ItemReference()
81+
ref.id = "yourparent!id" #path also supported
82+
83+
copy_operation = client.item(drive="me", id="youritemtocopy!id").copy(name="new copied name", parent_reference=ref).post()
84+
85+
#copy_operation.item will return None until the copy has completed.
86+
#If you would like to block until the operation has been completed
87+
#and copy_operation.item is no longer None
88+
copy_operation.poll_until_complete()
89+
90+
</code></pre>
91+
92+
Renaming an Item
93+
----------------
94+
95+
<pre><code>renamed_item = onedrivesdk.Item()
96+
renamed_item.name = "NewItemName"
97+
renamed_item.id = "youritemtorename!id"
98+
99+
new_item = client.item(drive="me", id=renamed_item.id).update(renamed_item)
100+
</code></pre>
101+
102+
Paging through a Collection
103+
---------------------------
104+
105+
<pre><code>#get the top 3 elements of root, leaving the next page for more elements
106+
collection = client.item(drive="me", id="root").children.request(top=3).get()
107+
108+
#get the first item in the collection
109+
item = collection[0]
110+
111+
#get next page of 3 elements, if none exist, returns None
112+
collection2 = collection.next_page_request.get()
113+
</code></pre>
114+
115+
Async operations
116+
----------------
117+
118+
<p>
119+
For async operations, you create an asyncio.coroutine which
120+
implements asyncio.ascompleted, and execute it with
121+
loop.run\_until\_complete.
122+
123+
<pre><code>import asyncio
124+
125+
@asyncio.coroutine
126+
def run_gets(client):
127+
coroutines = [client.drive("me").request().get_async() for i in range(3)]
128+
for future in asyncio.as_completed(coroutines):
129+
drive = yield from future
130+
print(drive.id)
131+
132+
loop = asyncio.get_event_loop()
133+
loop.run_until_complete(run_gets(client))
134+
</code></pre>

appveyor.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
environment:
2+
3+
global:
4+
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
5+
# /E:ON and /V:ON options are not enabled in the batch script intepreter
6+
# See: http://stackoverflow.com/a/13751649/163740
7+
WITH_COMPILER: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_compiler.cmd"
8+
9+
matrix:
10+
11+
- PYTHON: "C:\\Python27"
12+
PYTHON_VERSION: "2.7.x" # currently 2.7.9
13+
PYTHON_ARCH: "32"
14+
15+
- PYTHON: "C:\\Python33"
16+
PYTHON_VERSION: "3.3.x" # currently 3.3.5
17+
PYTHON_ARCH: "32"
18+
19+
- PYTHON: "C:\\Python34"
20+
PYTHON_VERSION: "3.4.x" # currently 3.4.3
21+
PYTHON_ARCH: "32"
22+
23+
- PYTHON: "C:\\Python27-x64"
24+
PYTHON_VERSION: "2.7.x" # currently 2.7.9
25+
PYTHON_ARCH: "64"
26+
WINDOWS_SDK_VERSION: "v7.0"
27+
28+
- PYTHON: "C:\\Python33-x64"
29+
PYTHON_VERSION: "3.3.x" # currently 3.3.5
30+
PYTHON_ARCH: "64"
31+
WINDOWS_SDK_VERSION: "v7.1"
32+
33+
- PYTHON: "C:\\Python34-x64"
34+
PYTHON_VERSION: "3.4.x" # currently 3.4.3
35+
PYTHON_ARCH: "64"
36+
WINDOWS_SDK_VERSION: "v7.1"
37+
38+
init:
39+
- "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%"
40+
41+
install:
42+
- "powershell appveyor\\install.ps1"
43+
- "%PYTHON%/python -m pip install Mock"
44+
- "%PYTHON%/python setup.py install"
45+
46+
build: off
47+
48+
test_script:
49+
- "%WITH_COMPILER% %PYTHON%/python setup.py test"
50+
51+
after_test:
52+
- "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel"
53+
54+
artifacts:
55+
- path: dist\*

appveyor/install.ps1

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Sample script to install Python and pip under Windows
2+
# Authors: Olivier Grisel and Kyle Kastner
3+
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
4+
5+
$BASE_URL = "https://www.python.org/ftp/python/"
6+
$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
7+
$GET_PIP_PATH = "C:\get-pip.py"
8+
9+
10+
function DownloadPython ($python_version, $platform_suffix) {
11+
$webclient = New-Object System.Net.WebClient
12+
$filename = "python-" + $python_version + $platform_suffix + ".msi"
13+
$url = $BASE_URL + $python_version + "/" + $filename
14+
15+
$basedir = $pwd.Path + "\"
16+
$filepath = $basedir + $filename
17+
if (Test-Path $filename) {
18+
Write-Host "Reusing" $filepath
19+
return $filepath
20+
}
21+
22+
# Download and retry up to 5 times in case of network transient errors.
23+
Write-Host "Downloading" $filename "from" $url
24+
$retry_attempts = 3
25+
for($i=0; $i -lt $retry_attempts; $i++){
26+
try {
27+
$webclient.DownloadFile($url, $filepath)
28+
break
29+
}
30+
Catch [Exception]{
31+
Start-Sleep 1
32+
}
33+
}
34+
Write-Host "File saved at" $filepath
35+
return $filepath
36+
}
37+
38+
39+
function InstallPython ($python_version, $architecture, $python_home) {
40+
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
41+
if (Test-Path $python_home) {
42+
Write-Host $python_home "already exists, skipping."
43+
return $false
44+
}
45+
if ($architecture -eq "32") {
46+
$platform_suffix = ""
47+
} else {
48+
$platform_suffix = ".amd64"
49+
}
50+
$filepath = DownloadPython $python_version $platform_suffix
51+
Write-Host "Installing" $filepath "to" $python_home
52+
$args = "/qn /i $filepath TARGETDIR=$python_home"
53+
Write-Host "msiexec.exe" $args
54+
Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru
55+
Write-Host "Python $python_version ($architecture) installation complete"
56+
return $true
57+
}
58+
59+
60+
function InstallPip ($python_home) {
61+
$pip_path = $python_home + "/Scripts/pip.exe"
62+
$python_path = $python_home + "/python.exe"
63+
if (-not(Test-Path $pip_path)) {
64+
Write-Host "Installing pip..."
65+
$webclient = New-Object System.Net.WebClient
66+
$webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH)
67+
Write-Host "Executing:" $python_path $GET_PIP_PATH
68+
Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru
69+
} else {
70+
Write-Host "pip already installed."
71+
}
72+
}
73+
74+
function InstallPackage ($python_home, $pkg) {
75+
$pip_path = $python_home + "/Scripts/pip.exe"
76+
& $pip_path install $pkg
77+
}
78+
79+
function main () {
80+
InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
81+
InstallPip $env:PYTHON
82+
InstallPackage $env:PYTHON wheel
83+
}
84+
85+
main

0 commit comments

Comments
 (0)