Exemple #1
0
 def update(self):
     ensure_path_nonexistent(self.parent.env_dir)
     if "__PYVENV_LAUNCHER__" in os.environ:
         del os.environ["__PYVENV_LAUNCHER__"]
     self.cmd("python{{component.python_version}} -m venv "
              "{{component.parent.env_dir}}")
     self.cmd("{{component.parent.env_dir}}/bin/python -m pip "
              "install --upgrade pip")
Exemple #2
0
def test_ensure_path_nonexistent_removes_broken_symlink(tmpdir):
    os.chdir(str(tmpdir))
    os.symlink('target', 'link')
    assert os.path.islink('link')
    assert not os.path.exists('target')
    ensure_path_nonexistent('link')
    assert not os.path.exists('link')
    assert not os.path.exists('target')
Exemple #3
0
def test_ensure_path_nonexistent_removes_broken_symlink(tmpdir):
    os.chdir(str(tmpdir))
    os.symlink("target", "link")
    assert os.path.islink("link")
    assert not os.path.exists("target")
    ensure_path_nonexistent("link")
    assert not os.path.exists("link")
    assert not os.path.exists("target")
Exemple #4
0
 def update(self):
     ensure_path_nonexistent(self.parent.env_dir)
     if '__PYVENV_LAUNCHER__' in os.environ:
         del os.environ['__PYVENV_LAUNCHER__']
     self.cmd(
         'python{{component.python_version}} -m venv '
         '{{component.parent.env_dir}}')
     self.cmd(
         '{{component.parent.env_dir}}/bin/python -m pip '
         'install --upgrade pip')
Exemple #5
0
def test_ensure_path_nonexistent_removes_normal_symlink(tmpdir):
    os.chdir(str(tmpdir))
    open("target", "w").close()
    os.symlink("target", "link")
    assert os.path.exists("link")
    assert os.path.exists("target")

    ensure_path_nonexistent("link")

    assert not os.path.exists("link")
    assert os.path.exists("target")
Exemple #6
0
def test_ensure_path_nonexistent_removes_normal_symlink(tmpdir):
    os.chdir(str(tmpdir))
    open('target', 'w').close()
    os.symlink('target', 'link')
    assert os.path.exists('link')
    assert os.path.exists('target')

    ensure_path_nonexistent('link')

    assert not os.path.exists('link')
    assert os.path.exists('target')
Exemple #7
0
def ensure_empty_directory(path):
    """Ensure path is an empty directory.

    Keep the directory if it exists or create a new one if it
    didn't or if it wasn't a directory.

    This helps in situations where the current workdir may be
    the existing path that needs to be cleaned up.
    """
    if not os.path.isdir(path):
        ensure_path_nonexistent(path)
        os.makedirs(path)
    for file in os.listdir(path):
        ensure_path_nonexistent(os.path.join(path, file))
Exemple #8
0
def main(editor, environment, edit_file=None, **kw):
    """Secrets editor console script.

    The main focus here is to avoid having unencrypted files accidentally
    ending up in the deployment repository.

    """
    if not os.path.exists("environments/{}.cfg".format(environment)):
        print("Environment '{}' does not exist. Typo?".format(environment))
        print("Existing environments:")
        print("\n".join(os.listdir("environments")).replace(".cfg", ""))
        sys.exit(1)

    if not os.path.isdir("secrets"):
        ensure_path_nonexistent("secrets")
        os.mkdir("secrets")

    editor = Editor(editor, environment, edit_file)
    editor.main()
Exemple #9
0
    def update(self):
        just_cloned = False
        if self._force_clone:
            ensure_path_nonexistent(self.target)
            self.cmd(self.expand(
                'git clone {{component.url}} {{component.target}}'))
            just_cloned = True
        with self.chdir(self.target):
            for filepath in self.untracked_files():
                os.unlink(os.path.join(self.target, filepath))
            if not just_cloned:
                self.cmd('git fetch')
            if self.branch:
                self.cmd(self.expand(
                    'git reset --hard origin/{{component.branch}}'))
            else:
                self.cmd(self.expand(
                    'git reset --hard {{component.revision}}'))

            # XXX We should re-think submodule support; e.g. which revision
            # shall the submodules be updated to?
            self.cmd('git submodule update --init --recursive')
Exemple #10
0
def main(editor, environment, **kw):
    """Secrets editor console script.

    The main focus here is to avoid having unencrypted files accidentally
    ending up in the deployment repository.

    """
    encrypted = 'secrets/{}.cfg'.format(environment)

    if not os.path.exists('environments/{}.cfg'.format(environment)):
        print("Environment '{}' does not exist. Typo?".format(environment))
        print("Existing environments:")
        print("\n".join(os.listdir('environments')).replace('.cfg', ''))
        sys.exit(1)

    if not os.path.isdir('secrets'):
        ensure_path_nonexistent('secrets')
        os.mkdir('secrets')

    with EncryptedConfigFile(encrypted, write_lock=True) as sf:
        editor = Editor(editor, sf)
        editor.main()
Exemple #11
0
 def update(self):
     for path in self.cleanup:
         ensure_path_nonexistent(os.path.join(".appenv", path))
Exemple #12
0
def test_ensure_path_does_not_fail_on_nonexisting_path():
    assert not os.path.exists("missing")
    ensure_path_nonexistent("missing")
    assert not os.path.exists("missing")
Exemple #13
0
def test_ensure_path_nonexistent_removes_directory(tmpdir):
    os.chdir(str(tmpdir))
    os.mkdir("dir")
    assert os.path.exists("dir")
    ensure_path_nonexistent("dir")
    assert not os.path.exists("dir")
Exemple #14
0
def test_ensure_path_nonexistent_removes_normal_file(tmpdir):
    open("asdf", "w").close()
    assert os.path.exists("asdf")
    ensure_path_nonexistent("asdf")
    assert not os.path.exists("asdf")
Exemple #15
0
def test_ensure_path_nonexistent_removes_normal_file(tmpdir):
    open('asdf', 'w').close()
    assert os.path.exists('asdf')
    ensure_path_nonexistent('asdf')
    assert not os.path.exists('asdf')