options, args = parser.parse_args()
    if len(args) > 0:
        parser.error("Unknown commandline options: " + str(args))
    if len(sys.argv) < 2:
        parser.print_help()
        parser.error("no options defined")
    params = {}
    for i in parser.option_list:
        if isinstance(i.dest, str):
            params[i.dest] = getattr(options, i.dest)
    return params


if __name__ == "__main__":
    params = parseOptions()
    apProject.setDBfromProjectId(params["projectid"])

    stackdata = apStack.getOnlyStackData(params["stackid"])
    stackpath = stackdata["path"]["path"]
    # generate stack if it doesn't exist.
    if not os.path.isdir(stackpath):
        os.makedirs(stackpath)
    fname = os.path.join(stackpath, stackdata["name"])

    # check if stack file already exists
    if os.path.isfile(fname):
        apDisplay.printError("file: '%s' already exists" % fname)

    vstackdata = apStack.getVirtualStackParticlesFromId(params["stackid"])
    plist = [int(p["particleNumber"]) - 1 for p in vstackdata["particles"]]
def setAppiondb(sessionname):
        projectid = apProject.getProjectIdFromSessionName(sessionname)
        apProject.setDBfromProjectId(projectid, die=True)
def setAppiondb(sessionname):
    projectid = apProject.getProjectIdFromSessionName(sessionname)
    apProject.setDBfromProjectId(projectid, die=True)
        selectq = " SELECT * FROM `install` WHERE `key`='version'"
        values = projectdb.returnCustomSQL(selectq)
        if values:
                projectdb.updateColumn("install", "value", "'2.0'", 
                        "install.key = 'version'",timestamp=False)
        else:
                insertq = "INSERT INTO `install` (`key`, `value`) VALUES ('version', '2.0')"
                projectdb.executeCustomSQL(insertq)

if __name__ == "__main__":
        projectids = getProjectIds()
        projectdb = dbupgrade.DBUpgradeTools('projectdata', drop=True)
        for projectid in projectids:
                appiondbname = apProject.getAppionDBFromProjectId(projectid, die=False)
                if appiondbname is None:
                        continue
                elif not projectdb.databaseExists(appiondbname):
                        print "\033[31merror database %s does not exist\033[0m"%(appiondbname)
                        time.sleep(1)
                        continue
                if apProject.setDBfromProjectId(projectid, die=False):
                        reconrunids = getReconRunsIds()
                        for reconrunid in reconrunids:
                                apRecon.setGoodBadParticlesFromReconId(reconrunid)
                        # Tomography upgrades
                        createExcludedColumnByFakeInsert()
                        allalignrundata = getTomoAlignmentRuns()
                        for alignrun in allalignrundata:
                                insertTiltsInAlign(alignrun)
        upgradeProjectDB(projectdb,backup=False)
    options, args = parser.parse_args()
    if len(args) > 0:
        parser.error("Unknown commandline options: " + str(args))
    if len(sys.argv) < 2:
        parser.print_help()
        parser.error("no options defined")
    params = {}
    for i in parser.option_list:
        if isinstance(i.dest, str):
            params[i.dest] = getattr(options, i.dest)
    return params


if __name__ == "__main__":
    params = parseOptions()
    apProject.setDBfromProjectId(params['projectid'])

    stackdata = apStack.getOnlyStackData(params['stackid'])
    stackpath = stackdata['path']['path']
    # generate stack if it doesn't exist.
    if not os.path.isdir(stackpath):
        os.makedirs(stackpath)
    fname = os.path.join(stackpath, stackdata['name'])

    # check if stack file already exists
    if os.path.isfile(fname):
        apDisplay.printError("file: '%s' already exists" % fname)

    vstackdata = apStack.getVirtualStackParticlesFromId(params['stackid'])
    plist = [int(p['particleNumber']) - 1 for p in vstackdata['particles']]
                               "'2.0'",
                               "install.key = 'version'",
                               timestamp=False)
    else:
        insertq = "INSERT INTO `install` (`key`, `value`) VALUES ('version', '2.0')"
        projectdb.executeCustomSQL(insertq)


if __name__ == "__main__":
    projectids = getProjectIds()
    projectdb = dbupgrade.DBUpgradeTools('projectdata', drop=True)
    for projectid in projectids:
        appiondbname = apProject.getAppionDBFromProjectId(projectid, die=False)
        if appiondbname is None:
            continue
        elif not projectdb.databaseExists(appiondbname):
            print "\033[31merror database %s does not exist\033[0m" % (
                appiondbname)
            time.sleep(1)
            continue
        if apProject.setDBfromProjectId(projectid, die=False):
            reconrunids = getReconRunsIds()
            for reconrunid in reconrunids:
                apRecon.setGoodBadParticlesFromReconId(reconrunid)
            # Tomography upgrades
            createExcludedColumnByFakeInsert()
            allalignrundata = getTomoAlignmentRuns()
            for alignrun in allalignrundata:
                insertTiltsInAlign(alignrun)
    upgradeProjectDB(projectdb, backup=False)
	options,args = parser.parse_args()
	if len(args) > 0:
		parser.error("Unknown commandline options: " +str(args))
	if len(sys.argv) < 2:
		parser.print_help()
		parser.error("no options defined")
	params = {}
	for i in parser.option_list:
		if isinstance(i.dest, str):
			params[i.dest] = getattr(options, i.dest)
	return params

if __name__=="__main__":
	params = parseOptions()
	apProject.setDBfromProjectId(params['projectid'])

	stackdata = apStack.getOnlyStackData(params['stackid'])
	stackpath = stackdata['path']['path']
	# generate stack if it doesn't exist.
	if not os.path.isdir(stackpath):
		os.makedirs(stackpath)
	fname = os.path.join(stackpath, stackdata['name'])

	# check if stack file already exists
	if os.path.isfile(fname):
		apDisplay.printError("file: '%s' already exists"%fname)
 
	vstackdata = apStack.getVirtualStackParticlesFromId(params['stackid'])
	plist = [int(p['particleNumber'])-1 for p in vstackdata['particles']]