Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 29.989.323 Times

entrypoint 0.1.5

Company: Conrad Irwin
Date Added: October 25, 2013  |  Visits: 211

entrypoint

Report Broken Link
Printer Friendly Version


Product Homepage
Download (17 downloads)

A decorator to interact with argparse based on function signature.<br /><br />This is a decorator library that helps one to write small scripts in Python.<br /><br />There are three main features that it provides:<br /><br /> * Automatically running a function when a script is called directly, but<br /> not when it is included as a module.<br /><br /> * Automatically generating argument parsers from function signatures and<br /> docstrings<br /><br /> * Automatically opening and closing files (with a codec or as binary) when<br /> a function is called and returns.<br /><br />The raison d'?*?*tre of this library is to be convenient, and it makes some<br />sacrifices in other areas. Notably there are some stringent conditions on<br />the order of application of decorators.<br /><br />For further information, see the explanations below, and the docstrings of the<br />functions. To report errors, request features, or submit patches, please email<br />conrad.irwin@gmail.com.<br /><br /><br />I've tried to comment-out sections of the documentation that are less relevant<br />to people trying to simply use the library. They contain background information<br />or extra interfaces for re-using components.<br /><br />1) Automatically running a function when the library has been called directly.<br /> This is conventionally done in Python using:<br /><br /> >>> def main():<br /> ... pass<br /><br /> >>> if __name__ == '__main__':<br /> ... main();<br /><br /> And can be re-written to<br /><br /> >>> @autorun<br /> ... def main():<br /> ... pass<br /><br /> WARNING: This will not work as expected unless it is the "outermost"<br /> decorator, i.e. the decorator that is listed first in the file and<br /> applied last to the function. If you only have one decorator, that<br /> should be fine - and that's why the library also provides @entrypoint,<br /> @entrywithfile and @runwithfile (see table below) so that you only<br /> need one decorator.<br /><br /> # Specifically, this decorator will call the function as part of the<br /> # process of decorating. Thus any decorators that are applied after<br /> # this one will not have been applied in the case the function is<br /> # called later.<br /><br /> # autorun can also be used as a standalone function, which is necessary if<br /> # you would like to use this functionality as part of another library.<br /> # In such a case you need to pass it a second parameter indicating how far<br /> # many levels above in the stack frame within autorun you would expect for<br /> # __name__ to equal '__main__'.<br /><br /> # >>> def autorunwithone(func):<br /> # ... autorun(lambda: func(1), 2)<br /> # >>> @autorunwithone<br /> # ... def puts(y):<br /> # ... print y<br /><br /><br /><br />2) Automatically opening and closing files with the appropriate encoding.<br /><br /> This is conventionally done using:<br /><br /> >>> from __future__ import with_statement<br /> >>> def main(filename):<br /> ... with codecs.open(filename, 'r', 'utf-8') as openfile:<br /> ... pass<br /><br /> And can be re-written to<br /><br /> >>> @withfile('r')<br /> ... def main(openfile):<br /> ... pass<br /><br /> It is possible to pass a codec's name as the first positional argument<br /> (or as __encoding) to @withfile. The default encoding is stored in<br /> entrypoint.ENCODING and is set to 'utf-8'.<br /><br /> >>> @withfile('utf-16', 'w')<br /> ... def main(openfile):<br /> ... pass<br /><br /> Or to open files in "binary" mode, with no codec, just suffix the<br /> spec with a 'b':<br /><br /> >>> @withfile('rb', 'a')<br /> ... def main(binaryfile, logfile):<br /> ... print >>logfile, process(binaryfile.read())<br /><br /> WARNING: Default arguments to functions are opened and closed on each entry<br /> to that function, when a function will be called more than once used 'a'<br /> instead of 'w' so that later calls don't overwrite the contents.<br /><br /> >>> @withfile('r', 'a')<br /> ... def main(readfile, log='/tmp/python.log'):<br /> ... log.write("Reading %s" % readfile.name)<br /><br /> For clarity, it is possible to give keyword arguments to @withfile, and<br /> it is necessary to do so if you wish to open all the arguments provided to<br /> the function's *args or **kwargs:<br /><br /> >>> @withfile('w', args='r', stderr='a')<br /> ... def main(catfile, *args, **kwargs):<br /> ... if args:<br /> ... catfile.write("n".join(arg.read() for arg in args))<br /> ... elif 'stderr' in kwargs:<br /> ... print >>kwargs['stderr'], "Nothing to cat"<br /><br /> Finally, following the convention of many command line tools, the special<br /> filename '-' is used to refer to sys.stdin for reading, and sys.stdout for<br /> writing and appending. Again this can be a default parameter or passed in<br /> by the caller:<br /><br /> >>> @withfile('r', 'w')<br /> ... def main(input, output='-'):<br /> ... pass<br /><br /> WARNING: The files are opened on entry to the function, not when you need them,<br /> if you open a file for writing, it will be created on disk, even if you don't<br /> write anything to it.<br /><br />3) Automatically parsing command-line arguments from a function's signature,<br /> and, if possible, from its doc-string.<br /><br /> Internally, this uses the argparse module, but removes the tedious syntax<br /> needed to get the most simple arguments parsed.<br /><br /> At its most basic, it simply converts a function that takes several<br /> positional arguments (**kwargs is not supported) into a function that takes<br /> an optional array of arguments, and defaults to sys.argv[1:]<br /><br /> >>> @acceptsargv<br /> ... def main(arg1, arg2):<br /> ... pass<br /> ...<br /> ... main()<br /> ... main(sys.argv[1:])<br /> ... main(['arg1', 'arg2'])<br /><br /> This can be coupled with the other magic above, so that the function is<br /> called automatically when it is defined:<br /><br /> >>> sys.argv[1:] = ['arg1', 'arg2']<br /> >>> @entrypoint<br /> ... def main(arg1, arg2)<br /> ... pass<br /><br /> The argument parser will abort the program if the arguments don't match, and<br /> print a usage message. More detail can be found by passing -h or --help at<br /> the command line as is normal.<br /><br /> >>> @entrypoint<br /> ... def main(arg1, arg2):<br /> ... pass<br /><br /> usage: test.py [-h] arg1 arg2<br /> : error: too few arguments<br /><br /> In addition to compulsary, positional, arguments as demonstrate above it is<br /> possible to add flag arguments. Flag arguments are signified by providing a<br /> default value for the parameter, of the same type as you wish the user to<br /> input. Positional arguments, and flags with a default value of None are<br /> always decoded as unicode strings. If the type conversion fails, it is<br /> presented to the user as an error.<br /><br /> >>> @entrypoint<br /> ... def main(filename, priority=1):<br /> ... assert isinstance(priority, int)<br /><br /> usage: [-h] [--priority PRIORITY] filename<br /><br /> If the default value is True or False, the flag will be treated as a toggle<br /> to flip that value:<br /><br /> >>> @entrypoint<br /> ... def main(filename, verbose=False):<br /> ... if verbose:<br /> ... print filename<br /><br /> usage: [-h] [--verbose] filename<br /><br /> It is also possible to use the *args of a function:<br /><br /> >>> @entrypoint<br /> ... def main(output, *input):<br /> ... print ", ".join(filenames)<br /><br /> usage: [-h] output [input [input ...]]<br /><br /> In addition to being able to parse the arguments automatically, @acceptargv<br /> can also be used to provide user-facing documentation in the same manner as<br /> argparse. It does this by parsing the function's doc string in the following<br /> ways:<br /><br /> >>> def main(filename, flag=True, verbosity=3):<br /> ... """<br /> ... Introductory paragraph.<br /> ...<br /> ... Description and clarification of arguments.<br /> ...<br /> ... Epilogue<br /> ...<br /> ... ----<br /> ...<br /> ... Internal documentation<br /> ... """<br /> ... pass<br /><br /> All parts are optional. The introductory paragraph and the epilogue are<br /> shown before and after the summary of arguments generated by argparse. The<br /> internal documentation (below the ----) is not displayed at all.<br /><br /> <argument> = <clarification>:<description><br /> <clarification> = [-<letter>[,] ] --<flagname> [=<varname>]<br /> = <argname> [/<displayname>]<br /><br /> The description can span multiple lines, and will be re-formed when<br /> displayed.<br /><br /> In the first case, the -<letter> gives a one-letter/number abbreviation for setting<br /> the flag:<br /><br /> >>> def main(flag=True):<br /> ... """<br /> ... -f --flag: Set the flag<br /> ... """<br /><br /> <argname>, <flagname>, <varname>, and <displayname> are limited to<br /> [a-zA-Z][a-zA-Z0-9_-]*<br /><br /> The flagname and the argname should match the actual name used in the<br /> function argument definition, while the displayname and varname are simply<br /> for displaying to the user.<br /><br /> Finally, any function that is wrapped in this manner can throw an<br /> entrypoint.UsageError, the first parameter of which will be displayed to<br /> the user as an error.<br /><br />Several combinations are available as pre-defined decorators:<br /><br /> Run Signature Open<br /> Automatically Parser Files<br /><br /> @autorun X<br /><br /> @entrypoint X X<br /><br /> @entrywithfile X X X*<br /><br /> @runwithfile X X<br /><br /> @withfile X<br /><br /> @withuserfile X*<br /><br /> @acceptargv X<br /><br />* Denotes that FileUsageErrors will be thrown instead of IOErrors to provide more<br /> user-friendly error reporting<br /><br />A set of tests can be run by calling "python test.py"<br /><br />#md5=cd5a0df713ab5ba3a85b10116765697d<br />#md5=2bc8862281e519803a51abc4c9ac4f71

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Arguments Automatically Autorun Called Decorator Default Documentation Entrypoint Filename Files Function Gtgtgt Input Library Mainfilename Print Quotquotquot Usage
Users rating: 0/10

