diff --git a/pyseq.py b/pyseq.py index acced59..10e54fc 100755 --- a/pyseq.py +++ b/pyseq.py @@ -86,11 +86,17 @@ def __init__(self, item): log.debug('adding %s' % item) self.item = item self.__path = getattr(item, 'path', os.path.abspath(str(item))) - self.__dirname = os.path.dirname(str(item)) + self.__dirname = os.path.dirname(self.__path) self.__filename = os.path.basename(str(item)) self.__digits = gDigitsRE.findall(self.name) self.__parts = gDigitsRE.split(self.name) - + + if os.path.isfile(self.__path): + self.__size = os.path.getsize(self.__path) + self.__mtime = os.path.getmtime(self.__path) + else: + self.__size = 0 + self.__mtime = 0 # modified by self.is_sibling() self.frame = '' self.head = self.name @@ -135,6 +141,18 @@ def parts(self): """ return self.__parts + @property + def size(self): + """filesize of item + """ + return self.__size + + @property + def mtime(self): + """modification time of item + """ + return self.__mtime + def isSibling(self, item): """Determines if this and item are part of the same sequence. @@ -193,6 +211,7 @@ def __init__(self, items): """ super(Sequence, self).__init__([Item(items.pop(0))]) self.__missing = [] + self.__NEEDREINDEX = False while items: f = Item(items.pop(0)) try: @@ -204,6 +223,8 @@ def __init__(self, items): except KeyboardInterrupt: log.info("Stopping.") break + + def __attrs__(self): """Replaces format directives with values""" @@ -294,7 +315,7 @@ def length(self): def frames(self): """:return: List of files in sequence.""" - if not hasattr(self, '__frames') or not self.__frames: + if not hasattr(self, '__frames') or not self.__frames or self.__NEEDREINDEX: self.__frames = list(map(int, self._get_frames())) self.__frames.sort() return self.__frames @@ -405,6 +426,63 @@ def append(self, item): self.__missing = None else: raise SequenceError('Item is not a member of this sequence') + + @property + def mtime(self): + """ + returns the latest mtime of all items + """ + maxDate = list() + for i in self: + maxDate.append(i.mtime) + return max(maxDate) + + @property + def size(self): + """ + returns the size all items + divide the result by 1024/1024 to get megabytes + """ + tempSize = list() + for i in self: + tempSize.append(i.size) + return sum(tempSize) + + def reIndex(self, addSub, padding=None): + """ + renames the files on disk + reIndex the items in the sequence object egg + 1001 + 100 = 1101 + can change the padding too + @param addSub int + @param padding str + @param run boolean + """ + if not padding: + padding = self.format("%p") + + if addSub > 0: + gen = ((image,frame) for (image,frame) in zip(reversed(self),reversed(self.frames()))) + else: + gen = ((image,frame) for (image,frame) in zip(self,self.frames())) + + for image,frame in gen: + oldName = image.path + newFrame = padding % (frame + addSub) + newFileName ="%s%s%s" % (self.format("%h"), newFrame , self.format("%t") ) + newName = os.path.join(image.dirname, newFileName) + try: + import shutil + shutil.move(oldName,newName) + except Exception,e: + log.error(e) + else: + log.info('renaming %s -->' % oldName) + log.info(' %s' % newName) + self.__NEEDREINDEX = True + image.frame = newFrame + else: + self.frames() def _get_padding(self): """:return: padding string, e.g. %07d"""