def update(self): if request.method == 'HEAD': return {} if request.method != 'POST': error('/errors/not_allowed', 'only POST request are accepted for this url') if self.repo_obj.type == 'raw': # raw repos need no asynch construction. Create # the paths, symlink the binaries, mark them ready. self.repo_obj.path = util.repo_paths(self.repo_obj)['absolute'] util.makedirs(self.repo_obj.path) for binary in self.repo_obj.binaries: src = binary.path dest = os.path.join(self.repo_obj.path, os.path.join(binary.arch, binary.name)) try: if not os.path.exists(dest): os.symlink(src, dest) except OSError: logger.exception( f'could not symlink raw binary {src} -> {dest}') self.repo_obj.needs_update = False asynch.post_ready(self.repo_obj) else: # Just mark the repo so that celery picks it up self.repo_obj.needs_update = True self.repo_obj.is_updating = False self.repo_obj.is_queued = False asynch.post_requested(self.repo_obj) return self.repo_obj
def index_delete(self): if not self.binary: abort(404) binary_path = self.binary.path repo = self.binary.repo project = self.binary.project self.binary.delete() try: if binary_path: os.remove(binary_path) except (IOError, OSError): msg = "Could not remove the binary path: %s" % binary_path logger.exception(msg) error('/errors/error/', msg) if repo.binaries.count() > 0: # there are still binaries related to this repo, mark it to rebuild repo.needs_update = True else: # there are no more binaries for this repo, delete the repo repo.delete() if project.binaries.count() == 0: project.delete() response.status = 204 return dict()
def index_post(self): contents = request.POST.get('file', False) if contents is False: error('/errors/invalid/', 'no file object found in "file" param in POST request') file_obj = contents.file filename = contents.filename self.binary = self.get_binary(filename) self.binary_name = filename if self.binary is not None: if os.path.exists(self.binary.path): if request.POST.get('force', False) is False: error('/errors/invalid', 'resource already exists and "force" key was not used') full_path = self.save_file(file_obj) if self.binary is None: path = full_path distro = request.context['distro'] distro_version = request.context['distro_version'] arch = request.context['arch'] ref = request.context['ref'] sha1 = request.context['sha1'] self.binary = Binary( self.binary_name, self.project, arch=arch, distro=distro, distro_version=distro_version, ref=ref, sha1=sha1, path=path, size=os.path.getsize(path) ) else: self.binary.path = full_path # check if this binary is interesting for other configured projects, # and if so, then mark those other repos so that they can be re-built self.mark_related_repos() return dict()
def index_post(self): contents = request.POST.get('file', False) if contents is False: error('/errors/invalid/', 'no file object found in "file" param in POST request') file_obj = contents.file filename = contents.filename self.binary = self.get_binary(filename) self.binary_name = filename if self.binary is not None: if os.path.exists(self.binary.path): if request.POST.get('force', False) is False: error('/errors/invalid', "resource already exists") full_path = self.save_file(file_obj) if self.binary is None: path = full_path distro = request.context['distro'] distro_version = request.context['distro_version'] arch = request.context['arch'] ref = request.context['ref'] Binary( self.binary_name, self.project, arch=arch, distro=distro, distro_version=distro_version, ref=ref, path=path, size=os.path.getsize(path) ) else: self.binary.path = full_path return dict()
def index_post(self): contents = request.POST.get('file', False) if self.binary is not None: if os.path.exists(self.binary.path): if request.POST.get('force', False) is False: error( '/errors/invalid', "resource already exists and 'force' flag was not set") if contents is False: error('/errors/invalid/', 'no file object found in "file" param in POST request') file_obj = contents.file full_path = self.save_file(file_obj) if self.binary is None: path = full_path distro = request.context['distro'] distro_version = request.context['distro_version'] arch = request.context['arch'] ref = request.context['ref'] Binary(self.binary_name, self.project, arch=arch, distro=distro, distro_version=distro_version, ref=ref, path=path, size=os.path.getsize(path)) else: self.binary.path = full_path return dict()
def extra(self): if request.method != 'POST': error( '/errors/not_allowed', 'only POST request are accepted for this url' ) self.repo_obj.extra = request.json return self.repo_obj
def index_put(self): contents = request.POST.get('file', False) if contents is False: error('/errors/invalid/', 'no file object found in "file" param in POST request') file_obj = contents.file # this looks odd, path is not changing, but we need to 'ping' the object by # re-saving the attribute so that the listener can update the checksum and modified # timestamps self.binary.path = self.save_file(file_obj) return dict()
def index(self): if request.method == 'POST': error('/errors/not_allowed', 'POST requests to this url are not allowed') resp = {} for ref in self.project.repo_refs: resp[ref] = list(set( [r.distro for r in self.project.built_repos.filter_by(ref=ref).all()] )) return resp
def update(self): if request.method == 'HEAD': return {} if request.method != 'POST': error( '/errors/not_allowed', 'only POST request are accepted for this url' ) # Just mark the repo so that celery picks it up self.repo.needs_update = True return self.repo
def index(self): if request.method == 'POST': error('/errors/not_allowed', 'POST requests to this url are not allowed') resp = {} for ref in self.project.repo_refs: resp[ref] = list( set([ r.sha1 for r in self.project.repos.filter_by(ref=ref).all() ])) return resp
def recreate(self): if request.method == 'HEAD': return {} if request.method != 'POST': error( '/errors/not_allowed', 'only POST request are accepted for this url' ) # completely remove the path to the repository logger.info('removing repository path: %s', self.repo.path) shutil.rmtree(self.repo.path) # mark the repo so that celery picks it up self.repo.needs_update = True return self.repo
def update(self): if request.method == 'HEAD': return {} if request.method != 'POST': error( '/errors/not_allowed', 'only POST request are accepted for this url' ) # Just mark the repo so that celery picks it up self.repo_obj.needs_update = True self.repo_obj.is_updating = False self.repo_obj.is_queued = False async.post_requested(self.repo_obj) return self.repo_obj
def apply_filters(self, filters): # TODO: allow operators query = None for k, v in filters.items(): if k not in self.filters: return error('/errors/not_allowed', 'invalid query params: %s' % k) if k in self.filters: query = self.filter_binary(k, v, query) return query
def apply_filters(self, filters): # TODO: allow operators query = None for k, v in filters.items(): if k not in self.filters: return error('/errors/not_allowed', 'invalid query params: %s' % k) if k in self.filters: query = self.filter_binary(self.filters[k], v, query) return query
def index_post(self): contents = request.POST.get('file', False) if contents is False: error('/errors/invalid/', 'no file object found in "file" param in POST request') file_obj = contents.file filename = contents.filename self.binary = self.get_binary(filename) self.binary_name = filename if self.binary is not None: if os.path.exists(self.binary.path): if request.POST.get('force', False) is False: error( '/errors/invalid', 'resource already exists and "force" key was not used') full_path = self.save_file(file_obj) if self.binary is None: path = full_path distro = request.context['distro'] distro_version = request.context['distro_version'] arch = request.context['arch'] ref = request.context['ref'] sha1 = request.context['sha1'] self.binary = models.Binary(self.binary_name, self.project, arch=arch, distro=distro, distro_version=distro_version, ref=ref, sha1=sha1, path=path, size=os.path.getsize(path), flavor=self.flavor) else: self.binary.path = full_path # check if this binary is interesting for other configured projects, # and if so, then mark those other repos so that they can be re-built self.mark_related_repos() return dict()
def recreate(self): if request.method == 'HEAD': return {} if request.method != 'POST': error('/errors/not_allowed', 'only POST request are accepted for this url') # completely remove the path to the repository logger.info('removing repository path: %s', self.repo_obj.path) try: shutil.rmtree(self.repo_obj.path) except OSError: logger.warning("could not remove repo path: %s", self.repo_obj.path) # mark the repo so that celery picks it up self.repo_obj.needs_update = True self.repo_obj.is_updating = False self.repo_obj.is_queued = False asynch.post_requested(self.repo_obj) return self.repo_obj
def index_delete(self): repo_path = self.repo_obj.path logger.info('nuke repository path: %s', repo_path) try: shutil.rmtree(repo_path) except OSError: msg = "could not remove repo path: {}".format(repo_path) logger.exception(msg) error('/errors/error/', msg) for binary in self.repo_obj.binaries: binary_path = binary.binary.path if binary_path: try: os.remove(binary_path) except (IOError, OSError): msg = "Could not remove the binary path: %s" % binary_path logger.exception(msg) binary.delete() self.repo_obj.delete() if self.project.repos.count() == 0: self.project.delete() response.status = 204 return dict()
def index_post(self): try: data = request.json name = data.get('name') except ValueError: error('/errors/invalid/', 'could not decode JSON body') # updates the binary only if explicitly told to do so if self.binary: if not data.get('force'): error('/errors/invalid/', 'file already exists and "force" flag was not used') else: # FIXME this looks like we need to implement PUT path = data.get('path') if path: try: data['size'] = os.path.getsize(path) except OSError: logger.exception('could not retrieve size from %s' % path) data['size'] = 0 self.binary.update_from_json(data) return {} # we allow empty data to be pushed if not name: error('/errors/invalid/', "could not find required key: 'name'") name = data.pop('name') path = data.get('path') if path: size = os.path.getsize(path) else: size = 0 Binary(name=name, project=self.project, arch=self.arch, distro=self.distro, distro_version=self.distro_version, ref=self.ref, size=size, sha1=self.sha1) return {}
def index_post(self): try: data = request.json name = data.get('name') except ValueError: error('/errors/invalid/', 'could not decode JSON body') # updates the binary only if explicitly told to do so binary = self.get_binary(name) if binary: if not data.get('force'): error('/errors/invalid/', 'file already exists and "force" flag was not used') else: # FIXME this looks like we need to implement PUT path = data.get('path') if path: try: data['size'] = os.path.getsize(path) except OSError: logger.exception('could not retrieve size from %s' % path) data['size'] = 0 binary.update_from_json(data) return {} # we allow empty data to be pushed if not name: error('/errors/invalid/', "could not find required key: 'name'") name = data.pop('name') path = data.get('path') if path: size = os.path.getsize(path) else: size = 0 Binary( name=name, project=self.project, arch=self.arch, distro=self.distro, distro_version=self.distro_version, ref=self.ref, size=size ) return {}
def index_post(self): error('/errors/not_allowed', 'POST requests to this url are not allowed')
def index_post(self): error("/errors/not_allowed", "POST requests to this url are not allowed")
def index(self): if request.method == 'POST': error('/errors/not_allowed', 'POST requests to this url are not allowed') return self.project