Esempio n. 1
0
def createNodeInfoFile(dirPath, toKeep):
    """
    Creates the .nodeInfo file in the directory specified by dirPath.
    The Node:Type must be set by concrete nodes
    @precondition: dirPath is a valid directory
    @postcondition: All sections/tags are created and set except "Type".
        "Type" must be set by concrete nodes.
    """
    print "in createNodeInfoFile"
    username = amu.getUsername()
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())

    nodeInfo = ConfigParser()
    nodeInfo.add_section("Node")
    nodeInfo.set("Node", "Type", "")

    nodeInfo.add_section("Versioning")
    nodeInfo.set("Versioning", "LatestVersion", "0")
    nodeInfo.set("Versioning", "VersionsToKeep", str(toKeep))
    nodeInfo.set("Versioning", "Locked", "False")
    nodeInfo.set("Versioning", "LastCheckoutTime", timestamp)
    nodeInfo.set("Versioning", "LastCheckoutUser", username)
    nodeInfo.set("Versioning", "LastCheckinTime", timestamp)
    nodeInfo.set("Versioning", "LastCheckinUser", username)
    nodeInfo.add_section("Comments")
    nodeInfo.set("Comments", "v000", "New")

    amu._writeConfigFile(os.path.join(dirPath, ".nodeInfo"), nodeInfo)
Esempio n. 2
0
def createNodeInfoFile(dirPath, toKeep):
    """
    Creates the .nodeInfo file in the directory specified by dirPath.
    The Node:Type must be set by concrete nodes
    @precondition: dirPath is a valid directory
    @postcondition: All sections/tags are created and set except "Type".
        "Type" must be set by concrete nodes.
    """
    print "in createNodeInfoFile"
    username = amu.getUsername()
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())

    nodeInfo = ConfigParser()
    nodeInfo.add_section('Node')
    nodeInfo.set('Node', 'Type', '')

    nodeInfo.add_section('Versioning')
    nodeInfo.set('Versioning', 'LatestVersion', '0')
    nodeInfo.set('Versioning', 'VersionsToKeep', str(toKeep))
    nodeInfo.set('Versioning', 'Locked', 'False')
    nodeInfo.set('Versioning', 'LastCheckoutTime', timestamp)
    nodeInfo.set('Versioning', 'LastCheckoutUser', username)
    nodeInfo.set('Versioning', 'LastCheckinTime', timestamp)
    nodeInfo.set('Versioning', 'LastCheckinUser', username)
    nodeInfo.add_section('Comments')
    nodeInfo.set('Comments', 'v000', 'New')

    amu._writeConfigFile(os.path.join(dirPath, ".nodeInfo"), nodeInfo)
Esempio n. 3
0
def checkin(asset, comment):
    """
    Checks a folder back in as the newest version
    @precondition: toCheckin is a valid path
    @precondition: canCheckin() == True OR all conflicts have been resolved
    """
    print "Checking in asset ", asset

    # First, we'll have to set the comment in here.
    assetToCheckIn = os.path.join(getUserCheckoutDir(),
                                  os.path.basename(os.path.dirname(asset)))
    setComment(assetToCheckIn, comment)

    # Then we configure everything that is in here.

    # print toCheckin
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(assetToCheckIn, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")
    lockedbyme = chkoutInfo.getboolean("Checkout", "lockedbyme")

    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    locked = nodeInfo.getboolean("Versioning", "locked")
    toKeep = nodeInfo.getint("Versioning", "Versionstokeep")
    newVersion = nodeInfo.getint("Versioning", "latestversion") + 1
    newVersionPath = os.path.join(chkInDest, "src",
                                  "v" + ("%03d" % newVersion))

    if not canCheckin(asset):
        print "Can not overwrite locked folder."
        raise Exception("Can not overwrite locked folder.")

    # Checkin
    shutil.copytree(assetToCheckIn, newVersionPath)

    # And fix permissions for the new version asset so that everyone can access it.
    os.system('chmod 774 -R ' + newVersionPath)

    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    nodeInfo.set("Versioning", "lastcheckintime", timestamp)
    nodeInfo.set("Versioning", "lastcheckinuser", getUsername())
    nodeInfo.set("Versioning", "latestversion", str(newVersion))
    nodeInfo.set("Versioning", "locked", "False")
    amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)

    #print glob.glob(os.path.join(chkInDest, "src", "*"))
    if toKeep > 0:
        amu.purge(os.path.join(chkInDest, "src"), nodeInfo,
                  newVersion - toKeep)
        amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)

    # Clean up
    shutil.rmtree(assetToCheckIn)
    os.remove(os.path.join(newVersionPath, ".checkoutInfo"))

    return chkInDest
