Base_getDescription.py 1020 Bytes
Newer Older
1
## Script (Python) "Base_getDescription"
Jean-Paul Smets's avatar
Jean-Paul Smets committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
from string import join

description = context.getComment('')
return description

# Try to cut the comment without cutting the words 
# pbl: capital letter are larger, and the test on the length of sentence isn't good ...
def recursive_string_cut(b,s):
  l = 80
  if len(s) < l:
    return b+s
  else:
    c = s[:l].split(' ')
    if len(c) < 2:
      # I don't think that a word with more than 80 caracters can exist ... and it can crash the memory
      return s[:l]
    else:
      return recursive_string_cut(b+join(c[:-2],' ')+'\n', join(c[-2:],' ')+s[l:] )
    

# get all the lines
description_lines = description.split('\n')

# cut the too long lines
result_description_lines = map( ( lambda x: recursive_string_cut('',x) ),description_lines)

# recreate a string
result = join(result_description_lines,'\n')

return result