From 34198974054098f0fa1254889243158964cfadf0 Mon Sep 17 00:00:00 2001 From: mao xiaojuan Date: Tue, 31 Jul 2018 11:41:51 +0800 Subject: [PATCH] Fix code format about pmb scripts. Change-Id: I7113ae2cca94d9e0bc863db2571cef03c090598f --- pmb/job_release_mail_sender.py | 402 +++++++++++++++++++------------------- pmb/trigger_tools_staging_test.py | 116 +++++------ 2 files changed, 259 insertions(+), 259 deletions(-) diff --git a/pmb/job_release_mail_sender.py b/pmb/job_release_mail_sender.py index b433a52..a034260 100644 --- a/pmb/job_release_mail_sender.py +++ b/pmb/job_release_mail_sender.py @@ -1,201 +1,201 @@ -#!/usr/bin/env python -# vim: ai ts=4 sts=4 et sw=4 -# -# Copyright (C) 2010, 2011, 2012, 2013, 2014 Intel, Inc. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -import os -import sys -import re -import requests -from bs4 import BeautifulSoup - -sys.path.insert(0, os.path.join(os.getcwd(), 'jenkins-scripts')) -from common.send_mail import prepare_mail - - -# set default char-set endcoding to utf-8 -reload(sys) -sys.setdefaultencoding('utf-8') # pylint: disable-msg=E1101 - -TOOLS_RELEASE_URL = "http://download.tizen.org/tools/archive/" -TOOLS_RELEASE_TITLE = '[Dev] Tizen SCM Tools Release - %s' - -TOOLS_RELEASE_BODY = 'Hi, Everyone.\n\n' \ - 'Tizen SCM Tools packages are released.\n' \ - '- Tizen SCM Tools : http://download.tizen.org/tools/latest-release/ ( http://download.tizen.org/tools/archive/%s/ )\n\n' \ - 'For details on \'New Features & Enhancements\' and \'Bug Fixes\', please refer to Release Notes : \n' \ - '- http://download.tizen.org/tools/archive/%s/RELEASE_NOTES_GBS.txt \n' \ - '- http://download.tizen.org/tools/archive/%s/RELEASE_NOTES_MIC.txt \n\n' \ - 'Best Regards.' \ - - -TOOLS_RELEASE_FOOTER = '\n\n--------------------------------------------------------\n'\ - 'Automatically generated by backend service.\n'\ - 'Please DO NOT Reply!' - -TOOLS_RELEASE_FILES = ["RELEASE_NOTES_GBS.txt",\ - "RELEASE_NOTES_MIC.txt",\ - "RELEASE_NOTES_REPA.txt"] - -def send_mail_tool_release_message(release_id): - """ send mail about tools release """ - - #make a message - title = TOOLS_RELEASE_TITLE % ( release_id) - email_body = TOOLS_RELEASE_BODY % (release_id, release_id, release_id) - - msg = email_body + TOOLS_RELEASE_FOOTER - - submitter = os.getenv('TO') - - if submitter: - prepare_mail("%s.env" % os.getenv('BUILD_TAG'), title, msg, - os.getenv('NOREPLY_EMAIL_SENDER'), submitter) - - print "\n\n--------------------------------------------------------\n" - print os.getenv('NOREPLY_EMAIL_SENDER') - print title - print msg - print submitter - -def check_mail_send_option(option): - #check option condition - check_result = "TRUE" - - if len(option) < 5: - print "Need more input data" - return "Need more input data" - - release_id = option[2] - destination = option[3] - - if release_id != None: - regex = re.compile(r'^[0-9]{2}.[0-9]{2}.[0-9]{1,3}$') - release_id_pattern = regex.search(release_id) - print release_id, release_id_pattern - if release_id_pattern == None: - return "Need change value for release_id : %s " % (release_id) - - if option[3] == "staging": - print "Jenkins destination parameter value is staging" - return "Need change value for destination" - - return check_result - - -def check_release_txt_file(option): - #check option condition - check_result = "TRUE" - url = TOOLS_RELEASE_URL+option[2] - f = requests.get(url, timeout=30) - if f.status_code != 200: - return ("%s url error" % (url)) - - soup = BeautifulSoup(f.text, 'html.parser') - - for l in TOOLS_RELEASE_FILES: - pattern_text = l - result=str(soup.findAll('a', attrs={'href': re.compile(pattern_text)})) - if pattern_text not in result: - return (" %s version is not in %s " % (pattern_text, url)) - - return check_result - - -def check_release_id_option(option): - #check option condition - check_result = "TRUE" - url = TOOLS_RELEASE_URL - - f = requests.get(url, timeout=30) - if f.status_code != 200: - return ("%s url error" % (url)) - - soup = BeautifulSoup(f.text, 'html.parser') - pattern_version=option[2] - result=str(soup.findAll('a', attrs={'href': re.compile(pattern_version)})) - - if pattern_version not in result: - return (" %s version is not in %s " % (pattern_version, url)) - - return check_result - - -def mail_send_condion_check(option): - """ Check condition before send mail """ - - #check option condition - check_result = "TRUE" - - #1) Check option - check_result = check_mail_send_option(option) - if check_result != "TRUE": - return check_result - else: - print "Checked : option for release mail send" - - #2) Check download Server - check_result = check_release_id_option(option) - if check_result != "TRUE": - return check_result - else: - print "Checked : %s version is in %s" % (option[2], TOOLS_RELEASE_URL) - - #3) Check release txt file - check_result = check_release_txt_file(option) - if check_result != "TRUE": - return check_result - else: - print "Checked : release txt files are in %s%s" % (TOOLS_RELEASE_URL, option[2] ) - - return check_result - -def main(option): - """ - Script entry point. - Parameters: - project - type of project for release - release_id - release version - destination - code release destination ( staging or download.tizen.org ) - update_latest_release ( version update or not ) - - """ - if len(option) < 5: - print "Need more input data" - return 0 - - script=option[0] - project = option[1] - release_id = option[2] - destination = option[3] - update_latest_release = option[4] - - - # Before Send mail , must check condition ( test result, public download server , and so on ) - check_mail_send_condition = mail_send_condion_check(option) - - if check_mail_send_condition == 'TRUE': - print "Create release mail body" - send_mail_tool_release_message(release_id) - else: - print "Mail send condition is wrong" - print check_mail_send_condition - -if __name__ == '__main__': - sys.exit(main(sys.argv)) - +#!/usr/bin/env python +# vim: ai ts=4 sts=4 et sw=4 +# +# Copyright (C) 2010, 2011, 2012, 2013, 2014 Intel, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import os +import sys +import re +import requests +from bs4 import BeautifulSoup + +sys.path.insert(0, os.path.join(os.getcwd(), 'jenkins-scripts')) +from common.send_mail import prepare_mail + + +# set default char-set endcoding to utf-8 +reload(sys) +sys.setdefaultencoding('utf-8') # pylint: disable-msg=E1101 + +TOOLS_RELEASE_URL = "http://download.tizen.org/tools/archive/" +TOOLS_RELEASE_TITLE = '[Dev] Tizen SCM Tools Release - %s' + +TOOLS_RELEASE_BODY = 'Hi, Everyone.\n\n' \ + 'Tizen SCM Tools packages are released.\n' \ + '- Tizen SCM Tools : http://download.tizen.org/tools/latest-release/ ( http://download.tizen.org/tools/archive/%s/ )\n\n' \ + 'For details on \'New Features & Enhancements\' and \'Bug Fixes\', please refer to Release Notes : \n' \ + '- http://download.tizen.org/tools/archive/%s/RELEASE_NOTES_GBS.txt \n' \ + '- http://download.tizen.org/tools/archive/%s/RELEASE_NOTES_MIC.txt \n\n' \ + 'Best Regards.' \ + + +TOOLS_RELEASE_FOOTER = '\n\n--------------------------------------------------------\n'\ + 'Automatically generated by backend service.\n'\ + 'Please DO NOT Reply!' + +TOOLS_RELEASE_FILES = ["RELEASE_NOTES_GBS.txt",\ + "RELEASE_NOTES_MIC.txt",\ + "RELEASE_NOTES_REPA.txt"] + +def send_mail_tool_release_message(release_id): + """ send mail about tools release """ + + #make a message + title = TOOLS_RELEASE_TITLE % ( release_id) + email_body = TOOLS_RELEASE_BODY % (release_id, release_id, release_id) + + msg = email_body + TOOLS_RELEASE_FOOTER + + submitter = os.getenv('TO') + + if submitter: + prepare_mail("%s.env" % os.getenv('BUILD_TAG'), title, msg, + os.getenv('NOREPLY_EMAIL_SENDER'), submitter) + + print "\n\n--------------------------------------------------------\n" + print os.getenv('NOREPLY_EMAIL_SENDER') + print title + print msg + print submitter + +def check_mail_send_option(option): + #check option condition + check_result = "TRUE" + + if len(option) < 5: + print "Need more input data" + return "Need more input data" + + release_id = option[2] + destination = option[3] + + if release_id != None: + regex = re.compile(r'^[0-9]{2}.[0-9]{2}.[0-9]{1,3}$') + release_id_pattern = regex.search(release_id) + print release_id, release_id_pattern + if release_id_pattern == None: + return "Need change value for release_id : %s " % (release_id) + + if option[3] == "staging": + print "Jenkins destination parameter value is staging" + return "Need change value for destination" + + return check_result + + +def check_release_txt_file(option): + #check option condition + check_result = "TRUE" + url = TOOLS_RELEASE_URL+option[2] + f = requests.get(url, timeout=30) + if f.status_code != 200: + return ("%s url error" % (url)) + + soup = BeautifulSoup(f.text, 'html.parser') + + for l in TOOLS_RELEASE_FILES: + pattern_text = l + result=str(soup.findAll('a', attrs={'href': re.compile(pattern_text)})) + if pattern_text not in result: + return (" %s version is not in %s " % (pattern_text, url)) + + return check_result + + +def check_release_id_option(option): + #check option condition + check_result = "TRUE" + url = TOOLS_RELEASE_URL + + f = requests.get(url, timeout=30) + if f.status_code != 200: + return ("%s url error" % (url)) + + soup = BeautifulSoup(f.text, 'html.parser') + pattern_version=option[2] + result=str(soup.findAll('a', attrs={'href': re.compile(pattern_version)})) + + if pattern_version not in result: + return (" %s version is not in %s " % (pattern_version, url)) + + return check_result + + +def mail_send_condion_check(option): + """ Check condition before send mail """ + + #check option condition + check_result = "TRUE" + + #1) Check option + check_result = check_mail_send_option(option) + if check_result != "TRUE": + return check_result + else: + print "Checked : option for release mail send" + + #2) Check download Server + check_result = check_release_id_option(option) + if check_result != "TRUE": + return check_result + else: + print "Checked : %s version is in %s" % (option[2], TOOLS_RELEASE_URL) + + #3) Check release txt file + check_result = check_release_txt_file(option) + if check_result != "TRUE": + return check_result + else: + print "Checked : release txt files are in %s%s" % (TOOLS_RELEASE_URL, option[2] ) + + return check_result + +def main(option): + """ + Script entry point. + Parameters: + project - type of project for release + release_id - release version + destination - code release destination ( staging or download.tizen.org ) + update_latest_release ( version update or not ) + + """ + if len(option) < 5: + print "Need more input data" + return 0 + + script=option[0] + project = option[1] + release_id = option[2] + destination = option[3] + update_latest_release = option[4] + + + # Before Send mail , must check condition ( test result, public download server , and so on ) + check_result = mail_send_condion_check(option) + + if check_result == 'TRUE': + print "Create release mail body" + send_mail_tool_release_message(release_id) + else: + print "Mail send condition is wrong" + print check_result + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/pmb/trigger_tools_staging_test.py b/pmb/trigger_tools_staging_test.py index 4ddfdcb..ba9f584 100644 --- a/pmb/trigger_tools_staging_test.py +++ b/pmb/trigger_tools_staging_test.py @@ -1,58 +1,58 @@ -from common.git import Git, clone_gitproject, GitError -from common.gerrit import Gerrit, GerritError -from gbp.git.repository import GitRepositoryError -import sys -import os -import datetime -from time import sleep - -def request_github_release_tag(release_version): - - WORKSPACE = os.getcwd() - git_tools_repo=['tools/mic', 'tools/gbs'] - gerrit = Gerrit('review.tizen.org', 'tizentools', 29418, 0) - - for git_repo in git_tools_repo: - git_cache = os.path.join(WORKSPACE) - prjdir = os.path.join(git_cache, git_repo) - - try: - gitprj = Git(prjdir) - except GitRepositoryError, err: - #clone project to local workspace if it doesn't exist in git cache - - localdir = os.path.join(WORKSPACE, git_repo) - if not clone_gitproject(git_repo, localdir, gerrit_hostname="review.tizen.org", gerrit_username="tizentools", gerrit_sshport=29418, git_cache_dir=WORKSPACE): - return -1 - gitprj = Git('%s/%s' % (WORKSPACE,git_repo)) - - message = 'Release Tools : %s ' % (release_version) - - release_tag = "released-tools-"+release_version - - commitid = gitprj.rev_parse('HEAD') - - gitprj.create_tag(release_tag, message, commitid) - sleep(1) - - remote = 'ssh://%s@%s:%s/%s' % (gerrit.username, gerrit.host, gerrit.port,git_repo) - - print "git_repo : ", git_repo - print "message : ", message - print "release_tag : ", release_tag - print "commitid : ", commitid - print "remote : ", remote - - try: - gitprj.push_tag(remote, release_tag) - except GitRepositoryError, gre: - print gre - return -1 - -def main(option): - release_version = option[1] - request_github_release_tag(release_version) - return 0 - -if __name__ == '__main__': - sys.exit(main(sys.argv)) +from common.git import Git, clone_gitproject, GitError +from common.gerrit import Gerrit, GerritError +from gbp.git.repository import GitRepositoryError +import sys +import os +import datetime +from time import sleep + +def request_github_release_tag(release_version): + + WORKSPACE = os.getcwd() + git_tools_repo=['tools/mic', 'tools/gbs'] + gerrit = Gerrit('review.tizen.org', 'tizentools', 29418, 0) + + for git_repo in git_tools_repo: + git_cache = os.path.join(WORKSPACE) + prjdir = os.path.join(git_cache, git_repo) + + try: + gitprj = Git(prjdir) + except GitRepositoryError, err: + #clone project to local workspace if it doesn't exist in git cache + + localdir = os.path.join(WORKSPACE, git_repo) + if not clone_gitproject(git_repo, localdir, gerrit_hostname="review.tizen.org", gerrit_username="tizentools", gerrit_sshport=29418, git_cache_dir=WORKSPACE): + return -1 + gitprj = Git('%s/%s' % (WORKSPACE,git_repo)) + + message = 'Release Tools : %s ' % (release_version) + + release_tag = "released-tools-"+release_version + + commitid = gitprj.rev_parse('HEAD') + + gitprj.create_tag(release_tag, message, commitid) + sleep(1) + + remote = 'ssh://%s@%s:%s/%s' % (gerrit.username, gerrit.host, gerrit.port,git_repo) + + print "git_repo : ", git_repo + print "message : ", message + print "release_tag : ", release_tag + print "commitid : ", commitid + print "remote : ", remote + + try: + gitprj.push_tag(remote, release_tag) + except GitRepositoryError, gre: + print gre + return -1 + +def main(option): + release_version = option[1] + request_github_release_tag(release_version) + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) -- 2.7.4