示例#1
0
文件: tagger.py 项目: rdswift/picard
 def add_files(self, filenames, target=None):
     """Add files to the tagger."""
     ignoreregex = None
     config = get_config()
     pattern = config.setting['ignore_regex']
     if pattern:
         try:
             ignoreregex = re.compile(pattern)
         except re.error as e:
             log.error(
                 "Failed evaluating regular expression for ignore_regex: %s",
                 e)
     ignore_hidden = config.setting["ignore_hidden_files"]
     new_files = []
     for filename in filenames:
         filename = normpath(filename)
         if ignore_hidden and is_hidden(filename):
             log.debug("File ignored (hidden): %r" % (filename))
             continue
         # Ignore .smbdelete* files which Applie iOS SMB creates by renaming a file when it cannot delete it
         if os.path.basename(filename).startswith(".smbdelete"):
             log.debug("File ignored (.smbdelete): %r", filename)
             continue
         if ignoreregex is not None and ignoreregex.search(filename):
             log.info("File ignored (matching %r): %r" %
                      (pattern, filename))
             continue
         if filename not in self.files:
             file = open_file(filename)
             if file:
                 self.files[filename] = file
                 new_files.append(file)
             QtCore.QCoreApplication.processEvents()
     if new_files:
         log.debug("Adding files %r", new_files)
         new_files.sort(key=lambda x: x.filename)
         self.window.set_sorting(False)
         self._pending_files_count += len(new_files)
         unmatched_files = []
         for i, file in enumerate(new_files):
             file.load(
                 partial(self._file_loaded,
                         target=target,
                         unmatched_files=unmatched_files))
             # Calling processEvents helps processing the _file_loaded
             # callbacks in between, which keeps the UI more responsive.
             # Avoid calling it to often to not slow down the loading to much
             # Using an uneven number to have the unclustered file counter
             # not look stuck in certain digits.
             if i % 17 == 0:
                 QtCore.QCoreApplication.processEvents()
示例#2
0
 def drop_urls(urls, target, move_to_multi_tracks=True):
     files = []
     new_paths = []
     tagger = QtCore.QObject.tagger
     for url in urls:
         log.debug("Dropped the URL: %r", url.toString(QtCore.QUrl.RemoveUserInfo))
         if url.scheme() == "file" or not url.scheme():
             filename = normpath(url.toLocalFile().rstrip("\0"))
             file = tagger.files.get(filename)
             if file:
                 files.append(file)
             else:
                 new_paths.append(filename)
         elif url.scheme() in ("http", "https"):
             file_lookup = tagger.get_file_lookup()
             file_lookup.mbid_lookup(url.path(), browser_fallback=False)
     if files:
         tagger.move_files(files, target, move_to_multi_tracks)
     if new_paths:
         tagger.add_paths(new_paths, target=target)