def get_mysql_credentials(cfg_file):
try:<EOL><INDENT>parser = ConfigParser.ConfigParser()<EOL>cfg_fp = open(cfg_file)<EOL>parser.readfp(cfg_fp)<EOL>cfg_fp.close()<EOL><DEDENT>except ConfigParser.NoOptionError:<EOL><INDENT>cfg_fp.close()<EOL>print('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>except IOError:<EOL><INDENT>print('<STR_LIT>', cfg_file)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>value = parser.get('<STR_LIT>', '<STR_LIT>')<EOL>try:<EOL><INDENT>sobj = re.search(r"<STR_LIT>", value)<EOL>indices = [sobj.start(<NUM_LIT:1>), sobj.start(<NUM_LIT:2>), sobj.start(<NUM_LIT:3>), sobj.start(<NUM_LIT:4>)]<EOL>cred = value[indices[<NUM_LIT:0>] + <NUM_LIT:3>:indices[<NUM_LIT:1>]].split('<STR_LIT::>')<EOL>host = value[indices[<NUM_LIT:1>] + <NUM_LIT:1>:indices[<NUM_LIT:2>]]<EOL>db_name = value[indices[<NUM_LIT:2>] + <NUM_LIT:1>:indices[<NUM_LIT:3>]]<EOL>charset = value[indices[<NUM_LIT:3>] + <NUM_LIT:1>:].split('<STR_LIT:=>')[<NUM_LIT:1>]<EOL>return cred[<NUM_LIT:0>], cred[<NUM_LIT:1>], host, db_name, charset<EOL><DEDENT>except (ValueError, IndexError, AttributeError):<EOL><INDENT>print('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>
Get the credentials and database name from options in config file.