# Path: kano_profile/paths.py
# TRACKER_UUIDS_PATH = os.path.join(kanoprofile_dir, 'tracker', 'uuids')
# PAUSED_SESSIONS_FILE = os.path.join(kanoprofile_dir, '.paused_sessions')
# 
# Path: kano_profile/tracker/tracking_utils.py
# class open_locked(file):
#     """ A version of open with an exclusive lock to be used within
#         controlled execution statements.
#     """
#     def __init__(self, *args, **kwargs):
#         super(open_locked, self).__init__(*args, **kwargs)
#         fcntl.flock(self, fcntl.LOCK_EX)


import os
import time
import hashlib
from kano.utils.file_operations import ensure_dir, chown_path
from kano.logging import logger
from kano_profile.paths import tracker_dir, tracker_token_file, \
    tracker_events_file
from kano_profile.tracker.tracking_utils import open_locked
#
# tracker_token.py
#
# Copyright (C) 2014 - 2017 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Tracking token manipulation
#





def load_token():
    """
        Reads the tracker token from the token file. If the file doesn't
        exists, it regenerates it.

        The token is regenerated on each boot and is inserted into every
        event to link together events that happened during the same start
        of the OS.

        :returns: The token.
        :rtype: str
    """


# Path: kano_profile/paths.py
# TRACKER_UUIDS_PATH = os.path.join(kanoprofile_dir, 'tracker', 'uuids')
# PAUSED_SESSIONS_FILE = os.path.join(kanoprofile_dir, '.paused_sessions')
# 
# Path: kano_profile/tracker/tracking_utils.py
# class open_locked(file):
#     """ A version of open with an exclusive lock to be used within
#         controlled execution statements.
#     """
#     def __init__(self, *args, **kwargs):
#         super(open_locked, self).__init__(*args, **kwargs)
#         fcntl.flock(self, fcntl.LOCK_EX)


# Path: kano_profile/tracker/tracker_token.py
import os
import time
import hashlib
from kano.utils.file_operations import ensure_dir, chown_path
from kano.logging import logger
from kano_profile.paths import tracker_dir, tracker_token_file, \
    tracker_events_file
from kano_profile.tracker.tracking_utils import open_locked

#
# tracker_token.py
#
# Copyright (C) 2014 - 2017 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Tracking token manipulation
#





def load_token():
    """
        Reads the tracker token from the token file. If the file doesn't
        exists, it regenerates it.

        The token is regenerated on each boot and is inserted into every
        event to link together events that happened during the same start
        of the OS.

        :returns: The token.
        :rtype: str
    """


    if os.path.exists(tracker_token_file):