Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sam ls: fixed --script option when displaying recursive items #577

Merged
merged 8 commits into from
Aug 26, 2016
19 changes: 7 additions & 12 deletions applications/sam/sam_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def _printItem(self, item, args, level):
detailed = '{:1}{:9}'.format(characterFromType, permissions)
detailed += ' {:8} {:8} {:8}'.format(itemStat.getUserName(), itemStat.getGroupName(), lastUpdate)
detailed += ' {:6} {:6} {:6}'.format(minSize, maxSize, samUtils.getReadableSize(itemStat.size))
detailed += '\t'

# only for sequences: [ begin : end ] nbFiles - nbMissingFiles
if itemType == sequenceParser.eTypeSequence:
Expand All @@ -158,8 +157,7 @@ def _printItem(self, item, args, level):

# sam-ls --relative-path
if args.relativePath:
filePath += (item.getFolder() if item.getFolder()[0] != '/' else '.')
filePath += ('/' if filePath[-1] != '/' else '')
filePath += item.getFolder()

# filename
filename = item.getFilename()
Expand All @@ -182,18 +180,17 @@ def _printItem(self, item, args, level):
filePath = colored.cyan(os.path.join(filePath, filename))
else:
filePath = colored.red(os.path.join(filePath, filename))
filePath += ' \t'

# sam-ls -R / sam-ls -L
# sam-ls -R / sam-ls -L / sam-ls --script
indentTree = ''
if args.recursive and args.level != 0:
if args.recursive and level != 0 and not args.script:
indentTree += '| ' * (level - 1)
indentTree += '|__ '

# display
toPrint = detailed + filePath + detailedSequence
toPrint = detailed + '\t' + filePath + ' \t' + detailedSequence
# if first level or no tree formatting
if level == 0 or args.level == 0:
if level == 0 or args.script:
puts(toPrint.format())
else:
with indent(level, quote=indentTree):
Expand Down Expand Up @@ -244,9 +241,7 @@ def _printItems(self, items, args, detectionMethod, filters, level=0):
newFolder = os.path.join(item.getFolder(), item.getFilename())
self.logger.debug('Browse in "' + newFolder + '" with the following filters: ' + str(filters))
newItems = sequenceParser.browse(newFolder, detectionMethod, filters)
level += 1
self._printItems(newItems, args, detectionMethod, filters, level)
level -= 1
self._printItems(newItems, args, detectionMethod, filters, level + 1)
except IOError as e:
# Permission denied for example
self.logger.warning(e)
Expand Down Expand Up @@ -299,7 +294,7 @@ def addFilter(self, filterToAdd):
inputsToBrowse.append(inputToBrowse)
# if no user input, will browse in the current working directory
if not inputsToBrowse:
inputsToBrowse.append(InputToBrowse(os.getcwd()))
inputsToBrowse.append(InputToBrowse('.'))

# sam-ls -a
detectionMethod = sequenceParser.eDetectionDefault
Expand Down