old_contents: # coding: utf-8
  
  # This file is part of Supysonic.
  #
  # Supysonic is a Python implementation of the Subsonic server API.
  # Copyright (C) 2013  Alban 'spl0k' Féron
  #
  # This program is free software: you can redistribute it and/or modify
  # it under the terms of the GNU Affero General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU Affero General Public License for more details.
  #
  # You should have received a copy of the GNU Affero General Public License
  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
  import os, sys, tempfile, ConfigParser
  
  config = ConfigParser.RawConfigParser({ 'cache_dir': os.path.join(tempfile.gettempdir(), 'supysonic') })
  
  def check():
  	try:
  		ret = config.read([ '/etc/supysonic', os.path.expanduser('~/.supysonic') ])
  	except (ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError), e:
  		print >>sys.stderr, "Error while parsing the configuration file(s):\n%s" % str(e)
  		return False
  
  	if not ret:
  		print >>sys.stderr, "No configuration file found"
  		return False
  
  	try:
  		config.get('base', 'database_uri')
  	except:
  		print >>sys.stderr, "No database URI set"
  		return False
  
  	return True
  
  def get(section, name):
  	try:
  		return config.get(section, name)
  	except:
  		return None
  
  
new_contents: # -*- coding: utf-8 -*-
  # vim:fenc=utf-8
  #
  # This file is part of Supysonic.
  # Supysonic is a Python implementation of the Subsonic server API.
  #
  # Copyright (C) 2013-2017 Alban 'spl0k' Féron
  #                    2017 Óscar García Amor
  #
  # Distributed under terms of the GNU AGPLv3 license.
  
  from ConfigParser import ConfigParser, NoOptionError, NoSectionError
  
  import mimetypes
  import os
  import tempfile
  
  class Config(object):
      """
      Config object to work with config file
      """
      def __init__(self):
          # Seek for standard locations
          config_file = [
                  'supysonic.conf',
                  os.path.expanduser('~/.config/supysonic/supysonic.conf'),
                  os.path.expanduser('~/.supysonic'),
                  '/etc/supysonic'
                  ]
          self.config = ConfigParser({ 'cache_dir': os.path.join(tempfile.gettempdir(), 'supysonic') })
          # Try read config file or raise error
          try:
              self.config.read(config_file)
          except Exception as e:
              err = 'Config file is corrupted.\n{0}'.format(e)
              raise SystemExit(err)
  
      def check(self):
          """
          Checks the config for mandatory fields
          """
          try:
              self.config.get('base', 'database_uri')
          except (NoSectionError, NoOptionError):
              raise SystemExit('No database URI set')
  
      def get(self, section, option):
          """
          Returns a config option value from config file
  
          :param section: section where the option is stored
          :param option: option name
          :return: a config option value
          :rtype: string
          """
          try:
              return self.config.get(section, option)
          except (NoSectionError, NoOptionError):
              return None
  
      def get_mime(self, extension):
          """
          Returns mimetype of an extension based on config file
  
          :param extension: extension string
          :return: mimetype
          :rtype: string
          """
          guessed_mime = mimetypes.guess_type('dummy.' + extension, False)[0]
          config_mime = self.get('mimetypes', extension)
          default_mime = 'application/octet-stream'
          return guessed_mime or config_mime or default_mime
  
subject: Rewrite config.py to make project more clean