Skip to content

Instantly share code, notes, and snippets.

@flying-sheep

flying-sheep/testdir.py

Last active Aug 29, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@flying-sheep flying-sheep commented Feb 5, 2014

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