def proxy_complete(self): if self.uploading is True: return if self.status.get('builder_status', None) == "BuilderStatus.ABORTING": buildid = self.status.get('buildid', None) job = Job.selectBy(id=buildid)[0] self.complete(job, JobStatus.CANCELED) if self.status.get('builder_status', None) == 'BuilderStatus.WAITING': buildid = self.status.get('build_id', None) try: job = Job.selectBy(id=buildid)[0] except Exception as e: print(e) return if self.status.get('build_status') == "BuildStatus.OK": job_status = JobStatus.BUILD_OK else: job_status = JobStatus.FAILED # notify build try: _package = job.package.dict() cwd = os.path.join(config['cache']['sources'], _package['pkgname']) command = "git show %s --pretty=%%ae | head -n 1" % _package['hashsum'] status, email = functions.getstatusoutput(command, cwd=cwd) if status != 0: email = None command = "git log -1 %s --pretty=%%s | head -n 1" % _package['hashsum'] status, subject = functions.getstatusoutput(command, cwd=cwd) if status != 0: subject = None message_text = "Build %(pkgname)s - %(pkgver)s to %(reponame)s" % _package message_text += " [Failed](%s/job/%s)" % (config['runtime']['url'], str(job.id)) attachments_text = "Action: %(action)s\nHashsum: %(hashsum)s\n" % _package if subject: attachments_text += "Subject: %s\n" % subject attachments = [{ "text": attachments_text, "color": "#ffa500" }] #Notify().notify('bearychat', message_text=message_text, # author_email=email, message_attachments=attachments) Notify().notify('deepinworknoticebot', message_text=message_text, author_email=email, message_attachments=attachments) except Exception as error: print(error) self.complete(job, job_status)
def get_result(): headers = request.getAllHeaders() content = cgi.FieldStorage(fp=request.content, headers=headers, environ={ 'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': headers['content-type'], }) repo_uri = content['reponame'].value repo_base = config['cache']['repos'] repo_json = os.path.join(repo_base, repo_uri, '%s.json' % repo_uri) if os.path.exists(repo_json): raise OSError("repo has already created.") if not os.path.exists(os.path.join(repo_base, repo_uri)): os.makedirs(os.path.join(repo_base, repo_uri)) with open(repo_json, 'w') as fp: fp.write(content['config'].value) env = os.environ.copy() env['REPOPATH'] = repo_base env['NAME'] = repo_uri command = "../tools/repo.py create" status, _message = functions.getstatusoutput(command, env=env) if status == 0: message = "repo %s create succeed." % repo_uri Log(section='repository', message=message) else: message = "repo create failed. %s " % _message return {'status': status, 'message': message}
def get_result(): content = json.loads(request.content.read()) repo_uri = content['reponame'] division_name = content['division'] base_repo = content['baserepo'] repo_base = config['cache']['repos'] repo_json = os.path.join(repo_base, repo_uri, '%s.json' % repo_uri) if not os.path.exists(repo_json): raise OSError("repo is not created.") repo_config = json.loads(open(repo_json, 'r').read()) if not repo_config.get(base_repo): raise OSError("division repo is not supported.") env = os.environ.copy() env['REPOPATH'] = repo_base env['NAME'] = repo_uri command = "../tools/repo.py division --base %(base)s --division %(division)s" % { "base": base_repo, "division": division_name } Log(section='repository', message='create division reponame %s/%s' % (repo_uri, division_name)) return dict( zip(['status', 'message'], functions.getstatusoutput(command, env=env)))
def upload_tasks(self): for package in Package.selectBy(upload_status=UploadStatus.WAIT)[:5]: package.upload_status = UploadStatus.UPLOADING repo_base = config['cache']['repos'] env = os.environ.copy() env['REPOPATH'] = repo_base env['NAME'] = package.reponame task_cache = os.path.join(config['cache']['tasks'], str(package.id)) command = "../tools/repo.py include --cache %(cache)s --base %(base)s" % { "cache": task_cache, "base": package.action } status, _ = functions.getstatusoutput(command, env=env) if status != 0: Log(status=False, section='task', message='upload tasks %(pkgname)s %(pkgver)s to %(reponame)s' % package.dict()) package.upload_status = UploadStatus.UPLOAD_FAILED else: package.upload_status = UploadStatus.UPLOAD_OK
def get_result(): content = json.loads(request.content.read()) repo_uri = content['repouri'] if repo_uri is None: raise OSError("reponame should not be none") repo_base = config['cache']['repos'] repo_path = os.path.join(repo_base, repo_uri) if os.path.exists(repo_path): Log(section='repository', message='destroy repository %s' % repo_uri) return dict( zip(['status', 'message'], functions.getstatusoutput("rm -r %s" % repo_path, env=env))) else: return dict( zip(['status', 'message'], [1, "%s is not exists" % repo_uri]))