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

PEP8 Standards Fixes #97

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys

import dropbox

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

import dropbox

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
65 changes: 47 additions & 18 deletions example/back-up-and-restore/backup-and-restore-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@
This is an example app for API v2.
"""

from __future__ import print_function

import sys

import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
from dropbox.files import WriteMode

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

LOCALFILE = 'my-file.txt'
BACKUPPATH = '/my-file-backup.txt'

# Uploads contents of LOCALFILE to Dropbox
def backup():
"""
Upload contents of LOCALFILE to Dropbox
"""
with open(LOCALFILE, 'rb') as f:
# We use WriteMode=overwrite to make sure that the settings in the file
# are changed on upload
print("Uploading " + LOCALFILE + " to Dropbox as " + BACKUPPATH + "...")
print(
"Uploading " +
LOCALFILE +
" to Dropbox as " +
BACKUPPATH +
"...")
try:
dbx.files_upload(f.read(), BACKUPPATH, mode=WriteMode('overwrite'))
except ApiError as err:
Expand All @@ -37,44 +48,62 @@ def backup():
print(err)
sys.exit()

# Change the text string in LOCALFILE to be new_content
# @param new_content is a string
def change_local_file(new_content):
"""
Change the text string in LOCALFILE to be new_content
Params: new_content:string
Return: None
"""
print("Changing contents of " + LOCALFILE + " on local machine...")
with open(LOCALFILE, 'wb') as f:
f.write(new_content)

# Restore the local and Dropbox files to a certain revision
def restore(rev=None):
# Restore the file on Dropbox to a certain revision
"""
Restore the file on Dropbox to a certain revision
Params: rev:string - revision number
Return: None
"""
print("Restoring " + BACKUPPATH + " to revision " + rev + " on Dropbox...")
dbx.files_restore(BACKUPPATH, rev)

# Download the specific revision of the file at BACKUPPATH to LOCALFILE
print("Downloading current " + BACKUPPATH + " from Dropbox, overwriting " + LOCALFILE + "...")
print(
"Downloading current " +
BACKUPPATH +
" from Dropbox, overwriting " +
LOCALFILE +
"...")
dbx.files_download_to_file(LOCALFILE, BACKUPPATH, rev)

# Look at all of the available revisions on Dropbox, and return the oldest one
def select_revision():
# Get the revisions for a file (and sort by the datetime object, "server_modified")
"""
Get revisions for a file (sort by datetime object "server_modified")

Params: None
Return: Revisions in descending order by date modified
"""
print("Finding available revisions on Dropbox...")
entries = dbx.files_list_revisions(BACKUPPATH, limit=30).entries # pylint: disable=no-member
entry_revisions = dbx.files_list_revisions(BACKUPPATH, limit=30)
entries = entry_revisions.entries # pylint: disable=no-member
revisions = sorted(entries, key=lambda entry: entry.server_modified)

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

# Return the oldest revision (first entry, because revisions was sorted oldest:newest)
# Return the oldest revision (first entry, because revisions was sorted
# oldest:newest)
return revisions[0].rev

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

# Create an instance of a Dropbox class, which can make requests to the API.
# Create an instance of a Dropbox class, which can make requests to the
# API.
print("Creating a Dropbox object...")
dbx = dropbox.Dropbox(TOKEN)

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

# Create a backup of the current settings file
backup()
Expand Down
19 changes: 10 additions & 9 deletions ez_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

This file can also be run as a script to install or upgrade setuptools.
"""
import contextlib
import optparse
import os
import platform
import shutil
import subprocess
import sys
import tempfile
import zipfile
import optparse
import subprocess
import platform
import textwrap
import contextlib

import time
import zipfile
from distutils import log

try:
Expand Down Expand Up @@ -181,7 +181,7 @@ def has_powershell():
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
except Exception as error:
return False
finally:
devnull.close()
Expand All @@ -199,7 +199,7 @@ def has_curl():
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
except Exception as error:
return False
finally:
devnull.close()
Expand All @@ -217,7 +217,7 @@ def has_wget():
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
except Exception as error:
return False
finally:
devnull.close()
Expand Down Expand Up @@ -284,6 +284,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
if not os.path.exists(saveto): # Avoid repeated downloads
log.warn("Downloading %s", url)
downloader = downloader_factory()
time.sleep(delay)
downloader(url, saveto)
return os.path.realpath(saveto)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pypy3 = lint

[flake8]

ignore = E127,E128,E226,E231,E301,E302,E305,E402,E701,W503
ignore = E127,E128,E226,E231,E301,E302,E305,E402,E701,E1101,W503
max-line-length = 100


Expand Down