
import os

I5COMP_EXE = os.path.abspath("./i5comp/i5comp.exe")


def extract(cabfile, group, dest):
    cabfile = os.path.abspath(cabfile)
    oldcwd = os.getcwd()
    os.chdir(dest) # I hate this
    cmdline = '"%s" x "-g%s" "%s"' % (I5COMP_EXE, group, cabfile)
    print cmdline
    r = os.popen(cmdline)
    os.chdir(oldcwd)
    #header = r.readline()+r.readline()
    #print header
    #if header != "InstallShield 5.x Cabinet Compression & Maintenance Util\nVersion 2.01 -] fOSSiL - 1999 [-\n":
    #    raise Exception("Unexpected output from i5comp.exe")
    files = []
    for line in r:
        line = line.rstrip('\n')
        print line
        files.append(line)
    return files
