# -*- coding: utf-8 -*-
import atexit
import fcntl, os, sys
import logging.config
from ConfigParser import ConfigParser

from openprocurement.complaints.queue.mysql import ComplaintsToMySQL

default_config = {
    'pidfile': None,
    'daemonize': None,
}


def daemonize(filename=False):
    if not filename:
        return

    if os.fork() > 0:
        sys.exit(0)

    os.chdir("/")
    os.setsid()

    if os.fork() > 0:
        sys.exit(0)

    fout = file(filename, 'a+')
    ferr = file(filename, 'a+', 0)
    sys.stdin.close(), os.close(0)
    os.dup2(fout.fileno(), 1)
    os.dup2(ferr.fileno(), 2)


def delpid(lock_file, filename):
    lock_file.close()
    os.remove(filename)


def pidfile(filename):
    if not filename:
        return
    # try get exclusive lock to prevent second start
    lock_file = open(filename, "w")
    fcntl.lockf(lock_file, fcntl.LOCK_EX+fcntl.LOCK_NB)
    lock_file.write(str(os.getpid())+"\n")
    lock_file.flush()
    atexit.register(delpid, lock_file, filename)
    return lock_file


def main():
    if len(sys.argv) < 2:
        print("Usage: complaints_queue config.ini")
        sys.exit(1)

    logging.config.fileConfig(sys.argv[1])

    parser = ConfigParser(defaults=default_config)
    parser.read(sys.argv[1])

    daemonize(parser.get('general', 'daemonize'))
    pidfile(parser.get('general', 'pidfile'))

    client_config = parser.items('client')
    mysql_config = parser.items('mysql')

    app = ComplaintsToMySQL(client_config, mysql_config)
    app.run()


if __name__ == "__main__":
    main()

@@ -188,74 +188,8 @@
 QL%0A%0A
-default_config = %7B%0A    'pidfile': None,%0A    'daemonize': None,%0A%7D%0A%0A
 %0Adef
@@ -960,16 +960,261 @@
 _file%0A%0A%0A
+class MyConfigParser(ConfigParser):%0A    def get(self, section, option, default=None):%0A        try:%0A            value = ConfigParser.get(self, section, option)%0A        except ConfigParser.Error:%0A            value = default%0A        return value%0A%0A%0A
 def main
@@ -1373,16 +1373,18 @@
 arser = 
+My
 ConfigPa
@@ -1392,31 +1392,8 @@
 ser(
-defaults=default_config
 )%0A  

fix ConfigParser