Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def test_cp_animator():
    """copy nonexistent file to new file"""
    # setup
    f1 = 'f1'
    f2 = 'f2'

    # run test
    with pytest.raises(IOError):
        cp(f1, f2)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def test_cp_animator():
    """copy nonexistent file to new file"""
    # setup
    f1 = "f1"
    f2 = "f2"

    # run test
    with pytest.raises(IOError):
        cp(f1, f2)
Ejemplo n.º 5
0
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")
Ejemplo n.º 6
0
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())
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
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)
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
0
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)
Ejemplo n.º 31
0
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)
Ejemplo n.º 32
0
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)
Ejemplo n.º 33
0
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)
Ejemplo n.º 34
0
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)
Ejemplo n.º 35
0
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)
Ejemplo n.º 36
0
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)
Ejemplo n.º 37
0
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)
Ejemplo n.º 38
0
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)
Ejemplo n.º 39
0
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)
Ejemplo n.º 40
0
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}'.")
Ejemplo n.º 41
0
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)
Ejemplo n.º 42
0
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)
Ejemplo n.º 43
0
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)
Ejemplo n.º 44
0
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)
Ejemplo n.º 45
0
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
Ejemplo n.º 46
0
 def restore(self):
     "Restores the backup copy of the file."
     cp(self.backup_path, self.path)
Ejemplo n.º 47
0
def copy_to_archive(path, archive):
    src = to_path(path)
    dest = archive / src.relative_to(to_path('~'))
    mkdir(dest.parent)
    cp(src, dest)