Have updated my script a little bit and naturally have more questions as I get my head around regular expressionism in python.
[Code] http://pastebin.com/b3x76pyi [Notable features] --[ Instead of creating a custom directory I'm simply using the offlineEdit filerule and query the path from that. This way I or anyone else can set the backup directory name within the default Maya workspace window and the script will output the versions to there. --[ The script is only 3 functions, ( clean_seperator ,get_version , save ) and it does as intended, creates an extra directory within my scenes directory and when I click my shelf button a versioned backup of my current scene gets placed into that directory without notions of duplicity. [Issue at hand] re.sub appears to work wonders, about time I would get used to this stuff instead of relying on os.system(r"sed s'\old\new\'g") and such trickeries, appreciate it. I have this thing in my script though: format_ext = '.mb' backups = [] for filename in os.listdir(path): rawname , ext = os.path.splitext( filename ) if format_ext==ext: if filename.startswith( rawname ): if rawname[ -( self.padding ) ].isdigit() and rawname[ -( self.padding ) - len( self.prefix ) ].isalpha(): if rawname[-(self.padding)-len(self.prefix):-self.padding] == self.prefix: backups.append( filename ) which is in lack of a more descriptive way to put it, just plain ugly and bloated. the logic goes like this: For every file in my offlineEdit filerule directory: --[ If the extension matches the extension on my current scene. --[ If the filename starts with the same name. --[ If the range of the length of my padding setting is digits at the back of the filename without the extension and the character before that an alpha --[ If the characters in the range of the length of my prefix are in front of the length of my padding setting and are the same characters as my prefix If a file gets through this, it's a match. That's only 4 things I'm checking and end up with terribly inefficient code, been trying a few things but note sure if I should be using re.search or re.match to run these 4 checks. Any help to get me started, a template for how to do one of those checks for example will help and I can take it from there? Other comments and input on the actual script of course welcome as well. -- 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.
