def mga2xme(mganame, xmename=''): """Given an mga file, it exports to xml format using the GME.Application COM object When the method exits the GME.Application object remains alive, so upon the next invokation the same object will be used. Beware if you make testcases involving the GME.Application object, leave the object in a state regarding that this method tries to open a project. """ if xmename == '': xmename = mganame + '.xme' try: gme = DispatchEx("GME.Application") except: raise 'Could not create GME.Application' try: gme.OpenProject("MGA=" + mganame) gme.ExportProject(xmename) gme.CloseProject(0) return xmename except: gme.CloseProject(0)
def doit(source, target): errors = 0 errors_with_files = "" fs = [] source_dir = '' target_dir = target if os.path.isdir(source): source_dir = source fs = mgafiles(os.path.abspath(os.path.join(os.path.curdir, source_dir))) elif os.path.isfile(source): fs.append(source) else: raise 'File/Directory not given consistently' for i in fs: mganame = os.path.join(source_dir, i) mganame = os.path.abspath(os.path.join(os.path.curdir, mganame)) xmename = os.path.join(target_dir, os.path.split(i)[1] + ".xme") xmename = os.path.abspath(os.path.join(os.path.curdir, xmename)) try: gme = DispatchEx("GME.Application") gme.Visible = 0 gme.OpenProject("MGA=" + mganame) gme.ExportProject(xmename) gme.CloseProject(0) except: errors = errors + 1 errors_with_files = errors_with_files + mganame + "\n" gme.CloseProject(0) pass return (errors, errors_with_files)