GithubHelp home page GithubHelp logo

tbarron / backscratcher Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 736 KB

"Every good work of software starts by scratching a developer's personal itch." Eric S. Raymond

License: Other

Makefile 0.40% Python 91.63% Perl 7.10% Shell 0.87%

backscratcher's Introduction

                        Backscratcher

"Every good work of software starts by scratching a developer's personal itch."

  • Eric Raymond

This is a collection of small programs I have developed over the years to take care of various tasks on the computer. Perhaps the one I use most is 'tps' (turbo-ps), which lets me grep the output of ps with strings rather than pids.

Another one I use a lot is fx (effects). It can do a number of tricks to issue a command on each of a collection of files, even commands that ordinarily only operate on a single file.

align.py
    Read a sequence of text lines and align their contents into
    columns.

ascii.py
    Display the ASCII collating sequence.

calc.py
    Simple calculator/expression evaluator.

chron.py
    Timer. Can count up (like a stopwatch) or down (like a kitchen
    timer).

clps.py
    Command Line Password Safe. Stores (host, user, password)
    tuples in an encrypted file, can copy a password to the
    clipboard for pasting into a password prompt without
    displaying it on the screen. Mac-specific, since it uses
    pbcopy and pbpaste.

dt.py
    Easy date arithmetic.

errno
    Feed it a number from errno.h, get back the symbolic name and
    meaning, or vice versa.

fab.py
    Poor man's make.

filter.py

fl.py
    File manipulations. Copy atime to mtime, mtime to atime; diff file
    against previous revision; revert file to previous revision; remove
    \r from a file (or add them); display all times associated with a
    file; make backup copy of a file; find unreadable files.

fx.py
    Command line effects. Turbo xargs; structured batch renames; etc.

hd.py
    Hexdump.

list.py (list.pl)
    Set arithmetic applied to lists generated by Unix commands.

mag.py (magnitude)
    2384192384283 -> 2.17 Tb

mcal
    Display analog calendar in various formats.

msh
    Start ssh with a control socket so that multiple sessions can
    piggyback over the same connection without repeated
    authentication.

odx.py (odx.pl)
    Report the octal, decimal, and hexadecimal variants of a
    number.

plwhich
    Which for the perl installation. eg., where does Data::Dumper live?

ptidy
    Cleanup up emacs debris.

pytool.py
    Generate python templates.

replay.py (replay.pl)
    Run a command over and over and watch its output.

rxlab
    Play with regular expressions.

scanpath
    Where in my $PATH is foo?

summarize.pl
    Apply "artificial ignorance" to a set of files.

testhelp.py [deprecated -- remove]
    Testing utility routines.

toolframe.py [deprecated -- remove]
    Easy launching for tool-style and simply python programs.

tpbtools.py
    Utility routines.

tps
    Turbo-ps -- find processes.

truth_table
    Generate truth tables for an arbitrary number of variables.

vipath
    Edit $PATH.

wcal
    Wide cal. Three months side by side.

workrpt.py
    Read my work log and generate a report.

wxfr
    Bulk file transfer.

xclean
    Remove emacs backup files (*~) and other debris left behind by work
    processes

You may notice that some of these are written in only perl while others have a python version and some are only in python. I learned perl first and used it alongside the tcl-based expect tool until I discovered python and realized that it provides pretty much everything perl and expect do in a single tool. I'm not a performance wonk, I just want to get the job done, so I didn't worry too much about whether python is as fast or efficient as perl. I just jumped in.

So now I'm in the middle of converting all these programs to python.

Even more recently, I have started using Perl::Expect. So now I know that perl can do expect-type stuff, too.


Regression tests now live in directory test.

backscratcher's People

Contributors

tbarron avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

scalp42

backscratcher's Issues

filter

2009-02-10 22:17: complete test suite in filter.py
2009-02-10 22:04: write perl version (filter.pm)
2009-02-10 22:04: add to git repo
2010-11-27 12:33: add -L code to link $@ -> $@.py, get rid of $@
as a separate file

magnitude should use MB, MiB properly

Distinguish between MB (1,000,000 bytes) and MiB (1024 * 1024 bytes) correctly.

Provide a command line option for selecting which set of units to report.

fab: add function diff

This will look at the files called out by 'status -a' and report their diffs from the installed files.

wcal

2009-02-10 21:59: add license info
2009-02-10 21:59: write python version
2009-02-10 21:59: add to git repo
2010-11-27 12:33: add -L code to link $@ -> $@.py, get rid of $@
as a separate file

tests for 'workrpt -m'

Also want to be able to limit -m selection by dates. Eg.:

  • workrpt -m RGX # match RGX across all dates
  • workrpt -m RGX -s 2001.0101 # match RGX after 2001.0101
  • workrpt -m RGX -e 2010.1231 # match RGX before 2010.1231
  • workrpt -m RGX -s 2001.0101 -e 2010.1231 # match RGX between 2001.0101 and 2010.1231

vipath

2009-02-10 21:59: write python version
2010-11-27 12:33: add -L code to link $@ -> $@.py, get rid of $@
as a separate file

dt

2009-02-10 22:15: implement in python
2009-02-10 22:15: implement in perl
2009-02-10 22:16: add to git repo
2010-11-27 12:33: add -L code to link $@ -> $@.py, get rid of $@
as a separate file

