Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flying-sheep/8832222 to your computer and use it in GitHub Desktop.
Save flying-sheep/8832222 to your computer and use it in GitHub Desktop.
import os.path
from base64 import b64decode
from PyQt4.QtCore import QDir
HOST_DB = os.path.expanduser('~/.dropbox/host.db')
def get_dropbox_dir():
with open(HOST_DB, 'rb') as hdb:
hdb.readline()
b64_path = hdb.readline()
return b64decode(b64_path).decode('utf-8')
def dropboxify_dir(dir_to_test):
print()
print(dir_to_test.path())
dropbox_root = QDir(get_dropbox_dir())
canonical_root = QDir(dropbox_root.canonicalPath())
relative = canonical_root.relativeFilePath(dir_to_test.canonicalPath())
print(relative)
if relative.startswith('..'):
print('not below Dropbox')
return None
else:
ret = QDir(dropbox_root) #root saved in dropbox settings
ret.cd(relative)
print(ret.path())
return ret
print(get_dropbox_dir())
dropboxify_dir(QDir(os.path.expanduser('~/Dropbox/Public')))
dropboxify_dir(QDir('/opt/Dropbox-Files/Dropbox/Dev'))
dropboxify_dir(QDir('/var/'))
@flying-sheep
Copy link
Author

output:

/opt/Dropbox-Files/Dropbox

/home/phil/Dropbox/Public
Public
/opt/Dropbox-Files/Dropbox/Public

/opt/Dropbox-Files/Dropbox/Dev
Dev
/opt/Dropbox-Files/Dropbox/Dev

/var
../../../var
not below Dropbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment