@classmethod<EOL><INDENT>@contextmanager<EOL>def acquire_lock(cls, mode, user=None):<DEDENT>
if not user:<EOL><INDENT>return<EOL><DEDENT>with EteSyncCache.lock:<EOL><INDENT>cls.user = user<EOL>cls.etesync = cls._get_etesync_for_user(cls.user)<EOL>if cls._should_sync():<EOL><INDENT>cls._mark_sync()<EOL>cls.etesync.get_or_create_user_info(force_fetch=True)<EOL>cls.etesync.sync_journal_list()<EOL>for journal in cls.etesync.list():<EOL><INDENT>cls.etesync.pull_journal(journal.uid)<EOL><DEDENT><DEDENT>yield<EOL>if cls.etesync.journal_list_is_dirty():<EOL><INDENT>cls.etesync.sync_journal_list()<EOL><DEDENT>for journal in cls.etesync.list():<EOL><INDENT>if cls.etesync.journal_is_dirty(journal.uid):<EOL><INDENT>cls.etesync.sync_journal(journal.uid)<EOL><DEDENT><DEDENT>cls.etesync = None<EOL>cls.user = None<EOL><DEDENT>
Set a context manager to lock the whole storage.

        ``mode`` must either be "r" for shared access or "w" for exclusive
        access.

        ``user`` is the name of the logged in user or empty.