# Path: ice/backups.py
# def default_backups_directory():
# def backup_filename(user, timestamp_format):
# def shortcuts_backup_path(directory, user, timestamp_format="%Y%m%d%H%M%S"):
# def backup_directory(config):
# def create_backup_of_shortcuts(config, user, dry_run=False):
#   def _create_directory_if_needed(directory):
# 
# Path: ice/configuration.py
# def get(store, option):
# def get_directory(store, option):
# def from_store(store):
# 
# Path: ice/consoles.py
# def console_roms_directory(configuration, console):
# def path_is_rom(console, path):
# 
# Path: ice/emulators.py
# def emulator_rom_launch_command(emulator, rom):
# def emulator_startdir(emulator):
# 
# Path: ice/paths.py
# def application_data_directory():
# def data_file_path(filename):
# def archive_path():
# def log_file_location():
# def default_roms_directory():
# 
# Path: ice/settings.py
# def find_settings_file(name, filesystem):
# def settings_file_path(name, filesystem, override = None):
# def load_configuration(filesystem, override = None):
# def load_emulators(filesystem, override = None):
# def load_consoles(emulators, filesystem, override = None):
# def load_app_settings(filesystem, file_overrides = {}):
# def image_provider(config):
# 
# Path: ice/logs.py
# STREAM_STRING_FORMAT = '%(leveltag)s%(message)s'
# FILE_STRING_FORMAT = '%(asctime)s [%(levelname)s][%(filename)s][%(funcName)s:%(lineno)s]: %(message)s'
# def is_test_stack_frame(frame):
# def is_running_in_test():
#   def _tag_for_level(self, levelno):
#   def filter(self, record):
# def create_stream_handler(level):
# def create_file_handler(level):
# def create_logger():
# class IceLevelTagFilter(logging.Formatter):
# 
# Path: ice/persistence/config_file_backing_store.py
# class ConfigFileBackingStore(backing_store.BackingStore):
# 
#   def __init__(self, path):
#     super(ConfigFileBackingStore, self).__init__(path)
#     self.configParser = ConfigParser.RawConfigParser()
#     self.configParser.read(self.path)
# 
#   def identifiers(self):
#     return self.configParser.sections()
# 
#   def add_identifier(self, ident):
#     try:
#       self.configParser.add_section(ident)
#     except ConfigParser.DuplicateSectionError:
#       raise ValueError("The identifier `%s` already exists" % str(ident))
# 
#   def remove_identifier(self, ident):
#     self.configParser.remove_section(ident)
# 
#   def keys(self, ident):
#     try:
#       return self.configParser.options(ident)
#     except ConfigParser.NoSectionError:
#       raise ValueError("No identifier named `%s` exists" % str(ident))
# 
#   def get(self, ident, key, default=None):
#     try:
#       val = self.configParser.get(ident, key.lower())
#       return val
#     except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
#       return default
# 
#   def set(self, ident, key, value):
#     self.configParser.set(ident, key.lower(), value)
# 
#   def save(self):
#     try:
#       with open(self.path, "w") as configFile:
#         self.configParser.write(configFile)
#     except IOError:
#       raise IOError("Cannot save data to `%s`. Permission Denied")


import os
from pysteam import paths as steam_paths
from pysteam import shortcuts
from pysteam import steam as steam_module
from ice import backups
from ice import configuration
from ice import consoles
from ice import emulators
from ice import paths
from ice import settings
from ice.logs import logger
from ice.persistence.config_file_backing_store import ConfigFileBackingStore
# encoding: utf-8




class TaskEngine(object):

  def __init__(self, steam):
    self.steam = steam

    logger.debug("Initializing Ice")
    # We want to ignore the anonymous context, cause theres no reason to sync
    # ROMs for it since you cant log in as said user.
    is_user_context = lambda context: context.user_id != 'anonymous'
    self.users = filter(is_user_context, steam_module.local_user_contexts(self.steam))

  def run(self, tasks, app_settings, dry_run=False):
    if self.steam is None:
      logger.error("Cannot run Ice because Steam doesn't appear to be installed")
      return


