def generate_tracker_token(): """ Generating the token is a simple md5hash of the current time. The token is saved to the `tracker_token_file`. :returns: The token. :rtype: str """ token = hashlib.md5(str(time.time())).hexdigest() ensure_dir(tracker_dir) try: f = open_locked(tracker_token_file, 'w') except IOError as e: logger.error( "Error opening tracker token file (generate) {}".format(e)) else: with f: f.write(token) if 'SUDO_USER' in os.environ: chown_path(tracker_token_file) # Make sure that the events file exist try: f = open(tracker_events_file, 'a') except IOError as e: logger.error("Error opening tracker events file {}".format(e)) else: f.close() if 'SUDO_USER' in os.environ: chown_path(tracker_events_file) return token
def set_chromium_policies(policies): if not os.path.exists(chromium_policy_file): ensure_dir(os.path.dirname(chromium_policy_file)) policy_config = {} else: policy_config = read_json(chromium_policy_file) for policy in policies: policy_config[policy[0]] = policy[1] write_json(chromium_policy_file, policy_config)
def ensure_lightdm_conf(): ''' If the LightDM config file is missing then the undesirable LXDE login screen appears rather than our greeter. Ensure that the file exists and create the correct one if it doesn't ''' if os.path.exists(LIGHTDM_CONF_FILE): return ensure_dir(os.path.dirname(LIGHTDM_CONF_FILE)) shutil.copy(DEFAULT_LIGHTDM_CONF_FILE, LIGHTDM_CONF_FILE) reconfigure_autostart_policy()
def setup_session_fixtures(cls, directory, sessions): from kano.utils.file_operations import ensure_dir from kano_profile.tracker.tracking_session import TrackingSession ensure_dir(directory) for session_f in os.listdir(directory): session_path = os.path.join(directory, session_f) if os.path.isfile(session_path): os.remove(session_path) for session in sessions: session_obj = TrackingSession(name=session['name'], pid=session['pid']) session_path = os.path.join(directory, session_obj.file) with open(session_path, 'w') as session_f: json.dump(session, session_f)
def setup_session_fixtures(cls, directory, sessions): from kano.utils.file_operations import ensure_dir from kano_profile.tracker.tracking_session import TrackingSession ensure_dir(directory) for session_f in os.listdir(directory): session_path = os.path.join(directory, session_f) if os.path.isfile(session_path): os.remove(session_path) for session in sessions: session_obj = TrackingSession( name=session['name'], pid=session['pid'] ) session_path = os.path.join(directory, session_obj.file) with open(session_path, 'w') as session_f: json.dump(session, session_f)
from kano.network import is_internet from kano.utils.audio import play_sound from kano.utils.file_operations import empty_directory, ensure_dir, \ recursively_copy from kano.logging import logger APP_NAME = 'kano-draw' PARENT_PID = None CHALLENGE_DIR = os.path.expanduser('~/Draw-content') WALLPAPER_DIR = os.path.join(CHALLENGE_DIR, 'wallpapers') STATIC_ASSET_DIR = os.path.join(os.path.expanduser('~'), '.make-art-assets') ensure_dir(CHALLENGE_DIR) ensure_dir(WALLPAPER_DIR) ensure_dir(STATIC_ASSET_DIR) def _copy_package_assets(): # Use abs paths for both src and dest for subsequent replacements to work src_dir = os.path.abspath(_get_package_static_dir()) dest_dir = os.path.abspath(STATIC_ASSET_DIR) # First Clear this cache empty_directory(dest_dir) # Now copy the static assets recursively_copy(src_dir, dest_dir)
from kano.logging import logger from kano.utils.user import get_user_unsudoed from kano.utils.file_operations import ensure_dir, read_json, write_json, \ chown_path from kano_settings.common import settings_dir from kano_settings.system.boards import get_board_props USER = None USER_ID = None username = get_user_unsudoed() if username != 'root': if os.path.exists(settings_dir) and os.path.isfile(settings_dir): os.rename(settings_dir, settings_dir + '.bak') ensure_dir(settings_dir) chown_path(settings_dir) settings_file = os.path.join(settings_dir, 'settings') def merge_dicts(base, override): for key, value in override.iteritems(): base[key] = value return base DEFAULT_CONFIG = { 'Keyboard-continent-index': 1, 'Keyboard-country-index': 21, 'Keyboard-variant-index': 0, 'Keyboard-continent-human': "america", 'Keyboard-country-human': _("United States"),
from kano.network import is_internet from kano.utils.audio import play_sound from kano.utils.file_operations import ensure_dir from kano.logging import logger APP_NAME = 'kano-draw' PARENT_PID = None CHALLENGE_DIR = os.path.expanduser('~/Draw-content') WALLPAPER_DIR = os.path.join(CHALLENGE_DIR, 'wallpapers') STATIC_ASSET_DIR = os.path.join(os.path.expanduser('~'), '.make-art-assets') # Create the directories if necessary ensure_dir(CHALLENGE_DIR) ensure_dir(WALLPAPER_DIR) ensure_dir(STATIC_ASSET_DIR) def _get_static_dir(): ''' Returns directory where http server content is located ''' return '/usr/share/kano-draw' def _get_image_from_str(img_str): ''' Returns a base64 encoded data of the img_str image file. ''' import base64