def Execute(self): try: default_passwd = "123456" for (account, email) in self.username: Log.Blue( "\n===============================================================\n" ) if not self.dryrun: self.default_mail_list.append(email) #判断一下这个帐号是不是已经存在了,存在就打印错误,继续下一个 if account not in self.GetAllNormalUserName( ) or email not in self.GetComment(account): # 判断是否在 用户列表中, 还要判断全名是否在这个用户的comment字段下面 Log.Error("%s not exists" % (account)) raise ManageUserException("%s not exists" % account) # 设置帐号密码 cmd = "sudo bash -c \"echo -ne %s:%s | chpasswd\"" % ( account, default_passwd) Log.Info("reset passwd cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("reset passwd fail") # 重置密码就要发邮件给 用户了 self.success_mail_list.append(email) # end for结束遍历 Log.Info("will send pass mail") self.SendPassMail() except Exception as e: Log.Error("reset passwd fail: %s, will send fail mail" % e) traceback.print_exc() self.SendFailMail("%s" % (e)) return 1 return 0
def CreatePropject(self, targetpath, targetbranch, repertory_L): # 获取gerrit上相关仓库 cmd = "ssh -p %s %s gerrit ls-projects | grep -E \"%s|%s\" " % (self.gerrit_port, self.gerrit_host, targetpath, self.proprietary_project) Log.Info("list project on gerrit: %s" % cmd) status, output = commands.getstatusoutput(cmd) if status == 0: project_L = output.splitlines() create_L = [] for repertory in repertory_L: project = os.path.join(targetpath, repertory) if repertory == "LINUX" or repertory == "proprietary": project = self.proprietary_project if project not in project_L: create_L.append(project) for basedir in create_L: cmd = "ssh -p %s %s gerrit create-project %s --empty-commit --parent Permission_parent/All-bsp " \ "--submit-type REBASE_IF_NECESSARY --branch %s" % ( self.gerrit_port, self.gerrit_host, basedir, targetbranch) Log.Info("will create project: %s" % cmd) if not self.dryrun and os.system(cmd) != 0: Log.Error("crate %s failed" % (basedir)) raise SubtreeGitError("create project fail")
def SubtreeRepertory(self, config=""): self.CloneGit() repertory_D = self.GetRepertory(config) self.CreatePropject(self.targetpath, self.targetbranch, repertory_D.keys()) os.chdir(self.qcom_base) for (repertory, basedir) in repertory_D.items(): # sepcial for proprietary and build 对于特殊的LINUX目录需要特殊处理 if repertory == "LINUX" or repertory == "proprietary": if repertory == "LINUX": # 这里等于LINUX的时候表明是没有填写配置文件的 basedir = "LINUX/android/vendor/qcom/proprietary" cmd = "git subtree split -P %s -b proprietary_master" % (basedir) Log.Info("subtree proprietary cmd: %s" % cmd) os.system(cmd) cmd = "git push ssh://%s:%s/%s proprietary_master:%s -f" % ( self.gerrit_host, self.gerrit_port, self.proprietary_project, self.targetbranch) Log.Info("will proprietary push to gerrit: %s" % cmd) if not self.dryrun and os.system(cmd) != 0: raise SubtreeGitError("push proprietary to gerrit fail") else: local_branch = repertory.replace("/", "__") cmd = "git subtree split -P %s -b %s_master" % (basedir, local_branch) Log.Info("subtree cmd: %s" % cmd) os.system(cmd) cmd = "git push ssh://%s:%s/%s/%s %s_master:%s -f" % ( self.gerrit_host, self.gerrit_port, self.targetpath, repertory, local_branch, self.targetbranch) Log.Info("will push to gerrit: %s" % cmd) if not self.dryrun and os.system(cmd) != 0: raise SubtreeGitError("push to gerrit fail") self.PrintGitLog(repertory_D.keys())
def Execute(self): try: default_work = "/work" for (account, email) in self.username: Log.Blue( "\n===============================================================\n" ) if account not in self.GetAllNormalUserName( ) or email not in self.GetComment(account): Log.Error("%s is not exists" % (account)) raise ManageUserException("%s not exists" % account) cmd = "sudo bash -c \"userdel -r %s\"" % (account) Log.Info("delete user cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("delete user fail") cmd = "sudo bash -c \"rm -rf %s\"" % (os.path.join( default_work, account)) Log.Info("delete user work dir cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("delete user work folder fail") Log.Info("will send pass mail") self.SendPassMail() except Exception as e: Log.Error("delete user fail: %s, will send fail mail" % e) traceback.print_exc() self.SendFailMail("%s" % (e)) return 1 return 0
def main(): (options, args) = parseargs() srcpath = options.srcpath.strip() # 需要复制的源路径 dstpath = options.dstpath.strip() # 复制的目的路径 assigner = options.assigner.strip() ignore_folder = os.environ.get("XD_FOLDER", "").strip() # 忽略不复制的子目录名称 dry_run = os.environ.get("DRY_RUN", "").strip() dry_run = True if dry_run == "true" else False if not dry_run: release_flog_file = os.path.join(srcpath, ".release.txt") mode = "a" if os.path.isfile(release_flog_file) else "w" with open(release_flog_file, mode) as fd: fd.write("release to: %s" % dstpath) if ignore_folder != "": # 忽略复制的目录 xd_option = " /xd %s " % ignore_folder else: xd_option = "" robocopy_cmd = "robocopy %s %s /e /v /mt:32 %s" % (srcpath, dstpath, xd_option) Log.Info("copy cmd: [%s]" % robocopy_cmd) if not dry_run: os.system(robocopy_cmd) if not dry_run: release_flog_file = os.path.join(dstpath, ".release.txt") mode = "a" if os.path.isfile(release_flog_file) else "w" with open(release_flog_file, mode) as fd: fd.write("release from: %s" % srcpath)
def Execute(self): publish_path = os.path.dirname(self.source_manifest_file) imsagedate = os.path.basename(publish_path) folers_L = os.listdir(publish_path) for folder in folers_L: product_path = os.path.join(publish_path, folder) if not os.path.isdir(product_path): continue if "_userdebug_" not in folder: # 只测试userdebug的版本 continue image_path = os.path.join(product_path, "flash") if not os.path.isdir(image_path): Log.Warning("%s path not exists" % image_path) continue image_path = "\\\\%s%s" % ("10.0.12.12", image_path.replace("/", "\\")) jsondata = { "TaskName": "[%s]-%s-%s" % ( self.build_type, imsagedate, folder), "Policy": "%s.xml" % folder, "Execute": True, "RecoveryPath": image_path, "Uname": self.build_type } Log.Info("json: \n%s" % jsondata) self.HttpPost(jsondata)
def PrintGitLog(self, repertory_L): Log.Info("The repertory info list is:") manifest_str = "" for repertory in repertory_L: if repertory == "LINUX" or repertory == "proprietary": log_cmd = "git log -1 -b proprietary_master --pretty=\"%H<gitlog>%s\"" else: local_branch = repertory.replace("/", "__") log_cmd = "git log -1 -b %s_master --pretty=\"%%H<gitlog>%%s\"" % (local_branch) status, output = commands.getstatusoutput(log_cmd) if status == 0: temp_L = output.strip().split("<gitlog>") Log.Red("%25s %s\n" % (repertory, temp_L)) git_commit_id = temp_L[0] if self.qcom_base == "proprietary": # 表明是proprietary需要分仓 manifest_str += " <project name=\"platform/vendor/qcom/proprietary/%s\" path=\"vendor/qcom/proprietary/%s\" revision=\"%s\" />\n" % ( repertory, repertory, self.targetbranch) else: # 其他的表示 高通的大仓库需要分仓 if repertory == "LINUX" or repertory == "proprietary": manifest_str += " <project name=\"platform/vendor/qcom/proprietary\" path=\"vendor/qcom/proprietary\" revision=\"%s\" />\n" % ( git_commit_id) else: manifest_str +=" <project name=\"AMSS/%s\" path=\"AMSS/%s\" revision=\"%s\" />\n" % ( repertory, repertory, git_commit_id) Log.Blue("\n%s\n" % manifest_str)
def CloneGit(self): if os.path.exists(self.qcom_base) and os.path.isdir(self.qcom_base): cmd = "cd %s && git fetch --all --tags && git checkout %s" % (self.qcom_base, self.srcbranch) else: cmd = "git clone ssh://%s:%s/%s %s && cd %s && git checkout %s" % (self.gerrit_host, self.gerrit_port, self.basepath, self.qcom_base, self.qcom_base, self.srcbranch) Log.Info("will clone/fetch base git and checkout to branch: %s, cmd: %s" % (self.srcbranch, cmd)) ret = os.system(cmd) if ret != 0: raise SubtreeGitError("git clone/fetch/checkout fail")
def Execute(self): try: for (account, email) in self.username: # 这里的account 就是 登陆时候的账号,email就是这个员工的邮箱地址 Log.Blue( "\n===============================================================\n" ) if not self.dryrun: self.default_mail_list.append(email) cmd = "sudo bash -c \"usermod -c %s %s\"" % (email, account) Log.Info("lock user cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("update user comment fail") Log.Info("will send pass mail") self.SendPassMail() except Exception as e: Log.Error("update user comment fail: %s, will send fail mail" % e) traceback.print_exc() self.SendFailMail("%s" % (e)) return 1 return 0
def Execute(self): try: for (account, email) in self.username: Log.Blue( "\n===============================================================\n" ) if account not in self.GetAllNormalUserName( ) or email not in self.GetComment(account): Log.Error("%s is not exists" % (account)) raise ManageUserException("%s not exists" % account) cmd = "sudo bash -c \"usermod -L %s\"" % (account) Log.Info("lock user cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("lock user fail") Log.Info("will send pass mail") self.SendPassMail() except Exception as e: Log.Error("lock user fail: %s, will send fail mail" % e) traceback.print_exc() self.SendFailMail("%s" % (e)) return 1 return 0
def main(): (options, args) = parseargs() srcpath = options.srcpath.strip() signjarpath = options.signjarpath.strip() product = options.product.strip() assigner = options.assigner.strip() keytype = options.keytype.strip() if not os.path.isfile(srcpath): Log.Error("src apk path not exists") return 1 if not os.path.isfile(signjarpath): Log.Error("sign.jar path not exists") return 1 if srcpath.endswith(".apk"): dstpath = srcpath + "_signed.apk" elif srcpath.endswith(".zip"): dstpath = srcpath + "_signed.zip" else: dstpath = srcpath + ".signed" cmd = "git clone ssh://gerrit.zeusis.com:29418/git/private/product_key" ret = os.system(cmd) if ret != 0: Log.Error("git clone key fail") return 1 wipe = os.environ.get("WIPE_USER_DATA", "").strip() wipe_user_data = True if wipe == "true" else False cmd = "java -Xmx2048m -jar %s " % (signjarpath) if wipe_user_data: cmd += " -w " cmd += " ./product_key/%s_key/%s.x509.pem ./product_key/%s_key/%s.pk8 %s %s" % ( product, keytype, product, keytype, srcpath, dstpath) Log.Info("sign apk/zip cmd: [%s]" % cmd) ret = os.system(cmd) if ret != 0: Log.Error("sign apk fail") return 1 sendmail(assigner, dstpath)
def Execute(self): publish_path = os.path.dirname(self.source_manifest_file) platform_path = os.path.dirname(publish_path) html_file = os.path.join(platform_path, "LAST_BUILD.%s.html" % self.platform) table = "" all_globpattern = "*_*" all_paths = glob.glob(os.path.join(platform_path, all_globpattern)) all_paths = list(reversed(all_paths)) for imagedate_path in all_paths: if os.path.isdir(imagedate_path): folders_L = os.listdir(imagedate_path) for folder in folders_L: product_path = os.path.join(imagedate_path, folder) if os.path.isdir(product_path): version = self.GetBuildId(product_path) Log.Info("imagepath: %s, %s, version: %s " % (imagedate_path, folder, version)) imdatedate = os.path.basename(imagedate_path) ip = os.environ.get("FILE_SERVER_IP", "10.0.12.12") smb_path = "\\\\%s%s" % (ip, imagedate_path.replace("/", "\\")) table += "<tr align=\"left\"><td width=\"50%%\"><a href=\"%s\"> %s </a></td><td width=\"25%%\">%s</td><td width=\"25%%\">%s</td></tr>\n" \ % (imdatedate, smb_path,folder, version) body = """ <br/> <br/> <table table width=\"80%%\" class=\"altrowstable\" border=\"1\"> %s </table> <br/> <br/> """ % table html = HTML % (TABLE_CSS_STYLE, body) with open(html_file, "w") as fd: fd.write(html)
def main(): yesterday = datetime.date.today() - datetime.timedelta(days=1) date_format = "%Y-%m-%d" # date to string format #sshd_log.2017 - 03 - 19. gz ssh_log_file_name = "sshd_log.%s.gz" % (yesterday.strftime(date_format)) ssh_log_file = os.path.join(GERRIT_LOG_PATH, ssh_log_file_name) if os.path.isfile(ssh_log_file): shutil.copy(ssh_log_file, ssh_log_file_name) os.system("gzip -df %s" % (ssh_log_file_name)) ssh_log_file_name = "sshd_log.%s" % (yesterday.strftime(date_format)) ssh_log_file = os.path.join(GERRIT_LOG_PATH, ssh_log_file_name) if os.path.isfile(ssh_log_file): shutil.copy(ssh_log_file, ssh_log_file_name) account_D = {} ssh_log_file_name = "sshd_log.%s" % (yesterday.strftime(date_format)) if os.path.isfile(ssh_log_file_name): with open(ssh_log_file_name, "r") as fd: for line in fd: if "git-upload-pack" in line: temp_L = line.split(" ") account = temp_L[4] if account_D.has_key(account): account_D[account] += 1 else: account_D.setdefault(account, 1) account_L = sorted(account_D.items(), key=operator.itemgetter(1), reverse=True) sql = "" for (account, download) in account_L: if download >= 50: sql += "account_external_ids.external_id = 'username:%s' or " % ( account) sql += " 2=1 " sql = SQL_ACCOUNT % (sql) cmd = "ssh -p 29418 %s gerrit gsql -c \" %s \" " % (GERRIT_IP, sql) status, output = commands.getstatusoutput(cmd) email_L = [] username_D = {} for line in output.splitlines(): if "username:"******"|") email_L.append(temp_L[1].strip()) username = temp_L[0].split(":")[1].strip() if username_D.has_key(username): username_D[username] = temp_L[2].strip() else: username_D.setdefault(username, temp_L[2].strip()) table = """ <tr> <th width=\"10%\">gerrit全名</th> <th width=\"10%\">gerrit账号</th> <th width=\"5%\">下载次数统计</th> </tr> """ for (account, download) in account_L: if download >= 50: table += "<tr><td width=\"5%%\">%s</td><td width=\"5%%\">%s</td><td width=\"5%%\">%s</td></tr>" % ( username_D.get(account, ""), account, download) subject = "[Gerrit][success][%s] 下代码人员统计" % ( yesterday.strftime(date_format)) body = WIKI_HTML_PRE body += """ <br/> <table table width=\"40%%\" class=\"altrowstable\" border=\"1\"> %s </table> <br/> """ % table html = HTML % (TABLE_CSS_STYLE, body) sm = SendMail() to = ["*****@*****.**"] assigner = os.environ.get("ASSIGNER", "*****@*****.**").strip().split(",") to.extend(assigner) to.extend(email_L) Log.Info("will send email to: %s" % to) sm.SendHtmlMail(to, subject, html) return
def Execute(self): try: default_passwd = "123456" default_work = "/work" for (account, email) in self.username: Log.Blue( "\n===============================================================\n" ) if not self.dryrun: self.default_mail_list.append(email) #判断一下这个帐号是不是已经存在了,存在就打印错误,继续下一个 all_username_L = self.GetAllUserName() if account in all_username_L: Log.Error("%s is already exists" % (account)) raise ManageUserException("%s is already exists" % account) #add user cmd = "sudo bash -c \"useradd -m -s /bin/bash -c %s %s\" " % ( email, account) Log.Info("adduser cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("adduser fail") # 设置帐号密码 cmd = "sudo bash -c \"echo -ne %s:%s | chpasswd\"" % ( account, default_passwd) Log.Info("set passwd cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("set passwd fail") # 设置smb的帐号密码 cmd = "sudo bash -c 'echo -ne \"%s\\n%s\\n\" |smbpasswd -a -s %s'" % ( default_passwd, default_passwd, account) Log.Info("set smb passwd cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("set smb passwd fail") # 创建连接 work 文件 user_work = os.path.join(default_work, account) link_work = "/home/%s/work" % (account) cmd = "sudo bash -c \"mkdir -p %s && chown %s:%s %s -R\"" % ( user_work, account, account, user_work) Log.Info("create work path cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("create user work path fail") # 创建连接 work的文件 cmd = "sudo bash -c \"ln -s %s %s && chown %s:%s %s -h\"" % ( user_work, link_work, account, account, link_work) Log.Info("create link work file cmd: [%s]" % cmd) if not self.dryrun and os.system(cmd) != 0: raise ManageUserException("create link work file fail") # 添加新的用户也是要发邮件给 用户了 self.success_mail_list.append(email) # end for Log.Info("will send pass mail") self.SendPassMail() except Exception as e: Log.Error("adduser fail: %s, will send fail mail" % e) traceback.print_exc() self.SendFailMail("%s" % (e)) return 1 return 0