From 9046a588c7f85a25f94023eab3295512b887e324 Mon Sep 17 00:00:00 2001 From: "J.B. Zimmerman" Date: Sun, 17 Apr 2016 11:24:09 -0400 Subject: [PATCH 1/3] Handle multiple dropbox folders on initial config/backup Switch to using info.json, falling back to host.db --- mackup/utils.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/mackup/utils.py b/mackup/utils.py index e20d33a72..6e842a8c6 100644 --- a/mackup/utils.py +++ b/mackup/utils.py @@ -1,5 +1,6 @@ """System static utilities being used by the modules.""" import base64 +import json import os import platform import shutil @@ -195,18 +196,41 @@ def error(message): def get_dropbox_folder_location(): """ - Try to locate the Dropbox folder. + Try to locate the Dropbox folder. If there are multiple folders, offer the + user the choice. Returns: (str) Full path to the current Dropbox folder """ - host_db_path = os.path.join(os.environ['HOME'], '.dropbox/host.db') + host_info_path = os.path.join(os.environ['HOME'], '.dropbox/info.json') try: - with open(host_db_path, 'r') as f_hostdb: - data = f_hostdb.read().split() + with open(host_info_path, 'r') as f_hostinfo: + data = f_hostinfo.read() + dropbox_home = False except IOError: - error("Unable to find your Dropbox install =(") - dropbox_home = base64.b64decode(data[1]) + try: + host_db_path = os.path.join(os.environ['HOME'], '.dropbox/host.db') + with open(host_db_path, 'r') as f_hostdb: + data = f_hostdb.read().split() + dropbox_home = base64.b64decode(data[1]) + except IOError: + error("Unable to find your Dropbox install =(") + + if not dropbox_home: + json_data = json.loads(data) + accounts = json_data.keys() + + if len(accounts) == 1: + dropbox_home = json_data[accounts[0]]['path'] + else: + print "Multiple Dropbox accounts found!" + for account in accounts: + print account + select = raw_input('Which account would you like to use? ') + if select not in accounts: + error("That's not a valid account.") + else: + dropbox_home = json_data[select]['path'] return dropbox_home From 2fcc3b1703b97b05dd1ff17249ffc608e2dc52f2 Mon Sep 17 00:00:00 2001 From: "J.B. Zimmerman" Date: Sun, 17 Apr 2016 11:29:03 -0400 Subject: [PATCH 2/3] Modded changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 937a8a6c2..68c040ca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Add support for liquidprompt (via @GochoMugo) - Add support for REdshift (via @orschiro) - Add support for ShowyEdge (via @zanderzhng) +- Add support for multiple linked Dropbox folders on initial config (via @jbz) ## Mackup 0.8.11 From 0a7eddc224edd2347ac402a225f36ec0c4e55050 Mon Sep 17 00:00:00 2001 From: "J.B. Zimmerman" Date: Sun, 17 Apr 2016 11:34:51 -0400 Subject: [PATCH 3/3] Made linter happy --- mackup/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mackup/utils.py b/mackup/utils.py index 6e842a8c6..d6aab5311 100644 --- a/mackup/utils.py +++ b/mackup/utils.py @@ -225,7 +225,7 @@ def get_dropbox_folder_location(): else: print "Multiple Dropbox accounts found!" for account in accounts: - print account + print account select = raw_input('Which account would you like to use? ') if select not in accounts: error("That's not a valid account.")