Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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'])
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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'])
Exemplo n.º 7
0
 def test_nested(self):
     console.info('1', ['1a', ['1b1', '1b2']])
     out, err = self.finish()
     self.assertEqual(out, ['1', '.1a', '..1b1', '..1b2'])