

def post(self, project_id):
    'Initiates a new snapshot for this project.'
    project = Project.get(project_id)
    if (not project):
        return ('', 404)
    args = self.post_parser.parse_args()
    repository = project.repository
    try:
        revision = identify_revision(repository, args.sha)
    except MissingRevision:
        return error('Unable to find a matching revision.')
    if revision:
        sha = revision.sha
    else:
        sha = args.sha
    plan_list = get_snapshottable_plans(project)
    if (not plan_list):
        return error('No snapshottable plans associated with project.')
    (source, _) = get_or_create(Source, where={
        'repository': repository,
        'revision_sha': sha,
        'patch_id': None,
    })
    build = Build(source_id=source.id, source=source, project_id=project.id, project=project, label='Create Snapshot', status=Status.queued, cause=Cause.snapshot, target=sha[:12], tags=['snapshot'], priority=BuildPriority.high)
    db.session.add(build)
    snapshot = Snapshot(project_id=project.id, source_id=source.id, build_id=build.id, status=SnapshotStatus.pending)
    db.session.add(snapshot)
    jobs = []
    for plan in plan_list:
        job = Job(build=build, build_id=build.id, project=project, project_id=project.id, source=build.source, source_id=build.source_id, status=build.status, label=('Create Snapshot: %s' % (plan.label,)))
        db.session.add(job)
        jobplan = JobPlan.build_jobplan(plan, job)
        db.session.add(jobplan)
        image = SnapshotImage(job=job, snapshot=snapshot, plan=plan)
        db.session.add(image)
        jobs.append(job)
    db.session.commit()
    for job in jobs:
        create_job.delay(job_id=job.id.hex, task_id=job.id.hex, parent_task_id=job.build_id.hex)
    db.session.commit()
    sync_build.delay(build_id=build.id.hex, task_id=build.id.hex)
    return self.respond(snapshot)

dataset/ETHPy150Open dropbox/changes/changes/api/project_snapshot_index.py ProjectSnapshotIndexAPIView.post/original