cleaner.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:nokia-deployer 作者: nokia 项目源码 文件源码
def _cleanup(self):
        if not os.path.exists(self.base_repos_path):
            logger.info("Base repo path {} does not exist yet, nothing to do.".format(self.base_repos_path))
            return
        now = datetime.utcnow()
        with session_scope() as session:
            deletion_candidates = set(os.listdir(self.base_repos_path))
            subquery = session.query(m.Environment.id, func.max(m.DeploymentView.queued_date).label("max_queued_date")).\
                filter(m.Environment.id == m.DeploymentView.environment_id).\
                group_by(m.Environment.id).subquery()
            recently_deployed_envs = session.query(m.Environment).\
                join((subquery, subquery.c.id == m.Environment.id)).\
                filter(subquery.c.max_queued_date > now - self.max_unused_age).\
                all()
            to_keep = set(e.local_repo_directory_name for e in recently_deployed_envs)
            for path in deletion_candidates - to_keep:
                path = os.path.join(self.base_repos_path, path)
                if os.path.exists(path):
                    with lock_repository_fetch(path), lock_repository_write(path):
                        rmtree(path)
                    logger.info(
                        "Deleted unused directory {}".format(path)
                    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号