Popular recipes tagged "commandline" but not "python"http://code.activestate.com/recipes/tags/commandline-python/2017-01-08T17:48:57-08:00ActiveState Code RecipesA utility like Unix seq (command-line), in Python (Python) 2017-01-08T17:48:57-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580744-a-utility-like-unix-seq-command-line-in-python/ <p style="color: grey"> Python recipe 580744 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/seq/">seq</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This recipe shows how to create a utility like Unix seq (command-line), in Python. seq is described here: </p> <p><a href="https://en.wikipedia.org/wiki/Seq_%28Unix%29" rel="nofollow">https://en.wikipedia.org/wiki/Seq_(Unix)</a></p> <p>but briefly, it is a command-line utility that takes 1 to 3 arguments (some being optional), the start, stop and step, and prints numbers from the start value to the stop value, on standard output. So seq has many uses in bigger commands or scripts; a common category of use is to quickly generate multiple filenames or other strings that contain numbers in them, for exhaustive testing, load testing or other purposes. A similar command called jot is found on some Unix systems.</p> <p>This recipe does not try to be exactly the same in functionality as seq. It has some differences. However the core functionality of generating integer sequences is the same (but without steps other than 1 for the range).</p> <p>More details and sample output are here:</p> <p><a href="https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html</a></p> <p>The code is below.</p> A UNIX-like "which" command for Python (Python) 2015-03-20T19:23:45-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579035-a-unix-like-which-command-for-python/ <p style="color: grey"> Python recipe 579035 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/commands/">commands</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/which/">which</a>). </p> <p>UNIX users are familiar with the which command. Given an argument called name, it checks the system PATH environment variable, to see whether that name exists (as a file) in any of the directories specified in the PATH. (The directories in the PATH are colon-separated on UNIX and semicolon-separated on Windows.)</p> <p>This recipe shows how to write a minimal which command in Python. It has been tested on Windows.</p> beep based alarm - command line utility (Python) 2014-10-25T22:29:10-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578953-beep-based-alarm-command-line-utility/ <p style="color: grey"> Python recipe 578953 by <a href="/recipes/users/4189558/">Tomas Nordin</a> (<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/commandline/">commandline</a>). Revision 2. </p> <p>An alarm beeping on you when the eggs are boiled.</p> Droids ( a text adventure ) (Python) 2013-07-27T09:44:06-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578618-droids-a-text-adventure/ <p style="color: grey"> Python recipe 578618 by <a href="/recipes/users/4186699/">jay</a> (<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/text/">text</a>). </p> <p>for beginners.</p> Create PDF at the end of a Unix pipeline with PDFWriter (Python) 2013-12-22T22:19:00-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578794-create-pdf-at-the-end-of-a-unix-pipeline-with-pdfw/ <p style="color: grey"> Python recipe 578794 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create PDF output at the end of a Unix or Linux pipeline, after all the text processing required, is done by previous components of the pipeline (which can use any of the standard tools of Unix such as sed, grep, awk, etc., as well as custom programs that act as filters).</p> Droids 2 ( IF ) (Python) 2013-08-13T09:12:11-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578636-droids-2-if/ <p style="color: grey"> Python recipe 578636 by <a href="/recipes/users/4186699/">jay</a> (<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/if/">if</a>, <a href="/recipes/tags/learning/">learning</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <h4 id="-for-learners-and-beginners-like-myself-">-For learner's and beginner's like myself -</h4> <h4 id="-and-for-anyone-who-may-have-enjoyed-droids-">-and for anyone who may have enjoyed Droids. -</h4> 2 very basic text games. (Python) 2013-07-09T03:08:47-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578596-2-very-basic-text-games/ <p style="color: grey"> Python recipe 578596 by <a href="/recipes/users/4186699/">jay</a> (<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/fun/">fun</a>, <a href="/recipes/tags/python3/">python3</a>). </p> <p>my versions of two games found in Al Sweigart's book "invent with python"</p> Extract Multiple TAR Files & Directories (Python) 2012-07-04T00:57:37-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578191-extract-multiple-tar-files-directories/ <p style="color: grey"> Python recipe 578191 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/tarfile/">tarfile</a>). </p> <p>Related to the popular <a href="http://code.activestate.com/recipes/442503/">recipe 442503</a>, this command-line program takes multiple TAR files or directories and can extract them in a batch operation. This is committed for archival to be run under Python 2.5 or later versions.</p> Linux to Windows (Python) 2012-07-04T01:18:50-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578192-linux-to-windows/ <p style="color: grey"> Python recipe 578192 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>When trying to work with Linux archive downloaded onto Windows, sometimes it is helpful to untar all found archives, give extension-less files the "txt" extension, and convert text files to Windows line endings (\r\n), and that is just what this program is designed to accomplish. This is committed for archival to be run under Python 2.5 or later versions.</p> FSM 2.5 Reader (Python) 2011-04-06T03:02:57-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577639-fsm-25-reader/ <p style="color: grey"> Python recipe 577639 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/file_io/">file_io</a>, <a href="/recipes/tags/file_share/">file_share</a>, <a href="/recipes/tags/messenger/">messenger</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/workaround/">workaround</a>). </p> <p>For those who would want to search the message logs produced by <a href="http://code.activestate.com/recipes/577638/">recipe 577638</a>, this program provides a command-line solution to searching messages according to their authors. If this program is placed in the message directory, the program may be executed on the command-line with the author's name as an argument. If and when the program is executed without an argument, usage information is shown on the screen before exiting. If an author was not found, the author's name is printed stating that nothing could be found. If a matching file was found, all timestamps and messages will be displayed that could be decoded correctly.</p> <p>If there are any recommendation for this recipe or if anyone wishes to down-vote this recipe, please provide corrective criticism showing the the program's faults and give suggestions on how you would fix any problems that it might have.</p> Directory Size (Console) (Python) 2011-02-09T13:29:56-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577566-directory-size-console/ <p style="color: grey"> Python recipe 577566 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/sizeof/">sizeof</a>, <a href="/recipes/tags/tree/">tree</a>). </p> <p>Have you ever wanted to find out how much room a particular directory was taking up on your hard drive? A roommate of mine in college was having trouble keeping track of where his hard drive space is going, so the following program provided a solution that allows a brief overview of a directory's size along with all of its children. A tree view is printed out in ASCII characters showing the relationship of each directory along with its size in a format easily readable to humans. The output can always be redirected to a text file if it needs to be saved for viewing later on.</p> Better quote module for bash shells (Python) 2010-12-03T09:16:45-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577483-better-quote-module-for-bash-shells/ <p style="color: grey"> Python recipe 577483 by <a href="/recipes/users/4173535/">Kevin L. Sitze</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/escape/">escape</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/quote/">quote</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>This Python module quotes a Python string so that it will be treated as a single argument to commands ran via os.system() (assuming bash is the underlying shell). In other words, this module makes arbitrary strings "command line safe" (for bash command lines anyway, YMMV if you're using Windows or one of the (less fine) posix shells).</p> argdeclare: declarative interface to argparse (Python) 2010-03-02T00:05:40-08:00Shakeeb Alirezahttp://code.activestate.com/recipes/users/4172101/http://code.activestate.com/recipes/576935-argdeclare-declarative-interface-to-argparse/ <p style="color: grey"> Python recipe 576935 by <a href="/recipes/users/4172101/">Shakeeb Alireza</a> (<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cmdln/">cmdln</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/getopt/">getopt</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/option/">option</a>). Revision 5. </p> <p>This is an implementation of the interface provided by the <a href="http://code.google.com/p/cmdln/">cmdln</a> module but using <a href="http://code.google.com/p/argparse/">argparse</a> to provide the option/arg heavy parsing.</p> <p>An example of usage is provided in the <code>test</code> function, which should produce the following from the command line:</p> <p>$ python argdeclare.py --help</p> <pre class="prettyprint"><code>usage: argdeclare.py [-h] [-v] {uninstall,install,delete} ... a description of the test app optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit subcommands: valid subcommands {uninstall,install,delete} additional help delete help text for delete subcmd install help text for install subcmd uninstall help text for uninstall subcmd </code></pre> <p>$ python argdeclare.py install --help</p> <pre class="prettyprint"><code>usage: argdeclare.py install [-h] [-t TYPE] [--log] [-f] package positional arguments: package package to be (un)installed optional arguments: -h, --help show this help message and exit -t TYPE, --type TYPE specify type of package --log, -l log is on -f, --force force through installation </code></pre> <p>enjoy!</p> <p>SA</p> download a URL with a console progress meter (Python) 2008-10-08T05:05:12-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/576530-download-a-url-with-a-console-progress-meter/ <p style="color: grey"> Python recipe 576530 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/download/">download</a>, <a href="/recipes/tags/url/">url</a>). </p> <p>A little script/function to download a given URL with a console progress meter. Usage:</p> <pre class="prettyprint"><code>python geturl.py <a href="http://example.com/downloads/bigfile.zip" rel="nofollow">http://example.com/downloads/bigfile.zip</a> </code></pre> <p>(This is from an <a href="http://mail.python.org/pipermail/python-list/2005-April/319818.html">old post to python-list</a>.)</p>