def convert(game):
    global compiler_output, missing_functions, no_of_missing_functions
    startingDir = os.getcwd()  # save our current directory

    enigmaDir = EnigmaSettings.getEnigmaDir()
    os.chdir(enigmaDir)  # change to the enigma directory

    print "INFO: The game to give to engima: " + game
    p = os.popen4('java -Djava.awt.headless=true -Xms600M -Xmx600M -jar plugins/LGMUtility.jar "' + game + '"')

    # pipe the java output to str1
    str1 = p[1].read()
    print "=== start normal output ==="
    print str1[-250:]
    print "=== end normal output ==="
    p[1].close()

    try:
        f = open("redirfile.txt")
        compiler_output = f.read()
        print "=== start of compiler output ==="
        print compiler_output[-500:]
        print "=== end of compiler output ==="
        f.close()
        os.remove("redirfile.txt")
    except Exception, exception:
        compiler_output = ""
        print "exception = ", exception
def compile_mingw():
    build_dir=EnigmaSettings.getEnigmaDir()
    cwd = os.getcwd() # get current directory
    try:
       os.chdir(build_dir)
       return ConvertingEnigma.run_command("make Game GMODE=Run GRAPHICS=OpenGL AUDIO=None COLLISION=BBox WIDGETS=None PLATFORM=Win32 CXX=\"/usr/local/i386-mingw32-4.3.0/bin/i386-mingw32-g++ -Wfatal-errors -w -I./Platforms/Win32/ffi -I./../additional/zlib -L./Platforms/Win32/ffi -L./../additional/zlib\" CC=\"/usr/local/i386-mingw32-4.3.0/bin/i386-mingw32-gcc -Wfatal-errors -w\" COMPILEPATH=MacOSX/Windows EXTENSIONS=\"Universal_System/Extensions/Alarms Universal_System/Extensions/Timelines Universal_System/Extensions/Paths Universal_System/Extensions/MotionPlanning Universal_System/Extensions/Unimplemented Universal_System/Extensions/DateTime Universal_System/Extensions/DataStructures\" OUTPUTNAME=\"/Users/alasdairmorrison/Enigma/Enigma_clean_April_2012/EnigmaXcode.exe\"")
    finally:
      os.chdir(cwd)
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###################################################################################

# PROBLEM: This could mess up when a new function is implemented (replaces by id)



import MySQLdb, EnigmaSettings
db=EnigmaSettings.mysql_connect()

maximum_number=2000
game_db="64D_mac_new"
missing_function_db="64D_mac__new_missingfunctions"

c=db.cursor()
db.query("""SELECT example, MissingFunctions, NoOfMissingFunctions FROM  """+game_db+""" WHERE example>0 ORDER BY example LIMIT """+str(maximum_number)) #ORDER BY ID DESC

r=db.store_result()
functionHTable={}
try:
 for download_rows in range(0,maximum_number):
    row=r.fetch_row()
    id= row[0][0]
    MissingFunctions = row[0][1]