Created
August 6, 2015 19:54
-
-
Save ahplummer/022e5d6b35fd0c517cb9 to your computer and use it in GitHub Desktop.
Exports MS Access objects into text files so that they can be revisioned in Source Control.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from comtypes.client import CreateObject | |
import shutil | |
import os | |
import argparse | |
parser = argparse.ArgumentParser(description='Mounts Access via COM wrapper, and extracts meta objects.') | |
parser.add_argument('-file','--file',help='File',required=True) | |
parser.add_argument('-exportpath','--exportpath',help='Export Path',required=False) | |
args = vars(parser.parse_args()) | |
filename = args['file'] | |
basefilename = os.path.basename(filename) | |
workingfilename = os.path.dirname(filename) + os.path.sep + basefilename + '-WORKING' + os.path.splitext(basefilename)[1] | |
exportPath = os.path.dirname(filename) + "\\export" | |
if args['exportpath'] != None: | |
exportPath = args['exportpath'] | |
else: | |
print "Since none provided, will use default export path: " + exportPath | |
if not os.path.exists(exportPath): | |
os.makedirs(exportPath) | |
#copy file to working version. | |
shutil.copyfile(filename, workingfilename) | |
accessApplication = CreateObject("Access.Application") | |
accessApplication.OpenAccessProject(workingfilename) | |
#constants | |
acForm = 2 | |
acModule= 5 | |
acMacro = 4 | |
acReport = 3 | |
dictionaryDelete = CreateObject("Scripting.Dictionary") | |
#FORMS | |
for f in accessApplication.CurrentProject.AllForms: | |
accessApplication.SaveAsText(acForm, f.FullName, exportPath + '\\' + f.FullName + '.form' ) | |
accessApplication.DoCmd.Close(acForm, f.FullName) | |
dictionaryDelete.Add("FO" + f.FullName, acForm) | |
#MODULES | |
for m in accessApplication.CurrentProject.AllModules: | |
accessApplication.SaveAsText(acModule, m.FullName, exportPath + '\\' + m.FullName + '.bas' ) | |
accessApplication.DoCmd.Close(acModule, m.FullName) | |
dictionaryDelete.Add("MO" + m.FullName, acModule) | |
#MACROS | |
for m in accessApplication.CurrentProject.AllMacros: | |
accessApplication.SaveAsText(acMacro, m.FullName, exportPath + '\\' + m.FullName + '.mac' ) | |
accessApplication.DoCmd.Close(acMacro, m.FullName) | |
dictionaryDelete.Add("MA" + m.FullName, acMacro) | |
#REPORTS | |
for r in accessApplication.CurrentProject.AllReports: | |
accessApplication.SaveAsText(acReport, r.FullName, exportPath + '\\' + r.FullName + '.report' ) | |
accessApplication.DoCmd.Close(acReport, r.FullName) | |
dictionaryDelete.Add("RE" + r.FullName, acReport) | |
accessApplication.CloseCurrentDatabase() | |
os.remove(workingfilename) | |
accessApplication.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment