# 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
import shutil
import stat
import tempfile
import unittest
from ice.persistence.config_file_backing_store import ConfigFileBackingStore
    #   },
    #   ...
    # }
    #
    # Will produce an output like this
    # [Section Name]
    # key=value
    # key=value
    #
    # [Section Name 2]
    # key2=value
    # key2=value
    f = open(path, "w")
    for section_name in sections_dict.keys():
      f.write("[%s]\n" % section_name)
      keyvalues = sections_dict[section_name]
      for key in keyvalues.keys():
        value = keyvalues[key]
        f.write("%s=%s\n" % (key, value))
      f.write("\n")
    f.close()

  def file_contents(self, path):
    f = open(path, "r")
    contents = f.read()
    f.close()
    return contents

  def test_empty_file(self):
    self.create_config_file(self.tempfile, {})

# 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: tests/config_file_backing_store_tests.py
import os
import shutil
import stat
import tempfile
import unittest
from ice.persistence.config_file_backing_store import ConfigFileBackingStore

    #   },
    #   ...
    # }
    #
    # Will produce an output like this
    # [Section Name]
    # key=value
    # key=value
    #
    # [Section Name 2]
    # key2=value
    # key2=value
    f = open(path, "w")
    for section_name in sections_dict.keys():
      f.write("[%s]\n" % section_name)
      keyvalues = sections_dict[section_name]
      for key in keyvalues.keys():
        value = keyvalues[key]
        f.write("%s=%s\n" % (key, value))
      f.write("\n")
    f.close()

  def file_contents(self, path):
    f = open(path, "r")
    contents = f.read()
    f.close()
    return contents

  def test_empty_file(self):
    self.create_config_file(self.tempfile, {})

    cfbs = ConfigFileBackingStore(self.tempfile)