Beispiel #1
0
def OpenRoot():
    if 0 != os.system("passwd root"):
        return "Failed to change password of root"
    #修改第一个文件项
    szConfig, szErr = maker_public.readTxtFile(
        "/usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf")
    if 0 < len(szErr):
        return szErr
    if None==re.search("\n[ \\t]*greeter-show-manual-login[ \\t]*=[ \\t]*.+", szConfig) and \
        None==re.search("^[ \\t]*greeter-show-manual-login[ \\t]*=[ \\t]*.+", szConfig):
        szConfig += "\ngreeter-show-manual-login=true"
    if None==re.search("\n[ \\t]*all-guest[ \\t]*=[ \\t]*.+", szConfig) and \
        None==re.search("^[ \\t]*all-guest[ \\t]*=[ \\t]*.+", szConfig):
        szConfig += "\nall-guest=false"
    szErr = maker_public.writeTxtFile(
        "/usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf", szConfig)
    if 0 < len(szErr):
        return szErr
    #修改第二个文件项
    szConfig, szErr = maker_public.readTxtFile("/etc/pam.d/gdm-autologin")
    if 0 < len(szErr):
        return szErr
    szConfig = re.sub("\n[ \\t]*auth[ \\t]+required[ \\t]+pam_succeed_if.so[ \\t]+user[ \\t]+!=[ \\t]+root[ \\t]+quiet_success", \
        "\n#auth required pam_succeed_if.so user != root quiet_success", szConfig)
    szConfig = re.sub("^[ \\t]*auth[ \\t]+required[ \\t]+pam_succeed_if.so[ \\t]+user[ \\t]+!=[ \\t]+root[ \\t]+quiet_success", \
        "#auth required pam_succeed_if.so user != root quiet_success", szConfig)
    szErr = maker_public.writeTxtFile("/etc/pam.d/gdm-password", szConfig)
    if 0 < len(szErr):
        return szErr
    #修改第三个文件
    szConfig, szErr = maker_public.readTxtFile("/etc/pam.d/gdm-password")
    if 0 < len(szErr):
        return szErr
    szConfig = re.sub("\n[ \\t]*auth[ \\t]+required[ \\t]+pam_succeed_if.so[ \\t]+user[ \\t]+!=[ \\t]+root[ \\t]+quiet_success", \
        "\n#auth required pam_succeed_if.so user != root quiet_success", szConfig)
    szConfig = re.sub("^[ \\t]*auth[ \\t]+required[ \\t]+pam_succeed_if.so[ \\t]+user[ \\t]+!=[ \\t]+root[ \\t]+quiet_success", \
        "#auth required pam_succeed_if.so user != root quiet_success", szConfig)
    szErr = maker_public.writeTxtFile("/etc/pam.d/gdm-password", szConfig)
    if 0 < len(szErr):
        return szErr
    #修改第四个文件
    szConfig, szErr = maker_public.readTxtFile("/root/.profile")
    if 0 < len(szErr):
        return szErr
    if None==re.search("\n[ \\t]*tty[ \\t]+-s[ \\t]*&&[ \\t]*mesg[ \\t]+n[ \\t]+\\|\\|[ \\t]+.+", szConfig) and \
        None==re.search("^[ \\t]*tty[ \\t]+-s[ \\t]*&&[ \\t]*mesg[ \\t]+n[ \\t]+\\|\\|[ \\t]+.+", szConfig):
        szConfig = re.sub("\n[ \\t]*mesg[ \\t]+n[ \\t]+\\|\\|[ \\t]+.+",
                          "\ntty -s&&mesg n || true", szConfig)
        szConfig = re.sub("^[ \\t]*mesg[ \\t]+n[ \\t]+\\|\\|[ \\t]+.+",
                          "\ntty -s&&mesg n || true", szConfig)

    szErr = maker_public.writeTxtFile("/root/.profile", szConfig)
    if 0 < len(szErr):
        return szErr
    #
    return ""
