jjcli (version 0.1.15)
index
/home/jj/svn/main/python/jjcli/jjcli.py

# Name
 
 jjcli - python module for command-line filter
 
Synopsis
========
 
as ascript:
 
    jjcli skel     ## a initial filter skeleton
    jjcli          ## manual
 
as a module: 
 
    from jjcli import *       ## re.* functions also imported
    c=clfilter(opt="do:")     ## options in c.opt  (...if "-d" in c.opt:)
                              ##    autostrip         (def=True)
                              ##    inplace           (def=False) 
                              ##    fs (for csvrow()) (def=",")
 
    for line in c.input():...    ## process one rstriped line at the time
    for txt in c.slurp():...     ## process one striped text at the time
       ## process txt            ##   (end of line spaces and   also removed)
    for par in c.paragraph():... ## process one striped paragraph at the time
    for tup in c.csvrow():...    ## process one csv row at the time
    for tup in c.tsvrow():...    ## process one tsv row at the time
 
    c.lineno()                ## line number
    c.filelineno()
    c.parno()                 ## paragraph number
    c.fileparno()
    c.filename()              ## filename or "<stdin>"
    c.nextfile()
    c.isfirstline()
 
# Description
 
__jjcli__ is a opinioned Python module that tries to simplify the creation of
__unix__ filters. It is based on:
 
- getopt  (for command line options and args)
- fileinput (for [files/stdin] arguments)
- re (regular expressions should be native)
- csv  (for csv and tsv inputs)
- urllib.request (to deal with input argumens that are url)
- subprocess 
 
## Regular expressions
 
We want to have all re.* functions available (as if they were native
functions).
 
In order to enable __re__ flags, use: re.I re.X re.S  
 
## Subprocesses   (qx, qxlines, qxsystem)
 
    a=qx( "ls" )
    for x in qxlines("find | grep '\.jpg$'"): 
      ...
    qxsystem("vim myfile")
 
### Execute command return its stdout
    qx(*x)      →  returns    subprocess.getoutput(x)
 
### Execute command return its stdout lines
    qxlines(*x) →  returns    subprocess.getoutput(x).splitlines()
 
### Execute command -- system
    qxsystem(*x) →  calls     subprocess.call(x,shell=True)
 
## Other functions
 
    slurpurlutf8(self,f)
 
    filename    = lambda s : F.filename()      # inherited from fileinput
    lineno      = lambda s : F.lineno()
    filelineno  = lambda s : F.filelineno()
    parno       = lambda s : s.parno_          # paragraph number
    fileparno   = lambda s : s.fileparno_
    nextfile    = lambda s : F.nextfile()
    isfirstline = lambda s : F.isfirstline()
    close       = lambda s : F.close()

 
Modules
       
fileinput
csv
getopt
re
subprocess
sys
urllib.request

 
Classes
       
builtins.object
clfilter

 
class clfilter(builtins.object)
    clfilter(opt='', rs='\n', fs=',', autostrip=True, inplace=False)
 
csfilter - Class for command line filters
 
  Methods defined here:
__init__(self, opt='', rs='\n', fs=',', autostrip=True, inplace=False)
Initialize self.  See help(type(self)) for accurate signature.
clean(self, s)
cleanpar(self, s)
close lambda s
csvrow(self, files=None)
filelineno lambda s
filename lambda s
fileparno lambda s
input(self, files=None)
isfirstline lambda s
lineno lambda s
nextfile lambda s
off_slurp(self, files=None)
paragraph(self, files=None)
parno lambda s
slurp(self, files=None)
slurpurlutf8(self, f)
tsvrow(self, files=None)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
main()
qx(*x)
# execute command return its stdout
qxlines(*x)
# execute command return its stdout lines
qxsystem(*x)
# execute command -- system

 
Data
        __docformat__ = 'markdown'