Good point. My uNkle isn’t broken, just a little dirty, thanks! I’ve updated my little script a little more, added more comments and a few things, but naturally have a few questions regarding what I’m doing so any and all help, comments, and insight, will continue to be awesome.
[ code ] http://pastebin.com/JJhrTwEq [ Gimmicks, Questions, and Ponderings ] --[ Separator support Although I’m a fan of using spaces in my filenames I’m not sure Linus Torvalds would agree, so to be able to use my script with ease on a UNIX system as well I added a separator swapping function. It feels bloated but does the trick. I chose to go with iterating over all the characters and swap out anything that isn’t a valid alpha or a digit, and only do so up to the last period. This way, rather than using .replace() a . can be used as a separator as well and the script doesn’t get confused and swaps out the last .mb for _mb for example. But isn’t there a middle ground somewhere between string.replace() and this clean_seperator() function to do this in an efficient manner with more elaborate catching. Sounds like such a common operation that there may even be a default library somewhere that does this for me, intended purpose is as simple as swap out all characters within a string, par from the last period? --[ Multiple file versioning I added if n.startswith( name ) to the get_version() function, this should allow multiple files to get versioned up. That is to say if I have one file in my scenes directory called ‘A Monkey.mb’ and another called ‘An_Elephant.mb’ within the backup directory each one will get a new version number. This line is what I’m using: backups = sorted( [ n for n in os.listdir( path ) if n.startswith( name ) and self.seperator in n ] ) Can anyone see a case where this function would return the version number of the wrong sequence within the backup directory? That comprehended list feels quite cheap, but sometimes cheap is the most effective I guess…. --[ Extension query I baked valid extensions into the class to avoid typing in ‘.mb’ and ‘.ma’ later down in my code but it’s only a 2 item dictionary, a tuple may be more efficient and a cleaner way to go about this. Any thoughts on this, drawbacks and features of using dictionaries vs tuples when dealing with only 2 items and their values? --[ Notion of duplicity I tried saving out a file with 40,000.- polyCubes, my file explorer says the size of the file is around 42MB , on first save after having copied the file into my backups the total size of my scenes directory is 84MB. Fair enough and as I save out more versions only that latest duplicate file becomes a small factor in my disk space. Would be nice if this decrease due to duplicity wasn’t there though. So I added a link thing the save function which creates a Windows Hard link between the two files. They are two files but share the same blocks on my hard drive so no reduction takes place. My file explorer still says the backup file I just saved out is 42MB but it’s only a representation, the space on my hard drive is still only the increase of the file itself, in case I browse into my backup folder and load the latest file from there, I will actually be loading the file in the root of my scenes directory, these are just backups so to say. This introduces a certain level of complexity to the script though. If I keep creating links for all the versions I will end up with a backup directory full of files pointing at my latest file and no actual backups are in there. Thankfully shutil comes to the rescue and whenever I create a link inside my backup directory the last version before that gets replaced with a physical file. Only the latest version is a mirror of my current workscene and the rest are backups. I verify the link is all working by saving out a .ma file, opening up my current scene file in a text editor and edit some attributes. The attributes get updated in the backup file and all is working fine, until I hit ctrl-s and save out a new current scene. This is when the two files get separated again, my current scene updates and my backup link becomes the only instance of the 2 previously linked files, retaining the backups intact and I’m back to only just working on my single scene in the root of my scenes directory until I run my increment script again. Comments and discussions naturally welcome. My current issue is os.path.islink( filename ) returns False so I guess it’s not technically a link, although I can verify the behaviour by measuring my free disk space… Any ideas? -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