Beispiel #2
0
def MakeProject(szLangType, szAppType, szProjPath):
    #建立include目录
    szErr = maker_public.makeDirs(szProjPath + "/include")
    if 0 < len(szErr):
        return szErr
    #建立src目录
    szErr = maker_public.makeDirs(szProjPath + "/src")
    if 0 < len(szErr):
        return szErr
    #建立.vscode目录
    szErr = maker_public.makeDirs(szProjPath + "/.vscode")
    if 0 < len(szErr):
        return szErr
    #建立makefile
    if "c" == szLangType:
        szErr = makeMakefile(szAppType, szProjPath, "gcc", ".c", "c11")
    else:
        szErr = makeMakefile(szAppType, szProjPath, "g++", ".cpp", "c++11")
    if 0 < len(szErr):
        return szErr
    #建立配置索引配置目录
    szErr = makePropertiesfile(szProjPath)
    if 0 < len(szErr):
        return szErr
    #建立编译任务
    szErr = makeBuildfile(szProjPath)
    if 0 < len(szErr):
        return szErr
    #建立调试任务
    szErr = makeDebugfile(szProjPath)
    if 0 < len(szErr):
        return szErr
    #建立主文件
    szData = \
        "//函数功能:主函数\n"\
        "//函数参数:可执行文件全路径,启动时加入的参数\n"\
        "//函数返回:执行成功返回0,否则返回负值的错误码\n"
    if "c" == szLangType:
        szData += \
            "int main(void){\n"\
            "    return 0;\n"\
            "}\n"
        szErr = maker_public.writeTxtFile(szProjPath + "/src/main.c", szData)
    else:
        szData += \
            "int main(){\n"\
            "    return 0;\n"\
            "}\n"
        szErr = maker_public.writeTxtFile(szProjPath + "/src/main.cpp", szData)
    if 0 < len(szErr):
        return szErr
    #
    return ""
Beispiel #3
0
def makeDebugfile(szProjPath):
    szConfig = \
        "{\n"\
        "    // Use IntelliSense to learn about possible attributes.\n"\
        "    // Hover to view descriptions of existing attributes.\n"\
        "    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n"\
        "    \"version\": \"0.2.0\",\n"\
        "    \"configurations\": [\n"\
        "        {\n"\
        "            \"name\": \"gcc build and debug active file\",\n"\
        "            \"type\": \"cppdbg\",\n"\
        "            \"request\": \"launch\",\n"\
        "            \"program\": \"${workspaceFolder}/debug/"+os.path.basename(szProjPath)+"\",\n"\
        "            \"args\": [],\n"\
        "            \"stopAtEntry\": false,\n"\
        "            \"cwd\": \"${workspaceFolder}\",\n"\
        "            \"environment\": [],\n"\
        "            \"externalConsole\": false,\n"\
        "            \"MIMode\": \"gdb\",\n"\
        "            \"setupCommands\": [\n"\
        "                {\n"\
        "                    \"description\": \"Enable pretty-printing for gdb\",\n"\
        "                    \"text\": \"-enable-pretty-printing\",\n"\
        "                    \"ignoreFailures\": true\n"\
        "                }\n"\
        "            ],\n"\
        "            \"preLaunchTask\": \"gcc build active file\",\n"\
        "            \"miDebuggerPath\": \"/usr/bin/gdb\"\n"\
        "        }\n"\
        "    ]\n"\
        "}\n"
    return maker_public.writeTxtFile(szProjPath + "/.vscode/launch.json",
                                     szConfig)
Beispiel #4
0
def ConfigDebSource():
    #获取Ubuntu的版本名称
    CodeNameObj = re.match("^Codename[ \\t]*\\:[ \\t]*([\\S]+)",
                           maker_public.execCmdAndGetOutput("lsb_release -c"))
    if None == CodeNameObj:
        return "Can not find codename!"
    szCodeName = CodeNameObj[1]
    #安装网易源
    szAptSource = \
        "deb http://mirrors.163.com/ubuntu/ "+szCodeName+" main restricted universe multiverse\n"\
        "deb http://mirrors.163.com/ubuntu/ "+szCodeName+"-security main restricted universe multiverse\n"\
        "deb http://mirrors.163.com/ubuntu/ "+szCodeName+"-updates main restricted universe multiverse\n"\
        "deb http://mirrors.163.com/ubuntu/ "+szCodeName+"-proposed main restricted universe multiverse\n"\
        "deb http://mirrors.163.com/ubuntu/ "+szCodeName+"-backports main restricted universe multiverse\n"\
        "deb-src http://mirrors.163.com/ubuntu/ "+szCodeName+" main restricted universe multiverse\n"\
        "deb-src http://mirrors.163.com/ubuntu/ "+szCodeName+"-security main restricted universe multiverse\n"\
        "deb-src http://mirrors.163.com/ubuntu/ "+szCodeName+"-updates main restricted universe multiverse\n"\
        "deb-src http://mirrors.163.com/ubuntu/ "+szCodeName+"-proposed main restricted universe multiverse\n"\
        "deb-src http://mirrors.163.com/ubuntu/ "+szCodeName+"-backports main restricted universe multiverse\n"
    #
    szErr = maker_public.writeTxtFile("/etc/apt/sources.list", szAptSource)
    if 0 < len(szErr):
        return szErr
    if 0 != os.system("apt-get update"):
        return "Update sources.list failed"
    return ""
