diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-05-23 09:00:04 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-05-23 09:00:04 +0200 |
commit | 453a43082e861318cce9b9e4aa5f0e8d67701240 (patch) | |
tree | a68e5ecd950ba9f44320104ef01cbec4ed8940aa | |
parent | e8bfb185b5e1eb495076983eb2a4440318cb5b57 (diff) | |
download | extrautils-453a43082e861318cce9b9e4aa5f0e8d67701240.tar.gz |
Add lorem
-rwxr-xr-x | lorem | 49 | ||||
-rw-r--r-- | lorem.1.in | 34 |
2 files changed, 83 insertions, 0 deletions
@@ -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 <liw@liw.fi> +.\" +.\" 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 <http://www.gnu.org/licenses/>. +.\" +.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). |