Skip to content

Commit

Permalink
Remove unused variable. PEP8, Catch pyperclip exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarizza committed May 23, 2018
1 parent ef724d9 commit 6277328
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Drosh
Script to upload Shutter screenshots to Dropbox and show a notification with the shared link created.
Use your favourite screenshot tool and let Drosh script upload it to Dropbox and create a shared link


![Example](https://www.dropbox.com/s/2vz4xuksyoaqu4a/screencast.gif?dl=0&raw=true)

Expand Down Expand Up @@ -50,3 +51,19 @@ stderr_logfile=/var/log/drosh-stderr.log
stdout_logfile=/var/log/drosh-std.log
environment=DROSH_DROPBOX_TOKEN='<your-dropbox-token>',DROSH_DROPBOX_FOLDER='<your-dropbox-screehshots-folder>',DROSH_SCREENSHOT_FOLDER='<your-system-screenshot-folder>',USER=<your-username>,HOME=<your-home-folder>,LOGNAME=<your-username>,DISPLAY=":0.0"
```


# Contributors
- [zamoroka](https://github.com/zamoroka)


### Troubleshooting

## The notification does not appear on my desktop
There is some problem with the env var `DISPLAY` or check the permision of your supervisorfile. You can see the discussion on this thread https://github.com/jcarizza/drosh/issues/3


## Pyperclip could not find a copy/paste mechanism for your system

Maybe you need some extra requirements, Pyperclip uses gtk or PyQt4 to access the paper clim. https://github.com/asweigart/pyperclip/blob/master/docs/introduction.rst

37 changes: 20 additions & 17 deletions src/drosh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

class Screenshot(object):
def __init__(self, path):
fileOnDropbox = self.upload_file(path)
url = self.create_shared_link(fileOnDropbox)
file_on_dropbox = self.upload_file(path)
url = self.create_shared_link(file_on_dropbox)
if url is None:
self.notify('Drosh', 'Error al crear link compartido')
self.notify('Drosh', 'Error in create shared link')
else:
self.notify('Drosh', url)


def notify(self, title, body):
"""
Expand All @@ -48,16 +48,16 @@ def upload_file(self, path):
"""

dbox = Drosh()
pathLocal = os.path.join(DROSH_SCREENSHOT_FOLDER, os.path.basename(path.decode('utf8')))
pathRemote = os.path.join(DROSH_DROPBOX_FOLDER, os.path.basename(path.decode('utf8')))
result = dbox.files_upload(pathLocal, pathRemote)
path_local = os.path.join(DROSH_SCREENSHOT_FOLDER, os.path.basename(path.decode('utf8')))
path_remote = os.path.join(DROSH_DROPBOX_FOLDER, os.path.basename(path.decode('utf8')))
result = dbox.files_upload(path_local, path_remote)

if result is not None:
logger.debug('File %r uploaded successfully', result.path_display)

return result.path_display
else:
logger.debug('Error in upload %r file', pathRemote)
logger.debug('Error in upload %r file', path_remote)

def create_shared_link(self, path):
"""
Expand All @@ -69,15 +69,18 @@ def create_shared_link(self, path):
result = dbox.create_shared_link(path)
if result is not None:
logger.debug('Shared link created %r for %r file', result.url, path)
pyperclip.copy(result.url)
try:
pyperclip.copy(result.url)
except pyperclip.PyperclipException:
pass
return result.url
else:
logger.debug('Error in create shared link for %r file', path)


class Drosh(object):

def __init__(self, folder=DROSH_DROPBOX_FOLDER):
def __init__(self):
self.client = dropbox.dropbox.Dropbox(DROSH_DROPBOX_TOKEN, timeout=30.0)

def get_file_size(self, filename):
Expand All @@ -91,24 +94,24 @@ def get_local_file(self, filename, i):
if (i > 6):
return -1

fileSize = self.get_file_size(filename)
file_size = self.get_file_size(filename)

if (fileSize > 0):
if (file_size > 0):
return open(filename, 'rb')
else:
time.sleep(1) # sometimes file is empty when we try to upload it
i = i+1
return self.get_local_file(filename, i)

def files_upload(self, pathLocal, pathRemote):
fileLocal = self.get_local_file(pathLocal, 0)
logger.debug("Uploading %s to Dropbox as %s", pathLocal, pathRemote)
def files_upload(self, path_local, path_remote):
file_local = self.get_local_file(path_local, 0)
logger.debug("Uploading %s to Dropbox as %s", path_local, path_remote)

# We use WriteMode=overwrite to make sure that the settings in the file are changed on upload
try:
success = self.client.files_upload(
fileLocal.read(),
pathRemote,
file_local.read(),
path_remote,
mode=WriteMode('overwrite'),
autorename=True
)
Expand Down

0 comments on commit 6277328

Please sign in to comment.