def __init__(self, ctx: click.Context, root=None): if root is None: cwd = Path.from_cwd() else: dirinfo =DirectoryInfo(root) if not dirinfo.is_directory(): ctx.fail(f'{root} is not a dir') cwd = dirinfo.path from .core.ioc import pkgit_ioc pkgit_ioc.register_value('cwd', cwd)
def remove_expired_files(path: str, before: datetime): path = resolve_path(path) dir_info = DirectoryInfo(path) if dir_info.is_directory(): for item in dir_info.iter_items(depth=99999): if item.node_type == NodeType.file: atime_int = os.path.getatime(item.path) access_time = datetime.fromtimestamp(atime_int) if before > access_time: item.delete() click.echo(click.style('Removed', fg='yellow') + ' ', nl=False) else: click.echo(click.style('Skiped', fg='cyan') + ' ', nl=False) click.echo(f'{item.path!s}.')