zoukankan      html  css  js  c++  java
  • Python发布Django项目的pyc版脚本

    import os
    import sys
    from py_compile import compile
    
    #print "argvs:",sys.argv
    
    if len(sys.argv) == 3:
        comd = sys.argv[1]
        path = sys.argv[2]
        if os.path.exists(path) and os.path.isdir(path):
            for parent,dirname,filename in os.walk(path):
                for cfile in filename:
                    fullname = os.path.join(parent,cfile)
                    if comd == 'clean' and cfile[-4:] == '.pyc':
                        try:
                            os.remove(fullname)
                            print "Success remove file:%s" % fullname
                        except:
                            print "Can't remove file:%s" % fullname
                    if comd == 'compile' and cfile[-3:] == '.py':
                        try:
                            compile(fullname)
                            print "Success compile file:%s" % fullname
                        except:
                            print "Can't compile file:%s" % fullname
                    if comd == 'remove' and cfile[-3:] == '.py' and cfile != 'settings.py' and cfile != 'wsgi.py':
                        try:
                            os.remove(fullname)
                            print "Success remove file:%s" % fullname
                        except:
                            print "Can't remove file:%s" % fullname
        else:
            print "Not an directory or Direcotry doesn't exist!"
    else:
        print "Usage:"
        print "	python compile_pyc.py clean PATH		#To clean all pyc files"
        print "	python compile_pyc.py compile PATH		#To generate pyc files"
        print "	python compile_pyc.py remove PATH		#To remove py files"
  • 相关阅读:
    poj 1753 Flip Game
    SDIBT 2345 (3.2.1 Factorials 阶乘)
    HDU 1176 免费馅饼
    HDU 1058 Humble Numbers
    HDU 1003 MAXSUM(最大子序列和)
    HDU1864 最大报销额
    HDU 1114 Piggy-Bank(完全背包)
    POJ 3624 Charm Bracelet
    处理textarea里Enter(回车换行符)
    uniApp打卡日历
  • 原文地址:https://www.cnblogs.com/flowjacky/p/4317380.html
Copyright © 2011-2022 走看看