From 96e35c5135e2d104dbb983e2696dd05475309422 Mon Sep 17 00:00:00 2001 From: Nick Dancer Date: Thu, 10 May 2018 19:37:34 +1000 Subject: [PATCH 1/2] Update config parser to have smarter default storage engine Currently parser always defaults to dropbox when no config found. This is useful as it allows you to bootstrap mackup easily but requires a manual restore of .mackup.cfg for any other engine. Have updated parser to select iCloud engine if mackup config found inside iCloud, otherwise dropbox continues to be the default. --- mackup/config.py | 10 +++++++++- tests/config_tests.py | 20 +++++++++++++++++++ .../com~apple~CloudDocs/Mackup/.mackup.cfg | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/default-to-icloud/Library/Mobile Documents/com~apple~CloudDocs/Mackup/.mackup.cfg diff --git a/mackup/config.py b/mackup/config.py index bb6de7c28..6dad4a96e 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -179,7 +179,15 @@ def _parse_engine(self): if self._parser.has_option('storage', 'engine'): engine = str(self._parser.get('storage', 'engine')) else: - engine = ENGINE_DROPBOX + icloud_config_path = os.path.expanduser(os.path.join( + '~/Library/Mobile Documents/com~apple~CloudDocs', + MACKUP_BACKUP_PATH, + MACKUP_CONFIG_FILE)) + + if os.path.exists(icloud_config_path): + engine = ENGINE_ICLOUD + else: + engine = ENGINE_DROPBOX assert isinstance(engine, str) diff --git a/tests/config_tests.py b/tests/config_tests.py index abfbe2594..99a93f39c 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -35,6 +35,26 @@ def test_config_no_config(self): assert cfg.apps_to_ignore == set() assert cfg.apps_to_sync == set() + def test_config_icloud_config_present(self): + realpath = os.path.dirname(os.path.realpath(__file__)) + os.environ['HOME'] = os.path.join(realpath, 'fixtures/default-to-icloud') + + cfg = Config() + + # Should should do the same as the a standard iCloud configuration + assert isinstance(cfg.engine, str) + assert cfg.engine == ENGINE_ICLOUD + + assert isinstance(cfg.path, str) + assert cfg.path == os.path.expanduser( + '~/Library/Mobile Documents/com~apple~CloudDocs/') + + assert isinstance(cfg.directory, str) + assert cfg.directory == u'Mackup' + + assert isinstance(cfg.fullpath, str) + assert cfg.fullpath.endswith(u'/com~apple~CloudDocs/Mackup') + def test_config_empty(self): cfg = Config('mackup-empty.cfg') diff --git a/tests/fixtures/default-to-icloud/Library/Mobile Documents/com~apple~CloudDocs/Mackup/.mackup.cfg b/tests/fixtures/default-to-icloud/Library/Mobile Documents/com~apple~CloudDocs/Mackup/.mackup.cfg new file mode 100644 index 000000000..0627976ba --- /dev/null +++ b/tests/fixtures/default-to-icloud/Library/Mobile Documents/com~apple~CloudDocs/Mackup/.mackup.cfg @@ -0,0 +1,2 @@ +[storage] +engine = icloud From 8ac2708e7ee7775f09c908b2497933f0d052ff8b Mon Sep 17 00:00:00 2001 From: Nick Dancer Date: Mon, 14 May 2018 20:18:52 +1000 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 122c2af38..3b75926a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Support for RubyMine 2018.01 (via @kibitan) - Support for IntelliJ Idea 2017.1, 2017.2, 2017.3, and 2018.1 (via @cool00geek) - Remove references to OpenSSH private key syncing - removed in dcb26ba (via @njdancer) +- Add logic to detect mackup config in iCloud (via @njdancer) ## Mackup 0.8.18