def delete(self, wanted): num = 0 for root, dirs, files in os.walk(self.destpath, topdown=False, followlinks=False): num += 1 if not num % 2000: self.progress(num) for d in dirs: d = os.path.normpath(os.path.join(root, d)) if d not in wanted: yield 'rmdir %s' % escape(d) for f in files: f = os.path.normpath(os.path.join(root, f)) if f not in wanted: yield 'rm %s' % escape(f)
def commands(self): commands = [] wanted = [] num = 0 if self.log: print >>self.log, "Walking source directory..." for root, dirs, files in os.walk(self.path, followlinks=True): num += 1 if not num % 200: self.progress(num) relpath = os.path.relpath(root, self.path) if relpath != '.': destpath = os.path.join(self.destpath, relpath) else: destpath = self.destpath try: d = Directory(root, destpath, self.options, _files=files) c = d.commands() if c: commands.append(c) wanted.extend(d.wanted()) except NotInteresting: pass except NotAllowed as e: commands.append(['echo %s' % escape('%s: %s' % (root, str(e)))]) if self.options['delete']: if self.log: print >>self.log, "Walking destination directory..." c = list(self.delete(wanted)) if c: commands.append(c) return commands
def touch(self, commands): mtime = os.path.getmtime(self.src()) i = localtime(mtime) stamp = "%s%s%s%s%s.%s" % (str(i.tm_year).zfill(4), str(i.tm_mon).zfill(2), str(i.tm_mday).zfill(2), str(i.tm_hour).zfill(2), str(i.tm_min).zfill(2), str(i.tm_sec).zfill(2)) commands.append('touch -t%s -c -m %s' % (stamp, escape(self.dest())))
def vorbisgain(self): return 'vorbisgain -q -s -f -a %s' % escape(os.path.join(self.destpath))
def mkdir(self): return 'mkdir -p %s' % escape(os.path.join(self.destpath))
def transcode(self, commands): rate, bits = self.resample() commands.append('sox -V1 %s -C %s%s %s%s' % (escape(self.src()), self.options['quality'], bits, escape(self.dest()), rate))
def copy(self, commands): if not self.sample_ok(): raise NotAllowed("Sample rate or bit depth too high") commands.append('cp %s %s' % (escape(self.src()), escape(self.dest())))