Beispiel #5
0
def ConfigSshd():
    #安装
    if 0 != os.system("apt-get -y install openssh-server"):
        return "Install openssh-server failed"
    #读取配置文件
    szSshdConf, szErr = maker_public.readTxtFile("/etc/ssh/sshd_config")
    if 0 < len(szErr):
        return szErr
    #修正配置文件内容
    #
    szSshdConf = re.sub("\\n[ \\t]*PubkeyAuthentication.+", \
        "\nPubkeyAuthentication yes", szSshdConf)
    szSshdConf = re.sub("\\n[ \\t]*#[ \\t]*PubkeyAuthentication.+", \
        "\nPubkeyAuthentication yes", szSshdConf)
    #
    szSshdConf = re.sub("\\n[ \\t]*AllowTcpForwarding.+", \
        "\nAllowTcpForwarding yes", szSshdConf)
    szSshdConf = re.sub("\\n[ \\t]*#[ \\t]*AllowTcpForwarding.+", \
        "\nAllowTcpForwarding yes", szSshdConf)
    #
    szSshdConf = re.sub("\\n[ \\t]*AuthorizedKeysFile.+", \
        "\nAuthorizedKeysFile .ssh/authorized_keys", szSshdConf)
    szSshdConf = re.sub("\\n[ \\t]*#[ \\t]*AuthorizedKeysFile.+", \
        "\nAuthorizedKeysFile .ssh/authorized_keys", szSshdConf)
    #写入配置文件
    szErr = maker_public.writeTxtFile("/etc/ssh/sshd_config", szSshdConf)
    if 0 < len(szErr):
        return szErr
    #重启服务
    if 0 != os.system("systemctl restart sshd"):
        return "restart sshd failed"
    return ""
Beispiel #6
0
def ConfigGolang():
    #安装 golang
    if False == os.path.exists("./go1.13.6.linux-amd64.tar.gz"):
        if 0 != os.system(
                "wget https://studygolang.com/dl/golang/go1.13.6.linux-amd64.tar.gz"
        ):
            return "Failed to download golang1.13.6"
    if -1 == maker_public.execCmdAndGetOutput(\
        "su -c \"/usr/local/go/bin/go version\"").find("go1.13.6"):
        os.system("rm -Rf /usr/local/go")
        if 0 != os.system(
                "tar -C /usr/local -zxvf ./go1.13.6.linux-amd64.tar.gz"):
            return "Failed to uncompress golang1.13.6"
        #设置环境变量
        szConfig, szErr = maker_public.readTxtFile("/etc/profile")
        if 0 < len(szErr):
            return szErr
        if None == re.search("\\nexport[ \\t]+GOPATH[ \\t]*=[ \\t]*\\/root/go",
                             szConfig):
            szConfig += "\nexport GOPATH=/root/go"
        if None == re.search(
                "\\nexport[ \\t]+PATH[ \\t]*=[ \\t]*\\$PATH:\\$GOPATH/bin:/usr/local/go/bin",
                szConfig):
            szConfig += "\nexport PATH=$PATH:$GOPATH/bin:/usr/local/go/bin"
        szErr = maker_public.writeTxtFile("/etc/profile", szConfig)
        if 0 < len(szErr):
            return szErr
    #安装工具
    szErr = maker_public.installGolangTools("/usr/local/go/bin/go")
    if 0 < len(szErr):
        return szErr
    #
    return ""
