def build_restore_batch(self, batch): """Populate a command batch for restoring the archive.""" restore_to_dir = disk.get_versioned_path( os.path.basename(self.path)[:-len(self.tar_extension)]) os.mkdir(restore_to_dir) console.info('Restoring to: %s' % restore_to_dir) #TO-DO: Untested batch.add_command('tar', self.tar_restore_options, self.path, '--strip-components', '1', '-C', restore_to_dir)
def check_output_directory(self): """Make sure there's a good output directory.""" if not os.path.isdir(self.options.outputdir): if os.path.exists(self.options.outputdir): console.abort('Output directory exists and is not a directory: %s' % self.options.outputdir) console.info('Creating output directory: %s' % self.options.outputdir) try: os.mkdir(self.options.outputdir) except (IOError, OSError) as exc: console.abort('Unable to create output directory', self.options.outputdir, exc)
def test_simple(self): console.info('info') console.verbose_info('verbose-') self.set_verbose(True) console.verbose_info('verbose+') console.debug('debug-') self.set_debug(True) console.debug('debug+') console.warning('warning') console.error('error') out, err = self.finish() self.assertEqual(out, ['info', 'INFO2: verbose+']) self.assertEqual(err, ['DEBUG: debug+', 'WARNING: warning', 'ERROR: error'])
def choose_archive(name, program_name, output_directory, **item_kwargs): """Prompt for choosing an archive.""" if not os.path.isdir(output_directory): console.abort('No %s directory exists' % output_directory) if name[-1] == '/': name = name[:-1] pat = os.path.join(output_directory, ARCHIVE_NAME_GLOB % name) archives = [] for ls_stream in os.popen('ls %s' % pat): archives.insert(0, ls_stream.strip()) if not archives: console.abort('No archives found') console.info('Newest archive is at the top. Empty input or zero response cancels the action.') for index, archive in range(len(archives)): console.info('%d) %s' % (index + 1, archive)) console.info('') path = None while path is None: archive_index = int( console.prompt_re('Select archive (1-n [none])', NUMBER_WITH_DEFAULT_RE, '0') ) if archive_index <= 0: console.abort('Canceled') if archive_index-1 < len(archives): path = archives[archive_index-1] else: console.error('bad index %d' % archive_index) return item_for_path(path, program_name, **item_kwargs)
def build_restore_batch(self, batch): """Populate a command batch for restoring the archive.""" target = disk.get_versioned_path(self.path) batch.add_copy_command(self.path, target) console.info('Restoring to: %s' % target)
def test_substitution(self): console.info('The {weather} in {country}', 'falls mainly on the {area}', weather='rain', country='Spain', area='plain') out, err = self.finish() self.assertEqual(out, ['The rain in Spain', 'falls mainly on the plain'])
def test_nested(self): console.info('1', ['1a', ['1b1', '1b2']]) out, err = self.finish() self.assertEqual(out, ['1', '.1a', '..1b1', '..1b2'])