當前位置: 首頁>>代碼示例>>Python>>正文


Python Database.find_message方法代碼示例

本文整理匯總了Python中notmuch.Database.find_message方法的典型用法代碼示例。如果您正苦於以下問題:Python Database.find_message方法的具體用法?Python Database.find_message怎麽用?Python Database.find_message使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在notmuch.Database的用法示例。


在下文中一共展示了Database.find_message方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_notmuch_message

# 需要導入模塊: from notmuch import Database [as 別名]
# 或者: from notmuch.Database import find_message [as 別名]
 def _get_notmuch_message(self, mid):
     """returns :class:`notmuch.database.Message` with given id"""
     mode = Database.MODE.READ_ONLY
     db = Database(path=self.path, mode=mode)
     try:
         return db.find_message(mid)
     except:
         errmsg = 'no message with id %s exists!' % mid
         raise NonexistantObjectError(errmsg)
開發者ID:dcbaker,項目名稱:alot,代碼行數:11,代碼來源:manager.py

示例2: get_message

# 需要導入模塊: from notmuch import Database [as 別名]
# 或者: from notmuch.Database import find_message [as 別名]
 def get_message(self, mid):
     """returns the message with given id as alot.message.Message object"""
     mode = Database.MODE.READ_ONLY
     db = Database(path=self.path, mode=mode)
     msg = db.find_message(mid)
     return Message(self, msg)
開發者ID:jhcepas,項目名稱:alot,代碼行數:8,代碼來源:db.py

示例3: main

# 需要導入模塊: from notmuch import Database [as 別名]
# 或者: from notmuch.Database import find_message [as 別名]

#.........這裏部分代碼省略.........
        print Notmuch().format_reply(msgs)
    #-------------------------------------
    elif sys.argv[1] == 'count':
        if len(sys.argv) == 2:
            # no further search term, count all
            querystr = ''
        else:
            # mangle arguments wrapping terms with spaces in quotes
            querystr = quote_query_line(sys.argv[2:])
	print Database().create_query(querystr).count_messages()
    #-------------------------------------
    elif sys.argv[1] == 'tag':
        # build lists of tags to be added and removed
        add = []
        remove = []
        while not sys.argv[2] == '--' and \
                (sys.argv[2].startswith('+') or sys.argv[2].startswith('-')):
                    if sys.argv[2].startswith('+'):
                        # append to add list without initial +
                        add.append(sys.argv.pop(2)[1:])
                    else:
                        # append to remove list without initial -
                        remove.append(sys.argv.pop(2)[1:])
        # skip eventual '--'
        if sys.argv[2] == '--': sys.argv.pop(2)
        # the rest is search terms
        querystr = quote_query_line(sys.argv[2:])
        db = Database(mode=Database.MODE.READ_WRITE)
        msgs  = Query(db, querystr).search_messages()
        for msg in msgs:
            # actually add and remove all tags
            map(msg.add_tag, add)
            map(msg.remove_tag, remove)
    #-------------------------------------
    elif sys.argv[1] == 'search-tags':
        if len(sys.argv) == 2:
            # no further search term
            print "\n".join(Database().get_all_tags())
        else:
            # mangle arguments wrapping terms with spaces in quotes
            querystr = quote_query_line(sys.argv[2:])
            db = Database()
            msgs  = Query(db, querystr).search_messages()
            print "\n".join([t for t in msgs.collect_tags()])
    #-------------------------------------
    elif sys.argv[1] == 'dump':
        # TODO: implement "dump <filename>"
        if len(sys.argv) == 2:
            f = sys.stdout
        else:
            f = open(sys.argv[2], "w")
        db = Database()
        query = Query(db, '')
        query.set_sort(Query.SORT.MESSAGE_ID)
        msgs = query.search_messages()
        for msg in msgs:
            f.write("%s (%s)\n" % (msg.get_message_id(), msg.get_tags()))
    #-------------------------------------
    elif sys.argv[1] == 'restore':
        if len(sys.argv) == 2:
            print("No filename given. Reading dump from stdin.")
            f = sys.stdin
        else:
            f = open(sys.argv[2], "r")

        # split the msg id and the tags
        MSGID_TAGS = re.compile("(\S+)\s\((.*)\)$")
        db = Database(mode=Database.MODE.READ_WRITE)

        #read each line of the dump file
        for line in f:
            msgs = MSGID_TAGS.match(line)
            if not msgs:
                sys.stderr.write("Warning: Ignoring invalid input line: %s" %
                        line)
                continue
            # split line in components and fetch message
            msg_id = msgs.group(1)
            new_tags = set(msgs.group(2).split())
            msg = db.find_message(msg_id)

            if msg == None:
                sys.stderr.write(
                        "Warning: Cannot apply tags to missing message: %s\n" % msg_id)
                continue

            # do nothing if the old set of tags is the same as the new one
            old_tags = set(msg.get_tags())
            if old_tags == new_tags: continue

            # set the new tags
            msg.freeze()
            # only remove tags if the new ones are not a superset anyway
            if not (new_tags > old_tags): msg.remove_all_tags()
            for tag in new_tags: msg.add_tag(tag)
            msg.thaw()
    #-------------------------------------
    else:
        # unknown command
        exit("Error: Unknown command '%s' (see \"notmuch help\")" % sys.argv[1])
開發者ID:irishjava,項目名稱:python-notmuch,代碼行數:104,代碼來源:notmuch.py


注:本文中的notmuch.Database.find_message方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。