• Python笔记


    环境:

    搭建教程: http://www.hankcs.com/program/python/python-ide.html

    1.  PyCharm : https://www.jetbrains.com/pycharm/download

    2. 安装解释器:http://www.python.org/getit/

    3. 破解:打开网站 http://idea.lanyus.com/ , 看到最新的授权服务器

    教程:

    基础教程: http://www.runoob.com/python/python-tutorial.html

    从C#到Python,不错: http://www.cnblogs.com/yanxy/archive/2010/02/22/ILovePython.html

    1. 常用框架

     Flask:轻量级Mvc

    示例讲解:http://www.jianshu.com/p/303057e51417

    自定义Flask中的响应类:http://www.itnpc.com/news/industry/144731529226137.html

    Flask知识点收集: http://blog.csdn.net/sasoritattoo/article/details/9703429

    系统教程,可导出PDF:http://dormousehole.readthedocs.io/en/latest/

    django

    http://www.nowamagic.net/academy/detail/13281808

    2. C语言扩展

    教程:http://www.cnblogs.com/phinecos/archive/2010/05/17/1737033.html

     3. 安装包

    https://pypi.org/project/pexpect/#files

    pip install pexpect

    自动部署,上传

    #!/usr/bin/env python3
    #coding=utf-8
    
    import os, sys, getopt ,pexpect,shutil
    from pprint import pprint
    import git_update
    
    version=""
    name=""
    server_ip="127.0.0.2"
    java_path=""
    html_path=""
    local=""
    product=""
    
    jwd_src_path =  os.path.abspath( os.path.join( __file__ ,"../../../" ) )
    os.chdir( jwd_src_path + "/pzx" )
    
    def help():
        #print(sys.version)
        print ('''  金维度发版工具
            -v --version,[prod|test|dev]
            -p --product,[html|java]
            -l --local 添加参数表示仅在本地编译,不进行git获取
            -h --help 帮助
        ''');
    
        sys.exit();
    
    def init():
        global version,name,java_path,html_path,local
        opts, args = getopt.getopt(sys.argv[1:], "v:p:lh" ,["version=","product=","local","help"] )
    
        for c, v in opts:
            if c in ("-v", "--version"):
                version = v
            if c in ("-p", "--product"):
                product=v
            elif c in ("-l", "--local"):
                local= True
            elif c in ( "-h", "--help" ):
                help()
    
        if version == "" :
            help();
    
        if version == "" :
            version="prod"
    
        if  version == "prod" :
            name= "正式版"
            java_path="/var/www/pzx_java"
            html_path="/var/www/pzx_html"
        elif  version == "test" :
            name= "测试版"
            java_path="/var/test/pzx_2081"
            html_path="/var/test/pzx_2080"
        elif version == "dev" :
            name= "开发版"
            java_path="/var/dev/pzx_3081"
            html_path="/var/dev/pzx_3080"
        else:
            help();
    
    
        name = '''品致信 - %s(%s)'''%(name,version)
    
        print()
        print( "=============================================")
        print()
        print( "             " + name   )
        print()
        print( "=============================================")
        print()
    
    def git__update():
        if not local :
            git_update.git_update(version);
    
    def rm_vue2():
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/dist" )
    
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/dist_cn" )
    
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/dist_en" )
    
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/html_cn" )
    
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/dist_en" )
    
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/src_cn" )
    
        if  os.path.exists( jwd_src_path + '/pzx_vue2/dist') :
            shutil.rmtree(jwd_src_path + "/pzx_vue2/src_en" )
    
    def p(code):
        if( code >> 8 ):
            print();
            print("系统出现错误!")
            sys.exit();
    
    if __name__=='__main__':
    
        init();
    
        git__update();
    
        p(os.system('''
            mvn install:install-file -Dfile=lib/pzx-entity-3.0.0.jar -DgroupId=jwd -DartifactId=pzx-entity -Dversion=3.0.0 -Dpackaging=jar
            mvn clean package -Dmaven.test.skip=true'''
        ))
    
        print('''%s Java程序打包完成,打包 Html 部分...'''%(name) );
    
        os.chdir( jwd_src_path + "/pzx_vue2" )
        rm_vue2();
    
        git__update();
    
        p(os.system('''
            npm install
            tag-lang-cli  --clean --file-type vue,js,html --config c:cn,e:en --source ./html
            tag-lang-cli  --clean --file-type vue,js,html --config c:cn,e:en --source ./src
            npm run build %s %s
            '''%( "cn" , version )
        ))
    
        print('''%s 前端程序打包完成,开始上传...'''%(name) );
    
        child=pexpect.spawn('''scp -r %s/pzx/target/pzx-3.0.0.jar root@%s:%s''' % (jwd_src_path,server_ip,java_path) )
        child.expect("password:", timeout=3);
        child.sendline("password");
        child.interact()
        child.close()
    
    
        path="%s/pzx_vue2/dist_cn"%(jwd_src_path)
        for  file in os.listdir( path)  :
            child=pexpect.spawn('''scp -r %s root@%s:%s_cn''' % (os.path.join(path,file),server_ip,html_path) )
            child.expect("password:", timeout=3);
            child.sendline("password");
            child.interact()
            child.close()
    
    
        child=pexpect.spawn('ssh  %s@%s' % ("root",server_ip) , timeout=3)
        child.expect("password:", timeout=3);
        child.sendline("password");
    
        child.expect("root@", timeout=3);
        child.sendline("cd %s"%(java_path));
    
        child.sendline("ps aux | grep  "pzx-3.0.0.jar --spring.profiles.active=%s" | awk '{print $2}' |xargs kill -9"%(version));
        child.expect("root@", timeout=3);
        child.sendline("nohup  java -jar %s/pzx-3.0.0.jar --spring.profiles.active=%s --pzxmq.consumer=true --pzx.myUtils.hostId=1  >/dev/null 2>&1 &"%(java_path,version));
    
        child.expect("root@", timeout=3);
        child.sendline("");
    
        child.expect("root@", timeout=3);
        child.sendline("exit");
    
        child.interact()
        child.close()
    #!/usr/bin/env python3
    #coding=utf-8
    
    import os, sys, getopt ,pexpect,shutil
    
    version=""
    name=""
    
    jwd_src_path =  os.path.abspath( os.path.join( __file__ ,"../../../" ) )
    os.chdir( jwd_src_path + "/pzx" )
    
    
    def help():
        print ('''  金维度 git update 工具
            [prod|test|dev]
        ''');
    
        sys.exit();
    
    def init():
        global version,name;
        if version == "" :
            version="prod"
    
        if  version == "prod" :
            name= "正式版"
        elif  version == "test" :
            name= "测试版"
        elif version == "dev" :
            name= "开发版"
        else:
            help();
    
    def p(code):
        if( code >> 8 ):
            print();
            print("系统出现错误!")
            sys.exit();
    
    def git_update(ver):
        global version
        version = ver
    
        init();
    
        print();
        print(  '''正在获取代码 %s %s(%s) ...'''%(os.getcwd(),name,version))
        print()
    
        if  os.path.exists( jwd_src_path + '/.git/index.lock') :
            os.remove(  jwd_src_path +"/.git/index.lock" )
    
    
        child=pexpect.spawn('git fetch' )
        child.expect ('Username for', timeout=3)
        child.sendline( "Git用户帐号")
    
        child.expect ('Password for', timeout=3)
        child.sendline( "Git用户密码")
    
        child.interact()
        child.close()
    
        p(os.system( 'git reset --hard origin/' + version ) )
    
    if __name__=='__main__':
        git_update(sys.argv[1]);

    笔记:

    1. context

    flask中又两种context(上下文),分别是application context和request context。
    
    其中request就是request context。当 HTTP 请求过来的时候,进入这个上下文。
    
    题主的那些方法都是一些flaks的hooks。用于针对request做一些操作,比如
    
    before_request:在请求收到之前绑定一个函数做一些事情。
    after_request: 每一个请求之后绑定一个函数,如果请求没有异常。
    teardown_request: 每一个请求之后绑定一个函数,即使遇到了异常。
    至于用来干嘛?可以做很多关于request pre的事情,和request after的事情。
    
    比如,before_request的时候创建一个db连接,然后teardown_request的时候断开这个连接.

    2. 如何设置全局的 before_equest,after_request ? 

    3. 

  • 相关阅读:
    luogu_1414 又是毕业季II
    luogu_1372 又是毕业季I
    luogu_1313 计算系数
    luogu_1134 阶乘问题
    luogu_1514 引水入城
    luogu_1120 小木棍
    文件操作
    快速排序
    c oth
    ANSI C与C89、C99、C11区别差异
  • 原文地址:https://www.cnblogs.com/newsea/p/5496741.html
Copyright © 2020-2023  润新知