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")
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')
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")
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')
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")
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')
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))
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()
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')
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()
def update(self): for path in self.cleanup: ensure_path_nonexistent(os.path.join(".appenv", path))
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")
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")
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")
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')