def patch_length(target_dir, verbose=False): song_dir = os.path.join(target_dir, u"In The Groove 2", u"Songs") all_files = [os.path.join(song_dir, f) for f in os.listdir(song_dir)] dirs = [d for d in all_files if os.path.isdir(d)] for song_dir in dirs: song_files = (os.path.join(song_dir, f) for f in os.listdir(song_dir)) ogg_files = (f for f in song_files if f.endswith(".ogg")) for ogg_file in ogg_files: if verbose: logger.info(u"Patching file: {0}".format(ogg_file)) oggpatch.patch_file(ogg_file, verbose=verbose)
def execute(self): input_file = self.input_file.get() if len(input_file) == 0: tkMessageBox.showinfo( title="No input file", message="Please select an input file") return elif not os.path.isfile(input_file): tkMessageBox.showinfo( title="Bad input file", message=("Could not find the specified input file. " "Please re-select the file.")) try: length = self.get_time() except ValueError: tkMessageBox.showinfo( title="Invalid song length", message="Enter a valid song length. (i.e. 1:45, 3:13:37, etc.)") return mode = self.mode.get() if mode == "patch": output_file = self.output_file.get() if len(output_file) == 0: output_file = input_file output_dir = os.path.split(output_file)[0] # Allow the output file to be a dir. In this case take # the input file's name and append it. if os.path.isdir(output_file): output_dir = output_file output_file = os.path.join(output_dir, os.path.basename(input_file)) if not os.path.exists(output_dir): tkMessageBox.showinfo( title="Output directory not found", message=("Output directory does not exist. " "Please check your output file name.")) elif not os.path.isdir(output_dir): tkMessageBox.showinfo( title="Bad output directory", message=("The specified output directory conflicts with " "an existing file. Please use a different " "output file name.")) self.hijack_output() try: oggpatch.patch_file( input_file, length, output_file=output_file, verbose=True) except: print traceback.format_exc() self.restore_output() elif mode == "check": self.hijack_output() try: oggpatch.check_file(input_file, length, verbose=True) except: print traceback.format_exc() self.restore_output() else: raise ValueError("Bad mode", mode)