Beispiel #7
0
def MakeProject(szLangType, szAppType, szProjPath):
    #建立.vscode目录
    szErr = maker_public.makeDirs(szProjPath + "/.vscode")
    if 0 < len(szErr):
        return szErr
    #建立主模块
    szErr = maker_public.makeDirs(szProjPath + "/main")
    if 0 < len(szErr):
        return szErr
    #建立主入口文件
    szData = \
        "{\n"\
        "    // Use IntelliSense to learn about possible attributes.\n"\
        "    // Hover to view descriptions of existing attributes.\n"\
        "    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n"\
        "    \"version\": \"0.2.0\",\n"\
        "    \"configurations\": [\n"\
        "        {\n"\
        "            \"type\": \"java\",\n"\
        "            \"name\": \"Debug (Launch) - Current File\",\n"\
        "            \"request\": \"launch\",\n"\
        "            \"mainClass\": \"${file}\",\n"\
        "            \"cwd\": \"${workspaceFolder}\"\n"\
        "        }\n"\
        "    ]\n"\
        "}\n"
    szErr = maker_public.writeTxtFile(szProjPath + "/.vscode/launch.json",
                                      szData)
    if 0 < len(szErr):
        return szErr
    #建立主文件
    szData = \
        "package main;\n\n\n"\
        "//函数功能:主函数\n"\
        "//函数参数:可执行文件全路径,启动时加入的参数\n"\
        "//函数返回:执行成功返回0,否则返回负值的错误码\n"\
        "public class projectmain{\n"\
        "    public static void main(String[] Args){\n"\
        "    }\n"\
        "}\n"
    szErr = maker_public.writeTxtFile(szProjPath + "/main/projectmain.java",
                                      szData)
    if 0 < len(szErr):
        return szErr
    #
    return ""
Beispiel #8
0
def MakeProject(szLangType, szAppType, szProjPath):
    #建立.vscode目录
    szErr = maker_public.makeDirs(szProjPath + "/.vscode")
    if 0 < len(szErr):
        return szErr
    #建立主入口文件
    szData = \
        "{\n"\
        "    // Use IntelliSense to learn about possible attributes.\n"\
        "    // Hover to view descriptions of existing attributes.\n"\
        "    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n"\
        "    \"version\": \"0.2.0\",\n"\
        "    \"configurations\": [\n"\
        "        {\n"\
        "            \"name\": \"Python: Current File\",\n"\
        "            \"type\": \"python\",\n"\
        "            \"request\": \"launch\",\n"\
        "            \"program\": \"${workspaceFolder}/__init__.py\",\n"\
        "            \"args\": [\n"\
        "                \"\"\n"\
        "            ],\n"\
        "            \"cwd\": \"${workspaceFolder}\",\n"\
        "            \"console\": \"integratedTerminal\"\n"\
        "        }\n"\
        "    ]\n"\
        "}\n"
    szErr = maker_public.writeTxtFile(szProjPath + "/.vscode/launch.json",
                                      szData)
    if 0 < len(szErr):
        return szErr
    #建立主文件
    szData = \
        "#!/usr/python/bin\n"\
        "# -*- coding: utf-8 -*-\n\n\n"\
        "#函数功能:主函数\n"\
        "#函数参数:可执行文件全路径,启动时加入的参数\n"\
        "#函数返回:执行成功返回0,否则返回负值的错误码\n"\
        "if __name__ == \"__main__\":\n"
    szErr = maker_public.writeTxtFile(szProjPath + "/__init__.py", szData)
    if 0 < len(szErr):
        return szErr
    #
    return ""
Beispiel #9
0
def makeBuildfile(szProjPath):
    szConfig = \
        "{\n"\
        "    // See https://go.microsoft.com/fwlink/?LinkId=733558\n"\
        "    // for the documentation about the tasks.json format\n"\
        "    \"version\": \"2.0.0\",\n"\
        "    \"tasks\": [\n"\
        "        {\n"\
        "            \"type\": \"shell\",\n"\
        "            \"label\": \"gcc build active file\",\n"\
        "            \"command\": \"/usr/bin/make\",\n"\
        "            \"args\": [\n"\
        "                \"-f\",\n"\
        "                \"${workspaceFolder}/makefile\",\n"\
        "                \"debug\"\n"\
        "            ],\n"\
        "            \"options\": {\n"\
        "                \"cwd\": \"${workspaceFolder}\"\n"\
        "            },\n"\
        "            \"problemMatcher\": [\n"\
        "                \"$gcc\"\n"\
        "            ],\n"\
        "            \"group\": {\n"\
        "                \"kind\": \"build\",\n"\
        "                \"isDefault\": true\n"\
        "            }\n"\
        "        },\n"\
        "        {\n"\
        "            \"type\": \"shell\",\n"\
        "            \"label\": \"gcc clean active file\",\n"\
        "            \"command\": \"/usr/bin/make\",\n"\
        "            \"args\": [\n"\
        "                \"-f\",\n"\
        "                \"${workspaceFolder}/makefile\",\n"\
        "                \"clean\"\n"\
        "            ],\n"\
        "            \"options\": {\n"\
        "                \"cwd\": \"${workspaceFolder}\"\n"\
        "            },\n"\
        "            \"problemMatcher\": [\n"\
        "                \"$gcc\"\n"\
        "            ],\n"\
        "            \"group\": {\n"\
        "                \"kind\": \"build\",\n"\
        "                \"isDefault\": true\n"\
        "            }\n"\
        "        }\n"\
        "    ]\n"\
        "}\n"
    return maker_public.writeTxtFile(szProjPath + "/.vscode/tasks.json",
                                     szConfig)
Beispiel #10
0
def MakeProject(szLangType, szAppType, szProjPath):
    #建立bin目录
    szErr = maker_public.makeDirs(szProjPath+"/bin")
    if 0 < len(szErr):
        return szErr
    #建立src目录
    szErr = maker_public.makeDirs(szProjPath+"/src")
    if 0 < len(szErr):
        return szErr
    #建立pkg目录
    szErr = maker_public.makeDirs(szProjPath+"/pkg")
    if 0 < len(szErr):
        return szErr
    #建立main目录
    szErr = maker_public.makeDirs(szProjPath+"/src/main")
    if 0 < len(szErr):
        return szErr
    #建立.vscode目录
    szErr = maker_public.makeDirs(szProjPath+"/.vscode")
    if 0 < len(szErr):
        return szErr
    #建立makefile
    szErr = makeMakefile(szAppType, szProjPath)
    if 0 < len(szErr):
        return szErr
    #建立编译任务
    szErr = makeBuildfile(szProjPath)
    if 0 < len(szErr):
        return szErr   
    #建立调试任务
    szErr = makeDebugfile(szProjPath)
    if 0 < len(szErr):
        return szErr
    #建立主文件
    szData = \
        "package main\n\n\n"\
        "import (\n"\
	    "    \"fmt\"\n"\
        ")\n\n\n"\
        "//函数功能:主函数\n"\
        "//函数参数:无\n"\
        "//函数返回:进程退出码\n"\
        "func main()  {\n"\
        "	fmt.Print(\"hello world\")\n"\
        "}"
    szErr = maker_public.writeTxtFile(szProjPath+"/src/main/main.go", szData)
    if 0 < len(szErr):
        return szErr
    #
    return ""
    
Beispiel #11
0
def makeMakefile(szAppType, szProjPath):
    #检测
    if "app"!=szAppType and "shared"!=szAppType and "static"!=szAppType:
        return ("Invalid output(%s)" %(szAppType))
    #读取基础的makefile文件
    szMakeCont,szErr = maker_public.readTxtFile( os.path.dirname(sys.argv[0])+"/golang_maker/makefile.conf" )
    if 0 < len(szErr):
        return szErr
    #替换编译选项
    if "app" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*GOFLAGS[ \\t]*:=.*", \
            "\nGOFLAGS := -a -v -gcflags \"-N -l\" -ldflags \"-w -s\"", szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*GOFLAGS_DBG[ \\t]*:=.*", \
            "\nGOFLAGS_DBG := -v -gcflags \"-N -l\"", szMakeCont)
    elif "shared" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*GOFLAGS[ \\t]*:=.*", \
            "\nGOFLAGS := -a -v -gcflags \"-N -l\" -ldflags \"-w -s\" -buildmode=plugin", szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*GOFLAGS_DBG[ \\t]*:=.*", \
            "\nGOFLAGS_DBG := -v -gcflags \"-N -l\" -buildmode=plugin", szMakeCont)
    else:
        szMakeCont = re.sub("\\n[ \\t]*GOFLAGS[ \\t]*:=.*", \
            "\nGOFLAGS := -a -v -gcflags \"-N -l\" -ldflags \"-w -s\" -buildmode=archive", szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*GOFLAGS_DBG[ \\t]*:=.*", \
            "\nGOFLAGS_DBG := -i -v -gcflags \"-N -l\" -buildmode=archive", szMakeCont)
    #替换编译命令
    if "app" == szAppType:
        szMakeCont = re.sub("\\n\\t\\$\\(GO\\)[ \\t]*\\$\\(GOFLAGS\\)[ \\t]*\\$\\(LIBS\\).*", \
            "\n\t$(GO) $(GOFLAGS) $(LIBS) ./...;\\\n\tcp -f $(TOP_DIR)/bin/main $(TOP_DIR)/bin/"+os.path.basename(szProjPath), \
                szMakeCont)
        szMakeCont = re.sub("\\n\\t\\$\\(GO\\)[ \\t]*\\$\\(GOFLAGS_DBG\\)[ \\t]*\\$\\(LIBS\\).*", \
            "\n\t$(GO) $(GOFLAGS_DBG) $(LIBS) ./...;\\\n\tcp -f $(TOP_DIR)/bin/main $(TOP_DIR)/bin/"+os.path.basename(szProjPath), \
                szMakeCont)   
    elif "shared" == szAppType:
        szMakeCont = re.sub("\\n\\t\\$\\(GO\\)[ \\t]*\\$\\(GOFLAGS\\)[ \\t]*\\$\\(LIBS\\).*", \
            "\n\t$(GO) $(GOFLAGS) $(LIBS) main;\\\n\tcp -f $(TOP_DIR)/pkg/linux_amd64_dynlink/main.a "\
                "$(TOP_DIR)/pkg/linux_amd64_dynlink/"+os.path.basename(szProjPath)+".a", \
                szMakeCont)
        szMakeCont = re.sub("\\n\\t\\$\\(GO\\)[ \\t]*\\$\\(GOFLAGS_DBG\\)[ \\t]*\\$\\(LIBS\\).*", \
            "\n\t$(GO) $(GOFLAGS_DBG) $(LIBS) main;\\\n\tcp -f $(TOP_DIR)/pkg/linux_amd64_dynlink/main.a "\
                "$(TOP_DIR)/pkg/linux_amd64_dynlink/"+os.path.basename(szProjPath)+".a", \
                szMakeCont)
    #else:
    #替换GOPATH
    szMakeCont = re.sub("\\n[ \\t]*GOPATH[ \\t]*:=.*", ("\nGOPATH := %s:%s" %(szProjPath, os.environ["HOME"]+"/go")), szMakeCont)
    #写入makefile文件
    szErr = maker_public.writeTxtFile(szProjPath+"/makefile", szMakeCont)
    return szErr
Beispiel #12
0
def makeDebugfile(szProjPath):
    szConfig = \
    "    {\n"\
    "        // Use IntelliSense to learn about possible attributes.\n"\
    "        // Hover to view descriptions of existing attributes.\n"\
    "        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n"\
    "        \"version\": \"0.2.0\",\n"\
    "        \"configurations\": [\n"\
    "            {\n"\
    "                \"name\": \"Launch\",\n"\
    "                \"type\": \"go\",\n"\
    "                \"request\": \"launch\",\n"\
    "                \"mode\": \"debug\",\n"\
    "                \"program\": \"${workspaceFolder}/src/main/main.go\",\n"\
    "                \"env\": {\n"\
    "                    \"GOPATH\":\"${workspaceFolder}:"+os.environ["HOME"]+"/go"+"\"\n"\
    "                },\n"\
    "                \"args\": []\n"\
    "            }\n"\
    "        ]\n"\
    "    }\n"
    return maker_public.writeTxtFile(szProjPath+"/.vscode/launch.json", szConfig)
Beispiel #13
0
def ConfigJava():
    szCurWorkPath = os.path.dirname(os.path.realpath(sys.argv[0]))
    print(
        "First:Please download JDK for https://www.oracle.com/java/technologies/javase-downloads.html."
    )
    print("Second: Move the RPM filr to %s." % (szCurWorkPath))
    raw_input("Last: Press any key to continue...")
    #获取JDKRPM包的名称
    szJdkRpm = ""
    szJdkName = ""
    FileList = os.listdir(os.path.dirname(os.path.realpath(sys.argv[0])))
    for szCurFile in FileList:
        if None != re.search("jdk\\-.+_linux\\-x64_bin\\.rpm", szCurFile):
            szJdkRpm = str(
                os.path.dirname(os.path.realpath(sys.argv[0])) + "/" +
                szCurFile)
            szJdkName = str(re.sub("_linux\\-x64_bin\\.rpm", "", szCurFile))
            break
    if 0 >= len(szJdkRpm):
        return "Can not find any file like jdk_xx.xx.xx_linux-x64_bin.rpm"
    #安装RPM包
    szErr = installOrUpdateRpm(szJdkName, "x86_64", szJdkRpm)
    if 0 < len(szErr):
        return szErr
    #设置配置文件
    szProFileConf, szErr = maker_public.readTxtFile("/etc/profile")
    if 0 < len(szErr):
        return szErr
    if None == re.search("\\nexport[ \\t]+JAVA_HOME[ \\t]*=.+", szProFileConf):
        szProFileConf += "\n\nexport JAVA_HOME=/usr/java/" + szJdkName
    else:
        szProFileConf = re.sub("\\nexport[ \\t]+JAVA_HOME[ \\t]*=.+", \
            "\nexport JAVA_HOME=/usr/java/"+szJdkName, szProFileConf)
    szErr = maker_public.writeTxtFile("/etc/profile", szProFileConf)
    if 0 < len(szErr):
        return szErr
    #返回
    return ""
Beispiel #14
0
def UpdateSystem():
    os.system("yum clean all")
    if 0 != os.system("yum -y update"):
        return "Update CentOS failed"
    #关闭防火墙
    os.system("systemctl stop firewalld.service")
    if 0 != os.system("systemctl disable firewalld.service"):
        return "Disable firewalld failed"
    #关闭SELINUX
    szSelinux, szErr = maker_public.readTxtFile("/etc/selinux/config")
    if 0 < len(szErr):
        return "Disable SELINUX failed"
    szSelinux = re.sub("\\n[ \\t]*SELINUX[ \\t]*=[ \\t]*.+",
                       "\nSELINUX=disabled", szSelinux)
    szErr = maker_public.writeTxtFile("/etc/selinux/config", szSelinux)
    if 0 < len(szErr):
        return "Disable SELINUX failed"
    #配置时钟同步
    os.system("systemctl enable ntpd.service")
    os.system("systemctl stop ntpd.service")
    os.system("systemctl start ntpd.service")
    os.system("systemctl status ntpd.service")
    return ""
Beispiel #15
0
def makePropertiesfile(szProjPath):
    szConfig = \
        "{\n"\
        "    \"configurations\": [\n"\
        "        {\n"\
        "            \"name\": \"Linux\",\n"\
        "            \"includePath\": [\n"\
        "                \"${workspaceFolder}/**\",\n"\
        "                \"/usr/include\",\n"\
        "                \"/usr/local/include\",\n"\
        "                \"/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include\"\n"\
        "            ],\n"\
        "            \"defines\": [],\n"\
        "            \"compilerPath\": \"/usr/bin/gcc\",\n"\
        "            \"cStandard\": \"c11\",\n"\
        "            \"cppStandard\": \"c++11\",\n"\
        "            \"intelliSenseMode\": \"gcc-x64\"\n"\
        "        }\n"\
        "    ],\n"\
        "    \"version\": 4\n"\
        "}"
    return maker_public.writeTxtFile(
        szProjPath + "/.vscode/c_cpp_properties.json", szConfig)
