コード例 #1
0
ファイル: wc_common.py プロジェクト: vivanno/myWah-cade
 def get_matching_filename(self, file_prefixes, file_formats):
     """return the filename if it exists from given formats & path
           file_prefixes = [(dir_name, filename), ...]
           file_formats = [file_ext1, file_ext2, ...]
     """
     #check lower & upper case filenames for each given prefix & format
     for dirname, fp in file_prefixes:
         if fp == '##random##':
             for ff in file_formats:
                 fnl = walk_dir(dirname, False, '*.%s' % ff.lower(), False) + \
                     walk_dir(dirname, False, '*.%s' % ff.upper(), False)
                 #return first valid match
                 for filename in fnl:
                     if os.path.isfile(filename):
                         return filename
         elif fp != '':
             if file_formats != '':
                 for ff in file_formats:
                     basename = '%s.%s' % (fp, ff)
                     #build list of possible filenames
                     fnl = [os.path.join(dirname, basename),
                            os.path.join(dirname, basename.lower()),
                            os.path.join(dirname, basename.upper())]
                     #return first valid match
                     for filename in fnl:
                         if os.path.isfile(filename):
                             return filename
             else:
                 filename = os.path.join(dirname, fp)
                 if os.path.isfile(filename):
                     return filename
     #done - nothing found
     return ''
コード例 #2
0
ファイル: wc_common.py プロジェクト: FruitieX/wahcade
 def get_matching_filename(self, file_prefixes, file_formats):
     """return the filename if it exists from given formats & path
           file_prefixes = [(dir_name, filename), ...]
           file_formats = [file_ext1, file_ext2, ...]
     """
     p = re.compile('(\.[^\.]+$)|(\s(\(|\[).+(?<=(\)|\]|\s))\.[^\.]+$)')
     self.wahcade_ini = MameWahIni(os.path.join(CONFIG_DIR, 'wahcade.ini'))
     l = self.wahcade_ini.get('layout')
     fz = self.wahcade_ini.getint('fuzzy_artwork_search')
     #check lower & upper case filenames for each given prefix & format
     for dirname, fp in file_prefixes:
         if fp == '##random##':
             for ff in file_formats:
                 fnl = walk_dir(dirname, False, '*.%s' % ff.lower(), False) + \
                     walk_dir(dirname, False, '*.%s' % ff.upper(), False)
                 #return first valid match
                 for filename in fnl:
                     if os.path.isfile(filename):
                         return filename
         elif fp != '':
             if file_formats != '':
                 # Check if this is a layout
                 if l not in dirname:
                     if fz:
                         # NB: we append a fake extension here to support the regex currently - sairuk
                         #     handles . appearing in filename being treated as an ext
                         fileset = glob.iglob(os.path.join(CONFIG_DIR, dirname, re.sub(p,'',fp + ".fix") + "*"))
                         for filename in fileset:
                             fn = os.path.basename(filename.lower())
                             f = re.sub(p,'',fn)
                             g = re.search(re.escape(f),fp.lower())
                             if f and g is not None:
                                 if f == g.group(0):
                                     return filename
                             else:
                                 self.log_msg(" [ARTWORK] No match for " + fp + " in " + dirname, 1)
                     else:
                         for ff in file_formats:
                             basename = '%s.%s' % (fp, ff)
                             #build list of possible filenames
                             fnl = [os.path.join(dirname, basename),
                                    os.path.join(dirname, basename.lower()),
                                    os.path.join(dirname, basename.upper())]
                             #return first valid match
                             for filename in fnl:
                                 if os.path.isfile(filename):
                                     return filename
                 else:
                     for ff in file_formats:
                         basename = '%s.%s' % (fp, ff)
                         #build list of possible filenames
                         fnl = [os.path.join(dirname, basename),
                                os.path.join(dirname, basename.lower()),
                                os.path.join(dirname, basename.upper())]
                         #return first valid match
                         for filename in fnl:
                             if os.path.isfile(filename):
                                 return filename
                             
             else:
                 filename = os.path.join(dirname, fp)
                 if os.path.isfile(filename):
                     return filename
     #done - nothing found
     return ''
