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)
def doit( source, target): errors = 0 errors_with_files = "" fs = [] source_dir = '' target_dir = target if os.path.isdir( source): source_dir = source dir2load = os.path.abspath(os.path.join( os.path.curdir, source_dir)) fs = xmefiles( dir2load) elif os.path.isfile( source): fs.append( source) else: raise 'File/Directory not given consistently' for i in fs: #fname = os.path.join( target_dir, s.path.split(i)[1] + ".xme" ) xmename = os.path.abspath( os.path.join( os.path.curdir, i)) try: gme = DispatchEx("GME.Application") gme.Visible = 0 paradigm = "MetaGME" # naming pattern: _tc5_A_sf.mga.xme # the part between the last '_' and the first '.' char indicates the paradigm name j = i[ : i.find('.')] if j.count('_') >= 1: u = j.rfind('_') p = j[ u + 1 : ] if p == 'sf': paradigm = "SF" elif p == 'fl': paradigm = "FloatAttr" elif p == 'me': paradigm = "MetaGME" else: print 'Other paradigm !!!' pass else: print 'Other naming pattern !!!' pass name = 'newproject' i = os.path.split(i)[1] if i.count('.') > 0: name = i[:i.rfind('.')] mgan = os.path.abspath( os.path.join( target_dir, name )) gme.CreateProject( paradigm, "MGA=" + mgan) gme.ImportProject(xmename) gme.SaveProject() gme.CloseProject(0) except: errors = errors + 1 errors_with_files = errors_with_files + mganame + "\n" gme.CloseProject(0) pass return ( errors, errors_with_files)