Permalink
Browse files

more comment improvements

  • Loading branch information...
lavelle committed Feb 10, 2013
1 parent 98497f5 commit 9d1367f23e4c35ffad0dfbf0345bb4e7fe7d0077
Showing with 44 additions and 46 deletions.
  1. +7 −8 clipboard.py
  2. +22 −29 dbox.py
  3. +5 −5 main.py
  4. +8 −2 message.py
  5. +2 −2 settings.py
View
@@ -12,16 +12,15 @@ def get(self):
'Are you sure that you currently have only plain text copied?'
return None
- def set(self, link):
+ def set(self, text):
"""
Set the contents of the user's clipboard to a string
- Arguments:
- - link: the url of the uploaded file to set the clipboard to
+ text - The text to be copied to the clipboard
"""
- r = Tk()
- r.withdraw()
- r.clipboard_clear()
- r.clipboard_append(link)
- r.destroy()
+ t = Tk()
+ t.withdraw()
+ t.clipboard_clear()
+ t.clipboard_append(text)
+ t.destroy()
View
51 dbox.py
@@ -11,7 +11,7 @@
class Dropbox:
"""Methods for interacting with the Dropbox API"""
- # we only need access to one folder in the user's Dropbox, not the entire thing.
+ # Access is only needed to one folder in the user's Dropbox
ACCESS_TYPE = 'app_folder'
def __init__(self, in_user_mode=True):
@@ -21,45 +21,41 @@ def __init__(self, in_user_mode=True):
session = DropboxSession(API_KEY, API_SECRET, self.ACCESS_TYPE)
- # if there is a token saved, that can be used to connect with dropbox
+ # If there is a token saved, that can be used to connect with Dropbox
if os.path.exists(TOKEN_PATH):
- # read the token and authenticate the session with it
+ # Read the token and authenticate the session with it
token = json.load(open(TOKEN_PATH))
session.set_token(token['key'], token['secret'])
- # otherwise we need to authenticate for the first time
+ # Otherwise it is necessary to authenticate for the first time
else:
- # request an access token
+ # Request an access token
request_token = session.obtain_request_token()
url = session.build_authorize_url(request_token)
- # open the auth page in the user's browser and wait for them to accept
+ # Open the authentication page in the user's browser and wait for them to accept
webbrowser.open(url, new=2)
print "Press enter once you have authorised the app in your browser"
raw_input()
- # get a new access token from the authenticated session
+ # Get a new access token from the authenticated session
# This will fail if the user didn't visit the above URL and press 'Allow'
try:
access_token = session.obtain_access_token(request_token)
- # except RESTSocketError:
- # if RESTSocketError.ERRNO == 10061:
- # print "Could not connect to the Dropbox servers \
- # because your network's proxy blocked it."
+
except Exception as error:
if DEBUG:
print error
print "You didn't authorise the app, or something else went wrong"
- print "Either way we can't continue"
- return
+ exit(1)
- # save the access token to a file so that next time we don't have to authenticate
+ # Save the access token to a file so that authentication is not needed next time the app is run
f = open(TOKEN_PATH, 'w+')
f.write(json.dumps({'key': access_token.key, 'secret': access_token.secret}))
f.close()
- # create a client from the finished session
+ # Create a Dropbox client from the session
client = DropboxClient(session)
self.client = client
@@ -68,9 +64,8 @@ def upload(self, path, filepath=None):
"""
Upload a file to the Dropbox servers
- Arguments:
- - path: The path to the local copy of the file to be uploaded
- - filepath: The path, including the filename given to the remote copy of the file
+ path - The path to the local copy of the file to be uploaded
+ filepath - The path, including the filename given to the remote copy of the file
once it is uploaded to Dropbox. If omitted it defaults to be the same as path
"""
@@ -87,10 +82,11 @@ def upload(self, path, filepath=None):
# Open the file located at path and upload it to the Dropbox servers
response = self.client.put_file(filepath, open(path, 'rb'))
self.m.message('Upload finished')
+
except Exception as error:
- self.m.message('Upload failed')
+ self.m.message('Upload failed', 2)
if DEBUG:
- print error
+ self.m.message(error, 2)
return
if DEBUG:
@@ -101,8 +97,7 @@ def upload_folder(self, folder):
"""
Upload a folder to the Dropbox servers
- Arguments:
- - folder: A string representing the path to the folder to be uploaded
+ folder - A string representing the path to the folder to be uploaded
"""
# Create a folder in the user's Dropbox with the same name as the local folder
@@ -121,22 +116,20 @@ def upload_folder(self, folder):
def get_link(self, filename):
"""
- Get the URL of the copy of a file or folder hosted on Dropbox
+ Get the URL of the Dropbox-hosted copy of a file or folder
- Arguments:
- - filename: The path to the file or folder within the user's Dropbox to get the URL of
+ filename - The path to the file or folder within the user's Dropbox
- Returns: A string containing the URL, in the format http://db.tt/xxxxxxxx
+ Returns the URL as a string in the format http://db.tt/xxxxxxxx
"""
return self.client.share(filename)['url']
def create_folder(self, folder_name, num=1):
"""
Create a folder in the user's Dropbox
- Arguments:
- - folder_name: The name of the folder to create
- - num: The number to append to the folder name if a folder with the specified name already exists
+ folder_name - The name of the folder to create
+ num - The number to append to the folder name if a folder with the specified name already exists
"""
new_folder_name = folder_name
View
10 main.py
@@ -22,10 +22,10 @@ def _save_record(self):
"""
Save the details of an uploaded file to the history file and send the link to its destination
- Arguments:
- - link: The link to the uploaded file
- - paths: An array of paths to all the files and folders that were uploaded
- - share_to: A string representing the destination of the link - clipboard, social network or stdout
+ link - The link to the uploaded file
+ paths - An array of paths to all the files and folders that were uploaded
+ share_to - A string describing the intended destination of the link -
+ either the clipboard, a social network or stdout
"""
if not self.link:
@@ -146,7 +146,7 @@ def screenshot(args):
screenshot.capture()
- c.handle_files([screenshot.path], [filename], args.share)
+ c.handle_files([screenshot.path], [screenshot.filename], args.share)
def upload(args):
View
@@ -1,8 +1,11 @@
+import sys
+
+
class Message:
def __init__(self, in_user_mode=True):
self.in_user_mode = in_user_mode
- def message(self, text):
+ def message(self, text, type=1):
"""
Display some text intended for a human to read
@@ -15,4 +18,7 @@ def message(self, text):
"""
if self.in_user_mode:
- print text
+ if type == 1:
+ print text
+ elif type == 2:
+ sys.stderr.write(text + '\n')
View
@@ -12,7 +12,7 @@
elif PLATFORM == 'Windows':
APP_PATH = os.path.join(os.environ['APPDATA'], APP_NAME)
elif PLATFORM == 'Linux':
- APP_PATH = os.path.expanduser(os.path.join("~", "." + APP_NAME))
+ APP_PATH = os.path.expanduser(os.path.join('~', '.' + APP_NAME))
# Directory for storing screenshots
SCREENSHOT_PATH = os.path.join(APP_PATH, 'img')
@@ -31,7 +31,7 @@
API_SECRET = "toe9kimrkhd4bx7"
# Services to send the link to the hosted file to
-SHARING_SERVICES = 'clipboard facebook twitter email stdout'.split(' ')
+SHARING_SERVICES = ['clipboard', 'facebook', 'twitter', 'email', 'stdout']
# Default message when shared to a social network
SHARE_MESSAGE = 'I just uploaded a file to ClipCloud - check it out.'

0 comments on commit 9d1367f

Please sign in to comment.