コード例 #3
0
    def get_matching_filename(self, file_prefixes, file_formats):
        """return the filename if it exists from given formats & path
              file_prefixes = [(dir_name, filename), ...]
              file_formats = [file_ext1, file_ext2, ...]
        """
        p = '^[\w\s,-/\'][^\.\(]+'
        #check lower & upper case filenames for each given prefix & format
        for dirname, fp in file_prefixes:
            if fp == '##random##':
                for ff in file_formats:
                    fnl = walk_dir(dirname, False, '*.%s' % ff.lower(), False) + \
                        walk_dir(dirname, False, '*.%s' % ff.upper(), False)
                    #return first valid match
                    for filename in fnl:
                        if os.path.isfile(filename):
                            return filename
            elif fp:
                if file_formats:
                    # Check if this is a layout
                    l = re.search(self.wahcade_ini.get('layout'),dirname)
                    if l is None:
                        if self.wahcade_ini.getint('fuzzy_artwork_search') == 1:
                            fileset = glob.iglob(os.path.join(CONFIG_DIR, dirname, fp[:4] + "*"))
                            for filename in fileset:
                                f = re.search(p,os.path.basename(filename.lower()))
                                g = re.search(p,fp.lower())
                                if f and g is not None:
                                    if f.group(0) == g.group(0):
                                        return filename
                                    else:
                                        self.log_msg(" [ARTWORK] No match for " + fp + " in " + dirname, 1)

                        else:
                            for ff in file_formats:
                                basename = '%s.%s' % (fp, ff)
                                #build list of possible filenames
                                fnl = [os.path.join(dirname, basename),
                                       os.path.join(dirname, basename.lower()),
                                       os.path.join(dirname, basename.upper())]
                                #return first valid match
                                for filename in fnl:
                                    if os.path.isfile(filename):
                                        return filename
                    else:
                        for ff in file_formats:
                            basename = '%s.%s' % (fp, ff)
                            #build list of possible filenames
                            fnl = [os.path.join(dirname, basename),
                                   os.path.join(dirname, basename.lower()),
                                   os.path.join(dirname, basename.upper())]
                            #return first valid match
                            for filename in fnl:
                                if os.path.isfile(filename):
                                    return filename
                                
                else:
                    filename = os.path.join(dirname, fp)
                    if os.path.isfile(filename):
                        return filename
        #done - nothing found
        return ''
コード例 #4
0
    def get_matching_filename(self, file_prefixes, file_formats):
        """return the filename if it exists from given formats & path
              file_prefixes = [(dir_name, filename), ...]
              file_formats = [file_ext1, file_ext2, ...]
        """
        p = re.compile('(\.[^\.]+$)|(\s(\(|\[).+(?<=(\)|\]|\s))\.[^\.]+$)')
        self.wahcade_ini = MameWahIni(os.path.join(CONFIG_DIR, 'wahcade.ini'))
        l = self.wahcade_ini.get('layout')
        fz = self.wahcade_ini.getint('fuzzy_artwork_search')
        #check lower & upper case filenames for each given prefix & format
        for dirname, fp in file_prefixes:
            if fp == '##random##':
                for ff in file_formats:
                    fnl = walk_dir(dirname, False, '*.%s' % ff.lower(), False) + \
                        walk_dir(dirname, False, '*.%s' % ff.upper(), False)
                    #return first valid match
                    for filename in fnl:
                        if os.path.isfile(filename):
                            return filename
            elif fp != '':
                if file_formats != '':
                    # Check if this is a layout
                    if l not in dirname:
                        if fz:
                            # NB: we append a fake extension here to support the regex currently - sairuk
                            #     handles . appearing in filename being treated as an ext
                            fileset = glob.iglob(
                                os.path.join(CONFIG_DIR, dirname,
                                             re.sub(p, '', fp + ".fix") + "*"))
                            for filename in fileset:
                                fn = os.path.basename(filename.lower())
                                f = re.sub(p, '', fn)
                                g = re.search(re.escape(f), fp.lower())
                                if f and g is not None:
                                    if f == g.group(0):
                                        return filename
                                else:
                                    self.log_msg(
                                        " [ARTWORK] No match for " + fp +
                                        " in " + dirname, 1)
                        else:
                            for ff in file_formats:
                                basename = '%s.%s' % (fp, ff)
                                #build list of possible filenames
                                fnl = [
                                    os.path.join(dirname, basename),
                                    os.path.join(dirname, basename.lower()),
                                    os.path.join(dirname, basename.upper())
                                ]
                                #return first valid match
                                for filename in fnl:
                                    if os.path.isfile(filename):
                                        return filename
                    else:
                        for ff in file_formats:
                            basename = '%s.%s' % (fp, ff)
                            #build list of possible filenames
                            fnl = [
                                os.path.join(dirname, basename),
                                os.path.join(dirname, basename.lower()),
                                os.path.join(dirname, basename.upper())
                            ]
                            #return first valid match
                            for filename in fnl:
                                if os.path.isfile(filename):
                                    return filename

                else:
                    filename = os.path.join(dirname, fp)
                    if os.path.isfile(filename):
                        return filename
        #done - nothing found
        return ''
