diff --git a/docs/conf.py b/docs/conf.py index 9fd4a906..30df932d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/example/back-up-and-restore/backup-and-restore-example.py b/example/back-up-and-restore/backup-and-restore-example.py index a85646f8..8dc646aa 100644 --- a/example/back-up-and-restore/backup-and-restore-example.py +++ b/example/back-up-and-restore/backup-and-restore-example.py @@ -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 +# See +# 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: @@ -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) @@ -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() diff --git a/ez_setup.py b/ez_setup.py index 1f668e5b..8b485fdc 100644 --- a/ez_setup.py +++ b/ez_setup.py @@ -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: @@ -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() @@ -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() @@ -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() @@ -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) diff --git a/tox.ini b/tox.ini index da1574ed..5e1c1e45 100644 --- a/tox.ini +++ b/tox.ini @@ -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