Skip to main content

# Name

Project description

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
cl=clfilter(opt="do:", doc=__doc__) 
                          ## options in cl.opt  (...if "-d" in cl.opt:)
                          ##    autostrip         (def=True)
                          ##    inplace           (def=False) 
                          ##    fs (for csvrow()) (def=",")
                          ##    doc=__doc__     (for --help)
                          ##    longopts=["op1",...]

for line in cl.input():...    ## process one rstriped line at the time
for txt in cl.text():...      ## process one striped text at the time
    ## process txt            ##   (end of line spaces and \\r also removed)
for par in cl.paragraph():... ## process one striped paragraph at the time
for tup in cl.csvrow():...    ## process one csv row at the time
for tup in cl.tsvrow():...    ## process one tsv row at the time

cl.lineno()         ## line number
cl.filelineno()
cl.parno()          ## paragraph number
cl.fileparno()
cl.filename()       ## filename or "<stdin>"
cl.nextfile()
cl.isfirstline()
cl.args  cl.opt     ## command line arguments and options (after clfilter())

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)
  • glob (glob.glob 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)

STDERR - warn, die

warn(*args)  → print to stderr
die(*args)   → warn and exit 1

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()
isfirstpar  = lambda s : s.fileparno == 1
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.26.tar.gz (6.9 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.26-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for jjcli-0.1.26.tar.gz
Algorithm Hash digest
SHA256 ef18ee1f7366a47805b7be5aecb4fcbeb466ceb3396d480bf0498242aec064b1
MD5 fa9c39162b0ee277b787798d52856084
BLAKE2b-256 1de9806e3c80df4eab34752b55120c9c6128304cc6af2dd324335385a1dc5204

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jjcli-0.1.26-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1d6406eccdc8f1b8c3d815f6bfdc6513d3ac22773afb57c8638d89b4c5e05e4e
MD5 a60f36e80528a9360ff254e3931b3954
BLAKE2b-256 9fb33d0a8e92ea5cd2fe0fb33cdd39c33d8c87b55871998782ff76e7578d0a57

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