Esempio n. 4
0
def checkin(asset, comment):
    """
    Checks a folder back in as the newest version
    @precondition: toCheckin is a valid path
    @precondition: canCheckin() == True OR all conflicts have been resolved
    """
    print "Checking in asset ", asset

    # First, we'll have to set the comment in here.
    assetToCheckIn = os.path.join(getUserCheckoutDir(), os.path.basename(os.path.dirname(asset)))
    setComment(assetToCheckIn, comment)

    # Then we configure everything that is in here.

    # print toCheckin
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(assetToCheckIn, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")
    lockedbyme = chkoutInfo.getboolean("Checkout", "lockedbyme")
    
    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    locked = nodeInfo.getboolean("Versioning", "locked")
    toKeep = nodeInfo.getint("Versioning", "Versionstokeep")
    newVersion = nodeInfo.getint("Versioning", "latestversion") + 1
    newVersionPath = os.path.join(chkInDest, "src", "v"+("%03d" % newVersion))
    
    if not canCheckin(asset):
        print "Can not overwrite locked folder."
        raise Exception("Can not overwrite locked folder.")
    
    # Checkin
    shutil.copytree(assetToCheckIn, newVersionPath)

    # And fix permissions for the new version asset so that everyone can access it.
    os.system('chmod 774 -R '+ newVersionPath)
    
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    nodeInfo.set("Versioning", "lastcheckintime", timestamp)
    nodeInfo.set("Versioning", "lastcheckinuser", getUsername())
    nodeInfo.set("Versioning", "latestversion", str(newVersion))
    nodeInfo.set("Versioning", "locked", "False")
    amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)
    
    #print glob.glob(os.path.join(chkInDest, "src", "*"))
    if toKeep > 0:
        amu.purge(os.path.join(chkInDest, "src"), nodeInfo, newVersion - toKeep)
        amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)

    # Clean up
    shutil.rmtree(assetToCheckIn)
    os.remove(os.path.join(newVersionPath, ".checkoutInfo"))

    return chkInDest
Esempio n. 5
0
def setComment(toCheckin, comment):
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(toCheckin, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")

    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    newVersion = nodeInfo.getint("Versioning", "latestversion") + 1
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    commentLine = getUsername() + ': ' + timestamp + ': ' + '"' + comment + '"' 
    nodeInfo.set("Comments", 'v' + "%03d" % (newVersion,), commentLine) 
    amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)
Esempio n. 6
0
def setComment(toCheckin, comment):
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(toCheckin, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")

    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    newVersion = nodeInfo.getint("Versioning", "latestversion") + 1
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    commentLine = getUsername() + ': ' + timestamp + ': ' + '"' + comment + '"'
    nodeInfo.set("Comments", 'v' + "%03d" % (newVersion, ), commentLine)
    amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)
Esempio n. 7
0
def checkout(coPath, lock):
    """
	Copies the 'latest version' from the src folder into the local directory
	@precondition: coAsset is the name of an actual asset
	@precondition: lock is a boolean value
	
	@postcondition: A copy of the 'latest version' will be placed in the local directory
		with the name of the versioned folder
	@postcondition: If lock == True coPath will be locked until it is released by checkin
	"""

    print "in checkoutDAO, running checkout"
    print "coPath ", coPath
    # First need to grab the path file first.
    #if not os.path.exists(os.path.join(coPath, ".nodeInfo")):
    if not amu.isVersionedFolder(coPath):
        raise Exception("Not a versioned folder.")

    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(coPath, ".nodeInfo"))
    if nodeInfo.get(
            "Versioning", "locked"
    ) == "False":  # Isn't this the point of the isCheckedOut method??
        version = nodeInfo.getint("Versioning", "latestversion")
        toCopy = os.path.join(coPath, "src", "v" + ("%03d" % version))
        dest = getCheckoutDest(coPath)

        if (os.path.exists(toCopy)):
            try:
                shutil.copytree(
                    toCopy, dest
                )  # Make the copy. Note that dest (user's checkout directory) MUST NOT exist for this to work.
            except Exception:
                print "checkoutDAO, checkout: Could not copy files."
                raise Exception("Could not copy files.")
            timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p",
                                      time.localtime())
            nodeInfo.set("Versioning", "lastcheckoutuser", amu.getUsername())
            nodeInfo.set("Versioning", "lastcheckouttime", timestamp)
            nodeInfo.set("Versioning", "locked", str(lock))

            amu._writeConfigFile(os.path.join(coPath, ".nodeInfo"), nodeInfo)
            amu._createCheckoutInfoFile(dest, coPath, version, timestamp, lock)
        else:
            raise Exception("Version doesn't exist " + toCopy)
    else:
        whoLocked = nodeInfo.get("Versioning", "lastcheckoutuser")
        whenLocked = nodeInfo.get("Versioning", "lastcheckouttime")
        logname, realname = amu.lockedBy(whoLocked)
        whoLocked = 'User Name: ' + logname + '\nReal Name: ' + realname + '\n'
        raise Exception("Can not checkout. Folder is locked by:\n\n" +
                        whoLocked + "\nat " + whenLocked)
    return dest
