Version-up script for Clarisse (Nuke Style)

Clarisse iFX11 字

一个参考Nuke升级文件的Clarisse python脚本

#
# Python script for Clarisse
# Saves a new version of the project by increasing the version number, Nuke-style.
# Use a "v" followed by a number with any padding in the filename such as "file_v001.project" and the script will find the version and save a new file for you.
#
 
 
 
def padding(s, num, p="0"):
    while len(s) < num: s = p + s
    return s
 
def log(i):
    ix.log_info(i)
 
def getProjectPath():
    path = ix.application.get_factory().get_vars().get("PDIR").get_string() + "/"
    project_file = ix.application.get_factory().get_vars().get("PNAME").get_string()
 
    if project_file.find(".project") == -1: project_file += ".project"
 
    project = path + project_file
 
    return path, project, project_file
 
 
def numeric(s):
    try:
        return int(s), True
    except:
        return "", False
 
def versionUp(n = ""):
    path, project, file_name = getProjectPath()
 
    file = project
 
    if len(n)>0: file = n                        # use argument passed if there is one
 
    v = file.rfind("v")
 
    if v == -1: return file, False               # no "v" found
 
    b = ""
    for i in range(v+1,len(file)):               # look for numbers following the "v"
        n, ok = numeric(file[i])
        if ok: b = b + file[i]
        else: break                              # stop looking at the first non-number
 
    pad = len(b)
    if pad == 0: return file, False              # the v had no numbers after it
 
    version, success = numeric(b)                # get integer from string
 
    if not success: return file, False           # non-number snuck in?
    version = version + 1
 
    restr = padding(str(version), pad)           # add back padding zeroes
 
    return file[:v] + "v" + restr + file[v+pad+1:], True    # construct new project name and return
 
 
 
 
 
new_name, success = versionUp()
 
if success: ix.save_project(new_name)
admin
博学之,审问之,慎思之,明辨之,笃行之。
OωO
开启隐私评论,您的评论仅作者和评论双方可见