当前位置: 首页>>代码示例>>Python>>正文


Python Session.rollback方法代码示例

本文整理汇总了Python中database.Session.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python Session.rollback方法的具体用法?Python Session.rollback怎么用?Python Session.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.Session的用法示例。


在下文中一共展示了Session.rollback方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def main():
    from_date = datetime.date(*map(int, sys.argv[1].split('-')))
    to_date = datetime.date(*map(int, sys.argv[2].split('-')))
    assert from_date <= to_date
    quote = decode_quote(sys.argv[3])
    #print quote

    session = Session()
    lit_years = {}
    date = from_date
    while date <= to_date:
        found = False
        session.rollback()
        lit_date = get_lit_date(date, lit_years, session)
        masses = []
        try:
            masses = lit_date.get_masses(strict=True)
        except SelectingMassException:
            pass
        for mass in masses:
            if found:
                break
            for reading in mass.readings:
                try:
                    verses = decode_quote(reading.quote)
                except BadQuoteException:
                    pass
                if quotes_intersect(quote, verses):
                    print "%s: %s" % (date, reading.quote)
                    found = True
                    break
        date += datetime.timedelta(days=1)
开发者ID:giomasce,项目名称:liturgy,代码行数:34,代码来源:find_days.py

示例2: get_announcements

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def get_announcements(course, url):
    '''Gets all new announcements

    Returns a list of all new announcements.
    '''
    session = Session()
    try:
        r = s.get('https://edux.pjwstk.edu.pl/Announcements.aspx', stream=True)
        r.raise_for_status()
        new_announcements = extract_announcements(r.content)
        # All pairs of (timestamp, message) are saved to db
        # if they arent there already
        for (timestamp, message) in new_announcements:
            announcement = session.query(Announcement). \
                filter_by(course=course,
                          created_at=timestamp,
                          message=message). \
                first()
            if announcement is None:
                # This is what we care about
                announcement = Announcement(
                    course=course,
                    created_at=timestamp,
                    message=message)
                session.add(announcement)
                print u'New announcement at {0}'.format(timestamp)
                yield (timestamp, message)
        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
开发者ID:mpapierski,项目名称:edux,代码行数:35,代码来源:edux.py

示例3: main

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def main():
    reading_id = int(sys.argv[1])
    session = Session()
    reading = session.query(Reading).filter(Reading.id == reading_id).one()
    text = reading.text
    PrependStream(sys.stdout, '    ').write('"' + text.strip() + '"')
    sys.stdout.write('\n')
    session.rollback()
开发者ID:giomasce,项目名称:liturgy,代码行数:10,代码来源:print_reading.py

示例4: save_album

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def save_album(album_name,album_id,album_cover):
    try:
        category = Albums(album_name=album_name,album_id=album_id,album_cover=album_cover)

        Session.add(category)
        Session.commit()
    except Exception as e:
        Session.rollback()
        raise e
开发者ID:maximusmai,项目名称:flask-test,代码行数:11,代码来源:model.py

示例5: save_cate

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def save_cate(cate_name,cate_id):
    try:
        category = Categories(category_name=cate_name,category_id=cate_id)

        Session.add(category)
        Session.commit()
    except Exception as e:
        Session.rollback()
        raise e
开发者ID:maximusmai,项目名称:flask-test,代码行数:11,代码来源:model.py

示例6: save_wallpaper

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def save_wallpaper(title, file_name, image_url, id=None, category=None, album_id=None, album_name=None ,username=None):
    try:
        wallpaper = Wallpapers(title=title, image_url=image_url, id=id, category_id=category, user_id=username,
                               album_id=album_id, album_name=album_name)

        Session.add(wallpaper)
        Session.commit()
    except Exception as e:
        Session.rollback()
        raise e
开发者ID:maximusmai,项目名称:flask-test,代码行数:12,代码来源:model.py

示例7: check_db

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def check_db(loud=False, delete_orphans=False, fix=False):
    session = Session()

    check_orphans(session, loud, delete_orphans)
    check_readings(session, loud, fix)
    check_masses(session, loud)
    check_events(session, loud)

    #session.commit()
    session.rollback()
    session.close()
开发者ID:giomasce,项目名称:liturgy,代码行数:13,代码来源:check_db.py

