def get_all(self): """Returns all builds.""" project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user, project_name) builds = [Build.fetch(project, b_id, False) for b_id in project.get_builds()] builds = [b for b in builds if b] return builds
def post(self, build): """ launch build """ project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user, project_name) if project is None: # The project doesn't exist # We have to create it # TODO Maybe it's better to force users to create project before # they can create builds project = Project.create(user, project_name, {"name": project_name}) build = Build.create(project, build) build_tasks.put(build) # TODO: save build in database ??? # for now is in build.cfg ... return {"result": {"build": int(build.id_)}}
def get(self): """Returns log of a specific distro.""" project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user, project_name) build_id = pecan.request.context['build_id'] if build_id in ["latest"]: build_id = project.get_latest_build() build = Build.fetch(project, build_id, full_data=True) if build is None: return # Get options archive = pecan.request.GET.get('archive', 'tgz') distro = pecan.request.GET.get('distro', None) if distro not in supported_distros: distro = None # Prepare content type content_type = archive_types.get(archive, 'application/x-gzip') pecan.core.override_template(None, content_type) # Get output folder output_folder = build.get_output_folder_path(distro) # Test if output folder exists if not os.path.isdir(output_folder): return # Prepare archive f = BytesIO() if archive == 'zip': # Zip zip_archive = zipfile.ZipFile(f, "w" ) for file_ in glob.glob(output_folder + "/*"): zip_archive.write(file_, os.path.basename(file_)) zip_archive.close() extension = "zip" else: # Tarball tar_archive = tarfile.open(fileobj=f, mode="w:gz") for file_ in glob.glob(output_folder + "/*"): tar_archive.add(file_, os.path.basename(file_)) tar_archive.close() extension = "tar.gz" # Set headers headers = pecan.response.headers if build.package_name is None: return filename = project_name + "_%(package_version)s-%(package_release)s" % build.as_dict() if distro is not None: filename = filename + "-" + distro else: filename = filename + "-all_distros" filename = ".".join((filename, extension)) headers.add("Content-Disposition", str("attachment;filename=%s" % filename)) # returns return f.getvalue()
def get(self): """Returns log of a specific distro.""" project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user, project_name) build_id = pecan.request.context['build_id'] if build_id in ["latest"]: build_id = project.get_latest_build() build = Build.fetch(project, build_id, full_data=True) job = Job.fetch(build, self.id_, False) return job
def get(self): """Returns build status""" project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user, project_name) build_id = self.id_ if self.id_ in ["latest"]: build_id = project.get_latest_build() build = Build.fetch(project, build_id, sub_objects=True) if build: return build return None
def get(self): """Returns project""" project = Project.fetch(self.user, self.project_name) return project