Last active
August 29, 2015 13:56
-
-
Save flying-sheep/8832222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output: