def test_accepts_good_format(self): good = obnamlib.RepositoryFormat6 fs = obnamlib.LocalFS(self.repodir) fs.write_file('metadata/format', good.format) factory = obnamlib.RepositoryFactory() repo = factory.open_existing_repo(fs) self.assertTrue(isinstance(repo, good))
def test_create_repo_is_ok_with_existing_repo(self): good = obnamlib.RepositoryFormat6 fs = obnamlib.LocalFS(self.repodir) fs.write_file('metadata/format', good.format) factory = obnamlib.RepositoryFactory() repo = factory.create_repo(fs, good) self.assertTrue(isinstance(repo, good))
def test_create_repo_twice_is_ok(self): good = obnamlib.RepositoryFormat6 fs = obnamlib.LocalFS(self.repodir) factory = obnamlib.RepositoryFactory() repo = factory.create_repo(fs, good) self.assertTrue(isinstance(repo, good)) repo2 = factory.create_repo(fs, good) self.assertTrue(isinstance(repo2, good))
def test_raises_exception_for_unknown_format(self): fs = obnamlib.LocalFS(self.repodir) fs.write_file('metadata/format', 'unknown') factory = obnamlib.RepositoryFactory() self.assertRaises( obnamlib.UnknownRepositoryFormat, factory.open_existing_repo, fs)
def setUp(self): self.tempdir = tempfile.mkdtemp() fs = obnamlib.LocalFS(self.tempdir) self.hooks = obnamlib.HookManager() repo_factory = obnamlib.RepositoryFactory() repo_factory.setup_hooks(self.hooks) self.repo = obnamlib.RepositoryFormat6(hooks=self.hooks) self.repo.set_fs(fs)
def setUp(self): self.tempdir = tempfile.mkdtemp() fs = obnamlib.LocalFS(self.tempdir) self.hooks = obnamlib.HookManager() repo_factory = obnamlib.RepositoryFactory() repo_factory.setup_hooks(self.hooks) self.repo = obnamlib.RepositoryFormatGA( hooks=self.hooks, current_time=time.time, dir_bag_size=1, dir_cache_size=0, checksum_algorithm='sha512') self.repo.set_fs(fs)
def test_raises_error_when_unknown_format_requested(self): fs = obnamlib.LocalFS(self.repodir) factory = obnamlib.RepositoryFactory() self.assertRaises(obnamlib.UnknownRepositoryFormatWanted, factory.create_repo, fs, int)
def test_returns_list_of_implementation_classes(self): factory = obnamlib.RepositoryFactory() self.assertEqual(type(factory.get_implementation_classes()), list)
def add_settings(self): # General settings. self.settings.string(['repository', 'r'], 'name of backup repository', metavar='URL') self.settings.string(['client-name'], 'name of client (defaults to hostname)', default=self.deduce_client_name()) self.settings.boolean( ['quiet'], 'be silent: show only error messages, no progress updates') self.settings.boolean( ['verbose'], 'be verbose: tell the user more of what is going on and ' 'generally make sure the user is aware of what is happening ' 'or at least that something is happening and ' 'also make sure their screen is getting updates frequently ' 'and that there is changes happening all the time so they ' 'do not get bored and that they in fact get frustrated by ' 'getting distracted by so many updates that they will move ' 'into the Gobi desert to live under a rock') self.settings.boolean(['pretend', 'dry-run', 'no-act'], 'do not actually change anything (works with ' 'backup, forget and restore only, and may only ' 'simulate approximately real behavior)') self.settings.integer(['lock-timeout'], 'when locking in the backup repository, ' 'wait TIMEOUT seconds for an existing lock ' 'to go away before giving up', metavar='TIMEOUT', default=60) # Performance related settings. perf_group = obnamlib.option_group['perf'] self.settings.bytesize( ['node-size'], 'size of B-tree nodes on disk; only affects new ' 'B-trees so you may need to delete a client ' 'or repository to change this for existing ' 'repositories', default=obnamlib.DEFAULT_NODE_SIZE, group=perf_group) self.settings.bytesize(['chunk-size'], 'size of chunks of file data backed up', default=obnamlib.DEFAULT_CHUNK_SIZE, group=perf_group) self.settings.bytesize(['upload-queue-size'], 'length of upload queue for B-tree nodes', default=obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE, group=perf_group) self.settings.bytesize(['lru-size'], 'size of LRU cache for B-tree nodes', default=obnamlib.DEFAULT_LRU_SIZE, group=perf_group) self.settings.integer(['idpath-depth'], 'depth of chunk id mapping', default=obnamlib.IDPATH_DEPTH, group=perf_group) self.settings.integer(['idpath-bits'], 'chunk id level size', default=obnamlib.IDPATH_BITS, group=perf_group) self.settings.integer(['idpath-skip'], 'chunk id mapping lowest bits skip', default=obnamlib.IDPATH_SKIP, group=perf_group) # Settings to help developers and development of Obnam. devel_group = obnamlib.option_group['devel'] self.settings.string_list(['trace'], 'add to filename patters for which trace ' 'debugging logging happens', group=devel_group) self.settings.string(['pretend-time'], 'pretend it is TIMESTAMP (YYYY-MM-DD HH:MM:SS); ' 'this is only useful for testing purposes', metavar='TIMESTAMP', group=devel_group) self.settings.integer(['crash-limit'], 'artificially crash the program after COUNTER ' 'files written to the repository; this is ' 'useful for crash testing the application, ' 'and should not be enabled for real use; ' 'set to 0 to disable (disabled by default)', metavar='COUNTER', group=devel_group) # The following needs to be done here, because it needs # to be done before option processing. This is a bit ugly, # but the best we can do with the current cliapp structure. # Possibly cliapp will provide a better hook for us to use # later on, but this is reality now. self.setup_ttystatus() self.fsf = obnamlib.VfsFactory() self.repo_factory = obnamlib.RepositoryFactory() self.setup_hooks() self.settings['log-level'] = 'info'
def list_formats(self, args): factory = obnamlib.RepositoryFactory() formats = factory.get_implementation_classes() for format in formats: self.app.output.write('%s\n' % format.format)