License: Freeware Size: 10.24 KB
ENTRYPOINT RELATED
Development Editors  -  TechWriter for XML Schemas 2009 4.2 Build 10
TechWriter for XML Schemas is a documentation generator for XML schemas that leverages the information locked inside your schema to automatically produce XML schema reference documentation. For many industries and agencies, providing...
 
Modules  -  Indic Language Comments 0.7
Indic Language plugin for Comments, It enables Indic Languages for comment form, When Visitors will write comments in Roman script this plugin automatically converts text into default Indian Script selected using google transliteration API....
10 KB  
Development Editors  -  Oracle VM VirtualBox SDK 4.0.4 r70112
The VirtualBox Software Development Kit (SDK) contains all the documentation and interface files that are needed to write code that interacts with VirtualBox. The Oracle VM VirtualBox Main API documentation describes the so-called VirtualBox Main...
 
Database Tools  -  CodeKit 1.0
CodeKit automatically compiles Less, Sass, Stylus, CoffeeScript, Jade & Haml files. It effortlessly combines, minifies and error-checks javascript. It supports Compass. It even optimizes jpeg & png images, auto-reloads your browser and lets you...
20.48 KB  
File Sharing  -  LimeWire Extreme Accelerator 3.5
LimeWire Extreme Accelerator is an add-on application for LimeWire that automatically increase the download process and finds the files you want with far more power than regular LimeWire searches. The program uses its high-end technology that...
1.44 KB  
MP3 Tools  -  MP3 Renaming 1.1
MP3 Renaming is a FREE program designed to automatically rename using ID3 tags in your mp3 files, according to rules that you specify. What MP3 Renaming can do for you? (1) Rename your mp3 files, using ID3 tags in your mp3 files. (2)...
402.5 KB  
Libraries  -  Pod::Usage 1.35
Pod::Usage, pod2usage() can print a usage message from embedded pod documentation. SYNOPSIS use Pod::Usage my $message_text = "This text precedes the usage message."; my $exit_status = 2; ## The exit status to use my $verbose_level = 0; ##...
97.28 KB  
Application Add-Ins  -  ProcrastiTracker 1.2
ProcrastriTracker is a time tracking tool that automatically tracks what applications and documents you use, and allows you to view statistics on your usage in great detail. It is written to be small and non-intrusive. It is useful for increasing...
2.89 MB  
Multimedia & Graphics  -  Media Library Lite 1. 1. 2003
Media Library Lite is a powerful DVD catalog tool, which can automatically retrieve the DVD info form Amazon, build and manage personal DVD library. If you have burned or purchased hundreds of DVDs and have no idea how to organize them; or...
1.3 MB  
HTML Utilities  -  QuiXample 1. 7. 2003
Plug-in tool for FutureBASIC (FB) that offers multipurpose searches: FB source code files, plain-text files, Apple documentation, Apple header files (converts declarations to FB syntax), Apple Error codes, FB Pouch (an online resource for the FB...
1.5 MB  
NEW DOWNLOADS IN LINUX SOFTWARE, PROGRAMMING
Linux Software  -  Polling Autodialer Software 3.4
ICTBroadcast Auto Dialer software has a survey campaign for telephone surveys and polls. This auto dialer software automatically dials a list of numbers and asks them a set of questions that they can respond to, by using their telephone keypad....
488 B  
Linux Software  -  Total Video Converter Mac Free 3.5.5
Total Video Converter Mac Free developed by EffectMatrix Ltd is the official legal version of Total Video Converter which was a globally recognized brand since 2006. Total Video Converter Mac Free is a free but powerful all-in-one video...
17.7 MB  
Linux Software  -  Skeith mod_log_sql Analyzer 2.10beta2
Skeith is a php based front end for analyzing logs for Apache using mod_log_sql.
47.5 KB  
Linux Software  -  SLAX 6.0+
Slax is a modern, portable, small and fast Linux operating system with a modular approach and outstanding design. Despite its small size, Slax provides a wide collection of pre-installed software for daily use, including a well organized graphical...
190 KB  
Linux Software  -  GTK+ 2.5
GTK+, which stands for the GIMP Toolkit, is a library for creating graphical user interfaces for the X Window System. It is designed to be small, efficient, and flexible. GTK+ is written in C with a very object-oriented approach. Language bindings...
60 MB  
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by freedesktop.org, it is used to describe information about an application such as the name and...
327.68 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB