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)
def checkedOutByMe(dirPath): # I feel like this should be checking both if it is locked and if it is checked out by the current user... nodeInfo = os.path.join(dirPath, ".nodeInfo") if not os.path.exists(nodeInfo): return False cp = ConfigParser() cp.read(nodeInfo) return cp.get("Versioning", "lastcheckoutuser") == amu.getUsername()
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)
def checkedOutByMe( dirPath ): # I feel like this should be checking both if it is locked and if it is checked out by the current user... nodeInfo = os.path.join(dirPath, ".nodeInfo") if not os.path.exists(nodeInfo): return False cp = ConfigParser() cp.read(nodeInfo) return cp.get("Versioning", "lastcheckoutuser") == amu.getUsername()
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
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
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
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