示例#1
0
 def __unicode__(self):
     string = ""
     for term in self._searchC:
         s = term[3] if (term[1] != EnumSong.DATESTAMP) else term[0]
         string += "%s %s %s\n"%(EnumSong.exifToString(term[1]),SEARCH(term[2]),s)
     for term in self._searchO:
         s = term[3] if (term[1] != EnumSong.DATESTAMP) else term[0]
         string += "%s %s %s\n"%(EnumSong.exifToString(term[1]),SEARCH(term[2]),s)
     for term in self._searchN:
         s = term[3] if (term[1] != EnumSong.DATESTAMP) else term[0]
         string += "%s %s %s\n"%(EnumSong.exifToString(term[1]),SEARCH(term[2]),s)
     i=1;    
     for lst in self._searchX:
         
         for term in lst:
             s = term[3] if (term[1] != EnumSong.DATESTAMP) else term[0]
             string += "%s %s %d %s\n"%(EnumSong.exifToString(term[1]),SEARCH(term[2]),i,s)
         i+=1;
     return string
示例#2
0
    def _compareSongElement(self,song,element):
        """
            compare a single song to a single compiled term
            the actual comparrison may need to convert the format
            of the song element first.
        """
        # song:
        #   a single song record.
        # element: 
        #   a tupple in form from compileSearchString()
        # return:
        #   True, song matches element, or False
        os = 0 # original string
        st = 1 # search type
        dm = 2 # direction
        cf = 3 # compiled form
        rf = 4 # alternate value for comparing ( of same type to cf )
        
        # RETRANSLATE TO OLD STYLE FORMAT
        # TODO: REMOVE THIS
        flag_dir  = element[dm]
        flag_type = element[st]
        #if    element[2]&SEARCH.GE==SEARCH.GE: flag_dir = EnumSong.GTEQUAL
        #elif  element[2]&SEARCH.LE==SEARCH.LE: flag_dir = EnumSong.LTEQUAL
        #elif  element[2]&SEARCH.GT           : flag_dir = EnumSong.GREATERTHAN
        #elif  element[2]&SEARCH.LT           : flag_dir = EnumSong.LESSTHAN
        #elif  element[2]&SEARCH.EQ           : flag_dir = EnumSong.EQUAL
        #else                                 : flag_dir = EnumSong.CONTAINS
        #element = (element[0],element[1],flag_dir,element[3],element[4])
        
        # split this function into special cases, 
        # then all string elements
        # then all number elements
        try:
            if flag_type == EnumSong.SELECTED :
                return song[EnumSong.SELECTED]

            elif flag_type == EnumSong.SPECIAL :
                return song[EnumSong.SPECIAL]

            elif flag_type == EnumSong.BANISH :
                return song.banish
                
            elif flag_type == EnumSong.SPEC_FREQ_G :

                old=song[EnumSong.DATEVALUE]
                if old != 0:
                    d =  max(1, int(float(element[cf] - old)/(60*60*24)) )
                else: 
                    d = 0;
                return d > song[EnumSong.FREQUENCY];
                
            elif flag_type == EnumSong.SPEC_FREQ_L :

                old=song[EnumSong.DATEVALUE]
                if old != 0:
                    d =  max(1, int(float(element[cf] - old)/(60*60*24)) )
                else: 
                    d = 0;
                return d < song[EnumSong.FREQUENCY];
            
            elif flag_type == EnumSong.SPEC_FREQ_E :

                old=song[EnumSong.DATEVALUE]
                if old != 0:
                    d =  max(1, int(float(element[cf] - old)/(60*60*24)) )
                else: 
                    d = 0;
                return d == song[EnumSong.FREQUENCY];
                
            elif flag_type == EnumSong.PATH :
                if flag_dir&SEARCH.EQ:
                    #return song[EnumSong.PATH].find(element[cf]) == 0
                    return comparePathLength(element[cf],song[EnumSong.PATH])
                    
                else:
                    return comparePartInPath(song[EnumSong.PATH],element[cf]) 
                    
            elif flag_type == EnumSong.DATESTAMP:
                # dates less than means time is greater
                # set or EnumSong.CONTAINS as default
                # defaults to >=, ex, not played fro x days or more
                if flag_dir&SEARCH.LT: # more recent
                    return (song[EnumSong.DATEVALUE] >=  element[cf])
                elif flag_dir&SEARCH.EQ==SEARCH.EQ : # equals one specific day
                    return (song[EnumSong.DATEVALUE] >= element[cf] and song[EnumSong.DATEVALUE] <= element[rf])
                else:   # older than date
                    return (song[EnumSong.DATEVALUE] <= element[cf])
                    
            elif flag_type == EnumSong.DATEADDED:
                # dates less than means time is greater
                # set or EnumSong.CONTAINS as default
                # defaults to >=, ex, not played fro x days or more
                if flag_dir&SEARCH.LT: # more recent
                    return (song[EnumSong.DATEADDED] >=  element[cf])
                elif flag_dir&SEARCH.EQ==SEARCH.EQ : # equals one specific day
                    return (song[EnumSong.DATEADDED] >= element[cf] and song[EnumSong.DATEADDED] <= element[rf])
                else:   # older than date
                    return (song[EnumSong.DATEADDED] <= element[cf])
                    
            elif flag_type < EnumSong.STRINGTERM :
                # contains, the element must be anywhere
                #  ex: 'st' will match 'stone' and 'rockstar'
                # equals the entered text must equal the equivalent length in the song
                #  ex: 'st' will match 'stone' but not 'rockstar'
                if flag_dir&SEARCH.EQ and flag_type != EnumSong.EXIF:
                    return song[flag_type].lower().find(element[cf]) == 0
                else:
                    return song[flag_type].lower().find(element[cf]) >= 0
                     
        except Exception as e:
            print "Error: [%s] %s"%(EnumSong.exifToString(flag_type),e.args)
            print song
            print element
        return False;