From 298679fecfa9157ccc024e95f187ef8ebb6e33ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Thu, 4 Apr 2013 14:14:09 +0200 Subject: [PATCH] fix ponysay-tool installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- setup.py | 8 +-- src/__main__.py | 3 +- src/ponysaytool.py | 128 +++++++++++++++++++++------------------------ 3 files changed, 65 insertions(+), 74 deletions(-) diff --git a/setup.py b/setup.py index 4c925008..a88686b8 100755 --- a/setup.py +++ b/setup.py @@ -558,17 +558,17 @@ class Setup(): if hasponies and os.path.isdir(sharedir): for toolcommand in ('--dimensions', '--metadata'): if not self.free: - print('%s, %s, %s' % ('./src/ponysay-tool.py', toolcommand, sharedir)) - Popen(['./src/ponysay-tool.py', toolcommand, sharedir], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() + print('%s, %s, %s' % ('./src/ponysaytool.py', toolcommand, sharedir)) + Popen(['./src/ponysaytool.py', toolcommand, sharedir], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() else: - params = ['./src/ponysay-tool.py', toolcommand, sharedir, '--'] + params = ['./src/ponysaytool.py', toolcommand, sharedir, '--'] for sharefile in os.listdir(sharedir): if sharefile.endswith('.pony') and (sharefile != '.pony'): if not Setup.validateFreedom(sharedir + '/' + sharefile): print('Skipping metadata correction for %s/%s, did not pass validation process made by setup settings' % (sharedir, sharefile)) else: params.append(sharefile) - print('%s, %s, %s (with files)' % ('./src/ponysay-tool.py', toolcommand, sharedir)) + print('%s, %s, %s (with files)' % ('./src/ponysaytool.py', toolcommand, sharedir)) Popen(params, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() print() diff --git a/src/__main__.py b/src/__main__.py index 308252c0..f8fcc55f 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -56,8 +56,7 @@ if __name__ == '__main__': istool = istool[:istool.find(os.extsep)] istool = istool.endswith('-tool') if istool: - from ponysaytool import * - startponysaytool() + from ponysaytool import * ## will start ponysay-tool exit(0) isthink = sys.argv[0] diff --git a/src/ponysaytool.py b/src/ponysaytool.py index 0fd03c79..7a8f1ecb 100755 --- a/src/ponysaytool.py +++ b/src/ponysaytool.py @@ -1184,75 +1184,67 @@ class TextArea(): # TODO support small screens ''' -Start the program +The user's home directory ''' -def startponysaytool(): - ''' - The user's home directory - ''' - HOME = os.environ['HOME'] if 'HOME' in os.environ else os.path.expanduser('~') - - ''' - Whether stdin is piped - ''' - pipelinein = not sys.stdin.isatty() - - ''' - Whether stdout is piped - ''' - pipelineout = not sys.stdout.isatty() - - ''' - Whether stderr is piped - ''' - pipelineerr = not sys.stderr.isatty() - - - usage_program = '\033[34;1mponysay-tool\033[21;39m' - - usage = '\n'.join(['%s %s' % (usage_program, '(--help | --version | --kms)'), - '%s %s' % (usage_program, '(--edit | --edit-rm) \033[33mPONY-FILE\033[39m'), - '%s %s' % (usage_program, '--edit-stash \033[33mPONY-FILE\033[39m > \033[33mSTASH-FILE\033[39m'), - '%s %s' % (usage_program, '--edit-apply \033[33mPONY-FILE\033[39m < \033[33mSTASH-FILE\033[39m'), - '%s %s' % (usage_program, '(--dimensions | --metadata) \033[33mPONY-DIR\033[39m'), - '%s %s' % (usage_program, '--browse \033[33mPONY-DIR\033[39m [-r \033[33mRESTRICTION\033[39m]*'), - ]) - - usage = usage.replace('\033[', '\0') - for sym in ('[', ']', '(', ')', '|', '...', '*'): - usage = usage.replace(sym, '\033[2m' + sym + '\033[22m') - usage = usage.replace('\0', '\033[') - - ''' - Argument parsing - ''' - opts = ArgParser(program = 'ponysay-tool', - description = 'Tool chest for ponysay', - usage = usage, - longdescription = None) - - opts.add_argumentless(['--no-term-init']) # for debugging - - opts.add_argumentless(['-h', '--help'], help = 'Print this help message.') - opts.add_argumentless(['-v', '--version'], help = 'Print the version of the program.') - opts.add_argumentless(['--kms'], help = 'Generate all kmsponies for the current TTY palette') - opts.add_argumented( ['--dimensions'], arg = 'PONY-DIR', help = 'Generate pony dimension file for a directory') - opts.add_argumented( ['--metadata'], arg = 'PONY-DIR', help = 'Generate pony metadata collection file for a directory') - opts.add_argumented( ['-b', '--browse'], arg = 'PONY-DIR', help = 'Browse ponies in a directory') - opts.add_argumented( ['-r', '--restrict'], arg = 'RESTRICTION', help = 'Metadata based restriction for --browse') - opts.add_argumented( ['--edit'], arg = 'PONY-FILE', help = 'Edit a pony file\'s metadata') - opts.add_argumented( ['--edit-rm'], arg = 'PONY-FILE', help = 'Remove metadata from a pony file') - opts.add_argumented( ['--edit-apply'], arg = 'PONY-FILE', help = 'Apply metadata from stdin to a pony file') - opts.add_argumented( ['--edit-stash'], arg = 'PONY-FILE', help = 'Print applyable metadata from a pony file') - - ''' - Whether at least one unrecognised option was used - ''' - unrecognised = not opts.parse() - - PonysayTool(args = opts) +HOME = os.environ['HOME'] if 'HOME' in os.environ else os.path.expanduser('~') + +''' +Whether stdin is piped +''' +pipelinein = not sys.stdin.isatty() + +''' +Whether stdout is piped +''' +pipelineout = not sys.stdout.isatty() + +''' +Whether stderr is piped +''' +pipelineerr = not sys.stderr.isatty() -if __name__ == '__main__': - startponysaytool() +usage_program = '\033[34;1mponysay-tool\033[21;39m' + +usage = '\n'.join(['%s %s' % (usage_program, '(--help | --version | --kms)'), + '%s %s' % (usage_program, '(--edit | --edit-rm) \033[33mPONY-FILE\033[39m'), + '%s %s' % (usage_program, '--edit-stash \033[33mPONY-FILE\033[39m > \033[33mSTASH-FILE\033[39m'), + '%s %s' % (usage_program, '--edit-apply \033[33mPONY-FILE\033[39m < \033[33mSTASH-FILE\033[39m'), + '%s %s' % (usage_program, '(--dimensions | --metadata) \033[33mPONY-DIR\033[39m'), + '%s %s' % (usage_program, '--browse \033[33mPONY-DIR\033[39m [-r \033[33mRESTRICTION\033[39m]*'), + ]) + +usage = usage.replace('\033[', '\0') +for sym in ('[', ']', '(', ')', '|', '...', '*'): + usage = usage.replace(sym, '\033[2m' + sym + '\033[22m') +usage = usage.replace('\0', '\033[') + +''' +Argument parsing +''' +opts = ArgParser(program = 'ponysay-tool', + description = 'Tool chest for ponysay', + usage = usage, + longdescription = None) + +opts.add_argumentless(['--no-term-init']) # for debugging + +opts.add_argumentless(['-h', '--help'], help = 'Print this help message.') +opts.add_argumentless(['-v', '--version'], help = 'Print the version of the program.') +opts.add_argumentless(['--kms'], help = 'Generate all kmsponies for the current TTY palette') +opts.add_argumented( ['--dimensions'], arg = 'PONY-DIR', help = 'Generate pony dimension file for a directory') +opts.add_argumented( ['--metadata'], arg = 'PONY-DIR', help = 'Generate pony metadata collection file for a directory') +opts.add_argumented( ['-b', '--browse'], arg = 'PONY-DIR', help = 'Browse ponies in a directory') +opts.add_argumented( ['-r', '--restrict'], arg = 'RESTRICTION', help = 'Metadata based restriction for --browse') +opts.add_argumented( ['--edit'], arg = 'PONY-FILE', help = 'Edit a pony file\'s metadata') +opts.add_argumented( ['--edit-rm'], arg = 'PONY-FILE', help = 'Remove metadata from a pony file') +opts.add_argumented( ['--edit-apply'], arg = 'PONY-FILE', help = 'Apply metadata from stdin to a pony file') +opts.add_argumented( ['--edit-stash'], arg = 'PONY-FILE', help = 'Print applyable metadata from a pony file') + +''' +Whether at least one unrecognised option was used +''' +unrecognised = not opts.parse() + +PonysayTool(args = opts)