From 453a43082e861318cce9b9e4aa5f0e8d67701240 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 23 May 2012 09:00:04 +0200 Subject: Add lorem --- lorem | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lorem.1.in | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 lorem create mode 100644 lorem.1.in diff --git a/lorem b/lorem new file mode 100755 index 0000000..a12df49 --- /dev/null +++ b/lorem @@ -0,0 +1,49 @@ +#!/usr/bin/python + +import cliapp +import random +import textwrap + + +wrapped_text = ''' +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat +non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +''' + + +class Lorem(cliapp.Application): + + max_sentences = 8 + + def add_settings(self): + self.settings.integer( + ['paragraphs', 'p'], + 'number of paragraphs to produce, approximately; each paragraph ' + 'is of a random, but fairly short length ' + '(default is infinite)', + metavar='N') + + def process_args(self, args): + text = ' '.join(x for x in wrapped_text.split('\n') if x) + sentences = [x for x in text.split('.') if x] + sentences = [' '.join(x.split()) + '.' for x in sentences] + + i = 0 + paragraphs = self.settings['paragraphs'] + while True: + n = random.randint(1, self.max_sentences) + paragraph = '\n'.join(random.choice(sentences) for i in range(n)) + self.output.write('\n'.join(textwrap.wrap(paragraph))) + self.output.write('\n') + i += 1 + if paragraphs and i >= paragraphs: + break + # Output empty line only between paragraphs, not after the last. + self.output.write('\n') + + +Lorem().run() diff --git a/lorem.1.in b/lorem.1.in new file mode 100644 index 0000000..ec4e7c1 --- /dev/null +++ b/lorem.1.in @@ -0,0 +1,34 @@ +.\" Copyright 2012 Lars Wirzenius +.\" +.\" This program is free software: you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation, either version 3 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with this program. If not, see . +.\" +.TH LOREM 1 +.SH NAME +lorem \- produce nonsense text +.SH SYNOPSIS +.SH DESCRIPTION +.B lorem +produces a stream of nonsense text, +for use as a filler, +based on the classic "Lorem ipsum dolor" pseudo-latin snippet. +The output can be useful for layout purposes, for example. +.PP +The output is generated by randomly picking a random number of +sentences from the pseudo-latin text, and combining the sentences into +a paragraph. +This gives more variation to the generated text than just repeating the +same snippet many times. +.SH OPTIONS +.SH "SEE ALSO" +.BR cliapp (5). -- cgit v1.2.1