def __save(self, *data): """Save the cover and spawn the program to edit it if selected""" filename = self.name_combo.get_active_text() # Allow support for filename patterns pattern = Pattern(filename) filename = fsencode(pattern.format(self.song)) file_path = os.path.join(self.dirname, filename) msg = (_('The file <b>%s</b> already exists.\n\nOverwrite?') % util.escape(filename)) if (os.path.exists(file_path) and not qltk.ConfirmAction(None, _('File exists'), msg).run()): return try: f = open(file_path, 'wb') f.write(self.current_data) f.close() except IOError: qltk.ErrorMessage(None, _('Saving failed'), _('Unable to save "%s".') % file_path).run() else: if self.open_check.get_active(): try: util.spawn([self.cmd.get_text(), file_path]) except: pass app.window.emit("artwork-changed", [self.song]) self.main_win.destroy()
def __save(self, *data): """Save the cover and spawn the program to edit it if selected""" save_format = self.name_combo.get_active_text() # Allow use of patterns in creating cover filenames pattern = ArbitraryExtensionFileFromPattern( save_format.decode("utf-8")) filename = pattern.format(self.song) print_d("Using '%s' as filename based on %s" % (filename, save_format)) file_path = os.path.join(self.dirname, filename) if os.path.exists(file_path): resp = ConfirmFileReplace(self, file_path).run() if resp != ConfirmFileReplace.RESPONSE_REPLACE: return try: f = open(file_path, 'wb') f.write(self.current_data) f.close() except IOError: qltk.ErrorMessage(None, _('Saving failed'), _('Unable to save "%s".') % file_path).run() else: if self.open_check.get_active(): try: util.spawn([self.cmd.get_text(), file_path]) except: pass app.cover_manager.cover_changed([self.song]) self.main_win.destroy()
def __save(self, *data): """Save the cover and spawn the program to edit it if selected""" save_format = self.name_combo.get_active_text() # Allow use of patterns in creating cover filenames pattern = ArbitraryExtensionFileFromPattern( save_format.decode("utf-8")) filename = pattern.format(self.song) print_d("Using '%s' as filename based on %s" % (filename, save_format)) file_path = os.path.join(self.dirname, filename) msg = (_('The file <b>%s</b> already exists.\n\nOverwrite?') % util.escape(filename)) if (os.path.exists(file_path) and not qltk.ConfirmAction(None, _('File exists'), msg).run()): return try: f = open(file_path, 'wb') f.write(self.current_data) f.close() except IOError: qltk.ErrorMessage(None, _('Saving failed'), _('Unable to save "%s".') % file_path).run() else: if self.open_check.get_active(): try: util.spawn([self.cmd.get_text(), file_path]) except: pass app.window.emit("artwork-changed", [self.song]) self.main_win.destroy()
def plugin_songs(self, songs): if self.prog_name is None: return args, reverse = self.burn_programs[self.prog_name] songs = sorted(songs, key=lambda s: s.sort_key, reverse=reverse) util.spawn(args + [song['~filename'] for song in songs])
def __save(self, *data): """Save the cover and spawn the program to edit it if selected""" save_format = self.name_combo.get_active_text() # Allow use of patterns in creating cover filenames pattern = ArbitraryExtensionFileFromPattern(save_format) filename = pattern.format(self.song) print_d("Using '%s' as filename based on %s" % (filename, save_format)) file_path = os.path.join(self.dirname, filename) if os.path.exists(file_path): resp = ConfirmFileReplace(self, file_path).run() if resp != ConfirmFileReplace.RESPONSE_REPLACE: return try: f = open(file_path, 'wb') f.write(self.current_data) f.close() except IOError: qltk.ErrorMessage(None, _('Saving failed'), _('Unable to save "%s".') % file_path).run() else: if self.open_check.get_active(): try: util.spawn([self.cmd.get_text(), file_path]) except: pass app.cover_manager.cover_changed([self.song._song]) self.main_win.destroy()
def run(self, songs): """ Runs this command on `songs`, splitting into multiple calls if necessary """ args = [] if self.parameter: value = GetStringDialog(None, _("Input value"), _("Value for %s?") % self.parameter).run() self.command = self.command.format(**{self.parameter: value}) print_d("Actual command=%s" % self.command) for song in songs: arg = str(self.__pat.format(song)) if not arg: print_w("Couldn't build shell command using \"%s\"." "Check your pattern?" % self.pattern) break if not self.unique: args.append(arg) elif arg not in args: args.append(arg) max = int((self.max_args or 10000)) com_words = self.command.split(" ") while args: print_d( "Running %s with %d substituted arg(s) (of %d%s total)..." % (self.command, min(max, len(args)), len(args), " unique" if self.unique else "")) util.spawn(com_words + args[:max]) args = args[max:]
def run(self, songs): """ Runs this command on `songs`, splitting into multiple calls if necessary """ args = [] if self.parameter: value = GetStringDialog(None, _("Input value"), _("Value for %s?") % self.parameter).run() self.command = self.command.format(**{self.parameter: value}) print_d("Actual command=%s" % self.command) for song in songs: arg = str(self.__pat.format(song)) if not arg: print_w("Couldn't build shell command using \"%s\"." "Check your pattern?" % self.pattern) break if not self.unique: args.append(arg) elif arg not in args: args.append(arg) max = int((self.max_args or 10000)) com_words = self.command.split(" ") while args: print_d("Running %s with %d substituted arg(s) (of %d%s total)..." % (self.command, min(max, len(args)), len(args), " unique" if self.unique else "")) util.spawn(com_words + args[:max]) args = args[max:]
def run(self, songs): if self.type == self.FOLDERS: files = [song("~dirname") for song in songs] elif self.type == self.FILES: files = [song("~filename") for song in songs] elif self.type == self.URIS: files = [song("~uri") for song in songs] files = dict.fromkeys(files).keys() util.spawn(self.command.split() + files)
def run(self, songs, playlist_name=None): """ Runs this command on `songs`, splitting into multiple calls if necessary. `playlist_name` if populated contains the Playlist's name. """ args = [] template_vars = {} if self.parameter: value = GetStringDialog(None, _("Input value"), _("Value for %s?") % self.parameter).run() template_vars[self.parameter] = value if playlist_name: print_d("Playlist command for %s" % playlist_name) template_vars["PLAYLIST"] = playlist_name actual_command = self.command.format(**template_vars) print_d("Actual command=%s" % actual_command) for i, song in enumerate(songs): wrapped = SongWrapper(song) if playlist_name: wrapped["~playlistname"] = playlist_name wrapped["~playlistindex"] = str(i + 1) wrapped["~#playlistindex"] = i + 1 arg = str(self.__pat.format(wrapped)) if not arg: print_w("Couldn't build shell command using \"%s\"." "Check your pattern?" % self.pattern) break if not self.unique: args.append(arg) elif arg not in args: args.append(arg) max = int((self.max_args or 10000)) com_words = actual_command.split(" ") if self.reverse: args.reverse() while args: print_d( "Running %s with %d substituted arg(s) (of %d%s total)..." % (actual_command, min(max, len(args)), len(args), " unique" if self.unique else "")) util.spawn(com_words + args[:max]) args = args[max:]
def run(self, songs, playlist_name=None): """ Runs this command on `songs`, splitting into multiple calls if necessary. `playlist_name` if populated contains the Playlist's name. """ args = [] template_vars = {} if self.parameter: value = GetStringDialog(None, _("Input value"), _("Value for %s?") % self.parameter).run() template_vars[self.parameter] = value if playlist_name: print_d("Playlist command for %s" % playlist_name) template_vars["PLAYLIST"] = playlist_name self.command = self.command.format(**template_vars) print_d("Actual command=%s" % self.command) for i, song in enumerate(songs): wrapped = SongWrapper(song) if playlist_name: wrapped["~playlistname"] = playlist_name wrapped["~playlistindex"] = str(i + 1) wrapped["~#playlistindex"] = i + 1 arg = str(self.__pat.format(wrapped)) if not arg: print_w("Couldn't build shell command using \"%s\"." "Check your pattern?" % self.pattern) break if not self.unique: args.append(arg) elif arg not in args: args.append(arg) max = int((self.max_args or 10000)) com_words = self.command.split(" ") while args: print_d("Running %s with %d substituted arg(s) (of %d%s total)..." % (self.command, min(max, len(args)), len(args), " unique" if self.unique else "")) util.spawn(com_words + args[:max]) args = args[max:]
def __stack_row_activated(self, view, path, column): model = view.get_model() filename = model[path][0] line = model[path][2] util.spawn(["sensible-editor", "+%d" % line, filename])
def test_get_output(self): if is_win: return fileobj = util.spawn(["echo", "'$1'", '"$2"', ">3"], stdout=True) self.failUnlessEqual(fileobj.read().split(), ["'$1'", '"$2"', ">3"])
def test_simple(self): if is_win: return self.failUnless(util.spawn(["ls", "."], stdout=True))
def test_simple(self): self.failUnless(util.spawn(["ls", "."], stdout=True))
def plugin_songs(self, songs): if self.prog_name is None: return cmd, arg = self.burn_programs[self.prog_name] util.spawn([cmd, arg] + [song['~filename'] for song in songs])