2012-05-28 93 views
6

version.py有一个方法get_git_version()当我执行./manage.py runserver这个错误是从version.py文件提出get_git_version找不到版本号

提高ValueError异常(“无法找到版本号!”)

def get_git_version(abbrev=4): 
    # Read in the version that's currently in RELEASE-VERSION. 

    release_version = read_release_version() 

    # First try to get the current version using "git describe". 

    version = call_git_describe(abbrev) 

    # If that doesn't work, fall back on the value that's in 
    # RELEASE-VERSION. 

    if version is None: 
     version = release_version 

    # If we still don't have anything, that's an error. 

    if version is None: 
     raise ValueError("Cannot find the version number!") 

    # If the current version is different from what's in the 
    # RELEASE-VERSION file, update the file to be current. 

    if version != release_version: 
     write_release_version(version) 

    # Finally, return the current version. 

    return version 


def read_release_version(): 
    try: 
     f = open("RELEASE-VERSION", "r") 

     try: 
      version = f.readlines()[0] 
      return version.strip() 

     finally: 
      f.close() 
    except: 
     return None 
+0

DEF read_release_version(): 尝试: F =打开( “释放VERSION”, “R”) 尝试: 版本= f.readlines()[0] 返回version.strip() 最后: f.close() 除外: 返回无 –

+1

检查'RELEASE-VERSION'文件的路径。另外通过在打开时附加文件扩展名来检查,如'RELEASE-VERSION.txt'。 –

回答

2

此脚本需要来自git注释标记(call_git_describe())的版本号,或者通过在名为RELEASE-VERSION的文件中查看版本号。它失败了,因为没有找到这两个东西,所以修复其中一个。在您的项目

运行它来创建注释当前标签承诺:

git tag 1.0 -m "this is version 1.0" 

我倾向于选择标记的版本管理,但版本在文本文件中也不错,情况因人而异。