Exemple #1
0
 def scan(self, paths, exclude=[], cofuncid=None):
     added = []
     exclude = [util.expanduser(path) for path in exclude if path]
     for fullpath in paths:
         print_d("Scanning %r." % fullpath, self)
         desc = _("Scanning %s") % (util.unexpand(util.fsdecode(fullpath)))
         with Task(_("Library"), desc) as task:
             if cofuncid: task.copool(cofuncid)
             fullpath = util.expanduser(fullpath)
             if filter(fullpath.startswith, exclude):
                 continue
             for path, dnames, fnames in os.walk(util.fsnative(fullpath)):
                 for filename in fnames:
                     fullfilename = os.path.join(path, filename)
                     if filter(fullfilename.startswith, exclude):
                         continue
                     if fullfilename not in self._contents:
                         fullfilename = os.path.realpath(fullfilename)
                         if filter(fullfilename.startswith, exclude):
                             continue
                         if fullfilename not in self._contents:
                             item = self.add_filename(fullfilename, False)
                             if item is not None:
                                 added.append(item)
                                 if len(added) > 20:
                                     self.add(added)
                                     added = []
                                     task.pulse()
                                     yield True
                 if added:
                     self.add(added)
                     added = []
                     task.pulse()
                     yield True
Exemple #2
0
    def run(self):
        resp = super(DeleteDialog, self).run()
        if self.__askonly:
            self.destroy()
            return resp

        if resp == 1 or resp == gtk.RESPONSE_DELETE_EVENT: return []
        elif resp == 0: s = _("Moving %(current)d/%(total)d.")
        elif resp == 2: s = _("Deleting %(current)d/%(total)d.")
        else: return []
        files = self.__files
        w = WaitLoadWindow(self, len(files), s)
        removed = []

        if resp == 0:
            for filename in files:
                try:
                    trash.trash(filename)
                except trash.TrashError:
                    fn = util.escape(util.fsdecode(util.unexpand(filename)))
                    ErrorMessage(self, _("Unable to move to trash"),
                        (_("Moving <b>%s</b> to the trash failed.") %
                        fn)).run()
                    break
                removed.append(filename)
                w.step()
        else:
            for filename in files:
                try:
                    os.unlink(filename)
                except EnvironmentError, s:
                    try: s = unicode(s.strerror, const.ENCODING, 'replace')
                    except TypeError:
                        s = unicode(s.strerror[1], const.ENCODING, 'replace')
                    s = "\n\n" + s
                    fn = util.escape(util.fsdecode(util.unexpand(filename)))
                    ErrorMessage(
                        self, _("Unable to delete file"),
                        (_("Deleting <b>%s</b> failed.") % fn) + s).run()
                    break
                removed.append(filename)
                w.step()
Exemple #3
0
    def __create_window(self, Kind, value, traceback, dump, minidump):
        window = gtk.Window()
        window.set_default_size(400, 400)
        window.set_border_width(12)
        window.set_title(_("Error Occurred"))

        label = gtk.Label(_("""\
An exception has occured in Quod Libet. A dump file has been saved to <b>%s</b> that will help us debug the crash. Please file a new issue at http://code.google.com/p/quodlibet/issues/list and attach this file or include its contents. This file may contain some identifying information about you or your system, such as a list of recent files played. If this is unacceptable, send <b>%s</b> instead with a description of what you were doing.

Quod Libet may now be unstable. Closing it and restarting is recommended. Your library will be saved.""")
                          % (util.unexpand(dump), util.unexpand(minidump)))
        label.set_selectable(True)
        label.set_use_markup(True)
        label.set_line_wrap(True)
        box = gtk.VBox(spacing=6)
        buttons = gtk.HButtonBox()
        view = gtk.TreeView()
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
        sw.set_shadow_type(gtk.SHADOW_IN)
        sw.add(view)
        model = gtk.ListStore(str, str, int)
        self.__fill_list(view, model, value, traceback)
        view.set_model(model)
        cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
        close = gtk.Button(stock=gtk.STOCK_QUIT)
        buttons.pack_start(close)
        buttons.pack_start(cancel)
        box.pack_start(label, expand=False)
        box.pack_start(sw)
        box.pack_start(buttons, expand=False)
        window.add(box)

        window.connect('destroy', self.__destroy)
        cancel.connect_object('clicked', gtk.Window.destroy, window)
        close.connect('clicked', lambda *x: app.quit())

        window.show_all()
        filename = util.unexpand(dump)
        offset = label.get_text().decode("utf-8").find(filename)
        label.select_region(offset, offset + len(filename))
        return window
Exemple #4
0
    def _file(self, song, box):
        def ftime(t):
            if t == 0:
                return _("Unknown")
            else:
                timestr = time.strftime("%c", time.localtime(t))
                return timestr.decode(const.ENCODING)

        fn = util.fsdecode(util.unexpand(song["~filename"]))
        length = util.format_time_long(song.get("~#length", 0))
        size = util.format_size(
            song.get("~#filesize") or util.size(song["~filename"]))
        mtime = ftime(util.mtime(song["~filename"]))
        bitrate = song.get("~#bitrate", 0)
        if bitrate != 0:
            bitrate = _("%d kbps") % int(bitrate)
        else: bitrate = False

        t = gtk.Table(4, 2)
        t.set_col_spacings(6)
        t.set_homogeneous(False)
        table = [(_("length"), length),
                 (_("file size"), size),
                 (_("modified"), mtime)]
        if bitrate:
            table.insert(1, (_("bitrate"), bitrate))
        fnlab = Label(fn)
        fnlab.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        t.attach(fnlab, 0, 2, 0, 1, xoptions=gtk.FILL)
        for i, (l, r) in enumerate(table):
            l = "<b>%s</b>" % util.capitalize(util.escape(l) + ":")
            lab = Label()
            lab.set_markup(l)
            t.attach(lab, 0, 1, i + 1, i + 2, xoptions=gtk.FILL)
            t.attach(Label(r), 1, 2, i + 1, i + 2)

        box.pack_start(Frame(_("File"), t), expand=False, fill=False)
Exemple #5
0
 def _cdf(self, column, cell, model, iter, tag):
     value = model[iter][0].comma(tag)
     if not self._needs_update(value): return
     cell.set_property('text', util.unexpand(util.fsdecode(value)))
Exemple #6
0
 def cdf(column, cell, model, iter):
     row = model[iter]
     cell.set_property('text', util.unexpand(row[0]))
Exemple #7
0
 def test_subfile(self):
     self.failUnlessEqual(
         util.unexpand(os.path.join(self.d, "la/la")), "~/la/la")
Exemple #8
0
 def test_noprefix(self):
     self.failUnlessEqual(
         util.unexpand(self.d + "foobar/"), self.d + "foobar/")
Exemple #9
0
 def test_base_trailing(self):
     self.failUnlessEqual(util.unexpand(self.d + "/"), "~/")
Exemple #10
0
 def test_base(self):
     self.failUnlessEqual(util.unexpand(self.d), "~")
Exemple #11
0
 def cdf(column, cell, model, iter):
     cell.set_property("markup", "<b>%s</b> line %d\n\t%s" % (
         util.escape(model[iter][1]), model[iter][2],
         util.escape(util.unexpand(model[iter][0]))))