pytool defects

  • it appears that the prefix is not put into the tool code correctly
  • the example function needs a doc string
  • the example should have a sample usage of OptionParser()

Add tox testing

add tox.ini for 2.6.9, 2.7, 3.5.2 and make sure all tests pass for all python versions

add test function to fab

fab's test function will call each of the managed items in fabfile.py's list in the appropriate way to test it

write tests for workrpt

Examples of tests needed:

  • should throw exception if times are out of order in the input file
  • should not be thrown off by whitespace in the input
  • missing COB at end of day should provoke a warning (not an error -- I have been known to work through midnight)
  • bad date/time format should get an error, however, we should be more tolerant of a variety of date/time formats
  • use first byte of payload as a separator and subtotal on unique supertasks

summarize

  • add license info
  • write python version
  • add to git repo
  • add -L code to link $@ -> $@.py, get rid of $@ as a separate file

align

  • use toolframe.ezlaunch
  • eliminate align as separate file
  • support filename on command line

fl

  • update the Subfunctions section of the doc string
  • write a test for fl_rm_cr
  • write fl_save
  • write fl_times
  • write fl_unreadable

toolframe.py

In tf_launch and ez_launch put the call to the payload routine in a try ... except ... structure and let the payload code define its own exception handler

deprecations when running dt.py tests

/Users/tbarron/bin/dt.py:279: SyntaxWarning: assertion is always true, perhaps remove parentheses?
assert(e.message, expected)
/Users/tbarron/bin/dt.py:375: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
self.message = message
/Users/tbarron/bin/dt.py:261: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
assert(e.message == expected)
/Users/tbarron/bin/dt.py:279: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
assert(e.message, expected)

tps

2009-02-10 21:59: add license info
2009-02-10 21:59: write python version
2009-02-10 21:59: add to git repo
2010-11-27 12:33: add -L code to link $@ -> $@.py, get rid of $@
as a separate file

ptidy

2009-02-10 21:59: add license info
2009-02-10 21:59: write python version
2009-02-10 21:59: add to git repo
2010-11-27 12:33: add -L code to link $@ -> $@.py, get rid of $@
as a separate file

use 'if __name__ == '__main__''

Some of the programs call toolframe.XX_launch() unconditionally. The launch routine should only be called if name == 'main'.

fl.py

failure importing util from bscr

$ stella help
 Traceback (most recent call last):
   File "/Users/tpb/bin/stella", line 4, in <module>
    import bscr.util
  File "/Users/tpb/Dropbox/prj/backscratcher/bscr/bscr.py", line 15, in <module>
    import util
  File "/Users/tpb/Dropbox/prj/backscratcher/bscr/util.py", line 521, in <module>
    bscr = package_module(__name__)
  File "/Users/tpb/Dropbox/prj/backscratcher/bscr/util.py", line 499, in package_module
    rval = sys.modules[sys.modules[module_name].__package__]
KeyError: None


$ cat stella.py
#!/usr/bin/env python
import os
import sys
import bscr.util

def main(args):
    """
    Top entry point
    """
    util.dispatch(__name__, 'stella', args)


def stella_start(args):
    """start - fire up the django server
    """

#     c = util.cmdline([{'opts': ['--repo', '-r'],
#                        'action': 'store',
#                        'default': 'sciwork',
#                        'help': 'which repo to use'}])
#     (o, a) = c.parse(args)

    print("This is stella start")
    path = os.path.expanduser("~/prj/stella/%s/django-fe" % o.repo)
    os.chdir(path)
    print os.getcwd()
    pypath = os.getenv("PYTHONPATH")
    if 'constellationfe' not in pypath:
        os.environ['PYTHONPATH'] = path + '/constellation/constellationfe'
    cmd = "python manage.py runserver 8080"
    os.system(cmd)


if __name__ == '__main__':
    main(sys.argv)

scanpath

2009-02-10 21:59: add license info
2009-02-10 21:59: write python version
2009-02-10 21:59: add to git repo
2010-11-27 12:33: add -L code to link $@ -&gt; $@.py, get rid of $@
as a separate file

rxlab

add license info
write python version
add to git repo
add -L code to link $@ -&gt; $@.py, get rid of $@ as a separate file

add ls function to fl.py

I'd like an ls with a long listing that looks like this:

-rwxrwxrwx 1 tpb staff 14.1K 2011.0323 HH:MM:SS fl.py
-rwxrwxrwx 1 tpb staff 25.8K 2011.0209 HH:MM:SS fx.py
-rwxrwxrwx 1 tpb staff 2.7K 2011.0323 HH:MM:SS hd.py
-rwxrwxrwx 1 tpb staff 2.4K 2011.0715 15:33:00 jump.py

Total: 45.0K

That is, the size is given in terms of kilo, mega, giga, etc., the file time is shown in YYYY.MMDD HH:MM:SS format and the total size of the files listed is given.

Ultimately, "fl ls" should support all the options the standard ls does.

truth_table

2009-02-10 21:59: add license info
2009-02-10 21:59: write python version
2009-02-10 21:59: add to git repo
2010-11-27 12:33: add -L code to link $@ -&gt; $@.py, get rid of $@
as a separate file

ascii

  • use toolframe.ezlaunch
  • eliminate python launcher file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.