Popular recipes tagged "meta:requires=argparse"http://code.activestate.com/recipes/tags/meta:requires=argparse/2016-08-07T20:41:12-07:00ActiveState Code RecipesRecursive find replace in files using regex (Python)
2016-04-28T13:24:15-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/580653-recursive-find-replace-in-files-using-regex/
<p style="color: grey">
Python
recipe 580653
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/search/">search</a>).
Revision 5.
</p>
<h4 id="recursively-find-and-replace-text-in-files-under-a-specific-folder-with-preview-of-changed-data-in-dry-run-mode">Recursively find and replace text in files under a specific folder with preview of changed data in dry-run mode</h4>
<h5 id="example-usage">Example Usage</h5>
<p><strong>See what is going to change (dry run):</strong></p>
<pre class="prettyprint"><code>find_replace.py --dir project/myfolder --search-regex "\d{4}-\d{2}-\d{2}" --replace-regex "2012-12-12" --dryrun
</code></pre>
<p><strong>Do actual replacement:</strong></p>
<pre class="prettyprint"><code>find_replace.py --dir project/myfolder --search-regex "\d{4}-\d{2}-\d{2}" --replace-regex "2012-12-12"
</code></pre>
<p><strong>Do actual replacement and create backup files:</strong></p>
<pre class="prettyprint"><code>find_replace.py --dir project/myfolder --search-regex "\d{4}-\d{2}-\d{2}" --replace-regex "2012-12-12" --create-backup
</code></pre>
<p><strong>Same action as previous command with short-hand syntax:</strong></p>
<pre class="prettyprint"><code>find_replace.py -d project/myfolder -s "\d{4}-\d{2}-\d{2}" -r "2012-12-12" -b
</code></pre>
<p>Output of <code>find_replace.py -h</code>:</p>
<pre class="prettyprint"><code>DESCRIPTION:
Find and replace recursively from the given folder using regular expressions
optional arguments:
-h, --help show this help message and exit
--dir DIR, -d DIR folder to search in; by default current folder
--search-regex SEARCH_REGEX, -s SEARCH_REGEX
search regex
--replace-regex REPLACE_REGEX, -r REPLACE_REGEX
replacement regex
--glob GLOB, -g GLOB glob pattern, i.e. *.html
--dryrun, -dr don't replace anything just show what is going to be
done
--create-backup, -b Create backup files
USAGE:
find_replace.py -d [my_folder] -s <search_regex> -r <replace_regex> -g [glob_pattern]
</code></pre>
Makes html with javascript to animate a sequence of images (Python)
2016-08-07T20:41:12-07:00Brian Fiedlerhttp://code.activestate.com/recipes/users/4194196/http://code.activestate.com/recipes/580675-makes-html-with-javascript-to-animate-a-sequence-o/
<p style="color: grey">
Python
recipe 580675
by <a href="/recipes/users/4194196/">Brian Fiedler</a>
(<a href="/recipes/tags/animation/">animation</a>, <a href="/recipes/tags/javascript/">javascript</a>).
Revision 2.
</p>
<p>Given paths to image files, produces the html file with embedded javascript to animate those images as a web page.</p>
bookmarks browser for firefox (Python)
2015-07-06T23:15:31-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/579077-bookmarks-browser-for-firefox/
<p style="color: grey">
Python
recipe 579077
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/bookmarks/">bookmarks</a>, <a href="/recipes/tags/firefox/">firefox</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>a small tkinter gui to browse the .json type bookmark files firefox automatically generates each day. It's meant to be run from a terminal. If a tree item is doubleclicked it prints the uri.</p>
Tail multiple pidgin IRC logfiles (Python)
2015-06-06T12:13:00-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/579066-tail-multiple-pidgin-irc-logfiles/
<p style="color: grey">
Python
recipe 579066
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/colorize/">colorize</a>, <a href="/recipes/tags/irc/">irc</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/logfiles/">logfiles</a>, <a href="/recipes/tags/merging/">merging</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/pidgin/">pidgin</a>, <a href="/recipes/tags/tail/">tail</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>Tail multiple pidgin IRC logfiles. </p>
<p>Pidgin should be connected to IRC with the channels one
wants to tail joined, and it should save logs as text.</p>
<p>The script needs two arguments:</p>
<pre class="prettyprint"><code>the directory containing the directories with channel logs
a list of channel names, quoted and separated by spaces
</code></pre>
<p>Example command:</p>
<p>python pidgin-irctail.py
-d <a href="mailto:~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net">~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net</a>
-c "#chan1 #chan2 #chan3"</p>
<p>Some text elements are higlighted, and channel names are
inserted into the log lines after the time info.</p>
<p>If more than one channel is entered, the output of the logs
is merged. </p>
Split file in place into two parts (Python)
2015-02-11T20:08:35-08:00shavy89http://code.activestate.com/recipes/users/4191634/http://code.activestate.com/recipes/579025-split-file-in-place-into-two-parts/
<p style="color: grey">
Python
recipe 579025
by <a href="/recipes/users/4191634/">shavy89</a>
(<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/splitting/">splitting</a>).
Revision 2.
</p>
<p>Split file in place into two parts </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>
Recursive Multimedia (audio, video) M3U Playlist Generator (Python)
2014-02-08T01:03:36-08:00Mano Bastardohttp://code.activestate.com/recipes/users/4182040/http://code.activestate.com/recipes/578771-recursive-multimedia-audio-video-m3u-playlist-gene/
<p style="color: grey">
Python
recipe 578771
by <a href="/recipes/users/4182040/">Mano Bastardo</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/ffmpeg/">ffmpeg</a>, <a href="/recipes/tags/generate/">generate</a>, <a href="/recipes/tags/m3u/">m3u</a>, <a href="/recipes/tags/mulitmedia/">mulitmedia</a>, <a href="/recipes/tags/os/">os</a>, <a href="/recipes/tags/playlist/">playlist</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/video/">video</a>).
Revision 9.
</p>
<p>Generate an m3u playlist searching recursively
for multimedia files (video or audio) in the given
directory.
Information from ID3 tags will be extracted for audio
files with <a href="http://en.wikipedia.org/wiki/FFmpeg">FFmpeg</a> available.</p>
'Which' for Windows (Python)
2013-08-16T09:14:07-07:00Robert Pyronhttp://code.activestate.com/recipes/users/4174781/http://code.activestate.com/recipes/578642-which-for-windows/
<p style="color: grey">
Python
recipe 578642
by <a href="/recipes/users/4174781/">Robert Pyron</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/which/">which</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 2.
</p>
<p>WHICH.PY scans through all directories specified in the system %PATH%
environment variable, looking for the specified COMMAND(s). It tries
to follow the sometimes bizarre rules for Windows command lookup.</p>
pack multiple images of different sizes into one image (Python)
2013-06-27T14:50:37-07:00Hugohttp://code.activestate.com/recipes/users/4183663/http://code.activestate.com/recipes/578585-pack-multiple-images-of-different-sizes-into-one-i/
<p style="color: grey">
Python
recipe 578585
by <a href="/recipes/users/4183663/">Hugo</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
</p>
<p>Packing images of different sizes into one image is often required in order to efficiently use hardware accelerated texture mapping functions of 3D video cards.</p>
Colorize Python -- Sourcecode Syntax Highlighting (Python)
2012-07-21T02:46:37-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/578178-colorize-python-sourcecode-syntax-highlighting/
<p style="color: grey">
Python
recipe 578178
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/highlighting/">highlighting</a>, <a href="/recipes/tags/syntax/">syntax</a>).
Revision 20.
</p>
<p>Generates colorized HTML, ANSI escaped text, or a LaTeX document from Python source code. Useful for publishing or viewing your code in a more readable way.</p>
Ghoster - Windows program to create 0kb clone of folder or drive (Python)
2012-09-02T13:30:29-07:00commentator8http://code.activestate.com/recipes/users/4182761/http://code.activestate.com/recipes/578251-ghoster-windows-program-to-create-0kb-clone-of-fol/
<p style="color: grey">
Python
recipe 578251
by <a href="/recipes/users/4182761/">commentator8</a>
(<a href="/recipes/tags/clone/">clone</a>, <a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>A program that will create a "ghost" of a given directory or drive on windows systems
(easily adaptable to unix etc) to a given destination. This will consist of a copy of all folders and files with only names and extensions retained, not size.
This allows browsing of a remote drive or network location when offline.</p>
A small python script to detect .net framwork versions installed on your local windows machine (Python)
2012-05-23T15:33:13-07:00Yong Zhaohttp://code.activestate.com/recipes/users/4182173/http://code.activestate.com/recipes/578143-a-small-python-script-to-detect-net-framwork-versi/
<p style="color: grey">
Python
recipe 578143
by <a href="/recipes/users/4182173/">Yong Zhao</a>
(<a href="/recipes/tags/dotnet/">dotnet</a>, <a href="/recipes/tags/framework/">framework</a>, <a href="/recipes/tags/python_scripts/">python_scripts</a>, <a href="/recipes/tags/windows_registry/">windows_registry</a>, <a href="/recipes/tags/_winreg/">_winreg</a>).
</p>
<p>This small script uses the _winreg module to find out the .net framwork versions installed on your local machine. tested using IronPython 2.7.1.</p>
Find a line of text in another file (Python)
2012-06-15T15:45:18-07:00sami janhttp://code.activestate.com/recipes/users/4064232/http://code.activestate.com/recipes/578164-find-a-line-of-text-in-another-file/
<p style="color: grey">
Python
recipe 578164
by <a href="/recipes/users/4064232/">sami jan</a>
(<a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/search/">search</a>).
Revision 2.
</p>
<p>This is a simple recipe - it reads a line in file, removes the line-ending and attempts to search throughout another file for the same line, anywhere in the file</p>
<p>In case a line is missing, the line number is printed to stdout</p>
Left-handed password generator (Python)
2011-10-31T12:51:14-07:00Alexhttp://code.activestate.com/recipes/users/4179771/http://code.activestate.com/recipes/577930-left-handed-password-generator/
<p style="color: grey">
Python
recipe 577930
by <a href="/recipes/users/4179771/">Alex</a>
(<a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/lefthand/">lefthand</a>, <a href="/recipes/tags/lefthanded/">lefthanded</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/passwords/">passwords</a>).
Revision 2.
</p>
<p>Generate passwords that can easily be typed with only the left hand, very simple script</p>
Generate automatically list of actions with argparse (Python)
2011-12-02T10:25:13-08:00Andrea Crottihttp://code.activestate.com/recipes/users/4179946/http://code.activestate.com/recipes/577947-generate-automatically-list-of-actions-with-argpar/
<p style="color: grey">
Python
recipe 577947
by <a href="/recipes/users/4179946/">Andrea Crotti</a>
(<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cli/">cli</a>).
Revision 2.
</p>
<p>This little sample script looks up in locals() to determine all the callables in <em>main</em>.</p>
<p>Then it passes them to parse_arguments, which show an help message as following
usage:</p>
<pre class="prettyprint"><code>prova.py [-h] {func2,func1}
positional arguments:
{func2,func1}
optional arguments:
-h, --help show this help message and exit
</code></pre>
<p>Useful to avoid duplication and make it easy to extend script functions.</p>
Simple Regular Expression Tester (Python)
2010-12-25T00:12:44-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577517-simple-regular-expression-tester/
<p style="color: grey">
Python
recipe 577517
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/quick/">quick</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/testing/">testing</a>).
Revision 2.
</p>
<p><strong><em>Is it possible to create a simple command line program that I can use to quickly test my regular expressions?</em></strong></p>
<p>Yes it is. This simple regular expression tester uses Python's re module as well as others to quickly allow you to test your regular expression in one go.</p>
<p>TODO:</p>
<ul>
<li>Add Support For Multiple Regular Expression Input</li>
</ul>
<p>Recent Changes:</p>
<ul>
<li>Made the output prettier with a little more whitespace. More bytes, but at least it's easier to read!</li>
</ul>
Holiday Leave (Python)
2010-07-01T13:21:09-07:00farciarzhttp://code.activestate.com/recipes/users/4172795/http://code.activestate.com/recipes/577280-holiday-leave/
<p style="color: grey">
Python
recipe 577280
by <a href="/recipes/users/4172795/">farciarz</a>
(<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/console/">console</a>, <a href="/recipes/tags/holiday/">holiday</a>, <a href="/recipes/tags/leave/">leave</a>).
</p>
<p>Simple console tool that helps in maintenance your free days from work + basic tutorial how to use argparse in practice. It's clear and few lines of code. Enjoy! :-)</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>
Send Email (Python)
2012-08-26T11:23:54-07:00sfwgeekhttp://code.activestate.com/recipes/users/4170734/http://code.activestate.com/recipes/576807-send-email/
<p style="color: grey">
Python
recipe 576807
by <a href="/recipes/users/4170734/">sfwgeek</a>
(<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/interface/">interface</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/send/">send</a>, <a href="/recipes/tags/smtplib/">smtplib</a>).
Revision 5.
</p>
<p>A Command Line Interface (CLI) program to send email.</p>