def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot ignore_errors = False if "--ignore-errors" in argv: argv.remove("--ignore-errors") ignore_errors = True if len(argv) != 2: usage(argv) return 1 if "--dry-run" in argv: print "\n".join(map(str, parse_schedule(schedule))) return 0 config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) dumpdb = os.path.join(os.path.dirname(__file__), "../../prod_mysqldump") if os.path.exists(dumpdb): print "Running %r..." % (dumpdb, ) res = os.system(dumpdb) if res: return res with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") s.__dict__.update(vals) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: if ignore_errors: continue raise Exception("invalid talk: %r" % (talk, )) actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name) assert actual_talk_owner.lower() == talk.owner_name.lower(), \ "bad data? owners don't match: %r != %r" %( actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by( talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot ignore_errors = False if "--ignore-errors" in argv: argv.remove("--ignore-errors") ignore_errors = True if len(argv) != 2: usage(argv) return 1 if "--dry-run" in argv: print "\n".join(map(str, parse_schedule(schedule))) return 0 config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) dumpdb = os.path.join(os.path.dirname(__file__), "../../prod_mysqldump") if os.path.exists(dumpdb): print "Running %r..." %(dumpdb, ) res = os.system(dumpdb) if res: return res with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") for (k, v) in vals.items(): setattr(s, k, v) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: if ignore_errors: continue raise Exception("invalid talk: %r" %(talk, )) actual_talk_owner = "%s %s" %(t.owner.first_name, t.owner.last_name) assert actual_talk_owner.lower() == talk.owner_name.lower(), \ "bad data? owners don't match: %r != %r" %( actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by(talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot if len(argv) != 2: usage(argv) sys.exit(1) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") s.__dict__.update(vals) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: raise Exception("invalid talk: %r" % (talk, )) actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name) assert actual_talk_owner.lower() == talk.owner_name.lower(), \ "bad data? owners don't match: %r != %r" %( actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by( talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot if len(argv) != 2: usage(argv) sys.exit(1) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, "sqlalchemy.") DBSession.configure(bind=engine) with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") s.__dict__.update(vals) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: raise Exception("invalid talk: %r" % (talk,)) actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name) assert ( actual_talk_owner.lower() == talk.owner_name.lower() ), "bad data? owners don't match: %r != %r" % (actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by(talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def save(self, instance): DBSession.add(instance) DBSession.flush()