Esempio n. 8
0
def unlock(ulPath):
	print "Inside checkoutDAO unlock"
	nodeInfo = ConfigParser()
	nodeInfo.read(os.path.join(ulPath, ".nodeInfo"))
	nodeInfo.set("Versioning", "locked", "False")

	toCopy = getCheckoutDest(ulPath)
	dirname = os.path.basename(toCopy) 
	parentPath = os.path.join(os.path.dirname(toCopy), ".unlocked")
	if not (os.path.exists(parentPath)):
		os.mkdir(parentPath)

	os.system('mv -f '+toCopy+' '+parentPath+'/')
	amu._writeConfigFile(os.path.join(ulPath, ".nodeInfo"), nodeInfo)
	return 0;
Esempio n. 9
0
def unlock(ulPath):
    print "Inside checkoutDAO unlock"
    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(ulPath, ".nodeInfo"))
    nodeInfo.set("Versioning", "locked", "False")

    toCopy = getCheckoutDest(ulPath)
    dirname = os.path.basename(toCopy)
    parentPath = os.path.join(os.path.dirname(toCopy), ".unlocked")
    if not (os.path.exists(parentPath)):
        os.mkdir(parentPath)

    os.system('mv -f ' + toCopy + ' ' + parentPath + '/')
    amu._writeConfigFile(os.path.join(ulPath, ".nodeInfo"), nodeInfo)
    return 0
Esempio n. 10
0
def checkout(coPath, lock):
	"""
	Copies the 'latest version' from the src folder into the local directory
	@precondition: coAsset is the name of an actual asset
	@precondition: lock is a boolean value
	
	@postcondition: A copy of the 'latest version' will be placed in the local directory
		with the name of the versioned folder
	@postcondition: If lock == True coPath will be locked until it is released by checkin
	"""

	print "in checkoutDAO, running checkout"
	print "coPath ", coPath
	# First need to grab the path file first.
	#if not os.path.exists(os.path.join(coPath, ".nodeInfo")):
	if not amu.isVersionedFolder(coPath):
		raise Exception("Not a versioned folder.")
	
	nodeInfo = ConfigParser()
	nodeInfo.read(os.path.join(coPath, ".nodeInfo"))
	if nodeInfo.get("Versioning", "locked") == "False": # Isn't this the point of the isCheckedOut method??
		version = nodeInfo.getint("Versioning", "latestversion")
		toCopy = os.path.join(coPath, "src", "v"+("%03d" % version))
		dest = getCheckoutDest(coPath)

		if(os.path.exists(toCopy)):
			try:
				shutil.copytree(toCopy, dest) # Make the copy. Note that dest (user's checkout directory) MUST NOT exist for this to work.
			except Exception:
				print "checkoutDAO, checkout: Could not copy files."
				raise Exception("Could not copy files.")
			timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
			nodeInfo.set("Versioning", "lastcheckoutuser", amu.getUsername())
			nodeInfo.set("Versioning", "lastcheckouttime", timestamp)
			nodeInfo.set("Versioning", "locked", str(lock))
			
			amu._writeConfigFile(os.path.join(coPath, ".nodeInfo"), nodeInfo)
			amu._createCheckoutInfoFile(dest, coPath, version, timestamp, lock)
		else:
			raise Exception("Version doesn't exist "+toCopy)
	else:
		whoLocked = nodeInfo.get("Versioning", "lastcheckoutuser")
		whenLocked = nodeInfo.get("Versioning", "lastcheckouttime")
		logname, realname = amu.lockedBy(whoLocked)
		whoLocked = 'User Name: ' + logname + '\nReal Name: ' + realname + '\n'
		raise Exception("Can not checkout. Folder is locked by:\n\n"+ whoLocked+"\nat "+ whenLocked)
	return dest