Beispiel #16
0
def makeMakefile(szAppType, szProjPath, szComplier, szSuffix, szStd):
    #检测
    if "app" != szAppType and "shared" != szAppType and "static" != szAppType:
        return ("Invalid output(%s)" % (szAppType))
    #读取基础的makefile文件
    szMakeCont, szErr = maker_public.readTxtFile(
        os.path.dirname(sys.argv[0]) + "/cxx_maker/makefile.conf")
    if 0 < len(szErr):
        return szErr
    #替换编译器
    szMakeCont = re.sub("\\n[ \\t]*CXX[ \\t]*:=.*",
                        ("\nCXX := %s" % (szComplier)), szMakeCont)
    #替换后缀
    szMakeCont = re.sub("\\n[ \\t]*SUFFIX[ \\t]*:=.*",
                        ("\nSUFFIX := %s" % (szSuffix)), szMakeCont)
    #替换编译选项
    if "app" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*CXXFLAGS[ \\t]*:=.*", \
            ("\nCXXFLAGS := -std=%s -Wall -m64 -O2 -fPIC -fmessage-length=0" %(szStd)), szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*CXXFLAGS_DBG[ \\t]*:=.*", \
            ("\nCXXFLAGS_DBG := -std=%s -Wall -m64 -O0 -g3 -fPIC -fmessage-length=0" %(szStd)), szMakeCont)
    elif "shared" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*CXXFLAGS[ \\t]*:=.*", \
            ("\nCXXFLAGS := -std=%s -Wall -m64 -O2 -fPIC -fmessage-length=0 -fvisibility=hidden" %(szStd)), szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*CXXFLAGS_DBG[ \\t]*:=.*", \
            ("\nCXXFLAGS_DBG := -std=%s -Wall -m64 -O0 -g3 -fPIC -fmessage-length=0 -fvisibility=hidden" %(szStd)), szMakeCont)
    else:
        szMakeCont = re.sub("\\n[ \\t]*CXXFLAGS[ \\t]*:=.*", \
            ("\nCXXFLAGS := -std=%s -Wall -m64 -O2 -fPIC -fmessage-length=0" %(szStd)), szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*CXXFLAGS_DBG[ \\t]*:=.*", \
            ("\nCXXFLAGS_DBG := -std=%s -Wall -m64 -O0 -g3 -fPIC -fmessage-length=0" %(szStd)), szMakeCont)
    #替换链接器
    if "app" == szAppType or "shared" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*LD[ \\t]*:=.*", "\nLD := gcc",
                            szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*LDOUTFLG[ \\t]*:=.*",
                            "\nLDOUTFLG := -o", szMakeCont)
    else:
        szMakeCont = re.sub("\\n[ \\t]*LD[ \\t]*:=.*", "\nLD := ar",
                            szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*LDOUTFLG[ \\t]*:=.*", "\nLDOUTFLG := ",
                            szMakeCont)
    #替换链接选项
    if "app" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*LDFLAGS[ \\t]*:=.*",
                            "\nLDFLAGS := -Wl,-rpath,./", szMakeCont)
    elif "shared" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*LDFLAGS[ \\t]*:=.*",
                            "\nLDFLAGS := -Wl,-rpath,./ -shared", szMakeCont)
    else:
        szMakeCont = re.sub("\\n[ \\t]*LDFLAGS[ \\t]*:=.*",
                            "\nLDFLAGS := -crv", szMakeCont)
    #替换最终目标
    szTarget = os.path.basename(szProjPath)
    if "app" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*TARGET[ \\t]*:=.*",
                            ("\nTARGET := $(BIN_DIR)/%s" % (szTarget)),
                            szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*TARGET_DBG[ \\t]*:=.*",
                            ("\nTARGET_DBG := $(BIN_DIR_DBG)/%s" % (szTarget)),
                            szMakeCont)
    elif "shared" == szAppType:
        szMakeCont = re.sub("\\n[ \\t]*TARGET[ \\t]*:=.*",
                            ("\nTARGET := $(BIN_DIR)/lib%s.so" % (szTarget)),
                            szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*TARGET_DBG[ \\t]*:=.*",
                            ("\nTARGET_DBG := $(BIN_DIR_DBG)/lib%s.so" %
                             (szTarget)), szMakeCont)
    else:
        szMakeCont = re.sub("\\n[ \\t]*TARGET[ \\t]*:=.*",
                            ("\nTARGET := $(BIN_DIR)/lib%s.a" % (szTarget)),
                            szMakeCont)
        szMakeCont = re.sub("\\n[ \\t]*TARGET_DBG[ \\t]*:=.*",
                            ("\nTARGET_DBG := $(BIN_DIR_DBG)/lib%s.a" %
                             (szTarget)), szMakeCont)
    #写入makefile文件
    szErr = maker_public.writeTxtFile(szProjPath + "/makefile", szMakeCont)
    return szErr