Skip to content

Commit b3d4ba1

Browse files
committed
PEP8 Standards Fixes
--------- BEGIN META VARIABLES -------- Project : dropbox-sdk-python Task : PEP8 Standards Fixes Done : 3-16-17 --------- END META VARIABLES --------
1 parent cb149fa commit b3d4ba1

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

docs/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import sys
1615
import os
16+
import sys
17+
18+
import dropbox
1719

1820
# Assumes that the dropbox package to generate docs for is one-level above in
1921
# the directory hierarchy. This takes precendence over other dropbox packages
2022
# that may be in the sys.path.
2123
sys.path.insert(0, os.path.abspath('..'))
2224

23-
import dropbox
2425

2526
# If extensions (or modules to document with autodoc) are in another directory,
2627
# add these directories to sys.path here. If the directory is relative to the

example/back-up-and-restore/backup-and-restore-example.py

+46-17
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@
33
This is an example app for API v2.
44
"""
55

6+
from __future__ import print_function
7+
68
import sys
9+
710
import dropbox
8-
from dropbox.files import WriteMode
911
from dropbox.exceptions import ApiError, AuthError
12+
from dropbox.files import WriteMode
1013

1114
# Add OAuth2 access token here.
1215
# You can generate one for yourself in the App Console.
13-
# See <https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/>
16+
# See
17+
# <https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/>
1418
TOKEN = ''
1519

1620
LOCALFILE = 'my-file.txt'
1721
BACKUPPATH = '/my-file-backup.txt'
1822

1923
# Uploads contents of LOCALFILE to Dropbox
24+
25+
2026
def backup():
2127
with open(LOCALFILE, 'rb') as f:
2228
# We use WriteMode=overwrite to make sure that the settings in the file
2329
# are changed on upload
24-
print("Uploading " + LOCALFILE + " to Dropbox as " + BACKUPPATH + "...")
30+
print(
31+
"Uploading " +
32+
LOCALFILE +
33+
" to Dropbox as " +
34+
BACKUPPATH +
35+
"...")
2536
try:
2637
dbx.files_upload(f.read(), BACKUPPATH, mode=WriteMode('overwrite'))
2738
except ApiError as err:
@@ -37,44 +48,62 @@ def backup():
3748
print(err)
3849
sys.exit()
3950

40-
# Change the text string in LOCALFILE to be new_content
41-
# @param new_content is a string
4251
def change_local_file(new_content):
52+
"""
53+
Change the text string in LOCALFILE to be new_content
54+
Params: new_content:string
55+
Return: None
56+
"""
4357
print("Changing contents of " + LOCALFILE + " on local machine...")
4458
with open(LOCALFILE, 'wb') as f:
4559
f.write(new_content)
4660

47-
# Restore the local and Dropbox files to a certain revision
4861
def restore(rev=None):
49-
# Restore the file on Dropbox to a certain revision
62+
"""
63+
Restore the file on Dropbox to a certain revision
64+
Params: rev:string - revision number
65+
Return: None
66+
"""
5067
print("Restoring " + BACKUPPATH + " to revision " + rev + " on Dropbox...")
5168
dbx.files_restore(BACKUPPATH, rev)
5269

5370
# Download the specific revision of the file at BACKUPPATH to LOCALFILE
54-
print("Downloading current " + BACKUPPATH + " from Dropbox, overwriting " + LOCALFILE + "...")
71+
print(
72+
"Downloading current " +
73+
BACKUPPATH +
74+
" from Dropbox, overwriting " +
75+
LOCALFILE +
76+
"...")
5577
dbx.files_download_to_file(LOCALFILE, BACKUPPATH, rev)
5678

57-
# Look at all of the available revisions on Dropbox, and return the oldest one
5879
def select_revision():
59-
# Get the revisions for a file (and sort by the datetime object, "server_modified")
80+
"""
81+
Get revisions for a file (sort by datetime object "server_modified")
82+
83+
Params: None
84+
Return: Revisions in descending order by date modified
85+
"""
6086
print("Finding available revisions on Dropbox...")
61-
entries = dbx.files_list_revisions(BACKUPPATH, limit=30).entries # pylint: disable=no-member
87+
entries = dbx.files_list_revisions(
88+
BACKUPPATH, limit=30).entries # pylint: disable=no-member
6289
revisions = sorted(entries, key=lambda entry: entry.server_modified)
6390

6491
for revision in revisions:
6592
print(revision.rev, revision.server_modified)
6693

67-
# Return the oldest revision (first entry, because revisions was sorted oldest:newest)
94+
# Return the oldest revision (first entry, because revisions was sorted
95+
# oldest:newest)
6896
return revisions[0].rev
6997

7098
if __name__ == '__main__':
7199
# Check for an access token
72-
if (len(TOKEN) == 0):
100+
if len(TOKEN) == 0:
73101
sys.exit("ERROR: Looks like you didn't add your access token. "
74-
"Open up backup-and-restore-example.py in a text editor and "
75-
"paste in your token in line 14.")
102+
"Open up backup-and-restore-example.py in a text editor and "
103+
"paste in your token in line 14.")
76104

77-
# Create an instance of a Dropbox class, which can make requests to the API.
105+
# Create an instance of a Dropbox class, which can make requests to the
106+
# API.
78107
print("Creating a Dropbox object...")
79108
dbx = dropbox.Dropbox(TOKEN)
80109

@@ -83,7 +112,7 @@ def select_revision():
83112
dbx.users_get_current_account()
84113
except AuthError as err:
85114
sys.exit("ERROR: Invalid access token; try re-generating an "
86-
"access token from the app console on the web.")
115+
"access token from the app console on the web.")
87116

88117
# Create a backup of the current settings file
89118
backup()

ez_setup.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
1414
This file can also be run as a script to install or upgrade setuptools.
1515
"""
16+
import contextlib
17+
import optparse
1618
import os
19+
import platform
1720
import shutil
21+
import subprocess
1822
import sys
1923
import tempfile
20-
import zipfile
21-
import optparse
22-
import subprocess
23-
import platform
2424
import textwrap
25-
import contextlib
26-
25+
import time
26+
import zipfile
2727
from distutils import log
2828

2929
try:
@@ -181,7 +181,7 @@ def has_powershell():
181181
try:
182182
try:
183183
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
184-
except:
184+
except Exception as error:
185185
return False
186186
finally:
187187
devnull.close()
@@ -199,7 +199,7 @@ def has_curl():
199199
try:
200200
try:
201201
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
202-
except:
202+
except Exception as error:
203203
return False
204204
finally:
205205
devnull.close()
@@ -217,7 +217,7 @@ def has_wget():
217217
try:
218218
try:
219219
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
220-
except:
220+
except Exception as error:
221221
return False
222222
finally:
223223
devnull.close()
@@ -284,6 +284,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
284284
if not os.path.exists(saveto): # Avoid repeated downloads
285285
log.warn("Downloading %s", url)
286286
downloader = downloader_factory()
287+
time.sleep(delay)
287288
downloader(url, saveto)
288289
return os.path.realpath(saveto)
289290

0 commit comments

Comments
 (0)