def archive_gpg(config, archive): """ Copy `~/.gnupg` into the archive. """ dest = archive / '.gnupg'; mkdir(dest) # Don't try to copy sockets (S.*); it won't work. srcs = list(ls('~/.gnupg', reject='S.*')) cp(srcs, dest)
def test_cp_animator(): """copy nonexistent file to new file""" # setup f1 = 'f1' f2 = 'f2' # run test with pytest.raises(IOError): cp(f1, f2)
def test_cp_ground(): """copy nonexistent file to new file""" # setup f1 = to_path('f1') f2 = to_path('f2') # run test with pytest.raises(IOError): cp(f1, f2)
def test_cp_animator(): """copy nonexistent file to new file""" # setup f1 = "f1" f2 = "f2" # run test with pytest.raises(IOError): cp(f1, f2)
def initialize_configs(initialize): with cd(tests_dir): cp("CONFIGS", ".config/emborg") rm(".config/emborg/subdir") for p in lsf(".config/emborg"): contents = p.read_text() contents = contents.replace('⟪EMBORG⟫', emborg_dir) p.write_text(contents) touch(".config/.nobackup")
def initialize(): with cd(tests_dir): rm("configs .config .local repositories configs.symlink".split()) cp("CONFIGS", "configs") mkdir(".config repositories .local".split()) ln("~/.local/bin", ".local/bin") ln("~/.local/lib", ".local/lib") ln("configs", "configs.symlink") os.environ["HOME"] = str(cwd())
def test_cp_ground(): """copy nonexistent file to new file""" # setup f1 = to_path("f1") f2 = to_path("f2") # run test with pytest.raises(IOError): cp(f1, f2)
def test_cp_real_downturn(): """copy existing file (ie: not generated by test_cp_real_downturn) to new file""" # setup f1 = to_path('tests/SRCFILE') f2 = to_path('f2') # run test cp(f1, f2) # check assert f2.is_file() # cleanup rm(f2)
def backup(self, extension): """Creates a backup copy of the file. The name of the new file has the specified extension prepended to the existing suffixes. """ # prepend extension to list of suffixes suffixes = self.path.suffixes stem = self.path.stem.partition(".")[0] # remove all suffixes new = to_path(self.path.parent, "".join([stem, extension] + suffixes)) self.backup_path = new cp(self.path, new) return new
def test_cp_demystify(): """copy file to new file""" # setup f1 = 'f1' touch(f1) f2 = 'f2' # run test cp(f1, f2) # check assert to_path(f2).is_file() # cleanup rm(f1, f2)
def test_cp_incense(): """copy two files into a nonexistent directory""" # setup d1 = to_path('d1') f1 = to_path('f1') touch(f1) f2 = to_path('f2') touch(f2) # run test with pytest.raises(OSError): cp([f1, f2], d1) # cleanup rm(f1, f2)
def test_cp_adieu(): """copy two files to a new directory""" # setup d1 = 'd1' f1 = 'f1' touch(f1) f2 = 'f2' touch(f2) # run test with pytest.raises(OSError): cp(f1, f2, d1) # cleanup rm(f1, f2, d1)
def test_cp_downturn(): """copy file to new file""" # setup f1 = to_path("f1") touch(f1) f2 = to_path("f2") # run test cp(f1, f2) # check assert f2.is_file() # cleanup rm(f1, f2)
def test_cp_incense(): """copy two files into a nonexistent directory""" # setup d1 = to_path("d1") f1 = to_path("f1") touch(f1) f2 = to_path("f2") touch(f2) # run test with pytest.raises(OSError): cp([f1, f2], d1) # cleanup rm(f1, f2)
def test_cp_cymbal(): """copy two files to a new directory""" # setup d1 = to_path('d1') f1 = to_path('f1') touch(f1) f2 = to_path('f2') touch(f2) # run test with pytest.raises(OSError): cp(f1, f2, d1) # cleanup rm(f1, f2, d1)
def test_cp_downturn(): """copy file to new file""" # setup f1 = to_path('f1') touch(f1) f2 = to_path('f2') # run test cp(f1, f2) # check assert f2.is_file() # cleanup rm(f1, f2)
def test_cp_adieu(): """copy two files to a new directory""" # setup d1 = "d1" f1 = "f1" touch(f1) f2 = "f2" touch(f2) # run test with pytest.raises(OSError): cp(f1, f2, d1) # cleanup rm(f1, f2, d1)
def test_cp_cymbal(): """copy two files to a new directory""" # setup d1 = to_path("d1") f1 = to_path("f1") touch(f1) f2 = to_path("f2") touch(f2) # run test with pytest.raises(OSError): cp(f1, f2, d1) # cleanup rm(f1, f2, d1)
def test_cp_dealer(): """copy two files into a nonexistent directory""" # setup d1 = 'd1' f1 = 'f1' touch(f1) f2 = 'f2' touch(f2) # run test with pytest.raises(OSError): cp([f1, f2], d1) # cleanup rm(f1, f2)
def test_cp_demystify(): """copy file to new file""" # setup f1 = "f1" touch(f1) f2 = "f2" # run test cp(f1, f2) # check assert to_path(f2).is_file() # cleanup rm(f1, f2)
def test_cp_dealer(): """copy two files into a nonexistent directory""" # setup d1 = "d1" f1 = "f1" touch(f1) f2 = "f2" touch(f2) # run test with pytest.raises(OSError): cp([f1, f2], d1) # cleanup rm(f1, f2)
def test_cp_endorse(): """copy file to existing file""" # setup f1 = to_path('f1') touch(f1) f2 = to_path('f2') touch(f2) # run test cp(f1, f2) # check assert f2.is_file() # cleanup rm(f1, f2)
def test_cp_overheat(): """copy file into an existing directory""" # setup d1 = 'd1' mkdir(d1) f1 = 'f1' touch(f1) # run test cp(f1, d1) # check assert to_path('d1/f1').is_file() # cleanup rm(d1)
def test_cp_ruminate(): """copy two files into an existing file""" # setup f1 = to_path('f1') touch(f1) f2 = to_path('f2') touch(f2) f3 = to_path('f2') touch(f3) # run test with pytest.raises(OSError): cp(f1, f2, f3) # cleanup rm(f1, f2, f3)
def test_cp_attache(): """copy two files into an existing file""" # setup f1 = "f1" touch(f1) f2 = "f2" touch(f2) f3 = "f2" touch(f3) # run test with pytest.raises(OSError): cp(f1, f2, f3) # cleanup rm(f1, f2, f3)
def test_cp_theorem(): """copy file to existing file""" # setup f1 = 'f1' touch(f1) f2 = 'f2' touch(f2) # run test cp(f1, f2) # check assert to_path(f2).is_file() # cleanup rm(f1, f2)
def test_cp_gathering(): """copy file into an existing directory""" # setup d1 = to_path("d1") mkdir(d1) f1 = to_path("f1") touch(f1) # run test cp(f1, d1) # check assert to_path("d1/f1").is_file() # cleanup rm(d1)
def test_cp_attache(): """copy two files into an existing file""" # setup f1 = 'f1' touch(f1) f2 = 'f2' touch(f2) f3 = 'f2' touch(f3) # run test with pytest.raises(OSError): cp(f1, f2, f3) # cleanup rm(f1, f2, f3)
def test_cp_ruminate(): """copy two files into an existing file""" # setup f1 = to_path("f1") touch(f1) f2 = to_path("f2") touch(f2) f3 = to_path("f2") touch(f3) # run test with pytest.raises(OSError): cp(f1, f2, f3) # cleanup rm(f1, f2, f3)
def test_cp_theorem(): """copy file to existing file""" # setup f1 = "f1" touch(f1) f2 = "f2" touch(f2) # run test cp(f1, f2) # check assert to_path(f2).is_file() # cleanup rm(f1, f2)
def test_cp_endorse(): """copy file to existing file""" # setup f1 = to_path("f1") touch(f1) f2 = to_path("f2") touch(f2) # run test cp(f1, f2) # check assert f2.is_file() # cleanup rm(f1, f2)
def test_cp_gathering(): """copy file into an existing directory""" # setup d1 = to_path('d1') mkdir(d1) f1 = to_path('f1') touch(f1) # run test cp(f1, d1) # check assert to_path('d1/f1').is_file() # cleanup rm(d1)
def test_cp_convict(): """copy directory into an nonexistent directory""" # setup d1 = 'd1' mkdir(d1) f1 = 'd1/f1' touch(f1) d2 = 'd2' # run test cp(d1, d2) # check assert to_path('d2/f1').is_file() # cleanup rm(d1, d2)
def test_cp_convict(): """copy directory into an nonexistent directory""" # setup d1 = "d1" mkdir(d1) f1 = "d1/f1" touch(f1) d2 = "d2" # run test cp(d1, d2) # check assert to_path("d2/f1").is_file() # cleanup rm(d1, d2)
def test_cp_calculate(): """copy two files into an existing directory""" # setup d1 = 'd1' mkdir(d1) f1 = 'f1' touch(f1) f2 = 'f2' touch(f2) # run test cp(f1, f2, d1) # check assert to_path('d1/f1').is_file() assert to_path('d1/f2').is_file() # cleanup rm(d1)
def test_cp_headstone(): """copy directory into an existing directory""" # setup d1 = 'd1' mkdir(d1) f1 = 'd1/f1' touch(f1) d2 = 'd2' mkdir(d2) # run test cp(d1, d2) # check assert to_path('d2/d1').is_dir() assert to_path('d2/d1/f1').is_file() # cleanup rm(d1, d2)
def test_cp_headstone(): """copy directory into an existing directory""" # setup d1 = "d1" mkdir(d1) f1 = "d1/f1" touch(f1) d2 = "d2" mkdir(d2) # run test cp(d1, d2) # check assert to_path("d2/d1").is_dir() assert to_path("d2/d1/f1").is_file() # cleanup rm(d1, d2)
def test_cp_liaise(): """copy two files into an existing directory""" # setup d1 = to_path('d1') mkdir(d1) f1 = to_path('f1') touch(f1) f2 = to_path('f2') touch(f2) # run test cp([f1, f2], d1) # check assert to_path('d1/f1').is_file() assert to_path('d1/f2').is_file() # cleanup rm(d1, f1, f2)
def publish_mount(config, workspace): """ Copy the archive to one or more mounted/mountable drives. """ drives = require_one_or_more(config, 'drive') remote_dir = config.get('remote_dir', 'backup/sparekeys') remote_dir = remote_dir.format(**PARAMS) for drive in drives: narrate(f"copying archive to '{drive}'.") try: with mount(drive): dest = to_path(drive, remote_dir) rm(dest); mkdir(dest) cp(workspace, dest) except Error as e: error(e, culprit=drive, codicil='Skipping.') else: display(f"Archive copied to '{drive}'.")
def test_cp_hairbrush(): """copy two files into an existing directory""" # setup d1 = "d1" mkdir(d1) f1 = "f1" touch(f1) f2 = "f2" touch(f2) # run test cp([f1, f2], d1) # check assert to_path("d1/f1").is_file() assert to_path("d1/f2").is_file() # cleanup rm(d1, f1, f2)
def test_cp_hairbrush(): """copy two files into an existing directory""" # setup d1 = 'd1' mkdir(d1) f1 = 'f1' touch(f1) f2 = 'f2' touch(f2) # run test cp([f1, f2], d1) # check assert to_path('d1/f1').is_file() assert to_path('d1/f2').is_file() # cleanup rm(d1, f1, f2)
def test_cp_mobilize(): """copy directory into an existing directory""" # setup d1 = to_path('d1') mkdir(d1) f1 = to_path('d1/f1') touch(f1) d2 = to_path('d2') mkdir(d2) # run test cp(d1, d2) # check assert to_path('d2/d1').is_dir() assert to_path('d2/d1/f1').is_file() # cleanup rm(d1, d2)
def test_cp_quisling(): """copy two files into an existing directory""" # setup d1 = to_path("d1") mkdir(d1) f1 = to_path("f1") touch(f1) f2 = to_path("f2") touch(f2) # run test cp(f1, f2, d1) # check assert to_path("d1/f1").is_file() assert to_path("d1/f2").is_file() # cleanup rm(d1)
def load_config(): config_dir = to_path(appdirs.user_config_dir(__slug__)) config_path = config_dir / 'config.toml' inform = get_informer() inform.set_logfile(config_dir / 'log') if not config_path.exists(): display(f"'{config_path}' not found, installing defaults.") defaults = to_path(__file__).parent / 'default_config.toml' mkdir(config_dir) cp(defaults, config_path) try: config = toml.load(config_path) except toml.decoder.TomlDecodeError as e: raise ConfigError(str(e), culprit=config_path) # Set default values for options that are accessed in multiple places: config.setdefault('plugins', {}) config['plugins'].setdefault('archive', []) config['plugins'].setdefault('auth', []) config['plugins'].setdefault('publish', []) return config_path, config
def restore(self): "Restores the backup copy of the file." cp(self.backup_path, self.path)
def copy_to_archive(path, archive): src = to_path(path) dest = archive / src.relative_to(to_path('~')) mkdir(dest.parent) cp(src, dest)