示例8: load

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def load(file_):
    nvdxml = utilities.NvdXml()
    session = Session()

    reader = csv.reader(file_)
    next(reader, None)   # Ignoring the header
    for row in reader:
        debug(row)
        cve = Cve(id=row[0], year=utilities.get_year(row[0]), product=row[1])
        nvd_details = nvdxml.get_details(cve.id)

        if nvd_details:
            cve.cvss = Cvss()

            cve.cvss.access_complexity = nvd_details['access-complexity']
            cve.cvss.access_vector = nvd_details['access-vector']
            cve.cvss.authentication = nvd_details['authentication']
            cve.cvss.availability_impact = nvd_details['availability-impact']
            cve.cvss.confidentiality_impact = nvd_details[
                    'confidentiality-impact'
                ]
            cve.cvss.integrity_impact = nvd_details['integrity-impact']
            cve.cvss.score = nvd_details['score']
            cve.cvss.exploitability_subscore = nvd_details[
                    'exploitability-subscore'
                ]
            cve.cvss.impact_subscore = nvd_details[
                    'impact-subscore'
                ]

            cve.bounty = Bounty()

            cve.bounty.amount = float(row[2].replace('$', '').replace(',', ''))

            session.add(cve)
            try:
                session.commit()
            except sqlalchemy.exc.IntegrityError as e:
                error('{} is a duplicate.'.format(cve.id))
                session.rollback()
        else:
            warning('{} was not found in NVD.'.format(cve.id))
开发者ID:andymeneely,项目名称:cvss_bounties,代码行数:44,代码来源:load_database.py

示例9: main

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def main():
    reading_id = int(sys.argv[1])
    session = Session()
    bible_query = BibleQuery()
    reading = session.query(Reading).filter(Reading.id == reading_id).one()
    text = reading.text if reading.text is not None else ""

    editor = Editor()

    # Fix wrong quotation marks
    text = re.sub(ur'"([a-zA-ZàòùèéìÒÀÙÈÉÌ0-9])', ur'“\1', text, count=0)
    text = re.sub(ur'([a-zA-ZàòùèéìÒÀÙÈÉÌ0-9\.?!])"', ur'\1”', text, count=0)

    # From http://stackoverflow.com/questions/15120346/emacs-setting-comment-character-by-file-extension
    PrependStream(editor.tempfile, '# ').write(u'-*- coding: utf-8; comment-start: "#"; -*-\n')
    PrependStream(editor.tempfile, '# ').write(u'Quote: %s\n' % (reading.quote))
    editor.tempfile.write(u'\n')
    editor.tempfile.write(text)
    editor.tempfile.write(u'\n')
    PrependStream(editor.tempfile, '# ').write(u'Useful characters: “”–\n\n')
    try:
        converted_quote = convert_quote_psalm_numbering(reading.quote, False)
        bible_text = bible_query.get_text(decode_quote(converted_quote, allow_only_chap=True))
    except:
        PrependStream(editor.tempfile, '# ').write(u'Quote: %s\nCould not retrieve bible text\n' % (reading.quote))
        print decode_quote(reading.quote, allow_only_chap=True)
        raise
    else:
        bible_text = "\n".join(map(lambda x: x.strip(), bible_text.split('\n')))
        PrependStream(editor.tempfile, '# ').write(u'Quote: %s\nConverted quote: %s\nBible text:\n\n%s' % (reading.quote, converted_quote, bible_text))

    editor.edit()

    new_text = u''.join(filter(lambda x: not x.startswith(u'#'), editor.edited_content)).strip() + u'\n'

    if editor.confirmation_request(new_text != reading.text):
        reading.text = new_text
        session.commit()
    else:
        session.rollback()
开发者ID:giomasce,项目名称:liturgy,代码行数:42,代码来源:edit_reading.py

示例10: main

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def main():
    session = Session()

    if len(sys.argv[1:]) == 1:
        mass_id = int(sys.argv[1])
        masses = [session.query(Mass).filter(Mass.id == mass_id).one()]
    elif len(sys.argv[1:]) == 3:
        year, month, day = map(int, sys.argv[1:])
        lit_years = {}
        lit_date = get_lit_date(datetime.date(year, month, day), lit_years, session)
        masses = lit_date.get_masses(strict=True)
    else:
        print >> sys.stderr, "Wrong number of arguments"
        sys.exit(1)

    fout = PrependStream(sys.stdout, '# ')

    for mass in sorted(masses, key=lambda x: x.order):
        num_reading = max(map(lambda x: x.order, mass.readings)) + 1
        quotes = []
        alt_quotes = []

        print >> fout, "Mass #%d (%s) in event %s - ID: %d" % (mass.order, mass.title, mass.event.title, mass.id)
        for reading in sorted(mass.readings, key=lambda x: (x.order, x.alt_num)):
            print >> fout, "  Lettura #%d.%d (%s): %s - ID: %d" % (reading.order, reading.alt_num, reading.title, reading.quote, reading.id)

        for i in xrange(num_reading):
            [reading] = filter(lambda x: x.order == i and x.alt_num == 0, mass.readings)
            if reading.only_on_sunday:
                alt_quotes[0].append(reading.quote)
                continue
            quotes.append(reading.quote)
            alt_quotes.append(map(lambda x: x.quote, sorted(filter(lambda x: x.order == i and x.alt_num > 0, mass.readings), key=lambda x: x.alt_num)))

        sys.stdout.write("citazioni: %s\n" % (json.dumps(quotes)))
        sys.stdout.write("citazioni_alt: %s\n" % (json.dumps(alt_quotes)))

    session.rollback()
