def delete_generated_source(source: Optional[str], target: str): """ Execute action """ force_remove(source) events.file.deleted(source) events.file.deleted(target)
def delete(self, template: str, target: str): """ Delete a rendered template """ if os.path.exists(target): force_remove(target) context.log.warning("%s removed", target) caches.get(self._cache_key).pop(target) events.file.deleted(target)
def _write_gitignore_content(gitignore: str, content: List[str]): if [line for line in content if line]: with open(gitignore, "w", encoding="utf-8") as gitignore_file: for lineno, line in enumerate(content): if lineno > 0: gitignore_file.write('\n') gitignore_file.write(line) else: force_remove(gitignore)
def self_update_binary(github_repository, version): """ Self update the ddb binary :param github_repository: :param version: :return: """ local_binary_path = get_local_binary_path() if not os.access(local_binary_path, os.W_OK): raise PermissionError(f"You don't have permission to write on ddb binary file. ({local_binary_path})") if not os.path.isfile(local_binary_path): raise ValueError(f"Local binary path is not a file. ({local_binary_path})") release_asset_name = config.data.get('core.release_asset_name') if not release_asset_name: print('ddb is running from a platform that doesn\'t support binary package mode.') return url = 'https://github.com/{}/releases/download/v{}/{}'.format(github_repository, version, release_asset_name) context.log.debug('Downloading ddb asset: %s', url) progress_bar = None with requests.get(url, stream=True) as response: response.raise_for_status() tmp = NamedTemporaryFile(delete=False) try: if not progress_bar: content_length = int(response.headers['content-length']) progress_bar = IncrementalBar('Downloading', max=content_length, suffix='%(percent)d%%') for chunk in response.iter_content(32 * 1024): progress_bar.next(len(chunk)) # pylint:disable=not-callable tmp.write(chunk) tmp.flush() finally: tmp.close() local_binary_path = get_binary_destination_path(local_binary_path) shutil.copymode(local_binary_path, tmp.name) force_remove(local_binary_path) # This is required on windows os.rename(tmp.name, local_binary_path) progress_bar.finish() config.data['core.check_updates'] = False print("ddb has been updated.")
def _render_template( self, template: str, target: str) -> Iterable[Tuple[Union[str, bytes, bool], str]]: """ Create a symbolic link """ reltemplate = os.path.relpath(template, os.path.dirname(target)) if os.path.islink(target) and os.readlink(target) == reltemplate: context.log.notice("%s -> %s", template, target) yield False, target else: if os.path.exists(target): force_remove(target) os.symlink(reltemplate, os.path.normpath(target)) context.log.success("%s -> %s", template, target) yield True, target
def remove_binary_shim(self, shims_path: str, name: str) -> Optional[str]: shim = os.path.join(shims_path, name + '.bat') if not os.path.isfile(shim): return None force_remove(shim) return shim