예제 #1
0
 def usage_msg(self):
     """Generate a help message using saved option info."""
     if self.__usage:
         return self.__usage
     app = self.__app
     if not app:
         app = sys.argv[0].split(os.sep)[-1]
     str = 'Usage: ' + app
     if len(self.__olist):
         str = str + ' [options]'
     if self.__args:
         str = str + ' ' + self.__args
     self.__usage = map(lambda s: s + '\n', str.split('\n'))
     if len(self.__olist):
         self.__usage = self.__usage + ['\n', 'Options:\n']
     # Loop over options
     for oinfo in self.__olist:
         lside = rside = ''
         # Left side is -x,--xthing xarg
         if oinfo['opt']:
             lside = lside + oinfo['opt']
         if oinfo['long']:
             if oinfo['opt']:
                 lside = lside + ','
             lside = lside + oinfo['long']
         if oinfo['arg']:
             lside = lside + ' ' + oinfo['arg']
         lside = [ string.ljust(lside, self.__usage_lwid) ]
         # Right side is usage, word wrapped to fit
         rside = word_wrap.wrap_list(oinfo['usage'], self.__usage_rwid)
         # Pad out extra blank lines on left side
         for i in range(len(rside) - 1):
             lside.append(string.ljust('', self.__usage_lwid))
         # Tack 'em together
         self.__usage = self.__usage +  map(lambda l, r: l + r + '\n',
                                            lside, rside)
     if self.__note:
         self.__usage.append('\n')
         tmp = map(lambda s: s + '\n',
                   word_wrap.wrap_str(self.__note, self.__usage_width, '\n\n'))
         self.__usage = self.__usage + tmp
     return self.__usage
예제 #2
0
# Repeat the game of stuffing text inside entities for the newly generated tags
html_tags = (
    'a',
    'p',
    'strong',
    'em',
    'li',
    'td',
)
for tag in html_tags:
    entities = newsoup.findAll(tag)
    [
        entity.setString('%s %s ' % (entity.text, PLACEHOLDER))
        for entity in entities
    ]

text = newsoup.text.replace("xml version='1.0' encoding='%SOUP-ENCODING%'", '')
text = text.encode('utf-8')
text = text.replace(' " ', ' ')

# make a space character out of the placeholder
text = text.replace(PLACEHOLDER, ' ')

text = "\n".join(wrap_str(text, 80))

fh = open(txtfile, 'w')
fh.write(text)
fh.close()

sys.exit('ok')
예제 #3
0
  top = "Benoit Caron\n"
  top += "Administrateur principal de système Unix\n"
  top += "Senior Unix systems administrator\n"
  top += "Canoe inc.\n"
  top += "[email protected] - 514-504-2768\n"



# On lit le fichier de signature
sigs = open("/home/benoit/signatures.txt").read()
sigs = string.split( sigs, "\n\n" )
sigs = filter( None, map( string.strip, sigs ))
bar = random.choice(sigs)

# Nettoie "bar"
lbar = word_wrap.wrap_str(bar,80)


# réécrit ce qu'on a trouvé
if re.search("stdout.py$", sys.argv[0]):
	sys.stdout.write(top)
	sys.stdout.write("------\n")
	for s in lbar:
		sys.stdout.write(s)
		if s and s[-1] != '\n':
			sys.stdout.write("\n")
else :
	if  sys.argv[1] == 'notezbien':
	    sig = open('/home/benoit/.signature.notezbien','w')
	else:
	    sig = open('/home/benoit/.signature','w')
stonesoup = BeautifulStoneSoup(
    text, convertEntities=BeautifulStoneSoup.XML_ENTITIES)

txt = stonesoup.prettify()
newsoup = BeautifulSoup("<html>%s</html>" % txt)

# Repeat the game of stuffing text inside entities for the newly generated tags
html_tags = (
    'a', 'p', 'strong', 'em', 'li', 'td',
)
for tag in html_tags:
    entities = newsoup.findAll(tag)
    [entity.setString('%s %s ' % (entity.text, PLACEHOLDER))
        for entity in entities]

text = newsoup.text.replace("xml version='1.0' encoding='%SOUP-ENCODING%'", '')
text = text.encode('utf-8')
text = text.replace(' " ', ' ')

# make a space character out of the placeholder
text = text.replace(PLACEHOLDER, ' ')


text = "\n".join(wrap_str(text, 80))

fh = open(txtfile, 'w')
fh.write(text)
fh.close()

sys.exit('ok')