def getSequence(inputSequence): """ Get sequence from the given file path. """ from pySequenceParser import sequenceParser sequence = sequenceParser.Sequence() isSequence = sequenceParser.browseSequence(sequence, inputSequence) if isSequence: return sequence raise ValueError("Given input '%s' is not recognized as an image sequence." % inputSequence)
def getSequence(inputSequence): """ Get sequence from the given file path. """ from pySequenceParser import sequenceParser sequence = sequenceParser.Sequence() isSequence = sequenceParser.browseSequence(sequence, inputSequence) if isSequence: return sequence raise ValueError( "Given input '%s' is not recognized as an image sequence." % inputSequence)
def run(self, parser): """ Process the list operation. """ # Parse command-line args = parser.parse_args() # inputs to scan inputs = [] for input in args.inputs: # if exists add the path if os.path.exists(input): inputs.append(input) # else use it as a filter expression else: args.expression.append(input) if not inputs: inputs.append(os.getcwd()) # sam-ls -a detectionMethod = sequenceParser.eDetectionDefault if args.all: detectionMethod = sequenceParser.eDetectionDefaultWithDotFile # sam-ls --detect-negative if args.detectNegative: detectionMethod = detectionMethod | sequenceParser.eDetectionNegative # sam-ls --detect-without-holes if args.detectWithoutHoles: detectionMethod = detectionMethod | sequenceParser.eDetectionSequenceWithoutHoles # sam-ls -e filters = [] for expression in args.expression: filters.append(expression) # get list of items for each inputs for input in inputs: items = [] try: items = sequenceParser.browse(input, detectionMethod, filters) except IOError as e: # if the given input does not correspond to anything if 'No such file or directory' in str(e): # try to create a sequence from the given input sequence = sequenceParser.Sequence() isSequence = sequenceParser.browseSequence(sequence, input) if isSequence: item = sequenceParser.Item(sequence, os.getcwd()) # check if the sequence contains at least one element if len(item.explode()): items.append(item) # else error else: self.logger.warning(e) continue # else it's not a directory: try a new browse with the given input name as filter else: # new path to browse newBrowsePath = os.path.dirname(input) if not newBrowsePath: newBrowsePath = '.' # new filter newFilter = [] newFilter.extend(filters) newFilter.append(os.path.basename(input)) # new browse items += sequenceParser.browse(newBrowsePath, detectionMethod, newFilter) if not len(items): self.logger.warning('No items found for input "' + input + '".') else: self.printItems(items, args, detectionMethod, filters)
def run(self, parser): """ Process the list operation. """ # Parse command-line args = parser.parse_args() # sam-ls --absolute-path --relative-path if args.absolutePath and args.relativePath: self._displayCommandLineHelp(parser) exit(1) # Set sam log level self.setLogLevel(args.verbose) class InputToBrowse(object): """ Represents an input to browse: a path and a list of filters. """ def __init__(self, inputPath): self.inputPath = inputPath self.filters = [] def addFilter(self, filterToAdd): self.filters.append(filterToAdd) # translate user inputs to a list of InputToBrowse inputsToBrowse = [] for inputPath in args.inputs: # if the input is a directory, add it and continue if os.path.isdir(inputPath): inputsToBrowse.append(InputToBrowse(inputPath)) continue # else split the input to a path and a filename subPath = os.path.dirname(inputPath) if not subPath: subPath = '.' filename = os.path.basename(inputPath) # add the path and the filename as an expression inputToBrowse = InputToBrowse(subPath) inputToBrowse.addFilter(filename) inputsToBrowse.append(inputToBrowse) # if no user input, will browse in the current working directory if not inputsToBrowse: inputsToBrowse.append(InputToBrowse(os.getcwd())) # sam-ls -a detectionMethod = sequenceParser.eDetectionDefault if args.all: detectionMethod = sequenceParser.eDetectionDefaultWithDotFile # sam-ls --detect-negative if args.detectNegative: detectionMethod = detectionMethod | sequenceParser.eDetectionNegative # sam-ls --detect-without-holes if args.detectWithoutHoles: detectionMethod = detectionMethod | sequenceParser.eDetectionSequenceWithoutHoles # sam-ls -e for expression in args.expression: for inputToBrowse in inputsToBrowse: inputToBrowse.addFilter(expression) error = 0 # for each input to browse, print the finding items for inputToBrowse in inputsToBrowse: items = [] inputPath = inputToBrowse.inputPath filters = inputToBrowse.filters try: self.logger.debug('Browse in "' + inputPath + '" with the following filters: ' + str(filters)) items = sequenceParser.browse(inputPath, detectionMethod, filters) except IOError as e: self.logger.debug('IOError raised: "' + str(e) + '".') # if the given input does not correspond to anything if 'No such file or directory' in str(e): # try to create a sequence from the given input sequence = sequenceParser.Sequence() self.logger.debug('BrowseSequence on "' + inputPath + '".') isSequence = sequenceParser.browseSequence(sequence, inputPath) if isSequence: item = sequenceParser.Item(sequence, os.getcwd()) # check if the sequence contains at least one element if len(item.explode()): items.append(item) # else error else: self.logger.warning(e) continue # else it's not a directory else: self.logger.debug('Try a new browse with the given input name as filter.') # new path to browse newBrowsePath = os.path.dirname(inputPath) if not newBrowsePath: newBrowsePath = '.' # new filter newFilter = [] newFilter.extend(filters) newFilter.append(os.path.basename(inputPath)) # new browse self.logger.debug('Browse in "' + newBrowsePath + '" with the following filters: ' + str(newFilter)) items += sequenceParser.browse(newBrowsePath, detectionMethod, newFilter) if not len(items): self.logger.warning('No items found for input "' + inputPath + '" with the following filters: ' + str(filters)) error = 1 else: self._printItems(items, args, detectionMethod, filters) exit(error)
def run(self, parser): """ Process the list operation. """ # Parse command-line args = parser.parse_args() # sam-ls --absolute-path --relative-path if args.absolutePath and args.relativePath: self._displayCommandLineHelp(parser) exit(1) # Set sam log level self.setLogLevel(args.verbose) class InputToBrowse(object): """ Represents an input to browse: a path and a list of filters. """ def __init__(self, inputPath): self.inputPath = inputPath self.filters = [] def addFilter(self, filterToAdd): self.filters.append(filterToAdd) # translate user inputs to a list of InputToBrowse inputsToBrowse = [] for inputPath in args.inputs: # if the input is a directory, add it and continue if os.path.isdir(inputPath): inputsToBrowse.append(InputToBrowse(inputPath)) continue # else split the input to a path and a filename subPath = os.path.dirname(inputPath) if not subPath: subPath = '.' filename = os.path.basename(inputPath) # add the path and the filename as an expression inputToBrowse = InputToBrowse(subPath) inputToBrowse.addFilter(filename) inputsToBrowse.append(inputToBrowse) # if no user input, will browse in the current working directory if not inputsToBrowse: inputsToBrowse.append(InputToBrowse(os.getcwd())) # sam-ls -a detectionMethod = sequenceParser.eDetectionDefault if args.all: detectionMethod = sequenceParser.eDetectionDefaultWithDotFile # sam-ls --detect-negative if args.detectNegative: detectionMethod = detectionMethod | sequenceParser.eDetectionNegative # sam-ls --detect-without-holes if args.detectWithoutHoles: detectionMethod = detectionMethod | sequenceParser.eDetectionSequenceWithoutHoles # sam-ls -e for expression in args.expression: for inputToBrowse in inputsToBrowse: inputToBrowse.addFilter(expression) error = 0 # for each input to browse, print the finding items for inputToBrowse in inputsToBrowse: items = [] inputPath = inputToBrowse.inputPath filters = inputToBrowse.filters try: self.logger.debug('Browse in "' + inputPath + '" with the following filters: ' + str(filters)) items = sequenceParser.browse(inputPath, detectionMethod, filters) except IOError as e: self.logger.debug('IOError raised: "' + str(e) + '".') # if the given input does not correspond to anything if 'No such file or directory' in str(e): # try to create a sequence from the given input sequence = sequenceParser.Sequence() self.logger.debug('BrowseSequence on "' + inputPath + '".') isSequence = sequenceParser.browseSequence( sequence, inputPath) if isSequence: item = sequenceParser.Item(sequence, os.getcwd()) # check if the sequence contains at least one element if len(item.explode()): items.append(item) # else error else: self.logger.warning(e) continue # else it's not a directory else: self.logger.debug( 'Try a new browse with the given input name as filter.' ) # new path to browse newBrowsePath = os.path.dirname(inputPath) if not newBrowsePath: newBrowsePath = '.' # new filter newFilter = [] newFilter.extend(filters) newFilter.append(os.path.basename(inputPath)) # new browse self.logger.debug('Browse in "' + newBrowsePath + '" with the following filters: ' + str(newFilter)) items += sequenceParser.browse(newBrowsePath, detectionMethod, newFilter) if not len(items): self.logger.warning('No items found for input "' + inputPath + '" with the following filters: ' + str(filters)) error = 1 else: self._printItems(items, args, detectionMethod, filters) exit(error)
def run(self, parser): """ Process the list operation. """ # Parse command-line args = parser.parse_args() # Set sam log level self.setLogLevel(args.verbose) # inputs to scan inputs = [] for input in args.inputs: # if exists add the path if os.path.exists(input): inputs.append(input) # else use it as a filter expression else: args.expression.append(input) if not inputs: inputs.append(os.getcwd()) # sam-ls -a detectionMethod = sequenceParser.eDetectionDefault if args.all: detectionMethod = sequenceParser.eDetectionDefaultWithDotFile # sam-ls --detect-negative if args.detectNegative: detectionMethod = detectionMethod | sequenceParser.eDetectionNegative # sam-ls --detect-without-holes if args.detectWithoutHoles: detectionMethod = detectionMethod | sequenceParser.eDetectionSequenceWithoutHoles # sam-ls -e filters = [] for expression in args.expression: filters.append(expression) # get list of items for each inputs for input in inputs: items = [] try: self.logger.info('Launch a browse on "' + input + '" with the following filters: ' + str(filters)) items = sequenceParser.browse(input, detectionMethod, filters) except IOError as e: # if the given input does not correspond to anything if 'No such file or directory' in str(e): # try to create a sequence from the given input sequence = sequenceParser.Sequence() self.logger.info('Launch a browseSequence on "' + input + '".') isSequence = sequenceParser.browseSequence(sequence, input) if isSequence: item = sequenceParser.Item(sequence, os.getcwd()) # check if the sequence contains at least one element if len(item.explode()): items.append(item) # else error else: self.logger.warning(e) continue # else it's not a directory: try a new browse with the given input name as filter else: # new path to browse newBrowsePath = os.path.dirname(input) if not newBrowsePath: newBrowsePath = '.' # new filter newFilter = [] newFilter.extend(filters) newFilter.append(os.path.basename(input)) # new browse self.logger.info('Launch a browse on "' + newBrowsePath + '" with the following filters: ' + str(newFilter)) items += sequenceParser.browse(newBrowsePath, detectionMethod, newFilter) if not len(items): self.logger.warning('No items found for input "' + input + '".') else: self.printItems(items, args, detectionMethod, filters)
def run(self, parser): """ Process the list operation. """ # Parse command-line args = parser.parse_args() # Set sam log level self.setLogLevel(args.verbose) inputs = [] # for each input to scan for inputPath in args.inputs: # if the input is a directory, add it and continue if os.path.isdir(inputPath): inputs.append(inputPath) continue # else split the input to a path and a filename subPath = os.path.dirname(inputPath) if not subPath: subPath = '.' filename = os.path.basename(inputPath) # add the path and the filename as an expression inputs.append(subPath) if filename: args.expression.append(filename) if not inputs: inputs.append(os.getcwd()) # sam-ls -a detectionMethod = sequenceParser.eDetectionDefault if args.all: detectionMethod = sequenceParser.eDetectionDefaultWithDotFile # sam-ls --detect-negative if args.detectNegative: detectionMethod = detectionMethod | sequenceParser.eDetectionNegative # sam-ls --detect-without-holes if args.detectWithoutHoles: detectionMethod = detectionMethod | sequenceParser.eDetectionSequenceWithoutHoles # sam-ls -e filters = [] for expression in args.expression: filters.append(expression) # get list of items for each inputs for inputPath in inputs: items = [] try: self.logger.debug('Browse in "' + inputPath + '" with the following filters: ' + str(filters)) items = sequenceParser.browse(inputPath, detectionMethod, filters) except IOError as e: self.logger.debug('IOError raised: "' + str(e) + '".') # if the given input does not correspond to anything if 'No such file or directory' in str(e): # try to create a sequence from the given input sequence = sequenceParser.Sequence() self.logger.debug('BrowseSequence on "' + inputPath + '".') isSequence = sequenceParser.browseSequence(sequence, inputPath) if isSequence: item = sequenceParser.Item(sequence, os.getcwd()) # check if the sequence contains at least one element if len(item.explode()): items.append(item) # else error else: self.logger.warning(e) continue # else it's not a directory else: self.logger.debug('Try a new browse with the given input name as filter.') # new path to browse newBrowsePath = os.path.dirname(inputPath) if not newBrowsePath: newBrowsePath = '.' # new filter newFilter = [] newFilter.extend(filters) newFilter.append(os.path.basename(inputPath)) # new browse self.logger.debug('Browse in "' + newBrowsePath + '" with the following filters: ' + str(newFilter)) items += sequenceParser.browse(newBrowsePath, detectionMethod, newFilter) if not len(items): self.logger.warning('No items found for input "' + inputPath + '".') else: self.printItems(items, args, detectionMethod, filters)