Esempio n. 11
0
def cloneShot(src_name, dst_name, currentIndex):

    paths = prepCloneShot(src_name, dst_name, currentIndex)
    src = paths[0]
    dst = paths[1]

    # First, check if the shot isn't checked out.
    if (amu.isCheckedOut(dst)):
        return False

    # I wish we could clean up the ConfigParser code in all of the buttons so that we write to utilities... But it might have to wait.
    src_cfg = ConfigParser()
    dst_cfg = ConfigParser()
    src_cfg.read(os.path.join(src, ".nodeInfo"))
    dst_cfg.read(os.path.join(dst, ".nodeInfo"))
    src_version = amu.getLatestVersion(src)
    dst_version = amu.getLatestVersion(dst)

    src_path = os.path.join(src, "src", 'v' + "%03d" % src_version)
    src_filepath = os.path.join(src_path, src_name + '_animation.mb')
    print dst_version
    dst_path = os.path.join(dst, "src", 'v' + "%03d" % (dst_version + 1))
    os.mkdir(dst_path)
    dst_filepath = os.path.join(dst_path, dst_name + '_animation.mb')
    print 'copying ' + src_filepath + ' to ' + dst_filepath
    shutil.copyfile(src_filepath, dst_filepath)

    # Fix permissions to the file.
    os.system('chmod 774 -R ' + dst_path)
    os.system('chmod 774 ' + dst_filepath)

    #write out new animation info
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    user = amu.getUsername()
    comment = 'copied from ' + src_name
    dst_cfg.set("Versioning", "lastcheckintime", timestamp)
    dst_cfg.set("Versioning", "lastcheckinuser", user)
    dst_cfg.set("Versioning", "latestversion", str(dst_version + 1))
    commentLine = user + ': ' + timestamp + ': ' + '"' + comment + '"'
    dst_cfg.set("Comments", 'v' + "%03d" % (dst_version + 1, ), commentLine)
    amu._writeConfigFile(os.path.join(dst, ".nodeInfo"), dst_cfg)
    return True
Esempio n. 12
0
def cloneShot(src_name, dst_name, currentIndex):

    paths = prepCloneShot(src_name, dst_name, currentIndex)
    src = paths[0]
    dst = paths[1]

    # First, check if the shot isn't checked out.
    if (amu.isCheckedOut(dst)):
        return False

    # I wish we could clean up the ConfigParser code in all of the buttons so that we write to utilities... But it might have to wait.
    src_cfg = ConfigParser()
    dst_cfg = ConfigParser()
    src_cfg.read(os.path.join(src, ".nodeInfo"))
    dst_cfg.read(os.path.join(dst, ".nodeInfo"))
    src_version = amu.getLatestVersion(src)
    dst_version = amu.getLatestVersion(dst)

    src_path = os.path.join(src, "src", 'v'+"%03d" % src_version)
    src_filepath = os.path.join(src_path, src_name+'_animation.mb')
    print dst_version
    dst_path = os.path.join(dst, "src", 'v'+"%03d" % (dst_version+1))
    os.mkdir(dst_path)
    dst_filepath = os.path.join(dst_path, dst_name+'_animation.mb')
    print 'copying '+src_filepath+' to '+dst_filepath
    shutil.copyfile(src_filepath, dst_filepath)

    # Fix permissions to the file.
    os.system('chmod 774 -R ' + dst_path)
    os.system('chmod 774 '+ dst_filepath)

    #write out new animation info
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    user = amu.getUsername()
    comment = 'copied from '+src_name
    dst_cfg.set("Versioning", "lastcheckintime", timestamp)
    dst_cfg.set("Versioning", "lastcheckinuser", user)
    dst_cfg.set("Versioning", "latestversion", str(dst_version+1))
    commentLine = user + ': ' + timestamp + ': ' + '"' + comment + '"' 
    dst_cfg.set("Comments", 'v' + "%03d" % (dst_version+1,), commentLine)   
    amu._writeConfigFile(os.path.join(dst, ".nodeInfo"), dst_cfg)
    return True
Esempio n. 13
0
def discard(filePath):
	"""
	Discards a local checked out folder without creating a new version.
	"""

	toDiscard = os.path.join(amu.getUserCheckoutDir(), os.path.basename(os.path.dirname(filePath)))
	print "toDiscard: ", toDiscard
	chkoutInfo = ConfigParser()
	chkoutInfo.read(os.path.join(toDiscard, ".checkoutInfo"))
	chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")

	nodeInfo = ConfigParser()
	nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))

	nodeInfo.set("Versioning", "locked", "False")
	amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)

	shutil.rmtree(toDiscard)
	if(os.path.exists(toDiscard)):
		os.rmdir(toDiscard)
Esempio n. 14
0
def discard(filePath):
    """
	Discards a local checked out folder without creating a new version.
	"""

    toDiscard = os.path.join(amu.getUserCheckoutDir(),
                             os.path.basename(os.path.dirname(filePath)))
    print "toDiscard: ", toDiscard
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(toDiscard, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")

    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))

    nodeInfo.set("Versioning", "locked", "False")
    amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)

    shutil.rmtree(toDiscard)
    if (os.path.exists(toDiscard)):
        os.rmdir(toDiscard)