def test_basic(self): if sys.platform == "win32": res = util.split_scan_dirs(r":Z:\foo:C:/windows:") self.assertEquals(res, [r"Z:\foo", "C:/windows"]) else: res = util.split_scan_dirs(":/home/user/Music:/opt/party:") self.assertEquals(res, ["/home/user/Music", "/opt/party"])
def refresh_cb(button): from quodlibet.library import library from quodlibet.util import copool paths = util.split_scan_dirs(config.get("settings", "scan")) exclude = config.get("library", "exclude").split(":") copool.add(library.rebuild, paths, False, exclude, cofuncid="library", funcid="library")
def get_init_select_dir(): scandirs = util.split_scan_dirs(config.get("settings", "scan")) if scandirs and os.path.isdir(scandirs[-1]): # start with last added directory return scandirs[-1] else: return const.HOME
def __init__(self): super(ScanBox, self).__init__(spacing=6) self.model = model = gtk.ListStore(str) view = RCMHintedTreeView(model) view.set_fixed_height_mode(True) view.set_headers_visible(False) view.set_tooltip_text(_("Songs in the listed folders will be " "added to the library during a library refresh")) menu = gtk.Menu() remove_item = gtk.ImageMenuItem(gtk.STOCK_REMOVE) menu.append(remove_item) menu.show_all() view.connect('popup-menu', self.__popup, menu) remove_item.connect_object('activate', self.__remove, view) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_IN) sw.add(view) sw.set_size_request(-1, max(sw.size_request()[1], 100)) render = gtk.CellRendererText() render.set_property('ellipsize', pango.ELLIPSIZE_END) def cdf(column, cell, model, iter): row = model[iter] cell.set_property('text', util.unexpand(row[0])) column = gtk.TreeViewColumn(None, render) column.set_cell_data_func(render, cdf) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) view.append_column(column) add = gtk.Button(stock=gtk.STOCK_ADD) add.connect("clicked", self.__add) remove = gtk.Button(stock=gtk.STOCK_REMOVE) selection = view.get_selection() selection.set_mode(gtk.SELECTION_MULTIPLE) selection.connect("changed", self.__select_changed, remove) selection.emit("changed") remove.connect_object("clicked", self.__remove, view) vbox = gtk.VBox(spacing=6) vbox.pack_start(add, expand=False) vbox.pack_start(remove, expand=False) self.pack_start(sw) self.pack_start(vbox, expand=False) self.show_all() paths = util.split_scan_dirs(config.get("settings", "scan")) paths = map(util.fsdecode, paths) for path in paths: model.append(row=[path])
def scan_library(library, force): """Start the global library re-scan If `force` is True, reload all existing valid items. """ paths = get_scan_dirs() exclude = util.split_scan_dirs(config.get("library", "exclude")) exclude = [util.fsnative(e) for e in exclude] copool.add(library.rebuild, paths, force, exclude, cofuncid="library", funcid="library")
def open_chooser(self, action): if not os.path.exists(self.last_dir): self.last_dir = const.HOME if action.get_name() == "AddFolders": chooser = FolderChooser(self, _("Add Music"), self.last_dir) cb = gtk.CheckButton(_("Watch this folder for new songs")) cb.set_active(not config.get("settings", "scan")) cb.show() chooser.set_extra_widget(cb) else: chooser = FileChooser( self, _("Add Music"), formats.filter, self.last_dir) cb = None fns = chooser.run() chooser.destroy() if fns: if action.get_name() == "AddFolders": self.last_dir = fns[0] copool.add(self.__library.scan, fns, funcid="library") else: self.last_dir = os.path.basename(fns[0]) for filename in map(os.path.realpath, map(util.fsnative, fns)): if filename in self.__library: continue song = self.__library.add_filename(filename) if not song: from traceback import format_exception_only as feo tb = feo(sys.last_type, sys.last_value) msg = _("%s could not be added to your library.\n\n") msg %= util.escape(util.fsdecode( os.path.basename(filename))) msg += util.escape("".join(tb).decode( const.ENCODING, "replace")) d = ErrorMessage(self, _("Unable to add song"), msg) d.label.set_selectable(True) d.run() continue if cb and cb.get_active(): dirs = util.split_scan_dirs(config.get("settings", "scan")) for fn in fns: if fn not in dirs: dirs.append(fn) dirs = ":".join(dirs) config.set("settings", "scan", dirs)
def __init__(self, library, main): super(FileSystem, self).__init__() sw = ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_IN) folders = filter(None, split_scan_dirs(config.get("settings", "scan"))) dt = DirectoryTree(folders=folders) targets = [("text/x-quodlibet-songs", gtk.TARGET_SAME_APP, 1), ("text/uri-list", 0, 2)] dt.drag_source_set(gtk.gdk.BUTTON1_MASK, targets, gtk.gdk.ACTION_COPY) dt.connect('drag-data-get', self.__drag_data_get) sel = dt.get_selection() sel.unselect_all() sel.connect_object('changed', copool.add, self.__songs_selected, dt) if main: dt.connect('row-activated', lambda *a: self.emit("activated")) sw.add(dt) self.pack_start(sw) self.show_all()
def _refresh(self, library, window, player): paths = util.split_scan_dirs(config.get("settings", "scan")) progress = window.statusbar.progress copool.add(library.rebuild, paths, progress, False, funcid="library")
def __rebuild(self, activator, force): paths = util.split_scan_dirs(config.get("settings", "scan")) exclude = config.get("library", "exclude").split(":") copool.add(self.__library.rebuild, paths, force, exclude, cofuncid="library", funcid="library")
def get_scan_dirs(): dirs = util.split_scan_dirs(config.get("settings", "scan")) return [util.fsnative(d) for d in dirs if d]