开发者ID:giomasce,项目名称:liturgy,代码行数:40,代码来源:print_quotes.py

示例11: get_quiz

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def get_quiz(course):
    '''Navigates to quiz

    Gets all quiz
    '''
    session = Session()
    try:
        r = s.get('https://edux.pjwstk.edu.pl/Quiz.aspx')
        r.raise_for_status()

        # quiz = []

        for (quiz_id,
             title,
             start_at,
             finish_at,
             duration,
             score) in extract_quiz(r.content):
            quiz = session.query(Quiz). \
                filter_by(quiz_id=quiz_id). \
                first()
            if quiz is None:
                quiz = Quiz(
                    course=course,
                    quiz_id=quiz_id,
                    title=title,
                    start_at=start_at,
                    finish_at=finish_at,
                    duration=duration,
                    score=score
                )
                session.add(quiz)
                print u'New quiz "{0}" {1} - {2}'.format(
                    quiz.title,
                    quiz.start_at,
                    quiz.finish_at)
                send_notify(u'Quiz "{0.title}" at {1.title}'.format(quiz,
                                                                    course),
                            u'''Quiz title: {0.title}
Course: {1.title}
Start: {0.start_at}
Finish: {0.finish_at}
Duration: {0.duration}
Score: {0.score}
'''.format(quiz, course))

            if (quiz.title != title or
                    quiz.start_at != start_at or
                    quiz.finish_at != finish_at or
                    quiz.duration != duration or
                    quiz.score != score):
                send_notify(u'Quiz "{0.title}" changed'.format(quiz,
                                                               course),
                            u'''Quiz title: {new[title]} (old: {0.title})
Course: {1.title}
Start: {new[start_at]} (old: {0.start_at})
Finish: {new[finish_at]} (old: {0.finish_at})
Duration: {new[duration]} (old: {0.duration})
Score: {new[score]} (old: {0.score})
'''.format(quiz, course, new={'title': title,
                              'start_at': start_at,
                              'finish_at': finish_at,
                              'duration': duration,
                              'score': score}))
                quiz.title = title
                quiz.start_at = start_at
                quiz.finish_at = finish_at
                quiz.duration = duration
                quiz.score = score
                session.add(quiz)

        session.commit()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
开发者ID:mpapierski,项目名称:edux,代码行数:79,代码来源:edux.py

示例12: edit_month

# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import rollback [as 别名]
def edit_month(year, month, single_day=None):
    session = Session()
    bible_query = BibleQuery()
    lit_years = {}

    editor = Editor()

    # From http://stackoverflow.com/questions/15120346/emacs-setting-comment-character-by-file-extension
    PrependStream(editor.tempfile, '# ').write(u'-*- coding: utf-8; comment-start: "#"; -*-\n')
    editor.tempfile.write(u'\n')

    def push_day(day):
        date = datetime.date(year, month, day)
        lit_date = get_lit_date(date, lit_years, session)
        events = map(lambda x: x[1], lit_date.competitors)
        print_lit_date(lit_date, PrependStream(editor.tempfile, u'# '), with_id=True)
        editor.tempfile.write(u'\n')
        editor.tempfile.write(json.dumps(map(lambda x: x.as_dict(), events), ensure_ascii=False, indent=2, sort_keys=True) + u'\n')
        editor.tempfile.write(u'---===---\n')
        editor.tempfile.write(u'\n')

    if single_day is not None:
        push_day(single_day)
    else:
        for day in real_itermonthdays(year, month):
            push_day(day)

    editor.edit()

    while True:
        lines = filter(lambda x: not x.startswith(u'#'), editor.edited_content)
        buf = u''

        try:
            for line in lines:
                if line.strip() == u'---===---':
                    data = json.loads(buf)
                    for piece in data:
                        from_dict(piece, session)
                    buf = u''
                else:
                    buf += line
            session.flush()

        except:
            traceback.print_exc()
            sys.stdout.write("Error while parsing new content. Re-edit? [Y/n] ")
            answer = sys.stdin.readline().strip()
            if answer != '':
                answer = answer[0]
            if answer == 'n' or answer == 'N':
                sys.stdout.write("Aborting\n")
                sys.exit(0)
            else:
                sys.stdout.write("Re-editing...\n")
                session.rollback()
                edited_content = editor.edited_content
                editor = Editor()
                editor.tempfile.write("".join(edited_content))
                editor.edit()

        else:
            break

    if editor.confirmation_request(session_has_pending_commit(session)):
        #reading.text = new_text
        session.commit()
    else:
        session.rollback()
开发者ID:giomasce,项目名称:liturgy,代码行数:71,代码来源:edit_month.py


注:本文中的database.Session.rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。