コード例 #5
0
ファイル: wc_common.py プロジェクト: gglass/blinkywah
 def get_matching_filename(self, file_prefixes, file_formats):
     """return the filename if it exists from given formats & path
           file_prefixes = [(dir_name, filename), ...]
           file_formats = [file_ext1, file_ext2, ...]
     """
     p = '^[\w\s,-/\'][^\.\(]+'
     #check lower & upper case filenames for each given prefix & format
     for dirname, fp in file_prefixes:
         if fp == '##random##':
             for ff in file_formats:
                 fnl = walk_dir(dirname, False, '*.%s' % ff.lower(), False) + \
                     walk_dir(dirname, False, '*.%s' % ff.upper(), False)
                 #return first valid match
                 for filename in fnl:
                     if os.path.isfile(filename):
                         return filename
         elif fp != '':
             filelist = []
             if file_formats != '':
                 # Check if this is a layout
                 l = re.search(self.wahcade_ini.get('layout'),dirname)
                 if l is None:
                     if self.wahcade_ini.getint('fuzzy_artwork_search') == 1:
                         #Strip down input name
                         f = re.search(p,fp.lower())
                         if f is not None:
                             # Fix for windows lookup
                             if dirname:
                                 if sys.platform != 'win32':
                                     mfile = dirname + '/' + f.group(0)
                                 else:
                                     mfile = dirname + f.group(0)
                                 fileset = glob.glob(os.path.join(CONFIG_DIR, dirname, "*"))
                                 for filename in fileset:
                                     m = re.search(p,filename.lower())
                                     if m is not None:
                                         if m.group(0) == mfile:
                                             return filename
                                 self.log_msg(" [ARTWORK] No match for " + fp + " using " + f.group(0) + " in " + dirname, 1)
                     else:
                         for ff in file_formats:
                             basename = '%s.%s' % (fp, ff)
                             #build list of possible filenames
                             fnl = [os.path.join(dirname, basename),
                                    os.path.join(dirname, basename.lower()),
                                    os.path.join(dirname, basename.upper())]
                             #return first valid match
                             for filename in fnl:
                                 if os.path.isfile(filename):
                                     return filename
                 else:
                     for ff in file_formats:
                         basename = '%s.%s' % (fp, ff)
                         #build list of possible filenames
                         fnl = [os.path.join(dirname, basename),
                                os.path.join(dirname, basename.lower()),
                                os.path.join(dirname, basename.upper())]
                         #return first valid match
                         for filename in fnl:
                             if os.path.isfile(filename):
                                 return filename
                             
             else:
                 filename = os.path.join(dirname, fp)
                 if os.path.isfile(filename):
                     return filename
     #done - nothing found
     return ''