Skip to main content

python module for command-line filter

Project description

##Name

jjcli - python module for command-line filter

##Synopsys

jjcli skel     ## for a initial filter skeleton
jjcli          ## for manual

--

from jjcli import *       ## re.* functions also imported
c=clfilter(opt="do:")     ## options 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 \r 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 python module that tries to simplify the creation of unix filters by importing:

  • getopt (for command line options ans args)
  • fileinput (for [files/stdin] arguments)
  • re (regular expressions)
  • csv (for csv and tsv inputs)
  • urllib.request (to deal with input argumens that are url)
  • subprocess

regular expressions

imports all functions from re.*
Use re.I re.X re.S   for regexp flags

subprocesses (qx, qxlines, qxsystem)

a=qx( "ls" )
for x in qxlines("find | grep '\.jpg$'"): 
  ...
qxsystem("vim myfile")

execute command return its stdout

def qx(*x)      : return subprocess.getoutput(x)

execute command return its stdout lines

def qxlines(*x) : return subprocess.getoutput(x).splitlines()

execute command -- system

def qxsystem(*x): subprocess.call(x,shell=True)

Other functions

def slurpurlutf8(self,f):

filename    = lambda s : F.filename()      # inherited from fileinput
filelineno  = lambda s : F.filelineno()
lineno      = lambda s : F.lineno()
fileparno   = lambda s : s.fileparno_
parno       = lambda s : s.parno_
nextfile    = lambda s : F.nextfile()
isfirstline = lambda s : F.isfirstline()
close       = lambda s : F.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jjcli-0.1.13.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jjcli-0.1.13-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file jjcli-0.1.13.tar.gz.

File metadata

  • Download URL: jjcli-0.1.13.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for jjcli-0.1.13.tar.gz
Algorithm Hash digest
SHA256 8155127e77458861311c020965f387e19d9a178e276a04abdc265cc11ead47a2
MD5 40e3b95343807957e70be184502f9c54
BLAKE2b-256 bb2e0fe56f7dbd61ee0ea8b495d74dc1bdfa55c2958bd1bca8455f2aeb25cea4

See more details on using hashes here.

File details

Details for the file jjcli-0.1.13-py2.py3-none-any.whl.

File metadata

  • Download URL: jjcli-0.1.13-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for jjcli-0.1.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 156ba2c22351d481fc86fee753cf26c35d14e7b3a9cecaa3d7a7b61e50c6a406
MD5 9ebe5c52d17dd8f74cf3906c14f1e5f5
BLAKE2b-256 256e62ade109018b220c6b4dc96f59b42da8117bbd61c6d7e2a6c432b794565a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page