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
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.text():...      ## 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()
c.args  c.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.19.tar.gz (3.2 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.19-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for jjcli-0.1.19.tar.gz
Algorithm Hash digest
SHA256 7b8f4b9989aeb3f44cd86a2c8749733169260d4d719e50c2a2b7d530f559038e
MD5 1dd1f39e20730329a008f7d193b52f81
BLAKE2b-256 f368d53004ffeaaf5e418b580a65a4eb5383a22d88a7d43783d8d0f20dc381ee

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jjcli-0.1.19-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 805a2c2a38ecd69bf32e5dac4236d42b974720d964d15d792db27735d8e7cafc
MD5 f520bec642b32e8d243d76ec08976b37
BLAKE2b-256 3afb8ba07f3d548cd908cf905445788e6a46494f0e19b6ca0ea74453f4f7696f

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