本文整理汇总了Python中changes.models.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, project_id, test_hash):
project = Project.get(project_id)
if not project:
return '', 404
# use the most recent test run to find basic details
test = TestCase.query.filter(
TestCase.project_id == project_id,
TestCase.name_sha == test_hash,
).order_by(TestCase.date_created.desc()).limit(1).first()
if not test:
return '', 404
first_test = TestCase.query.filter(
TestCase.project_id == project_id,
TestCase.name_sha == test_hash,
).order_by(TestCase.date_created.asc()).limit(1).first()
first_build = Build.query.options(
joinedload('author'),
joinedload('source').joinedload('revision'),
).filter(
Build.id == first_test.job.build_id,
).first()
context = self.serialize(test, {
TestCase: GeneralizedTestCase(),
})
context.update({
'firstBuild': first_build,
})
return self.respond(context, serialize=False)
示例2: get
def get(self, project_id):
project = Project.get(project_id)
if not project:
return '', 404
args = self.parser.parse_args()
if args.date:
try:
query_date = datetime.strptime(args.date, '%Y-%m-%d').date()
except:
return 'Can\'t parse date "%s"' % (args.date), 500
else:
# This `7` is hard-coded to match the code in config.py which kicks
# off the cron job 7 hours past midnight GMT (which corresponds to
# midnight PST)
delta = timedelta(days=2 if datetime.utcnow().hour < 7 else 1)
query_date = datetime.utcnow().date() - delta
data = {
'date': str(query_date),
'chartData': self.get_chart_data(project_id, query_date),
'flakyTests': self.get_flaky_tests(project_id, query_date)
}
return self.respond(data, serialize=False)
示例3: get
def get(self, project_id, commit_id):
project = Project.get(project_id)
if not project:
return '', 404
repo = project.repository
revision = Revision.query.filter(
Revision.repository_id == repo.id,
Revision.sha == commit_id,
).join(Revision.author).first()
if not revision:
return '', 404
build_list = list(Build.query.options(
joinedload('author'),
contains_eager('source'),
).join(
Source, Build.source_id == Source.id,
).filter(
Build.project_id == project.id,
Source.revision_sha == revision.sha,
Source.patch == None, # NOQA
).order_by(Build.date_created.desc()))[:100]
context = self.serialize(revision)
context.update({
'repository': repo,
'builds': build_list,
})
return self.respond(context)
示例4: get
def get(self, project_id):
project = Project.get(project_id)
if project is None:
return '', 404
args = self.get_parser.parse_args()
queryset = Plan.query.filter(
Plan.project_id == project.id,
)
if args.query:
queryset = queryset.filter(
func.lower(Plan.label).contains(args.query.lower()),
)
if args.status:
queryset = queryset.filter(
Plan.status == PlanStatus[args.status],
)
if args.sort == 'name':
queryset = queryset.order_by(Plan.label.asc())
elif args.sort == 'date':
queryset = queryset.order_by(Plan.date_created.asc())
return self.paginate(queryset)
示例5: get
def get(self, project_id):
project = Project.get(project_id)
if not project:
return '', 404
args = self.get_parser.parse_args()
filters = []
if args.authors:
filters.append(Build.author_id.in_([a.id for a in args.authors]))
elif args.authors is not None:
return []
if args.source:
filters.append(Build.target.startswith(args.source))
# is this from the search bar
if args.query:
clauses = []
# search by revision title
clauses.append(Build.label.contains(args.query))
# search by prefix
clauses.append(Build.target.startswith(args.query))
# allows users to paste a full commit hash and still
# find the relevant build(s). Should be fine for mercurial/git,
# and svn will never have long enough strings
if len(args.query) > 12:
clauses.append(Build.target.startswith(args.query[0:12]))
# if they searched for something that looks like a phabricator
# identifier, try to find it
if might_be_diffusion_iden(args.query):
possible_hash = get_hash_from_diffusion_iden(args.query)
if possible_hash:
# the query should always be at least as long or longer than
# our commit identifiers
clauses.append(
Build.target.startswith(possible_hash[0:12]))
filters.append(or_(*clauses))
if args.result:
filters.append(Build.result == Result[args.result])
if args.patches_only:
filters.append(Source.patch_id != None) # NOQA
elif not args.include_patches:
filters.append(Source.patch_id == None) # NOQA
queryset = Build.query.options(
joinedload('project', innerjoin=True),
joinedload('author'),
contains_eager('source').joinedload('revision'),
).join(
Source, Source.id == Build.source_id,
).filter(
Build.project_id == project.id,
*filters
).order_by(Build.date_created.desc())
return self.paginate(queryset)
示例6: get
def get(self, project_id):
project = Project.get(project_id)
if not project:
return '', 404
query = request.args.get('q', request.args.get('query'))
source = request.args.get('source')
filters = []
if source:
filters.append(Build.target.startswith(source))
if query:
filters.append(or_(
Build.label.contains(query),
Build.target.startswith(query),
))
queryset = Build.query.options(
joinedload('project', innerjoin=True),
joinedload('author'),
joinedload('source'),
).filter(
Build.project_id == project.id,
*filters
).order_by(Build.date_created.desc())
return self.paginate(queryset)
示例7: post
def post(self, project_id):
project = Project.get(project_id)
if project is None:
return '', 404
args = self.post_parser.parse_args()
if args.name:
project.name = args.name
if args.slug:
match = Project.query.filter(
Project.slug == args.slug,
Project.id != project.id,
).first()
if match:
return '{"error": "Project with slug %r already exists"}' % (args.slug,), 400
project.slug = args.slug
if args.repository:
repository = Repository.get(args.repository)
if repository is None:
return '{"error": "Repository with url %r does not exist"}' % (args.repository,), 400
project.repository = repository
db.session.add(project)
data = self.serialize(project)
data['repository'] = self.serialize(project.repository)
return self.respond(data, serialize=False)
示例8: get
def get(self, project_id, commit_id):
project = Project.get(project_id)
if not project:
return '', 404
repo = project.repository
revision = Revision.query.filter(
Revision.repository_id == repo.id,
Revision.sha == commit_id,
).join(Revision.author).first()
if not revision:
return '', 404
build_query = Build.query.options(
joinedload('author'),
contains_eager('source').joinedload('revision'),
).join(
Source, Build.source_id == Source.id,
).filter(
Build.project_id == project.id,
Source.revision_sha == revision.sha,
Source.patch == None, # NOQA
).order_by(Build.date_created.desc())
return self.paginate(build_query)
示例9: get
def get(self, project_id, commit_id):
project = Project.get(project_id)
if not project:
return '', 404
repo = project.repository
try:
revision = Revision.get_by_sha_prefix_query(
repo.id,
commit_id,
).options(
joinedload('author')
).scalar()
except MultipleResultsFound:
return '', 404
else:
if not revision:
return '', 404
context = self.serialize(revision)
context.update({
'repository': repo,
})
return self.respond(context)
示例10: get
def get(self, project_id):
project = Project.get(project_id)
if not project:
return '', 404
args = self.get_parser.parse_args()
filters = []
if args.source:
filters.append(Build.target.startswith(args.source))
if args.query:
filters.append(or_(
Build.label.contains(args.query),
Build.target.startswith(args.query),
))
if args.result:
filters.append(Build.result == Result[args.result])
queryset = Build.query.options(
joinedload('project', innerjoin=True),
joinedload('author'),
joinedload('source').joinedload('revision'),
).filter(
Build.project_id == project.id,
*filters
).order_by(Build.date_created.desc())
return self.paginate(queryset)
示例11: get
def get(self, project_id, source_id):
project = Project.get(project_id)
if not project:
return '', 404
repo = project.repository
source = Source.query.filter(
Source.id == source_id,
Source.repository_id == repo.id,
).first()
if source is None:
return '', 404
context = self.serialize(source)
if source.patch:
context['diff'] = source.patch.diff
else:
vcs = repo.get_vcs()
if vcs:
try:
context['diff'] = vcs.export(source.revision_sha)
except Exception:
context['diff'] = None
else:
context['diff'] = None
return self.respond(context)
示例12: get
def get(self, project_id):
project = Project.get(project_id)
if not project:
return error('project not found', http_code=404)
args = self.get_parser.parse_args()
# we want to only return commits in the repo that are within the
# project's whitelist
paths = None
if not args.every_commit:
paths = self.get_whitelisted_paths(project)
repo = project.repository
offset = (args.page - 1) * args.per_page
limit = args.per_page + 1 # +1 to tell if there are more revs to get
vcs = repo.get_vcs()
if vcs:
try:
commits = self.get_commits_from_vcs(
repo, vcs, offset, limit, paths, args.parent, args.branch)
except ValueError as err:
return error(err.message)
else:
if args.parent or args.branch:
param = 'Branches' if args.branch else 'Parents'
return error(
'{0} not supported for projects with no repository.'.format(param),
http_code=422)
# TODO: right now this fallback returns every commit for projects
# with whitelisted paths. At the very least, we need to tell the
# frontend about this (perhaps using a response header)
commits = self.get_commits_from_db(repo, offset, limit)
page_links = self.make_links(
current_page=args.page,
has_next_page=len(commits) > args.per_page,
)
# we fetched one extra commit so that we'd know whether to create a
# next link. Delete it
commits = commits[:args.per_page]
builds_map = {}
if commits:
builds_map = self.get_builds_for_commits(
commits, project, args.all_builds)
results = []
for result in commits:
if args.all_builds:
result['builds'] = builds_map.get(result['id'], [])
else:
result['build'] = builds_map.get(result['id'])
results.append(result)
return self.respond(results, serialize=False, links=page_links)
示例13: get
def get(self, project_id):
project = Project.get(project_id)
if project is None:
return '', 404
plans = Plan.query.options(
subqueryload_all(Plan.steps),
).filter(
Plan.projects.contains(project),
)
last_build = Build.query.options(
joinedload('author'),
contains_eager('source')
).join(
Source, Build.source_id == Source.id,
).filter(
Source.patch_id == None, # NOQA
Build.project == project,
Build.status == Status.finished,
).order_by(
Build.date_created.desc(),
).first()
if not last_build or last_build.result == Result.passed:
last_passing_build = last_build
else:
last_passing_build = Build.query.options(
joinedload('author'),
contains_eager('source')
).join(
Source, Build.source_id == Source.id,
).filter(
Source.patch_id == None, # NOQA
Build.project == project,
Build.result == Result.passed,
Build.status == Status.finished,
).order_by(
Build.date_created.desc(),
).first()
options = dict(
(o.name, o.value) for o in ProjectOption.query.filter(
ProjectOption.project_id == project.id,
)
)
for key, value in OPTION_DEFAULTS.iteritems():
options.setdefault(key, value)
data = self.serialize(project)
data['lastBuild'] = last_build
data['lastPassingBuild'] = last_passing_build
data['repository'] = project.repository
data['plans'] = list(plans)
data['options'] = options
data['stats'] = self._get_stats(project)
return self.respond(data)
示例14: get
def get(self, project_id, test_hash):
project = Project.get(project_id)
if not project:
return '', 404
# use the most recent test run to find basic details
test = TestCase.query.filter(
TestCase.project_id == project_id,
TestCase.name_sha == test_hash,
).order_by(TestCase.date_created.desc()).limit(1).first()
if not test:
return '', 404
# restrict the join to the last 1000 jobs otherwise this can get
# significantly expensive as we have to seek quite a ways
job_sq = Job.query.filter(
Job.status == Status.finished,
Job.project_id == project_id,
).order_by(Job.date_created.desc()).limit(1000).subquery()
recent_runs = list(TestCase.query.options(
contains_eager('job', alias=job_sq),
contains_eager('job.source'),
joinedload('job', 'build'),
).join(
job_sq, TestCase.job_id == job_sq.c.id,
).join(
Source, job_sq.c.source_id == Source.id,
).filter(
Source.patch_id == None, # NOQA
Source.revision_sha != None, # NOQA
TestCase.name_sha == test.name_sha,
).order_by(job_sq.c.date_created.desc())[:25])
first_build = Build.query.join(
Job, Job.build_id == Build.id,
).join(
TestCase, TestCase.job_id == Job.id,
).filter(
TestCase.project_id == project_id,
TestCase.name_sha == test_hash,
).order_by(TestCase.date_created.asc()).limit(1).first()
extended_serializers = {
TestCase: TestCaseWithJobSerializer(),
Job: JobWithBuildSerializer(),
}
context = self.serialize(test, {
TestCase: GeneralizedTestCase(),
})
context.update({
'results': self.serialize(recent_runs, extended_serializers),
'firstBuild': first_build,
})
return self.respond(context, serialize=False)
示例15: get
def get(self, project_id):
project = Project.get(project_id)
if not project:
return '', 404
queryset = Snapshot.query.filter(
Snapshot.project_id == project.id,
)
return self.paginate(queryset)