class DDOutput: def __init__(self, cmdo): self.pbar = ProgressBar(BAR_COLOR, block=BAR_CHAR_FULL, empty=BAR_CHAR_EMPTY, width=BAR_WIDTH) self.cmdo = cmdo self.tmp = {} self.tmp['speed'] = ['', ''] """ Update progress """ def put(self, **kwargs): if kwargs.get('f') and kwargs.get('state') == 'ft_finished': self.tmp['speed'] = kwargs.get('f').speed if self.cmdo.quiet: pass elif self.cmdo.verbose: self.put_verbose(*kwargs.values()) else: if self.cmdo.detailed: self.put_bar_extended(*kwargs.values()) else: self.put_bar(*kwargs.values()) """ Print -v(erbose) """ def put_verbose(self, state, task, instance, counter): print '{c}/{ca} {state} \'{from_path}\' \'{to_path}\' {speed}'.format( c=counter+1, ca=task.count(), state=state, from_path=instance.from_path, to_path=instance.to_path, speed=''.join(self.tmp['speed']) ) """ Print bar """ def put_bar(self, state, task, instance, counter): counter = counter+(state == 'ft_finished' and 1 or 0) percent = int(float(counter)/task.count()*100) self.pbar.render(percent, '100%\n[{c}/{ca}] {state} {f}'.format( c=counter, ca=task.count(), f=instance.file(), state=(state == 'ft_finished' and 'Finished' or 'Copying') )) """ Print -d(etailed) bar """ def put_bar_extended(self, state, task, instance, counter): counter = counter+(state == 'ft_finished' and 1 or 0) percent = int(float(counter)/task.count()*100) self.pbar.render(percent, '100%\n[{c}/{ca}] {speed} {state} {basepath}/{f}'.format( c=counter, ca=task.count(), f=instance.file(), state=(state == 'ft_finished' and 'Finished' or 'Copying'), basepath=instance.base_path, speed=''.join(self.tmp['speed']), )) """ Called when task finished, sends notify """ def finished(self, task): if not self.cmdo.quiet: os.system('notify-send %s' % quote('ddcp finished task (%s)' % task.count()))