コード例 #1
0
ファイル: adduser.py プロジェクト: yangzhang1992/script_tools
    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
コード例 #2
0
ファイル: adduser.py プロジェクト: yangzhang1992/script_tools
 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
コード例 #3
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")
コード例 #4
0
ファイル: adduser.py プロジェクト: yangzhang1992/script_tools
def main():
    (options, args) = parseargs()
    buildtype = options.buildtype.strip()
    username = options.username.strip().lower()
    assigner = options.assigner.strip()

    if buildtype == Type.ADDUSER:
        #add user
        add = AddUser(buildtype, username, assigner)
        ret = add.Execute()
    elif buildtype == Type.DELUSER:
        dele = DelUser(buildtype, username, assigner)
        ret = dele.Execute()
    elif buildtype == Type.LOCKUSER:
        lock = LockUser(buildtype, username, assigner)
        ret = lock.Execute()
    elif buildtype == Type.UNLOCKUSER:
        unlock = UnLockUser(buildtype, username, assigner)
        ret = unlock.Execute()
    elif buildtype == Type.RESETPW:
        reset = ResetPasswd(buildtype, username, assigner)
        ret = reset.Execute()
    elif buildtype == Type.UPDATEUSER:
        update = UpdateUser(buildtype, username, assigner)
        ret = update.Execute()
    else:
        Log.Error("invalid type %s " % buildtype)
        return 1

    return ret
コード例 #5
0
ファイル: signapk.py プロジェクト: yangzhang1992/script_tools
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)
コード例 #6
0
ファイル: adduser.py プロジェクト: yangzhang1992/script_tools
 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
コード例 #7
0
ファイル: adduser.py プロジェクト: yangzhang1992/script_tools
    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
コード例 #8
0
ファイル: adduser.py プロジェクト: yangzhang1992/script_tools
    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