# Path: ice/backups.py
# def default_backups_directory():
# def backup_filename(user, timestamp_format):
# def shortcuts_backup_path(directory, user, timestamp_format="%Y%m%d%H%M%S"):
# def backup_directory(config):
# def create_backup_of_shortcuts(config, user, dry_run=False):
#   def _create_directory_if_needed(directory):
# 
# Path: ice/configuration.py
# def get(store, option):
# def get_directory(store, option):
# def from_store(store):
# 
# Path: ice/consoles.py
# def console_roms_directory(configuration, console):
# def path_is_rom(console, path):
# 
# Path: ice/emulators.py
# def emulator_rom_launch_command(emulator, rom):
# def emulator_startdir(emulator):
# 
# Path: ice/paths.py
# def application_data_directory():
# def data_file_path(filename):
# def archive_path():
# def log_file_location():
# def default_roms_directory():
# 
# Path: ice/settings.py
# def find_settings_file(name, filesystem):
# def settings_file_path(name, filesystem, override = None):
# def load_configuration(filesystem, override = None):
# def load_emulators(filesystem, override = None):
# def load_consoles(emulators, filesystem, override = None):
# def load_app_settings(filesystem, file_overrides = {}):
# def image_provider(config):
# 
# Path: ice/logs.py
# STREAM_STRING_FORMAT = '%(leveltag)s%(message)s'
# FILE_STRING_FORMAT = '%(asctime)s [%(levelname)s][%(filename)s][%(funcName)s:%(lineno)s]: %(message)s'
# def is_test_stack_frame(frame):
# def is_running_in_test():
#   def _tag_for_level(self, levelno):
#   def filter(self, record):
# def create_stream_handler(level):
# def create_file_handler(level):
# def create_logger():
# class IceLevelTagFilter(logging.Formatter):
# 
# Path: ice/persistence/config_file_backing_store.py
# class ConfigFileBackingStore(backing_store.BackingStore):
# 
#   def __init__(self, path):
#     super(ConfigFileBackingStore, self).__init__(path)
#     self.configParser = ConfigParser.RawConfigParser()
#     self.configParser.read(self.path)
# 
#   def identifiers(self):
#     return self.configParser.sections()
# 
#   def add_identifier(self, ident):
#     try:
#       self.configParser.add_section(ident)
#     except ConfigParser.DuplicateSectionError:
#       raise ValueError("The identifier `%s` already exists" % str(ident))
# 
#   def remove_identifier(self, ident):
#     self.configParser.remove_section(ident)
# 
#   def keys(self, ident):
#     try:
#       return self.configParser.options(ident)
#     except ConfigParser.NoSectionError:
#       raise ValueError("No identifier named `%s` exists" % str(ident))
# 
#   def get(self, ident, key, default=None):
#     try:
#       val = self.configParser.get(ident, key.lower())
#       return val
#     except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
#       return default
# 
#   def set(self, ident, key, value):
#     self.configParser.set(ident, key.lower(), value)
# 
#   def save(self):
#     try:
#       with open(self.path, "w") as configFile:
#         self.configParser.write(configFile)
#     except IOError:
#       raise IOError("Cannot save data to `%s`. Permission Denied")


# Path: ice/tasks/engine.py
import os
from pysteam import paths as steam_paths
from pysteam import shortcuts
from pysteam import steam as steam_module
from ice import backups
from ice import configuration
from ice import consoles
from ice import emulators
from ice import paths
from ice import settings
from ice.logs import logger
from ice.persistence.config_file_backing_store import ConfigFileBackingStore

# encoding: utf-8




class TaskEngine(object):

  def __init__(self, steam):
    self.steam = steam

    logger.debug("Initializing Ice")
    # We want to ignore the anonymous context, cause theres no reason to sync
    # ROMs for it since you cant log in as said user.
    is_user_context = lambda context: context.user_id != 'anonymous'
    self.users = filter(is_user_context, steam_module.local_user_contexts(self.steam))

  def run(self, tasks, app_settings, dry_run=False):
    if self.steam is None:
      logger.error("Cannot run Ice because Steam doesn't appear to be installed")
      return


    logger.info("=========== Starting Ice ===========")