def __open(self, *args): try: if not os.path.exists(const.CONTROL): util.mkdir(const.USERDIR) os.mkfifo(const.CONTROL, 0600) fifo = os.open(const.CONTROL, os.O_NONBLOCK) f = os.fdopen(fifo, "r", 4096) gobject.io_add_watch( f, gtk.gdk.INPUT_READ, self.__process, *args) except (EnvironmentError, AttributeError): pass
def test_manydeep(self): self.failUnless(not os.path.isdir("nonext")) util.mkdir("nonext/test/test2/test3") try: self.failUnless(os.path.isdir("nonext/test/test2/test3")) finally: os.rmdir("nonext/test/test2/test3") os.rmdir("nonext/test/test2") os.rmdir("nonext/test") os.rmdir("nonext")
def rename(self, newname): """Rename a file. Errors are not handled. This shouldn't be used directly; use library.rename instead.""" if os.path.isabs(newname): util.mkdir(os.path.dirname(newname)) else: newname = os.path.join(self('~dirname'), newname) if not os.path.exists(newname): shutil.move(self['~filename'], newname) elif os.path.realpath(newname) != self['~filename']: raise ValueError self.sanitize(newname)
def get_thumbnail_folder(): """Returns a path to an existing folder""" if os.name == "nt": thumb_folder = os.path.join(USERDIR, "thumbnails") else: cache_folder = os.path.join(xdg_get_cache_home(), "thumbnails") thumb_folder = os.path.expanduser('~/.thumbnails') if os.path.exists(cache_folder) or not os.path.exists(thumb_folder): thumb_folder = cache_folder mkdir(thumb_folder, 0700) return thumb_folder
from tempfile import NamedTemporaryFile from quodlibet.browsers._base import Browser from quodlibet.formats._audio import AudioFile from quodlibet.util.collection import Playlist from quodlibet.qltk.songsmenu import SongsMenu from quodlibet.qltk.views import RCMHintedTreeView from quodlibet.qltk.wlw import WaitLoadWindow from quodlibet.qltk.getstring import GetStringDialog from quodlibet.qltk.x import ScrolledWindow, Alignment from quodlibet.util.uri import URI from quodlibet.util.dprint import print_d PLAYLISTS = os.path.join(const.USERDIR, "playlists") if not os.path.isdir(PLAYLISTS): util.mkdir(PLAYLISTS) def ParseM3U(filename, library=None): plname = util.fsdecode(os.path.basename( os.path.splitext(filename)[0])).encode('utf-8') filenames = [] for line in file(filename): line = line.strip() if line.startswith("#"): continue else: filenames.append(line) return __ParsePlaylist(plname, filename, filenames, library) def ParsePLS(filename, name="", library=None): plname = util.fsdecode(os.path.basename( os.path.splitext(filename)[0])).encode('utf-8') filenames = []
def test_exists(self): util.mkdir(".")
from quodlibet.util.collection import Album from quodlibet.util.library import background_filter from quodlibet.util.thumbnails import scale EMPTY = _("Songs not in an album") ALBUM_PATTERN = r"""\<b\><album|\<i\><album>\</i\>|%s>\</b\><date| \<small\>(<date>)\</small\>> \<small\><~discs|<~discs> - ><~tracks> - <~long-length>\</small\>""" % EMPTY UNKNOWN_PATTERN = "<b><i>%s</i></b>" % _("Unknown %s") MULTI_PATTERN = "<b><i>%s</i></b>" % _("Multiple %s Values") COUNT_PATTERN = " <span size='small' color='#777'>(%s)</span>" PAT = XMLFromPattern(ALBUM_PATTERN) ALBUM_QUERIES = os.path.join(const.USERDIR, "lists", "album_queries") util.mkdir(os.path.dirname(ALBUM_QUERIES)) def get_headers(): result = [] headers = config.get("browsers", "collection_headers", "") for h in headers.splitlines(): values = h.split() if len(values) != 2: continue tag, merge = values try: result.append((tag, bool(int(merge)))) except ValueError: continue return result
def get_thumbnail(path, boundary): """Get a thumbnail of an image. Will create/use a thumbnail in the user's thumbnail directory if possible. Follows the Free Desktop specification. http://specifications.freedesktop.org/thumbnail-spec/""" width, height = boundary # embedded thumbnails come from /tmp/ # and too big thumbnails make no sense if path.startswith(tempfile.gettempdir()) or \ width > 256 or height > 256 or mtime(path) == 0: return gtk.gdk.pixbuf_new_from_file_at_size(path, width, height) if width <= 128 and height <= 128: size_name = "normal" thumb_size = 128 else: size_name = "large" thumb_size = 256 thumb_folder = get_thumbnail_folder() cache_dir = os.path.join(thumb_folder, size_name) mkdir(cache_dir, 0700) bytes = path if isinstance(path, unicode): bytes = path.encode("utf-8") uri = "file://" + pathname2url(bytes) thumb_name = hash.md5(uri).hexdigest() + ".png" thumb_path = os.path.join(cache_dir, thumb_name) pb = meta_mtime = None if os.path.exists(thumb_path): pb = gtk.gdk.pixbuf_new_from_file(thumb_path) meta_mtime = pb.get_option("tEXt::Thumb::MTime") meta_mtime = meta_mtime and int(meta_mtime) if not pb or meta_mtime != int(mtime(path)): pb = gtk.gdk.pixbuf_new_from_file(path) #Too small picture, no thumbnail needed if pb.get_width() < thumb_size and pb.get_height() < thumb_size: return scale(pb, boundary) mime = gtk.gdk.pixbuf_get_file_info(path)[0]['mime_types'][0] options = { "tEXt::Thumb::Image::Width": str(pb.get_width()), "tEXt::Thumb::Image::Height": str(pb.get_height()), "tEXt::Thumb::URI": uri, "tEXt::Thumb::MTime": str(int(mtime(path))), "tEXt::Thumb::Size": str(os.path.getsize(fsnative(path))), "tEXt::Thumb::Mimetype": mime, "tEXt::Software": "QuodLibet" } pb = scale(pb, (thumb_size, thumb_size)) pb.save(thumb_path, "png", options) os.chmod(thumb_path, 0600) return scale(pb, boundary)